mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 17:31:29 +00:00
Initial instance methods and field layout; More cleanup
This commit is contained in:
@ -1,9 +1,22 @@
|
||||
class Animal {
|
||||
static MAX: i32 = 1;
|
||||
static add(a: i32, b: i32): i32 { return a + b; }
|
||||
static sub<T>(a: T, b: T): T { return a - b; } // tsc does not allow this
|
||||
class Animal<T> {
|
||||
static ONE: i32 = 1;
|
||||
static add(a: i32, b: i32): i32 { return a + b + Animal.ONE; }
|
||||
static sub<T>(a: T, b: T): T { return a - b + <T>Animal.ONE; } // tsc does not allow this
|
||||
|
||||
one: i32 = 1; // 4
|
||||
two: i16 = 2; // 6
|
||||
three: i8 = 3; // 7
|
||||
instanceAdd(a: i32, b: i32): i32 { return a + b + Animal.ONE; }
|
||||
instanceSub<T>(a: T, b: T): T { return a - b + <T>Animal.ONE; } // tsc does not allow this
|
||||
}
|
||||
|
||||
Animal.MAX;
|
||||
assert(sizeof<Animal<f64>>() == 7);
|
||||
|
||||
Animal.ONE;
|
||||
Animal.add(1,2);
|
||||
Animal.sub<f32>(1.0, 2.0);
|
||||
Animal.sub<f32>(1, 2);
|
||||
|
||||
export function test(animal: Animal<f64>): void {
|
||||
animal.instanceAdd(1, 2);
|
||||
animal.instanceSub<f32>(1, 2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user