mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 00:11:28 +00:00
Add webpack; Setup instructions
This commit is contained in:
@ -5,7 +5,7 @@ import { Type } from "./types";
|
||||
import { ExpressionRef, UnaryOp, BinaryOp, HostOp, NativeType } from "./module";
|
||||
import { Program, FunctionPrototype, Local } from "./program";
|
||||
|
||||
/** Initializes the specified program with builtin functions. */
|
||||
/** Initializes the specified program with built-in functions. */
|
||||
export function initialize(program: Program): void {
|
||||
addFunction(program, "clz", true);
|
||||
addFunction(program, "ctz", true);
|
||||
@ -34,15 +34,15 @@ export function initialize(program: Program): void {
|
||||
addFunction(program, "assert");
|
||||
}
|
||||
|
||||
/** Adds a builtin function to the specified program. */
|
||||
/** Adds a built-in function to the specified program. */
|
||||
function addFunction(program: Program, name: string, isGeneric: bool = false): void {
|
||||
let prototype: FunctionPrototype = new FunctionPrototype(program, name, null, null);
|
||||
prototype.isGeneric = isGeneric;
|
||||
prototype.isBuiltin = true;
|
||||
prototype.isBuiltIn = true;
|
||||
program.elements.set(name, prototype);
|
||||
}
|
||||
|
||||
/** Compiles a call to a builtin function. */
|
||||
/** Compiles a call to a built-in function. */
|
||||
export function compileCall(compiler: Compiler, internalName: string, typeArguments: Type[], operands: Expression[], reportNode: Node): ExpressionRef {
|
||||
const usizeType: Type = select<Type>(Type.usize64, Type.usize32, compiler.options.target == Target.WASM64);
|
||||
|
||||
@ -417,7 +417,7 @@ export function compileCall(compiler: Compiler, internalName: string, typeArgume
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Validates a call to a builtin function. */
|
||||
/** Validates a call to a built-in function. */
|
||||
function validateCall(compiler: Compiler, typeArguments: Type[], expectedTypeArguments: i32, operands: Expression[], expectedOperands: i32, reportNode: Node): bool {
|
||||
if (typeArguments.length != expectedTypeArguments) {
|
||||
compiler.error(DiagnosticCode.Expected_0_type_arguments_but_got_1, reportNode.range, expectedTypeArguments.toString(10), typeArguments.length.toString(10));
|
||||
|
@ -153,7 +153,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
compile(): Module {
|
||||
const program: Program = this.program;
|
||||
|
||||
// initialize lookup maps, builtins, imports, exports, etc.
|
||||
// initialize lookup maps, built-ins, imports, exports, etc.
|
||||
program.initialize(this.options.target);
|
||||
|
||||
// compile entry file (exactly one, usually)
|
||||
@ -1459,7 +1459,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (element.kind == ElementKind.FUNCTION_PROTOTYPE) {
|
||||
const functionPrototype: FunctionPrototype = <FunctionPrototype>element;
|
||||
let functionInstance: Function | null = null;
|
||||
if (functionPrototype.isBuiltin) {
|
||||
if (functionPrototype.isBuiltIn) {
|
||||
const k: i32 = expression.typeArguments.length;
|
||||
const resolvedTypeArguments: Type[] = new Array(k);
|
||||
sb.length = 0;
|
||||
|
@ -12,7 +12,12 @@ globalScope["select"] = function select<T>(ifTrue: T, ifFalse: T, condition: boo
|
||||
return condition ? ifTrue : ifFalse;
|
||||
};
|
||||
|
||||
const binaryen = require("binaryen");
|
||||
let binaryen: any;
|
||||
try {
|
||||
binaryen = require("binaryen");
|
||||
} catch (e) {
|
||||
binaryen = globalScope["Binaryen"];
|
||||
}
|
||||
for (const key in binaryen)
|
||||
if (/^_(?:Binaryen|Relooper|malloc$|free$)/.test(key))
|
||||
globalScope[key] = binaryen[key];
|
||||
|
@ -625,8 +625,6 @@ export class Program extends DiagnosticEmitter {
|
||||
return null;
|
||||
}
|
||||
|
||||
let ret: Element;
|
||||
|
||||
// local or global name
|
||||
if (expression.kind == NodeKind.IDENTIFIER) {
|
||||
const name: string = (<IdentifierExpression>expression).name;
|
||||
@ -708,7 +706,7 @@ export abstract class Element {
|
||||
internalName: string;
|
||||
isCompiled: bool = false;
|
||||
isImport: bool = false;
|
||||
isBuiltin: bool = false;
|
||||
isBuiltIn: bool = false;
|
||||
isDeclare: bool = false;
|
||||
|
||||
constructor(program: Program, internalName: string) {
|
||||
@ -825,7 +823,7 @@ export class FunctionPrototype extends Element {
|
||||
super(program, internalName);
|
||||
this.declaration = declaration;
|
||||
this.classPrototype = classPrototype;
|
||||
this.isGeneric = declaration ? declaration.typeParameters.length > 0 : false; // builtins set this
|
||||
this.isGeneric = declaration ? declaration.typeParameters.length > 0 : false; // built-ins set this
|
||||
}
|
||||
|
||||
get isExport(): bool { return this.declaration ? hasModifier(ModifierKind.EXPORT, this.declaration.modifiers) : /* internals aren't file-level exports */ false; }
|
||||
@ -942,7 +940,7 @@ export class Function extends Element {
|
||||
this.parameters = parameters;
|
||||
this.returnType = returnType;
|
||||
this.instanceMethodOf = instanceMethodOf;
|
||||
this.isBuiltin = prototype.isBuiltin;
|
||||
this.isBuiltIn = prototype.isBuiltIn;
|
||||
this.isDeclare = prototype.isDeclare;
|
||||
let localIndex: i32 = 0;
|
||||
if (instanceMethodOf) {
|
||||
@ -1053,7 +1051,7 @@ export class ClassPrototype extends Namespace {
|
||||
let resolvedTypeArguments: Type[] | null;
|
||||
if (this.isGeneric) {
|
||||
if (!this.declaration)
|
||||
throw new Error("not implemented"); // generic builtin
|
||||
throw new Error("not implemented"); // generic built-in
|
||||
resolvedTypeArguments = this.program.resolveTypeArguments(this.declaration.typeParameters, typeArgumentNodes, contextualTypeArguments, alternativeReportNode);
|
||||
if (!resolvedTypeArguments)
|
||||
return null;
|
||||
@ -1091,7 +1089,7 @@ export class Class extends Namespace {
|
||||
|
||||
// apply instance-specific contextual type arguments
|
||||
const declaration: ClassDeclaration | null = this.template.declaration;
|
||||
if (declaration) { // irrelevant for builtins
|
||||
if (declaration) { // irrelevant for built-ins
|
||||
const typeParameters: TypeParameter[] = declaration.typeParameters;
|
||||
if (typeParameters.length != typeArguments.length)
|
||||
throw new Error("unexpected type argument count mismatch");
|
||||
|
@ -16,10 +16,13 @@
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"outDir": "../out"
|
||||
"preserveConstEnums": true,
|
||||
"outDir": "../out",
|
||||
"sourceMap": true
|
||||
},
|
||||
"files": [
|
||||
"ast.ts",
|
||||
"builtins.ts",
|
||||
"compiler.ts",
|
||||
"diagnosticMessages.generated.ts",
|
||||
"diagnostics.ts",
|
||||
|
Reference in New Issue
Block a user