Naive parseFloat

This commit is contained in:
dcodeIO
2018-01-29 07:42:40 +01:00
parent d3f22637ed
commit 9e3b6f202d
7 changed files with 799 additions and 106 deletions

View File

@ -13,7 +13,8 @@ import {
import {
Node,
Expression,
BinaryExpression
BinaryExpression,
SourceKind
} from "./ast";
import {
@ -1539,6 +1540,8 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
compiler.error(DiagnosticCode.Operation_not_supported, reportNode.range);
return module.createUnreachable();
}
if (reportNode.range.source.sourceKind != SourceKind.STDLIB)
compiler.warning(DiagnosticCode.Operation_is_unsafe, reportNode.range);
return arg0; // any usize to any usize
case "assert": // assert<T?>(isTrueish: T, message?: string) -> T with T != null (see also assembly.d.ts)

View File

@ -102,6 +102,7 @@ import {
ParenthesizedExpression,
PropertyAccessExpression,
TernaryExpression,
ArrayLiteralExpression,
StringLiteralExpression,
UnaryPostfixExpression,
UnaryPrefixExpression,
@ -2835,8 +2836,13 @@ export class Compiler extends DiagnosticEmitter {
compileLiteralExpression(expression: LiteralExpression, contextualType: Type): ExpressionRef {
switch (expression.literalKind) {
// case LiteralKind.ARRAY:
// return this.compileStaticArray(...);
case LiteralKind.ARRAY:
var classType = contextualType.classType;
if (classType && classType == this.program.elements.get("Array") && classType.typeArguments && classType.typeArguments.length == 1)
return this.compileStaticArray(classType.typeArguments[0], (<ArrayLiteralExpression>expression).elementExpressions);
this.error(DiagnosticCode.Operation_not_supported, expression.range);
return this.module.createUnreachable();
case LiteralKind.FLOAT: {
var floatValue = (<FloatLiteralExpression>expression).value;
@ -2904,7 +2910,19 @@ export class Compiler extends DiagnosticEmitter {
: this.module.createI32(stringOffset.lo);
}
compileStaticArray(elementType: Type, expressions: Expression): ExpressionRef {
compileStaticArray(elementType: Type, expressions: (Expression | null)[]): ExpressionRef {
// compile as static if all element expressions are precomputable, otherwise
// initialize in place.
var exprs = new Array<ExpressionRef>(expressions.length);
var isStatic = true;
var expr: BinaryenExpressionRef;
for (var i = 0; i < expressions.length; ++i) {
exprs[i] = expressions[i] ? this.compileExpression(<Expression>expressions[i], elementType) : elementType.toNativeZero(this.module);
if (isStatic && _BinaryenExpressionGetId(expr = this.precomputeExpressionRef(exprs[i])) == ExpressionId.Const) {
// TODO: use multiple arrays of possible native types?
} else
isStatic = false;
}
throw new Error("not implemented");
}