Math scaffolding

This commit is contained in:
dcodeIO
2018-03-24 17:18:15 +01:00
parent 19a616dd96
commit 721d77012b
15 changed files with 1637 additions and 25 deletions

View File

@ -1795,7 +1795,7 @@ export function compileCall(
}
return ret;
}
case "offsetof": { // offsetof<T!>(fieldName?)
case "offsetof": { // offsetof<T!>(fieldName?: string) -> usize
compiler.currentType = compiler.options.usizeType;
if (operands.length > 1) {
if (!(typeArguments && typeArguments.length == 1)) {

View File

@ -1745,6 +1745,7 @@ export class Compiler extends DiagnosticEmitter {
);
continue;
}
let isInlined = false;
if (declaration.is(CommonFlags.CONST)) {
if (init) {
init = this.precomputeExpressionRef(init);
@ -1787,10 +1788,10 @@ export class Compiler extends DiagnosticEmitter {
DiagnosticCode.Duplicate_identifier_0,
declaration.name.range, name
);
return 0;
return this.module.createUnreachable();
}
scopedLocals.set(name, local);
return 0;
isInlined = true;
} else {
this.warning(
DiagnosticCode.Compiling_constant_with_non_constant_initializer_as_mutable,
@ -1804,13 +1805,15 @@ export class Compiler extends DiagnosticEmitter {
);
}
}
if (declaration.is(CommonFlags.LET)) { // here: not top-level
currentFunction.flow.addScopedLocal(name, type, declaration.name); // reports
} else {
currentFunction.addLocal(type, name); // reports
}
if (init) {
initializers.push(this.compileAssignmentWithValue(declaration.name, init));
if (!isInlined) {
if (declaration.isAny(CommonFlags.LET | CommonFlags.CONST)) { // here: not top-level
currentFunction.flow.addScopedLocal(name, type, declaration.name); // reports
} else {
currentFunction.addLocal(type, name); // reports
}
if (init) {
initializers.push(this.compileAssignmentWithValue(declaration.name, init));
}
}
}
return initializers.length // we can unwrap these here because the

View File

@ -75,7 +75,9 @@ import {
VariableStatement,
VariableDeclaration,
VoidStatement,
WhileStatement
WhileStatement,
mangleInternalPath
} from "./ast";
const builtinsFile = LIBRARY_PREFIX + "builtins.ts";
@ -108,11 +110,12 @@ export class Parser extends DiagnosticEmitter {
// check if already parsed
var normalizedPath = normalizePath(path);
var internalPath = mangleInternalPath(normalizedPath);
var sources = program.sources;
for (let i = 0, k = sources.length; i < k; ++i) {
if (sources[i].normalizedPath == normalizedPath) return;
if (sources[i].internalPath == internalPath) return;
}
this.seenlog.add(normalizedPath);
this.seenlog.add(internalPath);
// create the source element
var source = new Source(
@ -1803,9 +1806,10 @@ export class Parser extends DiagnosticEmitter {
}
}
let ret = Node.createExportStatement(members, path, flags, tn.range(startPos, tn.pos));
if (ret.normalizedPath && !this.seenlog.has(<string>ret.normalizedPath)) {
this.backlog.push(<string>ret.normalizedPath);
this.seenlog.add(<string>ret.normalizedPath);
let internalPath = ret.internalPath;
if (internalPath != null && !this.seenlog.has(internalPath)) {
this.backlog.push(internalPath);
this.seenlog.add(internalPath);
}
tn.skip(Token.SEMICOLON);
return ret;
@ -1914,9 +1918,10 @@ export class Parser extends DiagnosticEmitter {
} else {
ret = Node.createImportStatement(members, path, tn.range(startPos, tn.pos));
}
if (!this.seenlog.has(ret.normalizedPath)) {
this.backlog.push(ret.normalizedPath);
this.seenlog.add(ret.normalizedPath);
let internalPath = ret.internalPath;
if (!this.seenlog.has(internalPath)) {
this.backlog.push(internalPath);
this.seenlog.add(internalPath);
}
tn.skip(Token.SEMICOLON);
return ret;