mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-05-01 09:52:19 +00:00
* Rename memory instructions as proposed by the bulk-memory-operations spec. * Rename memory manager functions to memory.* as well * Remove automatic inlining of constant globals (Binaryen does this now) * Improve 'const' enum compatibility * Improve module-level export generation * Enable the inline decorator for constant variables * Add ERROR, WARNING and INFO macros that emit a user-defined diagnostic * Reintroduce builtin decorator so these can appear anywhere in stdlib again * Inline isNaN and isFinite by default * Make an interface around gc.* similar to memory.* * Emit an error when trying to inline a mutable variable * Slim down CI stages * Add a more convenient tracing utility for debugging * Implement some prequesites for an eventual bundled GC
61 lines
1.2 KiB
TypeScript
61 lines
1.2 KiB
TypeScript
import "allocator/arena";
|
|
|
|
// top-level function
|
|
export function add(a: i32, b: i32): i32 {
|
|
return a + b;
|
|
}
|
|
|
|
export function subOpt(a: i32, b: i32 = 0): i32 {
|
|
return a - b;
|
|
}
|
|
|
|
// namespaced function
|
|
export namespace math {
|
|
export function sub(a: i32, b: i32): i32 {
|
|
return a - b;
|
|
}
|
|
}
|
|
|
|
// top-level enum
|
|
export const enum Animal {
|
|
CAT,
|
|
DOG
|
|
}
|
|
|
|
// namespaced enum
|
|
export namespace animals {
|
|
export const enum Animal {
|
|
CAT,
|
|
DOG
|
|
}
|
|
}
|
|
|
|
// top-level class
|
|
export class Car {
|
|
static readonly TIRES: i32 = 4;
|
|
static getNumTires(): i32 { return this.TIRES; }
|
|
constructor(public doors: i32 = 2) { this.doors = doors; }
|
|
get numDoors(): i32 { return this.doors; }
|
|
set numDoors(doors: i32) { this.doors = doors; }
|
|
openDoors(): void {}
|
|
}
|
|
|
|
// namespaced class
|
|
export namespace vehicles {
|
|
export class Car {
|
|
static readonly TIRES: i32 = 4;
|
|
static getNumTires(): i32 { return this.TIRES; }
|
|
constructor(public doors: i32 = 2) { this.doors = doors; }
|
|
get numDoors(): i32 { return this.doors; }
|
|
set numDoors(doors: i32) { this.doors = doors; }
|
|
openDoors(): void {}
|
|
}
|
|
}
|
|
|
|
// namespaced namespace
|
|
export namespace outer {
|
|
export namespace inner {
|
|
export const a = 42;
|
|
}
|
|
}
|