mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Add webpack; Setup instructions
This commit is contained in:
parent
40b814ac73
commit
df212653a8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
npm-debug.*
|
npm-debug.*
|
||||||
|
dist/
|
||||||
out/
|
out/
|
||||||
raw/
|
raw/
|
||||||
|
29
README.md
29
README.md
@ -25,3 +25,32 @@ Side effects:
|
|||||||
- Good fire test for the compiler
|
- Good fire test for the compiler
|
||||||
- Good benchmark when comparing both versions
|
- Good benchmark when comparing both versions
|
||||||
- Benefits standard library design ideas
|
- Benefits standard library design ideas
|
||||||
|
|
||||||
|
Getting started
|
||||||
|
---------------
|
||||||
|
|
||||||
|
If you'd like to try out NEXT today or even plan to contribute, this is how you do it:
|
||||||
|
|
||||||
|
```
|
||||||
|
$> git clone https://github.com/AssemblyScript/next.git
|
||||||
|
$> cd next
|
||||||
|
$> npm install
|
||||||
|
$> node bin\asc yourModule.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
Building a browser bundle to `dist/assemblyscript.js` (requires [binaryen.js](https://github.com/AssemblyScript/binaryen.js)):
|
||||||
|
|
||||||
|
```
|
||||||
|
$> npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Running the [tests](./tests):
|
||||||
|
|
||||||
|
```
|
||||||
|
$> npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
Development status
|
||||||
|
------------------
|
||||||
|
|
||||||
|
For now, see the [compiler tests](https://github.com/AssemblyScript/next/tree/master/tests/compiler) for an overview of what's supposed to be working already.
|
||||||
|
2101
package-lock.json
generated
2101
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -17,14 +17,16 @@
|
|||||||
"diff": "^3.4.0",
|
"diff": "^3.4.0",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
"long": "^3.2.0",
|
"long": "^3.2.0",
|
||||||
|
"ts-loader": "^3.2.0",
|
||||||
"ts-node": "^3.3.0",
|
"ts-node": "^3.3.0",
|
||||||
"typescript": "^2.6.2"
|
"typescript": "^2.6.2",
|
||||||
|
"webpack": "^3.10.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"asc": "bin/asc.js"
|
"asc": "bin/asc.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -P src",
|
"build": "webpack",
|
||||||
"test:parser": "ts-node -P src tests/parser",
|
"test:parser": "ts-node -P src tests/parser",
|
||||||
"test:compiler": "ts-node -P src tests/compiler",
|
"test:compiler": "ts-node -P src tests/compiler",
|
||||||
"test": "npm run test:parser && npm run test:compiler"
|
"test": "npm run test:parser && npm run test:compiler"
|
||||||
|
@ -5,7 +5,7 @@ import { Type } from "./types";
|
|||||||
import { ExpressionRef, UnaryOp, BinaryOp, HostOp, NativeType } from "./module";
|
import { ExpressionRef, UnaryOp, BinaryOp, HostOp, NativeType } from "./module";
|
||||||
import { Program, FunctionPrototype, Local } from "./program";
|
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 {
|
export function initialize(program: Program): void {
|
||||||
addFunction(program, "clz", true);
|
addFunction(program, "clz", true);
|
||||||
addFunction(program, "ctz", true);
|
addFunction(program, "ctz", true);
|
||||||
@ -34,15 +34,15 @@ export function initialize(program: Program): void {
|
|||||||
addFunction(program, "assert");
|
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 {
|
function addFunction(program: Program, name: string, isGeneric: bool = false): void {
|
||||||
let prototype: FunctionPrototype = new FunctionPrototype(program, name, null, null);
|
let prototype: FunctionPrototype = new FunctionPrototype(program, name, null, null);
|
||||||
prototype.isGeneric = isGeneric;
|
prototype.isGeneric = isGeneric;
|
||||||
prototype.isBuiltin = true;
|
prototype.isBuiltIn = true;
|
||||||
program.elements.set(name, prototype);
|
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 {
|
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);
|
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;
|
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 {
|
function validateCall(compiler: Compiler, typeArguments: Type[], expectedTypeArguments: i32, operands: Expression[], expectedOperands: i32, reportNode: Node): bool {
|
||||||
if (typeArguments.length != expectedTypeArguments) {
|
if (typeArguments.length != expectedTypeArguments) {
|
||||||
compiler.error(DiagnosticCode.Expected_0_type_arguments_but_got_1, reportNode.range, expectedTypeArguments.toString(10), typeArguments.length.toString(10));
|
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 {
|
compile(): Module {
|
||||||
const program: Program = this.program;
|
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);
|
program.initialize(this.options.target);
|
||||||
|
|
||||||
// compile entry file (exactly one, usually)
|
// compile entry file (exactly one, usually)
|
||||||
@ -1459,7 +1459,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
if (element.kind == ElementKind.FUNCTION_PROTOTYPE) {
|
if (element.kind == ElementKind.FUNCTION_PROTOTYPE) {
|
||||||
const functionPrototype: FunctionPrototype = <FunctionPrototype>element;
|
const functionPrototype: FunctionPrototype = <FunctionPrototype>element;
|
||||||
let functionInstance: Function | null = null;
|
let functionInstance: Function | null = null;
|
||||||
if (functionPrototype.isBuiltin) {
|
if (functionPrototype.isBuiltIn) {
|
||||||
const k: i32 = expression.typeArguments.length;
|
const k: i32 = expression.typeArguments.length;
|
||||||
const resolvedTypeArguments: Type[] = new Array(k);
|
const resolvedTypeArguments: Type[] = new Array(k);
|
||||||
sb.length = 0;
|
sb.length = 0;
|
||||||
|
@ -12,7 +12,12 @@ globalScope["select"] = function select<T>(ifTrue: T, ifFalse: T, condition: boo
|
|||||||
return condition ? ifTrue : ifFalse;
|
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)
|
for (const key in binaryen)
|
||||||
if (/^_(?:Binaryen|Relooper|malloc$|free$)/.test(key))
|
if (/^_(?:Binaryen|Relooper|malloc$|free$)/.test(key))
|
||||||
globalScope[key] = binaryen[key];
|
globalScope[key] = binaryen[key];
|
||||||
|
@ -625,8 +625,6 @@ export class Program extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret: Element;
|
|
||||||
|
|
||||||
// local or global name
|
// local or global name
|
||||||
if (expression.kind == NodeKind.IDENTIFIER) {
|
if (expression.kind == NodeKind.IDENTIFIER) {
|
||||||
const name: string = (<IdentifierExpression>expression).name;
|
const name: string = (<IdentifierExpression>expression).name;
|
||||||
@ -708,7 +706,7 @@ export abstract class Element {
|
|||||||
internalName: string;
|
internalName: string;
|
||||||
isCompiled: bool = false;
|
isCompiled: bool = false;
|
||||||
isImport: bool = false;
|
isImport: bool = false;
|
||||||
isBuiltin: bool = false;
|
isBuiltIn: bool = false;
|
||||||
isDeclare: bool = false;
|
isDeclare: bool = false;
|
||||||
|
|
||||||
constructor(program: Program, internalName: string) {
|
constructor(program: Program, internalName: string) {
|
||||||
@ -825,7 +823,7 @@ export class FunctionPrototype extends Element {
|
|||||||
super(program, internalName);
|
super(program, internalName);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
this.classPrototype = classPrototype;
|
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; }
|
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.parameters = parameters;
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
this.instanceMethodOf = instanceMethodOf;
|
this.instanceMethodOf = instanceMethodOf;
|
||||||
this.isBuiltin = prototype.isBuiltin;
|
this.isBuiltIn = prototype.isBuiltIn;
|
||||||
this.isDeclare = prototype.isDeclare;
|
this.isDeclare = prototype.isDeclare;
|
||||||
let localIndex: i32 = 0;
|
let localIndex: i32 = 0;
|
||||||
if (instanceMethodOf) {
|
if (instanceMethodOf) {
|
||||||
@ -1053,7 +1051,7 @@ export class ClassPrototype extends Namespace {
|
|||||||
let resolvedTypeArguments: Type[] | null;
|
let resolvedTypeArguments: Type[] | null;
|
||||||
if (this.isGeneric) {
|
if (this.isGeneric) {
|
||||||
if (!this.declaration)
|
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);
|
resolvedTypeArguments = this.program.resolveTypeArguments(this.declaration.typeParameters, typeArgumentNodes, contextualTypeArguments, alternativeReportNode);
|
||||||
if (!resolvedTypeArguments)
|
if (!resolvedTypeArguments)
|
||||||
return null;
|
return null;
|
||||||
@ -1091,7 +1089,7 @@ export class Class extends Namespace {
|
|||||||
|
|
||||||
// apply instance-specific contextual type arguments
|
// apply instance-specific contextual type arguments
|
||||||
const declaration: ClassDeclaration | null = this.template.declaration;
|
const declaration: ClassDeclaration | null = this.template.declaration;
|
||||||
if (declaration) { // irrelevant for builtins
|
if (declaration) { // irrelevant for built-ins
|
||||||
const typeParameters: TypeParameter[] = declaration.typeParameters;
|
const typeParameters: TypeParameter[] = declaration.typeParameters;
|
||||||
if (typeParameters.length != typeArguments.length)
|
if (typeParameters.length != typeArguments.length)
|
||||||
throw new Error("unexpected type argument count mismatch");
|
throw new Error("unexpected type argument count mismatch");
|
||||||
|
@ -16,10 +16,13 @@
|
|||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"noImplicitThis": true,
|
"noImplicitThis": true,
|
||||||
"outDir": "../out"
|
"preserveConstEnums": true,
|
||||||
|
"outDir": "../out",
|
||||||
|
"sourceMap": true
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ast.ts",
|
"ast.ts",
|
||||||
|
"builtins.ts",
|
||||||
"compiler.ts",
|
"compiler.ts",
|
||||||
"diagnosticMessages.generated.ts",
|
"diagnosticMessages.generated.ts",
|
||||||
"diagnostics.ts",
|
"diagnostics.ts",
|
||||||
|
34
webpack.config.js
Normal file
34
webpack.config.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
var path = require("path");
|
||||||
|
var webpack = require("webpack");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: [ "./src/glue/js.ts", "./src/index.ts" ],
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.ts$/,
|
||||||
|
use: "ts-loader",
|
||||||
|
exclude: /node_modules/
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
externals: [ "binaryen" ],
|
||||||
|
resolve: {
|
||||||
|
extensions: [ ".ts", ".js" ]
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
filename: "assemblyscript.js",
|
||||||
|
path: path.resolve(__dirname, "dist"),
|
||||||
|
library: "assemblyscript",
|
||||||
|
libraryTarget: "umd"
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
minimize: true,
|
||||||
|
sourceMap: true
|
||||||
|
}),
|
||||||
|
new webpack.SourceMapDevToolPlugin({
|
||||||
|
filename: "assemblyscript.js.map"
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user