diff --git a/src/ast.ts b/src/ast.ts index 0502b9bb..968e80b9 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -10,7 +10,7 @@ import { Range } from "./tokenizer"; -import{ +import { CharCode } from "./util/charcode"; diff --git a/src/builtins.ts b/src/builtins.ts index d99357a2..cd0a3551 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -694,11 +694,11 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty if (!validateCall(compiler, typeArguments, 1, operands, 1, reportNode)) return module.createUnreachable(); arg0 = compiler.compileExpression(operands[0], Type.void, ConversionKind.NONE); - if ((compiler.currentType == usizeType && (typeArguments)[1].classType) || (compiler.currentType.classType && (typeArguments)[1] == usizeType)) { - compiler.currentType = (typeArguments)[1]; + if ((compiler.currentType == usizeType && (typeArguments)[0].classType) || (compiler.currentType.classType && (typeArguments)[0] == usizeType)) { + compiler.currentType = (typeArguments)[0]; return arg0; } - compiler.error(DiagnosticCode.Type_0_cannot_be_changed_to_type_1, reportNode.range, (typeArguments)[0].toString(), (typeArguments)[1].toString()); + compiler.error(DiagnosticCode.Type_0_cannot_be_changed_to_type_1, reportNode.range, compiler.currentType.toString(), (typeArguments)[0].toString()); return module.createUnreachable(); case "assert": // assert(isTrue: bool) -> void diff --git a/src/parser.ts b/src/parser.ts index 1f664c88..a0b27e01 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1506,7 +1506,17 @@ export class Parser extends DiagnosticEmitter { return Node.createFloatLiteral(tn.readFloat(), tn.range(startPos, tn.pos)); // RegexpLiteralExpression - case Token.REGEXPLITERAL: + /* + case Token.SLASH: + var regexpLit = Node.createRegexpLiteral(tn.readRegexp(), tn.range(startPos, tn.pos)); + if (!tn.skip(Token.SLASH)) { + this.error(DiagnosticCode._0_expected, tn.range(), "/"); + return null; + } + // TODO: modifiers, may be move to tokenizer + return regexpLit; + */ + case Token.REGEXPLITERAL: // not yet supported return Node.createRegexpLiteral(tn.readRegexp(), tn.range(startPos, tn.pos)); default: diff --git a/tests/compiler/class.optimized-inlined.wast b/tests/compiler/class.optimized-inlined.wast index 57d5223d..3af01bf7 100644 --- a/tests/compiler/class.optimized-inlined.wast +++ b/tests/compiler/class.optimized-inlined.wast @@ -3,14 +3,14 @@ (type $fff (func (param f32 f32) (result f32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $ifff (func (param i32 f32 f32) (result f32))) - (type $iv (func (param i32))) + (type $ii (func (param i32) (result i32))) (type $v (func)) (global $class/Animal.ONE (mut i32) (i32.const 1)) (memory $0 1) (export "test" (func $class/test)) (export "memory" (memory $0)) (start $start) - (func $class/test (; 0 ;) (type $iv) (param $0 i32) + (func $class/test (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -63,6 +63,7 @@ ) ) ) + (get_local $0) ) (func $start (; 1 ;) (type $v) (local $0 i32) diff --git a/tests/compiler/class.optimized.wast b/tests/compiler/class.optimized.wast index 86d6a2f9..9fcb30fb 100644 --- a/tests/compiler/class.optimized.wast +++ b/tests/compiler/class.optimized.wast @@ -3,7 +3,7 @@ (type $fff (func (param f32 f32) (result f32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $ifff (func (param i32 f32 f32) (result f32))) - (type $iv (func (param i32))) + (type $ii (func (param i32) (result i32))) (type $v (func)) (global $class/Animal.ONE (mut i32) (i32.const 1)) (memory $0 1) @@ -50,7 +50,7 @@ ) ) ) - (func $class/test (; 4 ;) (type $iv) (param $0 i32) + (func $class/test (; 4 ;) (type $ii) (param $0 i32) (result i32) (drop (call $class/Animal#instanceAdd (get_local $0) @@ -65,6 +65,7 @@ (f32.const 2) ) ) + (get_local $0) ) (func $start (; 5 ;) (type $v) (drop diff --git a/tests/compiler/class.ts b/tests/compiler/class.ts index 2966c3c9..84a52692 100644 --- a/tests/compiler/class.ts +++ b/tests/compiler/class.ts @@ -16,7 +16,11 @@ Animal.ONE; Animal.add(1,2); Animal.sub(1, 2); -export function test(animal: Animal): void { +export function test(animal: Animal): Animal { animal.instanceAdd(1, 2); animal.instanceSub(1, 2); + + var ptr = changetype(animal); + var cls = changetype>(ptr); + return cls; } diff --git a/tests/compiler/class.wast b/tests/compiler/class.wast index 866040c8..1240cc16 100644 --- a/tests/compiler/class.wast +++ b/tests/compiler/class.wast @@ -3,7 +3,7 @@ (type $fff (func (param f32 f32) (result f32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $ifff (func (param i32 f32 f32) (result f32))) - (type $iv (func (param i32))) + (type $ii (func (param i32) (result i32))) (type $v (func)) (global $class/Animal.ONE (mut i32) (i32.const 1)) (global $HEAP_BASE i32 (i32.const 4)) @@ -59,7 +59,9 @@ ) ) ) - (func $class/test (; 4 ;) (type $iv) (param $0 i32) + (func $class/test (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) (drop (call $class/Animal#instanceAdd (get_local $0) @@ -74,6 +76,19 @@ (f32.const 2) ) ) + (block + (set_local $1 + (get_local $0) + ) + ) + (block + (set_local $2 + (get_local $1) + ) + ) + (return + (get_local $2) + ) ) (func $start (; 5 ;) (type $v) (if