Skip to content

Commit

Permalink
Merge with Upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Sep 13, 2019
2 parents 3edc33a + a4dd3a9 commit 21f4ff4
Show file tree
Hide file tree
Showing 50 changed files with 32,346 additions and 9,510 deletions.
2 changes: 1 addition & 1 deletion bindings/dist/transformerBundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/asc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/asc.js.map

Large diffs are not rendered by default.

265 changes: 137 additions & 128 deletions dist/assemblyscript.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assemblyscript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assemblyscript.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/n-body/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
"build": "npm run asbuild && npm run tsbuild",
"server": "http-server . -o -c-1",
"test": "node --noliftoff --nowasm-tier-up --wasm-lazy-compilation --wasm-no-bounds-checks --expose-gc tests"
"test": "node --wasm-lazy-compilation --wasm-no-bounds-checks --expose-gc tests"
},
"devDependencies": {
"http-server": "^0.11.1",
Expand Down
6 changes: 5 additions & 1 deletion lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ function postInstantiate(baseModule, instance) {

/** Reads (copies) the values of an array from the module's memory. */
function __getArray(arr) {
return Array.from(__getArrayView(arr));
const input = __getArrayView(arr);
const len = input.length;
const out = new Array(len);
for (let i = 0; i < len; i++) out[i] = input[i];
return out;
}

baseModule.__getArray = __getArray;
Expand Down
13 changes: 3 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
"source-map-support": "^0.5.12"
},
"devDependencies": {
"bignum": "github:WebAssemblyOS/bignum.wasm#near_dist",
"assemblyscript-json": "github:nearprotocol/assemblyscript-json",
"near-runtime-ts": "github:nearprotocol/near-runtime-ts",
"@types/node": "^12.6.6",
"browser-process-hrtime": "^1.0.0",
"diff": "^4.0.1",
"near-runtime-ts": "github:nearprotocol/near-runtime-ts",
"ts-loader": "^6.0.4",
"ts-node": "^6.2.0",
"tslint": "^5.18.0",
Expand Down
123 changes: 63 additions & 60 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export abstract class Node {
stmt.range = range;
stmt.name = name;
stmt.arguments = args;
stmt.decoratorKind = decoratorNameToKind(name);
stmt.decoratorKind = DecoratorKind.fromNode(name);
return stmt;
}

Expand Down Expand Up @@ -1187,73 +1187,76 @@ export enum DecoratorKind {
UNSAFE
}

/** Returns the kind of the specified decorator. Defaults to {@link DecoratorKind.CUSTOM}. */
export function decoratorNameToKind(name: Expression): DecoratorKind {
// @global, @inline, @operator, @sealed, @unmanaged
if (name.kind == NodeKind.IDENTIFIER) {
let nameStr = (<IdentifierExpression>name).text;
assert(nameStr.length);
switch (nameStr.charCodeAt(0)) {
case CharCode.b: {
if (nameStr == "builtin") return DecoratorKind.BUILTIN;
break;
}
case CharCode.e: {
if (nameStr == "external") return DecoratorKind.EXTERNAL;
break;
}
case CharCode.g: {
if (nameStr == "global") return DecoratorKind.GLOBAL;
break;
}
case CharCode.i: {
if (nameStr == "inline") return DecoratorKind.INLINE;
break;
}
case CharCode.l: {
if (nameStr == "lazy") return DecoratorKind.LAZY;
break;
}
case CharCode.o: {
if (nameStr == "operator") return DecoratorKind.OPERATOR;
break;
}
case CharCode.s: {
if (nameStr == "sealed") return DecoratorKind.SEALED;
break;
}
case CharCode.u: {
if (nameStr == "unmanaged") return DecoratorKind.UNMANAGED;
if (nameStr == "unsafe") return DecoratorKind.UNSAFE;
break;
}
}
} else if (
name.kind == NodeKind.PROPERTYACCESS &&
(<PropertyAccessExpression>name).expression.kind == NodeKind.IDENTIFIER
) {
let nameStr = (<IdentifierExpression>(<PropertyAccessExpression>name).expression).text;
assert(nameStr.length);
let propStr = (<PropertyAccessExpression>name).property.text;
assert(propStr.length);
// @operator.binary, @operator.prefix, @operator.postfix
if (nameStr == "operator") {
switch (propStr.charCodeAt(0)) {
export namespace DecoratorKind {

/** Returns the kind of the specified decorator name node. Defaults to {@link DecoratorKind.CUSTOM}. */
export function fromNode(nameNode: Expression): DecoratorKind {
// @global, @inline, @operator, @sealed, @unmanaged
if (nameNode.kind == NodeKind.IDENTIFIER) {
let nameStr = (<IdentifierExpression>nameNode).text;
assert(nameStr.length);
switch (nameStr.charCodeAt(0)) {
case CharCode.b: {
if (propStr == "binary") return DecoratorKind.OPERATOR_BINARY;
if (nameStr == "builtin") return DecoratorKind.BUILTIN;
break;
}
case CharCode.p: {
switch (propStr) {
case "prefix": return DecoratorKind.OPERATOR_PREFIX;
case "postfix": return DecoratorKind.OPERATOR_POSTFIX;
}
case CharCode.e: {
if (nameStr == "external") return DecoratorKind.EXTERNAL;
break;
}
case CharCode.g: {
if (nameStr == "global") return DecoratorKind.GLOBAL;
break;
}
case CharCode.i: {
if (nameStr == "inline") return DecoratorKind.INLINE;
break;
}
case CharCode.l: {
if (nameStr == "lazy") return DecoratorKind.LAZY;
break;
}
case CharCode.o: {
if (nameStr == "operator") return DecoratorKind.OPERATOR;
break;
}
case CharCode.s: {
if (nameStr == "sealed") return DecoratorKind.SEALED;
break;
}
case CharCode.u: {
if (nameStr == "unmanaged") return DecoratorKind.UNMANAGED;
if (nameStr == "unsafe") return DecoratorKind.UNSAFE;
break;
}
}
} else if (
nameNode.kind == NodeKind.PROPERTYACCESS &&
(<PropertyAccessExpression>nameNode).expression.kind == NodeKind.IDENTIFIER
) {
let nameStr = (<IdentifierExpression>(<PropertyAccessExpression>nameNode).expression).text;
assert(nameStr.length);
let propStr = (<PropertyAccessExpression>nameNode).property.text;
assert(propStr.length);
// @operator.binary, @operator.prefix, @operator.postfix
if (nameStr == "operator") {
switch (propStr.charCodeAt(0)) {
case CharCode.b: {
if (propStr == "binary") return DecoratorKind.OPERATOR_BINARY;
break;
}
case CharCode.p: {
switch (propStr) {
case "prefix": return DecoratorKind.OPERATOR_PREFIX;
case "postfix": return DecoratorKind.OPERATOR_POSTFIX;
}
break;
}
}
}
}
return DecoratorKind.CUSTOM;
}
return DecoratorKind.CUSTOM;
}

/** Represents a decorator. */
Expand Down
55 changes: 34 additions & 21 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,29 +595,38 @@ export function compileCall(
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.unreachable();
let classType = type.classReference;
if (classType) {
let stringInstance = compiler.program.stringInstance;
if (stringInstance && classType.isAssignableTo(stringInstance)) return module.i32(1);
if (type.is(TypeFlags.REFERENCE)) {
let classReference = type.classReference;
if (classReference) {
let stringInstance = compiler.program.stringInstance;
if (stringInstance && classReference.isAssignableTo(stringInstance)) return module.i32(1);
}
}
return module.i32(0);
}
case BuiltinSymbols.isArray: { // isArray<T!>() / isArray<T?>(value: T) -> bool
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.unreachable();
let classReference = type.classReference;
if (!classReference) return module.i32(0);
let classPrototype = classReference.prototype;
return module.i32(classPrototype.extends(compiler.program.arrayPrototype) ? 1 : 0);
if (type.is(TypeFlags.REFERENCE)) {
let classReference = type.classReference;
if (classReference) {
return module.i32(classReference.prototype.extends(compiler.program.arrayPrototype) ? 1 : 0);
}
}
return module.i32(0);
}
case BuiltinSymbols.isArrayLike: { // isArrayLike<T!>() / isArrayLike<T?>(value: T) -> bool
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.unreachable();
let classReference = type.classReference;
if (!classReference) return module.i32(0);
return module.i32(classReference.isArrayLike ? 1 : 0);
if (type.is(TypeFlags.REFERENCE)) {
let classReference = type.classReference;
if (classReference) {
return module.i32(classReference.isArrayLike ? 1 : 0);
}
}
return module.i32(0);
}
case BuiltinSymbols.isFunction: { // isFunction<T!> / isFunction<T?>(value: T) -> bool
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
Expand All @@ -637,7 +646,7 @@ export function compileCall(
checkTypeAbsent(typeArguments, reportNode, prototype) |
checkArgsRequired(operands, 1, reportNode, compiler)
) return module.unreachable();
let element = compiler.resolver.resolveExpression(
let element = compiler.resolver.lookupExpression(
operands[0],
compiler.currentFlow,
Type.auto,
Expand Down Expand Up @@ -747,8 +756,9 @@ export function compileCall(
checkTypeRequired(typeArguments, reportNode, compiler) |
checkArgsOptional(operands, 0, 1, reportNode, compiler)
) return module.unreachable();
let classType = typeArguments![0].classReference;
if (!classType) {
let typeArgument = typeArguments![0];
let classType = typeArgument.classReference;
if (!(typeArgument.is(TypeFlags.REFERENCE) && classType !== null)) {
compiler.error(
DiagnosticCode.Operation_not_supported,
reportNode.typeArgumentsRange
Expand Down Expand Up @@ -2436,8 +2446,9 @@ export function compileCall(
if (
checkTypeRequired(typeArguments, reportNode, compiler, true)
) return module.unreachable();
let classInstance = typeArguments![0].classReference;
if (!classInstance) {
let typeArgument = typeArguments![0];
let classInstance = typeArgument.classReference;
if (!(typeArgument.is(TypeFlags.REFERENCE) && classInstance !== null)) {
compiler.error(
DiagnosticCode.Operation_not_supported,
reportNode.typeArgumentsRange
Expand Down Expand Up @@ -3665,7 +3676,7 @@ export function compileCall(
}

let classReference = type.classReference;
if (!classReference || classReference.hasDecorator(DecoratorFlags.UNMANAGED)) {
if (!type.is(TypeFlags.REFERENCE) || !classReference || classReference.hasDecorator(DecoratorFlags.UNMANAGED)) {
compiler.error(
DiagnosticCode.Operation_not_supported,
reportNode.range
Expand Down Expand Up @@ -4102,11 +4113,13 @@ export function compileVisitGlobals(compiler: Compiler): void {
for (let element of compiler.program.elementsByName.values()) {
if (element.kind != ElementKind.GLOBAL) continue;
let global = <Global>element;
let classReference = global.type.classReference;
let globalType = global.type;
let classType = globalType.classReference;
if (
global.is(CommonFlags.COMPILED) &&
classReference !== null &&
!classReference.hasDecorator(DecoratorFlags.UNMANAGED)
globalType.is(TypeFlags.REFERENCE) &&
classType !== null &&
!classType.hasDecorator(DecoratorFlags.UNMANAGED) &&
global.is(CommonFlags.COMPILED)
) {
if (global.is(CommonFlags.INLINED)) {
let value = global.constantIntegerValue;
Expand Down
Loading

0 comments on commit 21f4ff4

Please sign in to comment.