Elements can be namespaces; Static properties and methods

This commit is contained in:
dcodeIO
2017-12-15 02:50:55 +01:00
parent b69c07af45
commit 8085a02df3
8 changed files with 460 additions and 224 deletions

View File

@ -77,14 +77,20 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
}
}
} else {
var expected = fs.readFileSync(__dirname + "/compiler/" + fixture, { encoding: "utf8" });
var diffs = diff("compiler/" + fixture, expected, actual);
if (diffs !== null) {
try {
var expected = fs.readFileSync(__dirname + "/compiler/" + fixture, { encoding: "utf8" });
var diffs = diff("compiler/" + fixture, expected, actual);
if (diffs !== null) {
process.exitCode = 1;
console.log(diffs);
console.log(chalk.default.red("diff ERROR"));
} else {
console.log(chalk.default.green("diff OK"));
}
} catch (e) {
process.exitCode = 1;
console.log(diffs);
console.log(e.message);
console.log(chalk.default.red("diff ERROR"));
} else {
console.log(chalk.default.green("diff OK"));
}
}

View File

@ -0,0 +1,46 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(type $v (func))
(memory $0 1)
(export "memory" (memory $0))
(start $start)
(func $start (; 0 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 f32)
(local $3 f32)
(drop
(block (result i32)
(block $__inlined_func$class/Animal.add (result i32)
(set_local $0
(i32.const 1)
)
(set_local $1
(i32.const 2)
)
(i32.add
(get_local $0)
(get_local $1)
)
)
)
)
(drop
(block (result f32)
(block $__inlined_func$class/Animal.sub<f32> (result f32)
(set_local $2
(f32.const 1)
)
(set_local $3
(f32.const 2)
)
(f32.sub
(get_local $2)
(get_local $3)
)
)
)
)
)
)

View File

@ -0,0 +1,34 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(type $v (func))
(memory $0 1)
(export "memory" (memory $0))
(start $start)
(func $class/Animal.add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $class/Animal.sub<f32> (; 1 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(f32.sub
(get_local $0)
(get_local $1)
)
)
(func $start (; 2 ;) (type $v)
(drop
(call $class/Animal.add
(i32.const 1)
(i32.const 2)
)
)
(drop
(call $class/Animal.sub<f32>
(f32.const 1)
(f32.const 2)
)
)
)
)

9
tests/compiler/class.ts Normal file
View File

@ -0,0 +1,9 @@
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
}
Animal.MAX;
Animal.add(1,2);
Animal.sub<f32>(1.0, 2.0);

80
tests/compiler/class.wast Normal file
View File

@ -0,0 +1,80 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(type $v (func))
(global $class/Animal.MAX (mut i32) (i32.const 1))
(global $HEAP_START i32 (i32.const 4))
(memory $0 1)
(export "memory" (memory $0))
(start $start)
(func $class/Animal.add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.add
(get_local $0)
(get_local $1)
)
)
)
(func $class/Animal.sub<f32> (; 1 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(return
(f32.sub
(get_local $0)
(get_local $1)
)
)
)
(func $start (; 2 ;) (type $v)
(drop
(get_global $class/Animal.MAX)
)
(drop
(call $class/Animal.add
(i32.const 1)
(i32.const 2)
)
)
(drop
(call $class/Animal.sub<f32>
(f32.const 1)
(f32.const 2)
)
)
)
)
(;
[program.elements]
clz
ctz
popcnt
rotl
rotr
abs
ceil
copysign
floor
max
min
nearest
sqrt
trunc
current_memory
grow_memory
unreachable
load
store
reinterpret
select
sizeof
changetype
isNaN
isFinite
assert
parseInt
parseFloat
class/Animal
class/Animal.MAX
class/Animal.add
class/Animal.sub
[program.exports]
;)