diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..ec4a8fa --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://npm.pkg.github.com/kengorab diff --git a/abra_wasm/abra_wasm.d.ts b/abra_wasm/abra_wasm.d.ts deleted file mode 100644 index 456f85d..0000000 --- a/abra_wasm/abra_wasm.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* tslint:disable */ - -import { Error } from './types/error' -import { Module } from './types/module' - -export interface TypecheckSuccess { - success: true, -} - -export interface TypecheckFailure { - success: false, - error: Error, - errorMessage: string -} - -export type TypecheckResult = TypecheckSuccess | TypecheckFailure - -/** - * Reads the input string as Abra code, and typechecks it, using the wasm implementation - * of the compiler. - * This will either return an error if unsuccessful, or nothing if successful. - */ -export function typecheck(input: string): TypecheckResult | null; - -export interface CompileSuccess { - success: true, - module: Module -} - -export interface CompileFailure { - success: false, - error: Error, - errorMessage: string -} - -export type CompileResult = CompileSuccess | CompileFailure - -/** - * Compiles the input string as Abra code, using the wasm implementation of the compiler. - * This will either return an error if unsuccessful, or a compiled module if successful. - */ -export function compile(input: string): CompileResult | null; - -export interface RunSuccess { - success: true, - data: any -} - -export interface RunFailure { - success: false, - error: Error, - errorMessage: string -} - -export type RunResult = RunSuccess | RunFailure - -/** - * Compiles and executes the input string as Abra code, returning the result. This could - * result in a runtime error. - */ -export function runSync(input: string): RunResult; - -/** - * Compiles and executes the input string as Abra code, resolving with the - * result. This could result in a runtime error, which will also resolve as a successful Promise - */ -export function runAsync(input: string): Promise; - -export interface DisassembleSuccess { - success: true, - disassembled: string -} - -export interface DisassembleFailure { - success: false, - error: Error, - errorMessage: string -} - -export type DisassembleResult = DisassembleSuccess | DisassembleFailure - -/** - * Compiles the input and returns a stringified disassembly - */ -export function disassemble(input: string): DisassembleResult | null; - -export default function init(moduleName: string): Promise; diff --git a/abra_wasm/abra_wasm.js b/abra_wasm/abra_wasm.js deleted file mode 100644 index b52a1b8..0000000 --- a/abra_wasm/abra_wasm.js +++ /dev/null @@ -1,301 +0,0 @@ - -let wasm; - -let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - -cachedTextDecoder.decode(); - -let cachegetUint8Memory0 = null; -function getUint8Memory0() { - if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { - cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); - } - return cachegetUint8Memory0; -} - -function getStringFromWasm0(ptr, len) { - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} - -const heap = new Array(32).fill(undefined); - -heap.push(undefined, null, true, false); - -let heap_next = heap.length; - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; - return idx; -} - -function getObject(idx) { return heap[idx]; } - -function dropObject(idx) { - if (idx < 36) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -function makeMutClosure(arg0, arg1, dtor, f) { - const state = { a: arg0, b: arg1, cnt: 1 }; - const real = (...args) => { - // First up with a closure we increment the internal reference - // count. This ensures that the Rust closure environment won't - // be deallocated while we're invoking it. - state.cnt++; - const a = state.a; - state.a = 0; - try { - return f(a, state.b, ...args); - } finally { - if (--state.cnt === 0) wasm.__wbindgen_export_0.get(dtor)(a, state.b); - else state.a = a; - } - }; - real.original = state; - return real; -} -function __wbg_adapter_10(arg0, arg1, arg2) { - wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd79dee99152d20bc(arg0, arg1, addHeapObject(arg2)); -} - -let WASM_VECTOR_LEN = 0; - -let cachedTextEncoder = new TextEncoder('utf-8'); - -const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); -} - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; -}); - -function passStringToWasm0(arg, malloc, realloc) { - - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length); - getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); - WASM_VECTOR_LEN = buf.length; - return ptr; - } - - let len = arg.length; - let ptr = malloc(len); - - const mem = getUint8Memory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = realloc(ptr, len, len = offset + arg.length * 3); - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - - offset += ret.written; - } - - WASM_VECTOR_LEN = offset; - return ptr; -} -/** -* @param {string} input -* @returns {any} -*/ -export function disassemble(input) { - var ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - var ret = wasm.disassemble(ptr0, len0); - return takeObject(ret); -} - -/** -* @param {string} input -* @returns {any} -*/ -export function typecheck(input) { - var ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - var ret = wasm.typecheck(ptr0, len0); - return takeObject(ret); -} - -/** -* @param {string} input -* @returns {any} -*/ -export function compile(input) { - var ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - var ret = wasm.compile(ptr0, len0); - return takeObject(ret); -} - -/** -* @param {string} input -* @returns {any} -*/ -export function runSync(input) { - var ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - var ret = wasm.runSync(ptr0, len0); - return takeObject(ret); -} - -/** -* @param {string} input -* @returns {Promise} -*/ -export function runAsync(input) { - var ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - var ret = wasm.runAsync(ptr0, len0); - return takeObject(ret); -} - -function handleError(e) { - wasm.__wbindgen_exn_store(addHeapObject(e)); -} -function __wbg_adapter_20(arg0, arg1, arg2, arg3) { - wasm.wasm_bindgen__convert__closures__invoke2_mut__h7f0356f533042ecb(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); -} - -async function load(module, imports) { - if (typeof Response === 'function' && module instanceof Response) { - - if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports); - - } catch (e) { - if (module.headers.get('Content-Type') != 'application/wasm') { - console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); - - } else { - throw e; - } - } - } - - const bytes = await module.arrayBuffer(); - return await WebAssembly.instantiate(bytes, imports); - - } else { - - const instance = await WebAssembly.instantiate(module, imports); - - if (instance instanceof WebAssembly.Instance) { - return { instance, module }; - - } else { - return instance; - } - } -} - -async function init(input) { - if (typeof input === 'undefined') { -// input = import.meta.url.replace(/\.js$/, '_bg.wasm'); - } - const imports = {}; - imports.wbg = {}; - imports.wbg.__wbindgen_json_parse = function(arg0, arg1) { - var ret = JSON.parse(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); - }; - imports.wbg.__wbg_log_022eb750364e566f = function(arg0, arg1) { - console.log(getStringFromWasm0(arg0, arg1)); - }; - imports.wbg.__wbindgen_cb_drop = function(arg0) { - const obj = takeObject(arg0).original; - if (obj.cnt-- == 1) { - obj.a = 0; - return true; - } - var ret = false; - return ret; - }; - imports.wbg.__wbg_call_1ad0eb4a7ab279eb = function(arg0, arg1, arg2) { - try { - var ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); - return addHeapObject(ret); - } catch (e) { - handleError(e) - } - }; - imports.wbg.__wbg_new_1bf1b0dbcaa9ee96 = function(arg0, arg1) { - try { - var state0 = {a: arg0, b: arg1}; - var cb0 = (arg0, arg1) => { - const a = state0.a; - state0.a = 0; - try { - return __wbg_adapter_20(a, state0.b, arg0, arg1); - } finally { - state0.a = a; - } - }; - var ret = new Promise(cb0); - return addHeapObject(ret); - } finally { - state0.a = state0.b = 0; - } - }; - imports.wbg.__wbg_resolve_3e5970e9c931a3c2 = function(arg0) { - var ret = Promise.resolve(getObject(arg0)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_then_d797310661d9e275 = function(arg0, arg1) { - var ret = getObject(arg0).then(getObject(arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_throw = function(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - }; - imports.wbg.__wbindgen_closure_wrapper737 = function(arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, 172, __wbg_adapter_10); - return addHeapObject(ret); - }; - - if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { - input = fetch(input); - } - - const { instance, module } = await load(await input, imports); - - wasm = instance.exports; - init.__wbindgen_wasm_module = module; - - return wasm; -} - -export default init; - diff --git a/abra_wasm/abra_wasm_bg.d.ts b/abra_wasm/abra_wasm_bg.d.ts deleted file mode 100644 index 4aec6e7..0000000 --- a/abra_wasm/abra_wasm_bg.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export function disassemble(a: number, b: number): number; -export function typecheck(a: number, b: number): number; -export function compile(a: number, b: number): number; -export function runSync(a: number, b: number): number; -export function runAsync(a: number, b: number): number; -export const __wbindgen_export_0: WebAssembly.Table; -export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd79dee99152d20bc(a: number, b: number, c: number): void; -export function __wbindgen_malloc(a: number): number; -export function __wbindgen_realloc(a: number, b: number, c: number): number; -export function __wbindgen_exn_store(a: number): void; -export function wasm_bindgen__convert__closures__invoke2_mut__h7f0356f533042ecb(a: number, b: number, c: number, d: number): void; diff --git a/abra_wasm/abra_wasm_bg.wasm b/abra_wasm/abra_wasm_bg.wasm deleted file mode 100644 index 2192ed3..0000000 Binary files a/abra_wasm/abra_wasm_bg.wasm and /dev/null differ diff --git a/abra_wasm/package.json b/abra_wasm/package.json deleted file mode 100644 index eeae180..0000000 --- a/abra_wasm/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "abra_wasm", - "collaborators": [ - "Ken Gorab " - ], - "version": "0.4.0", - "files": [ - "abra_wasm_bg.wasm", - "abra_wasm.js", - "abra_wasm.d.ts" - ], - "module": "abra_wasm.js", - "types": "abra_wasm.d.ts", - "sideEffects": false -} \ No newline at end of file diff --git a/abra_wasm/types/abra-types.d.ts b/abra_wasm/types/abra-types.d.ts deleted file mode 100644 index 338267a..0000000 --- a/abra_wasm/types/abra-types.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -export type Type - = Types.Int - | Types.Unit - | Types.Any - | Types.Or - | Types.Float - | Types.String - | Types.Bool - | Types.Array - | Types.Option - | Types.Fn - -export namespace Types { - interface Int { - kind: 'Int' - } - - interface Unit { - kind: 'Unit' - } - - interface Any { - kind: 'Any' - } - - interface Or { - kind: 'Or', - options: Type[] - } - - interface Float { - kind: 'Float' - } - - interface String { - kind: 'String' - } - - interface Bool { - kind: 'Bool' - } - - interface Array { - kind: 'Array', - innerType: Type - } - - interface Option { - kind: 'Option', - innerType: Type - } - - interface Fn { - kind: 'Fn', - args: [string, Type][], - returnType: Type - } -} diff --git a/abra_wasm/types/binary-op.d.ts b/abra_wasm/types/binary-op.d.ts deleted file mode 100644 index 90df56b..0000000 --- a/abra_wasm/types/binary-op.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export type BinaryOp - = 'Add' - | 'Sub' - | 'Mul' - | 'Div' - | 'And' - | 'Or' - | 'Coalesce' - | 'Lt' - | 'Lte' - | 'Gt' - | 'Gte' - | 'Neq' - | 'Eq' diff --git a/abra_wasm/types/error.d.ts b/abra_wasm/types/error.d.ts deleted file mode 100644 index 078fb07..0000000 --- a/abra_wasm/types/error.d.ts +++ /dev/null @@ -1,358 +0,0 @@ -import { Token } from './token' -import { Position, Range } from './position' -import { Type } from './abra-types' -import { BinaryOp } from './binary-op' - -export type Error - = Errors.ParseError - | Errors.LexerError - | Errors.TypecheckerError - | Errors.InterpretError - -interface BaseError { - range: Range | null -} - -export namespace Errors { - export type ParseError - = ParseErrors.UnexpectedToken - | ParseErrors.UnexpectedEof - | ParseErrors.ExpectedToken - - export namespace ParseErrors { - interface UnexpectedToken extends BaseError { - kind: 'parseError', - subKind: 'unexpectedToken', - token: Token - } - - interface UnexpectedEof extends BaseError { - kind: 'parseError', - subKind: 'unexpectedEof' - } - - interface ExpectedToken extends BaseError { - kind: 'parseError', - subKind: 'expectedToken', - expectedType: string, - token: Token - } - } - - export type LexerError - = LexerErrors.UnexpectedEof - | LexerErrors.UnexpectedChar - | LexerErrors.UnterminatedString - - export namespace LexerErrors { - interface UnexpectedEof extends BaseError { - kind: 'lexerError', - subKind: 'unexpectedEof', - pos: Position - } - - interface UnexpectedChar extends BaseError { - kind: 'lexerError', - subKind: 'unexpectedChar', - pos: Position, - char: string - } - - interface UnterminatedString extends BaseError { - kind: 'lexerError', - subKind: 'unterminatedString', - startPos: Position, - endPos: Position - } - } - - export type TypecheckerError - = TypecheckerErrors.Mismatch - | TypecheckerErrors.InvalidIfConditionType - | TypecheckerErrors.InvalidOperator - | TypecheckerErrors.MissingRequiredAssignment - | TypecheckerErrors.DuplicateBinding - | TypecheckerErrors.DuplicateField - | TypecheckerErrors.DuplicateType - | TypecheckerErrors.UnknownIdentifier - | TypecheckerErrors.InvalidAssignmentTarget - | TypecheckerErrors.AssignmentToImmutable - | TypecheckerErrors.UnannotatedUninitialized - | TypecheckerErrors.UnknownType - | TypecheckerErrors.MissingIfExprBranch - | TypecheckerErrors.IfExprBranchMismatch - | TypecheckerErrors.InvalidInvocationTarget - | TypecheckerErrors.IncorrectArity - | TypecheckerErrors.UnexpectedParamName - | TypecheckerErrors.DuplicateParamName - | TypecheckerErrors.RecursiveRefWithoutReturnType - | TypecheckerErrors.InvalidBreak - | TypecheckerErrors.InvalidRequiredArgPosition - | TypecheckerErrors.InvalidIndexingTarget - | TypecheckerErrors.InvalidIndexingSelector - | TypecheckerErrors.UnknownMember - | TypecheckerErrors.MissingRequiredParams - | TypecheckerErrors.InvalidMixedParamType - | TypecheckerErrors.InvalidTypeFuncInvocation - | TypecheckerErrors.InvalidSelfParamPosition - | TypecheckerErrors.InvalidSelfParam - | TypecheckerErrors.MissingRequiredTypeAnnotation - | TypecheckerErrors.InvalidTypeDeclDepth - | TypecheckerErrors.ForbiddenUnknownType - | TypecheckerErrors.InvalidInstantiation - - export namespace TypecheckerErrors { - interface Mismatch extends BaseError { - kind: 'typecheckerError', - subKind: 'mismatch', - token: Token, - expected: Type, - actual: Type - } - - interface InvalidIfConditionType extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidIfConditionType', - token: Token, - actual: Type - } - - interface InvalidOperator extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidOperator', - token: Token, - op: BinaryOp, - lType: Type, - rType: Type - } - - interface MissingRequiredAssignment extends BaseError { - kind: 'typecheckerError', - subKind: 'missingRequiredAssignment', - ident: Token - } - - interface DuplicateBinding extends BaseError { - kind: 'typecheckerError', - subKind: 'duplicateBinding', - ident: Token, - origIdent: Token - } - - interface DuplicateField extends BaseError { - kind: 'typecheckerError', - subKind: 'duplicateField', - ident: Token, - origIdent: Token - origType: Type - } - - interface DuplicateType extends BaseError { - kind: 'typecheckerError', - subKind: 'duplicateType', - ident: Token, - origIdent: Token | null - } - - interface UnknownIdentifier extends BaseError { - kind: 'typecheckerError', - subKind: 'unknownIdentifier', - ident: Token - } - - interface InvalidAssignmentTarget extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidAssignmentTarget', - token: Token - } - - interface AssignmentToImmutable extends BaseError { - kind: 'typecheckerError', - subKind: 'assignmentToImmutable', - token: Token, - origIdent: Token, - } - - interface UnannotatedUninitialized extends BaseError { - kind: 'typecheckerError', - subKind: 'unannotatedUninitialized', - ident: Token, - isMutable: boolean - } - - interface UnknownType extends BaseError { - kind: 'typecheckerError', - subKind: 'unknownType', - typeIdent: Token - } - - interface MissingIfExprBranch extends BaseError { - kind: 'typecheckerError', - subKind: 'missingIfExprBranch', - ifToken: Token, - isIfBranch: boolean - } - - interface IfExprBranchMismatch extends BaseError { - kind: 'typecheckerError', - subKind: 'ifExprBranchMismatch', - ifToken: Token, - ifType: Type, - elseType: Type, - } - - interface InvalidInvocationTarget extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidInvocationTarget', - token: Token, - targetType: Type - } - - interface IncorrectArity extends BaseError { - kind: 'typecheckerError', - subKind: 'incorrectArity', - token: Token, - expected: number, - actual: number - } - - interface UnexpectedParamName extends BaseError { - kind: 'typecheckerError', - subKind: 'unexpectedParamName', - token: Token - } - - interface DuplicateParamName extends BaseError { - kind: 'typecheckerError', - subKind: 'duplicateParamName', - token: Token - } - - interface RecursiveRefWithoutReturnType extends BaseError { - kind: 'typecheckerError', - subKind: 'recursiveRefWithoutReturnType', - token: Token, - origToken: Token - } - - interface InvalidBreak extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidBreak', - token: Token - } - - interface InvalidRequiredArgPosition extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidRequiredArgPosition', - token: Token - } - - interface InvalidIndexingTarget extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidIndexingTarget', - token: Token, - targetType: Type - } - - interface InvalidIndexingSelector extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidIndexingSelector', - token: Token, - targetType: Type, - selectorType: Type - } - - interface UnknownMember extends BaseError { - kind: 'typecheckerError', - subKind: 'unknownMember', - token: Token, - targetType: Type - } - - interface MissingRequiredParams extends BaseError { - kind: 'typecheckerError', - subKind: 'missingRequiredParams', - token: Token, - missingParams: string[] - } - - interface InvalidMixedParamType extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidMixedParamType', - token: Token - } - - interface InvalidTypeFuncInvocation extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidTypeFuncInvocation', - token: Token - } - - interface InvalidSelfParamPosition extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidSelfParamPosition', - token: Token - } - - interface InvalidSelfParam extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidSelfParam', - token: Token - } - - interface MissingRequiredTypeAnnotation extends BaseError { - kind: 'typecheckerError', - subKind: 'missingRequiredTypeAnnotation', - token: Token - } - - interface InvalidTypeDeclDepth extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidTypeDeclDepth', - token: Token - } - - interface ForbiddenUnknownType extends BaseError { - kind: 'typecheckerError', - subKind: 'forbiddenUnknownType', - token: Token - } - - interface InvalidInstantiation extends BaseError { - kind: 'typecheckerError', - subKind: 'invalidInstantiation', - token: Token, - type: Type - } - } - - export type InterpretError - = InterpretErrors.StackEmpty - | InterpretErrors.ConstIdxOutOfBounds - | InterpretErrors.EndOfBytes - | InterpretErrors.TypeError - - export namespace InterpretErrors { - interface StackEmpty extends BaseError { - kind: 'interpretError', - subKind: 'stackEmpty' - } - - interface ConstIdxOutOfBounds extends BaseError { - kind: 'interpretError', - subKind: 'constIdxOutOfBounds' - } - - interface EndOfBytes extends BaseError { - kind: 'interpretError', - subKind: 'endOfBytes' - } - - interface TypeError extends BaseError { - kind: 'interpretError', - subKind: 'typeError', - expected: string, - actual: string - } - } -} \ No newline at end of file diff --git a/abra_wasm/types/index.d.ts b/abra_wasm/types/index.d.ts deleted file mode 100644 index 0f91507..0000000 --- a/abra_wasm/types/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import './abra-types' -import './binary-op' -import './error' -import './position' -import './token' -import './value' diff --git a/abra_wasm/types/module.ts b/abra_wasm/types/module.ts deleted file mode 100644 index 4911b31..0000000 --- a/abra_wasm/types/module.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Value } from './value' - -export interface Module { - code: [string, number[] | null][], - constants: Value[], -} diff --git a/abra_wasm/types/position.d.ts b/abra_wasm/types/position.d.ts deleted file mode 100644 index f601d3e..0000000 --- a/abra_wasm/types/position.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type Position = [number, number] - -export interface Range { - start: Position, - end: Position -} diff --git a/abra_wasm/types/token.d.ts b/abra_wasm/types/token.d.ts deleted file mode 100644 index ac0ccd3..0000000 --- a/abra_wasm/types/token.d.ts +++ /dev/null @@ -1,214 +0,0 @@ -import { Position } from './position' - -export type Token - = Tokens.Int - | Tokens.Float - | Tokens.String - | Tokens.Bool - | Tokens.Func - | Tokens.Val - | Tokens.Var - | Tokens.If - | Tokens.Else - | Tokens.Ident - | Tokens.Assign - | Tokens.Plus - | Tokens.Minus - | Tokens.Star - | Tokens.Slash - | Tokens.And - | Tokens.Or - | Tokens.Elvis - | Tokens.GT - | Tokens.GTE - | Tokens.LT - | Tokens.LTE - | Tokens.Eq - | Tokens.Neq - | Tokens.Bang - | Tokens.LParen - | Tokens.RParen - | Tokens.LBrack - | Tokens.RBrack - | Tokens.LBrace - | Tokens.RBrace - | Tokens.Colon - | Tokens.Comma - | Tokens.Question - -export namespace Tokens { - interface Int { - kind: 'int', - pos: Position, - val: number - } - - interface Float { - kind: 'float', - pos: Position, - val: number - } - - interface String { - kind: 'string', - pos: Position, - val: string - } - - interface Bool { - kind: 'bool', - pos: Position, - val: boolean - } - - interface Func { - kind: 'func', - pos: Position, - } - - interface Val { - kind: 'val', - pos: Position, - } - - interface Var { - kind: 'var', - pos: Position, - } - - interface If { - kind: 'if', - pos: Position, - } - - interface Else { - kind: 'else', - pos: Position, - } - - interface Ident { - kind: 'ident', - pos: Position, - val: string - } - - interface Assign { - kind: 'assign', - pos: Position, - } - - interface Plus { - kind: 'plus', - pos: Position, - } - - interface Minus { - kind: 'minus', - pos: Position, - } - - interface Star { - kind: 'star', - pos: Position, - } - - interface Slash { - kind: 'slash', - pos: Position, - } - - interface And { - kind: 'and', - pos: Position, - } - - interface Or { - kind: 'or', - pos: Position, - } - - interface Elvis { - kind: 'elvis', - pos: Position, - } - - interface GT { - kind: 'gt', - pos: Position, - } - - interface GTE { - kind: 'gte', - pos: Position, - } - - interface LT { - kind: 'lt', - pos: Position, - } - - interface LTE { - kind: 'lte', - pos: Position, - } - - interface Eq { - kind: 'eq', - pos: Position, - } - - interface Neq { - kind: 'neq', - pos: Position, - } - - interface Bang { - kind: 'bang', - pos: Position, - } - - interface LParen { - kind: 'lParen', - pos: Position, - } - - interface RParen { - kind: 'rParen', - pos: Position, - } - - interface LBrack { - kind: 'lBrack', - pos: Position, - } - - interface RBrack { - kind: 'rBrack', - pos: Position, - } - - interface LBrace { - kind: 'lBrace', - pos: Position, - } - - interface RBrace { - kind: 'rBrace', - pos: Position, - } - - interface Colon { - kind: 'colon', - pos: Position, - } - - interface Comma { - kind: 'comma', - pos: Position, - } - - interface Question { - kind: 'question', - pos: Position, - } -} diff --git a/abra_wasm/types/value.d.ts b/abra_wasm/types/value.d.ts deleted file mode 100644 index 08c3537..0000000 --- a/abra_wasm/types/value.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -export type Value - = Values.Int - | Values.Float - | Values.Bool - | Values.Obj - | Values.Fn - | Values.Nil - -export namespace Values { - interface Int { - kind: 'int', - value: number - } - - interface Float { - kind: 'float', - value: number - } - - interface Bool { - kind: 'bool', - value: boolean - } - - interface Obj { - kind: 'obj', - value: ObjectValue - } - - interface Fn { - kind: 'fn', - name: string - } - - interface Nil { - kind: 'nil' - } -} - -export type ObjectValue - = ObjectValues.StringObj - | ObjectValues.ArrayObj - | ObjectValues.MapObj - -export namespace ObjectValues { - interface StringObj { - kind: 'stringObj', - value: string - } - - interface ArrayObj { - kind: 'arrayObj', - value: Value[] - } - - interface MapObj { - kind: 'mapObj', - value: [string, Value][] - } -} \ No newline at end of file diff --git a/build-abra_wasm.sh b/build-abra_wasm.sh deleted file mode 100755 index 8131f36..0000000 --- a/build-abra_wasm.sh +++ /dev/null @@ -1,39 +0,0 @@ -# This script facilitates the manual post-install step of setting up the abra_wasm package. -# This needs to be done manually, since we can't rely on `cargo` and `wasm-pack` to be installed -# everywhere; this will build the abra_wasm package within the abra-lang git submodule, copy it -# out into the top-level directory, and install it as an npm dependency. -# -# Before installing as an npm dependency though, something dumb and annoying needs to happen. -# There's a line in the generated glue code that relies on a future js language feature (the -# import.meta feature); due to the fact that we're in create-react-app land (and for some reason -# the rescripts babel rewrite which would enable the import-meta syntax didn't seem to work...) -# this line will cause problems at build-time. Since we don't use that particular code path, we -# can comment out that line using a wonderfully hacky sed command (I know, this is _stupid_). -# -# Also due to the inability to customize babel configs from within CRA, loading wasm files needs to -# be done in a weird way. It won't be bundled with the app (as one would expect), but instead served -# up with the static assets, and then referenced in the `init` function that the glue code provides. -# This means that the compiled wasm file needs to be placed in the public/ directory, so at dev- and -# build-time, it'll be available to serve statically. - -# pwd = root -git clone git@github.com:kengorab/abra-lang.git -cd abra-lang -cargo build -cd abra_wasm -WASM_PACK_TARGET=web ./build.sh -cp -R pkg ../../abra_wasm - -# pwd = root again -cd ../.. -rm abra_wasm/.gitignore -sed 's/^.*import\.meta/\/\/&/' abra_wasm/abra_wasm.js > abra_wasm/abra_wasm_.js -mv abra_wasm/abra_wasm_.js abra_wasm/abra_wasm.js - -# The init function type declaration needs to be added manually, for the WASM_PACK_TARGET=web target -echo "\nexport default function init(moduleName: string): Promise;" >> abra_wasm/abra_wasm.d.ts -npm i ./abra_wasm - -cp abra_wasm/abra_wasm_bg.wasm public/abra_wasm/abra_wasm_bg.wasm - -rm -rf abra-lang diff --git a/package-lock.json b/package-lock.json index 9c7dcbd..718c2a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1194,6 +1194,11 @@ "@types/yargs": "^12.0.9" } }, + "@kengorab/abra_wasm": { + "version": "0.4.0", + "resolved": "https://npm.pkg.github.com/download/@kengorab/abra_wasm/0.4.0/3d70036fe455c936b4412ae5a309fccb823c8efb60de0352da8d3fa0d3d9f036", + "integrity": "sha512-GHQAq6gZtobzrW5wfqU6wn2dZTgAOlhAyxvjSvyc4dRKJErggwXK0TP3ESMj3AbPqYPjvaMGOQ3LfQHDhVXeXg==" + }, "@mrmlnc/readdir-enhanced": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz", @@ -1431,6 +1436,7 @@ "version": "24.0.15", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.15.tgz", "integrity": "sha512-MU1HIvWUme74stAoc3mgAi+aMlgKOudgEvQDIm1v4RkrDudBh1T+NFp5sftpBAdXdx1J0PbdpJ+M2EsSOi1djA==", + "dev": true, "requires": { "@types/jest-diff": "*" } @@ -1438,7 +1444,8 @@ "@types/jest-diff": { "version": "20.0.1", "resolved": "https://registry.npmjs.org/@types/jest-diff/-/jest-diff-20.0.1.tgz", - "integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==" + "integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==", + "dev": true }, "@types/node": { "version": "12.6.2", @@ -1448,7 +1455,8 @@ "@types/prop-types": { "version": "15.7.1", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.1.tgz", - "integrity": "sha512-CFzn9idOEpHrgdw8JsoTkaDDyRWk1jrzIV8djzcgpq0y9tG4B4lFT+Nxh52DVpDXV+n4+NPNv7M1Dj5uMp6XFg==" + "integrity": "sha512-CFzn9idOEpHrgdw8JsoTkaDDyRWk1jrzIV8djzcgpq0y9tG4B4lFT+Nxh52DVpDXV+n4+NPNv7M1Dj5uMp6XFg==", + "dev": true }, "@types/q": { "version": "1.5.2", @@ -1459,6 +1467,7 @@ "version": "16.8.23", "resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.23.tgz", "integrity": "sha512-abkEOIeljniUN9qB5onp++g0EY38h7atnDHxwKUFz1r3VH1+yG1OKi2sNPTyObL40goBmfKFpdii2lEzwLX1cA==", + "dev": true, "requires": { "@types/prop-types": "*", "csstype": "^2.2.0" @@ -1468,6 +1477,7 @@ "version": "16.8.4", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.8.4.tgz", "integrity": "sha512-eIRpEW73DCzPIMaNBDP5pPIpK1KXyZwNgfxiVagb5iGiz6da+9A5hslSX6GAQKdO7SayVCS/Fr2kjqprgAvkfA==", + "dev": true, "requires": { "@types/react": "*" } @@ -1777,9 +1787,6 @@ "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.0.tgz", "integrity": "sha512-sY5AXXVZv4Y1VACTtR11UJCPHHudgY5i26Qj5TypE6DKlIApbwb5uqhXcJ5UUGbvZNRh7EeIoW+LrJumBsKp7w==" }, - "abra_wasm": { - "version": "file:abra_wasm" - }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -4154,7 +4161,8 @@ "csstype": { "version": "2.6.6", "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.6.tgz", - "integrity": "sha512-RpFbQGUE74iyPgvr46U9t1xoQBM8T4BL8SxrN66Le2xYAPSaDJJKeztV3awugusb3g3G9iL8StmkBBXhcbbXhg==" + "integrity": "sha512-RpFbQGUE74iyPgvr46U9t1xoQBM8T4BL8SxrN66Le2xYAPSaDJJKeztV3awugusb3g3G9iL8StmkBBXhcbbXhg==", + "dev": true }, "cyclist": { "version": "0.2.2", diff --git a/package.json b/package.json index 438739c..eceb7e1 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "@types/jest": "24.0.15", - "@types/node": "12.6.2", - "@types/react": "16.8.23", - "@types/react-dom": "16.8.4", - "abra_wasm": "file:abra_wasm", + "@kengorab/abra_wasm": "0.4.0", "code-prettify": "^0.1.0", "codemirror": "^5.48.0", "react": "^16.8.6", @@ -21,19 +17,20 @@ "typescript": "3.5.3" }, "scripts": { - "postinstall": "npm i ./abra_wasm", "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject", - "build-abra_wasm": "rimraf abra_wasm && ./build-abra_wasm.sh" + "eject": "react-scripts eject" }, "devDependencies": { "@types/codemirror": "0.0.76", + "@types/jest": "24.0.15", + "@types/node": "12.6.2", + "@types/react": "16.8.23", + "@types/react-dom": "16.8.4", "@types/react-router-dom": "^4.3.4", "@types/react-router-hash-link": "^1.2.1", - "@types/styled-components": "^4.1.16", - "rimraf": "^2.6.3" + "@types/styled-components": "^4.1.16" }, "eslintConfig": { "extends": "react-app" diff --git a/public/abra_wasm/abra_wasm_bg.wasm b/public/abra_wasm/abra_wasm_bg.wasm index 2192ed3..af07785 100644 Binary files a/public/abra_wasm/abra_wasm_bg.wasm and b/public/abra_wasm/abra_wasm_bg.wasm differ diff --git a/src/abra-lang/wrapper.ts b/src/abra-lang/wrapper.ts index b0e7249..1e4ccec 100644 --- a/src/abra-lang/wrapper.ts +++ b/src/abra-lang/wrapper.ts @@ -1,4 +1,4 @@ -import * as Abra from 'abra_wasm' +import * as Abra from '@kengorab/abra_wasm' const _init = Abra.default