Implement asc in js for dist

This commit is contained in:
dcodeIO
2017-12-05 15:06:44 +01:00
parent df212653a8
commit 330752908a
12 changed files with 348 additions and 173 deletions

View File

@ -32,13 +32,16 @@ export function initialize(program: Program): void {
addFunction(program, "isNaN", true);
addFunction(program, "isFinite", true);
addFunction(program, "assert");
// addFunction(program, "fmod", false, true);
// addFunction(program, "pow", true, true);
}
/** Adds a built-in function to the specified program. */
function addFunction(program: Program, name: string, isGeneric: bool = false): void {
function addFunction(program: Program, name: string, isGeneric: bool = false, isImport: bool = false): void {
let prototype: FunctionPrototype = new FunctionPrototype(program, name, null, null);
prototype.isGeneric = isGeneric;
prototype.isBuiltIn = true;
prototype.isGeneric = isGeneric;
prototype.isImport = isImport;
program.elements.set(name, prototype);
}
@ -413,6 +416,9 @@ export function compileCall(compiler: Compiler, internalName: string, typeArgume
compiler.module.createUnary(UnaryOp.EqzI32, arg0),
compiler.module.createUnreachable()
);
// case "fmod":
// case "pow":
}
return 0;
}

View File

@ -698,7 +698,12 @@ export class Compiler extends DiagnosticEmitter {
}
compileBlockStatement(statement: BlockStatement): ExpressionRef {
return this.module.createBlock(null, this.compileStatements(statement.statements), NativeType.None);
const statements: Statement[] = statement.statements;
if (statements.length == 0)
return this.module.createNop();
if (statements.length == 1)
return this.compileStatement(statements[0]);
return this.module.createBlock(null, this.compileStatements(statements), NativeType.None);
}
compileBreakStatement(statement: BreakStatement): ExpressionRef {
@ -962,7 +967,7 @@ export class Compiler extends DiagnosticEmitter {
throw new Error("unexpected expression kind");
}
if (conversionKind != ConversionKind.NONE) {
if (conversionKind != ConversionKind.NONE && this.currentType != contextualType) {
expr = this.convertExpression(expr, this.currentType, contextualType, conversionKind, expression);
this.currentType = contextualType;
}