Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Test1
- test1:: () -> {
- alias f32: float32;
- f := new f32(10.97); // *float
- d := new f32(-6.1); // *float
- fr := &f;
- fr += -3.0;
- swap(f, d);
- delete(d, f);
- }
- swap:: <T>(lhs: *T, rhs: *T) -> {
- tmp := &lhs;
- lhs = &rhs;
- rhs = tmp;
- }
- /// Test2
- test2:: () -> {
- u: U;
- u.y = 'p';
- assert(u.x == 112);
- }
- U:: union {
- x: int;
- y: char;
- }
- /// Test3
- test3:: () -> {
- f: foo; // foo
- j: int[3]; // int[3]
- k := int[](1, 2, 3); // int[3]
- l := new int[](1, 2, 3); // *int[3]
- f.matches(*k);
- matches(*f, l);
- if (typeof(a) == typeof(b)) {
- printf("Hello world!\n");
- }
- }
- A:: struct {
- prefix := "Foo";
- }
- // No method body so it's virtual
- matches:: ($this: *A, lhs: *int[], l: int) -> bool;
- B:: struct {
- }
- add_val:: <T>($this: *B, lhs: ?T, i: T) -> T;
- foo:: struct {
- // Subtype polymorphism
- using a: A;
- using b: B;
- }
- // Must have the same function declaration as A::matches, with the implementors $this type.
- matches:: ($this: *foo, lhs: *int[], l: int) -> bool {
- prefix := a::prefix;
- ret lhs.count == l;
- }
- add_val:: <T>($this: *foo, lhs: ?T, i: T) -> T {
- if (lhs) {
- return &lhs + i;
- }
- return i;
- }
- exten printf:: (format: *int8, ...) -> void;
- /// Main
- main:: () -> {
- test1();
- test2();
- test3();
- }
Advertisement
Add Comment
Please, Sign In to add comment