Skip to content

Commit

Permalink
Numerous improvements
Browse files Browse the repository at this point in the history
- Added error highlighting in the try-it-now editor
- Also refactored a bunch and cleaned a bunch of stuff up
  • Loading branch information
kengorab committed Aug 5, 2020
1 parent e321870 commit 9b3e1d5
Show file tree
Hide file tree
Showing 17 changed files with 683 additions and 295 deletions.
42 changes: 38 additions & 4 deletions abra_wasm/abra_wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@
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
error: Error,
errorMessage: string
}

export type CompileResult = CompileSuccess | CompileFailure
Expand All @@ -21,17 +41,30 @@ export type CompileResult = CompileSuccess | CompileFailure
*/
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): Error | any;
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<any>;
export function runAsync(input: string): Promise<RunResult>;

export interface DisassembleSuccess {
success: true,
Expand All @@ -40,7 +73,8 @@ export interface DisassembleSuccess {

export interface DisassembleFailure {
success: false,
error: Error
error: Error,
errorMessage: string
}

export type DisassembleResult = DisassembleSuccess | DisassembleFailure
Expand Down
25 changes: 16 additions & 9 deletions abra_wasm/abra_wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
real.original = state;
return real;
}
function __wbg_adapter_12(arg0, arg1, arg2) {
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));
}

Expand Down Expand Up @@ -134,6 +134,17 @@ export function disassemble(input) {
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}
Expand Down Expand Up @@ -170,7 +181,7 @@ export function runAsync(input) {
function handleError(e) {
wasm.__wbindgen_exn_store(addHeapObject(e));
}
function __wbg_adapter_21(arg0, arg1, arg2, arg3) {
function __wbg_adapter_20(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h7f0356f533042ecb(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}

Expand Down Expand Up @@ -220,10 +231,6 @@ async function init(input) {
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
var ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbg_log_022eb750364e566f = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};
Expand Down Expand Up @@ -251,7 +258,7 @@ async function init(input) {
const a = state0.a;
state0.a = 0;
try {
return __wbg_adapter_21(a, state0.b, arg0, arg1);
return __wbg_adapter_20(a, state0.b, arg0, arg1);
} finally {
state0.a = a;
}
Expand All @@ -273,8 +280,8 @@ async function init(input) {
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbindgen_closure_wrapper702 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 159, __wbg_adapter_12);
imports.wbg.__wbindgen_closure_wrapper737 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 172, __wbg_adapter_10);
return addHeapObject(ret);
};

Expand Down
1 change: 1 addition & 0 deletions abra_wasm/abra_wasm_bg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* 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;
Expand Down
Binary file modified abra_wasm/abra_wasm_bg.wasm
Binary file not shown.
Loading

0 comments on commit 9b3e1d5

Please sign in to comment.