porffor 0.37.28 → 0.37.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/builtins/error.js +4 -1
- package/compiler/builtins_precompiled.js +30 -0
- package/compiler/codegen.js +16 -68
- package/compiler/wrap.js +0 -32
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/runner/repl.js +17 -22
@@ -10,7 +10,7 @@ export default () => {
|
|
10
10
|
|
11
11
|
const obj: object = Porffor.allocate();
|
12
12
|
|
13
|
-
const _name: bytestring = '${name}';
|
13
|
+
const _name: bytestring = '${name.split('_').pop()}';
|
14
14
|
|
15
15
|
obj.name = _name;
|
16
16
|
obj.message = message;
|
@@ -40,5 +40,8 @@ export const __${name}_prototype_toString = (_this: ${name}) => {
|
|
40
40
|
error('EvalError');
|
41
41
|
error('URIError');
|
42
42
|
|
43
|
+
error('__Porffor_TodoError');
|
44
|
+
error('Test262Error');
|
45
|
+
|
43
46
|
return out;
|
44
47
|
};
|
@@ -1569,6 +1569,36 @@ locals:[124,124,127,124,124,127,127,124],localNames:["_this","_this#type","obj",
|
|
1569
1569
|
usedTypes:[46,7,195],
|
1570
1570
|
data:{"bytestring: __URIError_prototype_toString/bridge":[2,0,0,0,58,32]},
|
1571
1571
|
};
|
1572
|
+
this.__Porffor_TodoError = {
|
1573
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __Porffor_TodoError/_empty','i8'),124),[33,6],[32,4],[68,0],[97],[32,5],[65,128,1],[114],[65,128,1],[65,128,1],[114],[70],[113],[4,64],[32,6],[34,4],[65,195,1],[33,5],[26],[5],[32,4],[32,5],[16,builtin('__ecma262_ToString')],[34,7],[33,5],[33,4],[11],[16,builtin('__Porffor_allocate')],[183],[33,8],...number(allocPage(_,'bytestring: __Porffor_TodoError/_name','i8'),124),[33,9],[32,8],[33,12],[16,builtin('__Porffor_allocate')],[184],[34,13],[252,3],[34,14],[65,4],[54,1,0],[32,14],[65,238,0],[58,0,4],[32,14],[65,225,0],[58,0,5],[32,14],[65,237,0],[58,0,6],[32,14],[65,229,0],[58,0,7],[32,14],[184],[33,13],[32,12],[252,2],[65,7],[32,13],[252,3],[65,195,1],[32,9],[65,195,1],[16,builtin('__Porffor_object_set')],[26],[26],[32,8],[33,12],[16,builtin('__Porffor_allocate')],[184],[34,13],[252,3],[34,14],[65,7],[54,1,0],[32,14],[65,237,0],[58,0,4],[32,14],[65,229,0],[58,0,5],[32,14],[65,243,0],[58,0,6],[32,14],[65,243,0],[58,0,7],[32,14],[65,225,0],[58,0,8],[32,14],[65,231,0],[58,0,9],[32,14],[65,229,0],[58,0,10],[32,14],[184],[33,13],[32,12],[252,2],[65,7],[32,13],[252,3],[65,195,1],[32,4],[32,5],[16,builtin('__Porffor_object_set')],[26],[26],[32,8],[33,15],[65,7],[33,16],[32,15],[32,16],[15]],
|
1574
|
+
params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1575
|
+
locals:[124,127,124,124,124,127,124,124,127,124,127],localNames:["#newtarget","#newtarget#type","#this","#this#type","message","message#type","_empty","#last_type","obj","_name","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#makearray_pointer_tmp","out","out#type"],
|
1576
|
+
usedTypes:[195,7],
|
1577
|
+
data:{"bytestring: __Porffor_TodoError/_name":[9,0,0,0,84,111,100,111,69,114,114,111,114]},
|
1578
|
+
constr:1,
|
1579
|
+
};
|
1580
|
+
this.____Porffor_TodoError_prototype_toString = {
|
1581
|
+
wasm:(_,{allocPage,builtin})=>[[32,0],[34,2],[33,5],...number(allocPage(_,'bytestring: ____Porffor_TodoError_prototype_toString/#member_prop','i8'),124),[34,6],[252,3],[34,8],[65,7],[54,1,0],[32,8],[65,237,0],[58,0,4],[32,8],[65,229,0],[58,0,5],[32,8],[65,243,0],[58,0,6],[32,8],[65,243,0],[58,0,7],[32,8],[65,225,0],[58,0,8],[32,8],[65,231,0],[58,0,9],[32,8],[65,229,0],[58,0,10],[32,8],[184],[33,6],[32,5],[252,2],[65,7],[32,6],[252,3],[65,195,1],[16,builtin('__Porffor_object_get')],[34,7],[33,4],[34,3],[252,3],[40,1,0],[184],[68,0],[97],[65,1],[65,128,1],[114],[65,1],[65,128,1],[114],[70],[113],[4,64],[32,2],[33,5],[68,2818048],[34,6],[252,3],[34,8],[65,4],[54,1,0],[32,8],[65,238,0],[58,0,4],[32,8],[65,225,0],[58,0,5],[32,8],[65,237,0],[58,0,6],[32,8],[65,229,0],[58,0,7],[32,8],[184],[33,6],[32,5],[252,2],[65,7],[32,6],[252,3],[65,195,1],[16,builtin('__Porffor_object_get')],[34,7],[15],[11],...number(allocPage(_,'bytestring: ____Porffor_TodoError_prototype_toString/bridge','i8'),124),[33,9],[32,2],[33,5],[68,2818048],[34,6],[252,3],[34,8],[65,4],[54,1,0],[32,8],[65,238,0],[58,0,4],[32,8],[65,225,0],[58,0,5],[32,8],[65,237,0],[58,0,6],[32,8],[65,229,0],[58,0,7],[32,8],[184],[33,6],[32,5],[252,2],[65,7],[32,6],[252,3],[65,195,1],[16,builtin('__Porffor_object_get')],[34,7],[32,9],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,3],[32,4],[16,builtin('__Porffor_concatStrings')],[34,7],[15]],
|
1582
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1583
|
+
locals:[124,124,127,124,124,127,127,124],localNames:["_this","_this#type","obj","message","message#type","#member_obj","#member_prop","#last_type","#makearray_pointer_tmp","bridge"],
|
1584
|
+
usedTypes:[7,195],
|
1585
|
+
data:{"bytestring: ____Porffor_TodoError_prototype_toString/bridge":[2,0,0,0,58,32]},
|
1586
|
+
};
|
1587
|
+
this.Test262Error = {
|
1588
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: Test262Error/_empty','i8'),124),[33,6],[32,4],[68,0],[97],[32,5],[65,128,1],[114],[65,128,1],[65,128,1],[114],[70],[113],[4,64],[32,6],[34,4],[65,195,1],[33,5],[26],[5],[32,4],[32,5],[16,builtin('__ecma262_ToString')],[34,7],[33,5],[33,4],[11],[16,builtin('__Porffor_allocate')],[183],[33,8],...number(allocPage(_,'bytestring: Test262Error/_name','i8'),124),[33,9],[32,8],[33,12],[16,builtin('__Porffor_allocate')],[184],[34,13],[252,3],[34,14],[65,4],[54,1,0],[32,14],[65,238,0],[58,0,4],[32,14],[65,225,0],[58,0,5],[32,14],[65,237,0],[58,0,6],[32,14],[65,229,0],[58,0,7],[32,14],[184],[33,13],[32,12],[252,2],[65,7],[32,13],[252,3],[65,195,1],[32,9],[65,195,1],[16,builtin('__Porffor_object_set')],[26],[26],[32,8],[33,12],[16,builtin('__Porffor_allocate')],[184],[34,13],[252,3],[34,14],[65,7],[54,1,0],[32,14],[65,237,0],[58,0,4],[32,14],[65,229,0],[58,0,5],[32,14],[65,243,0],[58,0,6],[32,14],[65,243,0],[58,0,7],[32,14],[65,225,0],[58,0,8],[32,14],[65,231,0],[58,0,9],[32,14],[65,229,0],[58,0,10],[32,14],[184],[33,13],[32,12],[252,2],[65,7],[32,13],[252,3],[65,195,1],[32,4],[32,5],[16,builtin('__Porffor_object_set')],[26],[26],[32,8],[33,15],[65,7],[33,16],[32,15],[32,16],[15]],
|
1589
|
+
params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1590
|
+
locals:[124,127,124,124,124,127,124,124,127,124,127],localNames:["#newtarget","#newtarget#type","#this","#this#type","message","message#type","_empty","#last_type","obj","_name","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#makearray_pointer_tmp","out","out#type"],
|
1591
|
+
usedTypes:[195,7],
|
1592
|
+
data:{"bytestring: Test262Error/_name":[12,0,0,0,84,101,115,116,50,54,50,69,114,114,111,114]},
|
1593
|
+
constr:1,
|
1594
|
+
};
|
1595
|
+
this.__Test262Error_prototype_toString = {
|
1596
|
+
wasm:(_,{allocPage,builtin})=>[[32,0],[34,2],[33,5],...number(allocPage(_,'bytestring: __Test262Error_prototype_toString/#member_prop','i8'),124),[34,6],[252,3],[34,8],[65,7],[54,1,0],[32,8],[65,237,0],[58,0,4],[32,8],[65,229,0],[58,0,5],[32,8],[65,243,0],[58,0,6],[32,8],[65,243,0],[58,0,7],[32,8],[65,225,0],[58,0,8],[32,8],[65,231,0],[58,0,9],[32,8],[65,229,0],[58,0,10],[32,8],[184],[33,6],[32,5],[252,2],[65,7],[32,6],[252,3],[65,195,1],[16,builtin('__Porffor_object_get')],[34,7],[33,4],[34,3],[252,3],[40,1,0],[184],[68,0],[97],[65,1],[65,128,1],[114],[65,1],[65,128,1],[114],[70],[113],[4,64],[32,2],[33,5],[68,3145728],[34,6],[252,3],[34,8],[65,4],[54,1,0],[32,8],[65,238,0],[58,0,4],[32,8],[65,225,0],[58,0,5],[32,8],[65,237,0],[58,0,6],[32,8],[65,229,0],[58,0,7],[32,8],[184],[33,6],[32,5],[252,2],[65,7],[32,6],[252,3],[65,195,1],[16,builtin('__Porffor_object_get')],[34,7],[15],[11],...number(allocPage(_,'bytestring: __Test262Error_prototype_toString/bridge','i8'),124),[33,9],[32,2],[33,5],[68,3145728],[34,6],[252,3],[34,8],[65,4],[54,1,0],[32,8],[65,238,0],[58,0,4],[32,8],[65,225,0],[58,0,5],[32,8],[65,237,0],[58,0,6],[32,8],[65,229,0],[58,0,7],[32,8],[184],[33,6],[32,5],[252,2],[65,7],[32,6],[252,3],[65,195,1],[16,builtin('__Porffor_object_get')],[34,7],[32,9],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,3],[32,4],[16,builtin('__Porffor_concatStrings')],[34,7],[15]],
|
1597
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1598
|
+
locals:[124,124,127,124,124,127,127,124],localNames:["_this","_this#type","obj","message","message#type","#member_obj","#member_prop","#last_type","#makearray_pointer_tmp","bridge"],
|
1599
|
+
usedTypes:[7,195],
|
1600
|
+
data:{"bytestring: __Test262Error_prototype_toString/bridge":[2,0,0,0,58,32]},
|
1601
|
+
};
|
1572
1602
|
this.escape = {
|
1573
1603
|
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: escape/lut','i8'),127),[33,2],[32,0],[40,1,0],[34,3],[33,4],[32,0],[33,5],[32,1],[65,195,1],[70],[4,64],[32,5],[32,3],[106],[33,6],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[34,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[12,3],[11],[11],[32,4],[65,2],[106],[33,4],[12,1],[11],[11],[32,4],[32,3],[70],[4,64],[32,0],[32,1],[15],[11],[16,builtin('__Porffor_allocate')],[34,8],[34,10],[32,4],[34,9],[54,1,0],[32,0],[33,5],[32,8],[33,11],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[34,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[32,11],[32,11],[65,1],[106],[33,11],[32,7],[58,0,4],[12,3],[11],[11],[32,11],[32,11],[65,1],[106],[33,11],[65,37],[58,0,4],[32,7],[65,15],[113],[65,48],[106],[34,12],[65,57],[74],[4,64],[32,12],[65,7],[106],[33,12],[11],[32,7],[65,4],[117],[65,48],[106],[34,13],[65,57],[74],[4,64],[32,13],[65,7],[106],[33,13],[11],[32,11],[32,11],[65,1],[106],[33,11],[32,13],[58,0,4],[32,11],[32,11],[65,1],[106],[33,11],[32,12],[58,0,4],[12,1],[11],[11],[32,8],[65,195,1],[15],[11],[32,5],[32,3],[65,2],[108],[106],[33,6],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[47,0,4],[33,7],[32,5],[65,2],[106],[33,5],[32,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[12,3],[11],[11],[32,7],[65,128,2],[72],[4,64],[32,4],[65,2],[106],[33,4],[5],[32,4],[65,5],[106],[33,4],[11],[12,1],[11],[11],[32,4],[32,3],[70],[4,64],[32,0],[32,1],[15],[11],[16,builtin('__Porffor_allocate')],[34,8],[34,10],[32,4],[34,9],[54,1,0],[32,0],[33,5],[32,8],[33,11],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[47,0,4],[33,7],[32,5],[65,2],[106],[33,5],[32,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[32,11],[32,11],[65,1],[106],[33,11],[32,7],[58,0,4],[12,3],[11],[11],[32,7],[65,128,2],[72],[4,64],[32,11],[32,11],[65,1],[106],[33,11],[65,37],[58,0,4],[32,7],[65,15],[113],[65,48],[106],[34,12],[65,57],[74],[4,64],[32,12],[65,7],[106],[33,12],[11],[32,7],[65,4],[117],[65,48],[106],[34,13],[65,57],[74],[4,64],[32,13],[65,7],[106],[33,13],[11],[32,11],[32,11],[65,1],[106],[33,11],[32,13],[58,0,4],[32,11],[32,11],[65,1],[106],[33,11],[32,12],[58,0,4],[5],[32,11],[65,165,234,1],[59,0,4],[32,11],[65,2],[106],[33,11],[32,7],[65,12],[117],[65,15],[113],[65,48],[106],[34,14],[65,57],[74],[4,64],[32,14],[65,7],[106],[33,14],[11],[32,11],[32,11],[65,1],[106],[33,11],[32,14],[58,0,4],[32,7],[65,8],[117],[65,15],[113],[65,48],[106],[34,14],[65,57],[74],[4,64],[32,14],[65,7],[106],[33,14],[11],[32,11],[32,11],[65,1],[106],[33,11],[32,14],[58,0,4],[32,7],[65,4],[117],[65,15],[113],[65,48],[106],[34,14],[65,57],[74],[4,64],[32,14],[65,7],[106],[33,14],[11],[32,11],[32,11],[65,1],[106],[33,11],[32,14],[58,0,4],[32,7],[65,15],[113],[65,48],[106],[34,14],[65,57],[74],[4,64],[32,14],[65,7],[106],[33,14],[11],[32,11],[32,11],[65,1],[106],[33,11],[32,14],[58,0,4],[11],[12,1],[11],[11],[32,8],[65,195,1],[15]],
|
1574
1604
|
params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
|
package/compiler/codegen.js
CHANGED
@@ -32,7 +32,7 @@ const todo = (scope, msg, expectsValue = undefined) => {
|
|
32
32
|
throw new TodoError(msg);
|
33
33
|
|
34
34
|
case 'runtime':
|
35
|
-
return internalThrow(scope, '
|
35
|
+
return internalThrow(scope, '__Porffor_TodoError', msg, expectsValue);
|
36
36
|
}
|
37
37
|
};
|
38
38
|
|
@@ -4722,6 +4722,8 @@ const generateThrow = (scope, decl) => {
|
|
4722
4722
|
idx: tags.length
|
4723
4723
|
});
|
4724
4724
|
|
4725
|
+
if (constructor && constructor.startsWith('__')) constructor = constructor.split('_').pop();
|
4726
|
+
|
4725
4727
|
let exceptId = exceptions.findIndex(x => x.constructor === constructor && x.message === message);
|
4726
4728
|
if (exceptId === -1) exceptId = exceptions.push({ constructor, message }) - 1;
|
4727
4729
|
|
@@ -4747,61 +4749,6 @@ const generateThrow = (scope, decl) => {
|
|
4747
4749
|
[ Opcodes.throw, tags[0].idx ]
|
4748
4750
|
];
|
4749
4751
|
}
|
4750
|
-
|
4751
|
-
if (exceptionMode === 'stackest') {
|
4752
|
-
let message = decl.argument, constructor = null;
|
4753
|
-
|
4754
|
-
// support `throw (new)? Error(...)`
|
4755
|
-
if (message.type === 'NewExpression' || message.type === 'CallExpression') {
|
4756
|
-
constructor = decl.argument.callee;
|
4757
|
-
message = decl.argument.arguments[0];
|
4758
|
-
}
|
4759
|
-
|
4760
|
-
message ??= DEFAULT_VALUE();
|
4761
|
-
|
4762
|
-
if (tags.length === 0) tags.push({
|
4763
|
-
params: [ valtypeBinary, valtypeBinary, Valtype.i32 ],
|
4764
|
-
results: [],
|
4765
|
-
idx: tags.length
|
4766
|
-
});
|
4767
|
-
|
4768
|
-
return [
|
4769
|
-
...(constructor == null ? number(-1) : generate(scope, constructor)),
|
4770
|
-
...generate(scope, message),
|
4771
|
-
...getNodeType(scope, message),
|
4772
|
-
[ Opcodes.throw, tags[0].idx ]
|
4773
|
-
];
|
4774
|
-
}
|
4775
|
-
|
4776
|
-
if (exceptionMode === 'partial') {
|
4777
|
-
let message = decl.argument, constructor = null;
|
4778
|
-
|
4779
|
-
// support `throw (new)? Error(...)`
|
4780
|
-
if (message.type === 'NewExpression' || message.type === 'CallExpression') {
|
4781
|
-
constructor = decl.argument.callee.name;
|
4782
|
-
message = decl.argument.arguments[0];
|
4783
|
-
}
|
4784
|
-
|
4785
|
-
message ??= DEFAULT_VALUE();
|
4786
|
-
|
4787
|
-
if (tags.length === 0) tags.push({
|
4788
|
-
params: [ Valtype.i32, valtypeBinary, Valtype.i32 ],
|
4789
|
-
results: [],
|
4790
|
-
idx: tags.length
|
4791
|
-
});
|
4792
|
-
|
4793
|
-
let exceptId = exceptions.push({ constructor }) - 1;
|
4794
|
-
|
4795
|
-
scope.exceptions ??= [];
|
4796
|
-
scope.exceptions.push(exceptId);
|
4797
|
-
|
4798
|
-
return [
|
4799
|
-
...number(exceptId, Valtype.i32),
|
4800
|
-
...generate(scope, message),
|
4801
|
-
...getNodeType(scope, message),
|
4802
|
-
[ Opcodes.throw, tags[0].idx ]
|
4803
|
-
];
|
4804
|
-
}
|
4805
4752
|
};
|
4806
4753
|
|
4807
4754
|
const generateTry = (scope, decl) => {
|
@@ -5975,6 +5922,18 @@ const generateFunc = (scope, decl) => {
|
|
5975
5922
|
generate() {
|
5976
5923
|
if (func.wasm) return func.wasm;
|
5977
5924
|
|
5925
|
+
let errorWasm = null;
|
5926
|
+
if (decl.generator) {
|
5927
|
+
errorWasm = todo(func, 'generator functions are not supported');
|
5928
|
+
}
|
5929
|
+
|
5930
|
+
if (errorWasm) {
|
5931
|
+
return func.wasm = errorWasm.concat([
|
5932
|
+
...number(UNDEFINED),
|
5933
|
+
...number(TYPES.undefined, Valtype.i32)
|
5934
|
+
]);
|
5935
|
+
}
|
5936
|
+
|
5978
5937
|
// generating, stub _wasm
|
5979
5938
|
func.wasm = [];
|
5980
5939
|
|
@@ -6066,7 +6025,7 @@ const generateFunc = (scope, decl) => {
|
|
6066
6025
|
// inject promise job runner func at the end of main if promises are made
|
6067
6026
|
if (Object.hasOwn(funcIndex, 'Promise') || Object.hasOwn(funcIndex, '__Promise_resolve') || Object.hasOwn(funcIndex, '__Promise_reject')) {
|
6068
6027
|
wasm.push(
|
6069
|
-
[ Opcodes.call, includeBuiltin(
|
6028
|
+
[ Opcodes.call, includeBuiltin(func, '__Porffor_promise_runJobs').index ],
|
6070
6029
|
[ Opcodes.drop ],
|
6071
6030
|
[ Opcodes.drop ]
|
6072
6031
|
);
|
@@ -6085,17 +6044,6 @@ const generateFunc = (scope, decl) => {
|
|
6085
6044
|
funcIndex[name] = func.index;
|
6086
6045
|
funcs.push(func);
|
6087
6046
|
|
6088
|
-
let errorWasm = null;
|
6089
|
-
if (decl.generator) errorWasm = todo(scope, 'generator functions are not supported');
|
6090
|
-
|
6091
|
-
if (errorWasm) {
|
6092
|
-
// func.params = [];
|
6093
|
-
func.wasm = errorWasm.concat([
|
6094
|
-
...number(UNDEFINED),
|
6095
|
-
...number(TYPES.undefined, Valtype.i32)
|
6096
|
-
]);
|
6097
|
-
}
|
6098
|
-
|
6099
6047
|
if (typedInput && decl.returnType) {
|
6100
6048
|
const { type } = extractTypeAnnotation(decl.returnType);
|
6101
6049
|
if (type != null && !Prefs.indirectCalls) {
|
package/compiler/wrap.js
CHANGED
@@ -524,38 +524,6 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
524
524
|
|
525
525
|
throw porfToJSValue({ memory, funcs, pages }, value, type);
|
526
526
|
}
|
527
|
-
|
528
|
-
if (exceptionMode === 'stackest') {
|
529
|
-
const constructorIdx = e.getArg(exceptTag, 0);
|
530
|
-
const constructorName = constructorIdx == -1 ? null : funcs.find(x => (x.index - importedFuncs.length) === constructorIdx)?.name;
|
531
|
-
|
532
|
-
const value = e.getArg(exceptTag, 1);
|
533
|
-
const type = e.getArg(exceptTag, 2);
|
534
|
-
const message = porfToJSValue({ memory, funcs, pages }, value, type);
|
535
|
-
|
536
|
-
// no constructor, just throw message
|
537
|
-
if (!constructorName) throw message;
|
538
|
-
|
539
|
-
const constructor = globalThis[constructorName] ?? eval(`class ${constructorName} extends Error { constructor(message) { super(message); this.name = "${constructorName}"; } }; ${constructorName}`);
|
540
|
-
throw new constructor(message);
|
541
|
-
}
|
542
|
-
|
543
|
-
if (exceptionMode === 'partial') {
|
544
|
-
const exceptId = e.getArg(exceptTag, 0);
|
545
|
-
const exception = exceptions[exceptId];
|
546
|
-
|
547
|
-
const constructorName = exception.constructor;
|
548
|
-
|
549
|
-
const value = e.getArg(exceptTag, 1);
|
550
|
-
const type = e.getArg(exceptTag, 2);
|
551
|
-
const message = porfToJSValue({ memory, funcs, pages }, value, type);
|
552
|
-
|
553
|
-
// no constructor, just throw message
|
554
|
-
if (!constructorName) throw message;
|
555
|
-
|
556
|
-
const constructor = globalThis[constructorName] ?? eval(`class ${constructorName} extends Error { constructor(message) { super(message); this.name = "${constructorName}"; } }; ${constructorName}`);
|
557
|
-
throw new constructor(message);
|
558
|
-
}
|
559
527
|
}
|
560
528
|
|
561
529
|
if (e instanceof WebAssembly.RuntimeError) {
|
package/package.json
CHANGED
package/runner/index.js
CHANGED
package/runner/repl.js
CHANGED
@@ -88,36 +88,31 @@ const run = (source, _context, _filename, callback, run = true) => {
|
|
88
88
|
let toRun = (prev ? (prev + `;\nprint(-0x1337);\n`) : '') + source;
|
89
89
|
|
90
90
|
let shouldPrint = !prev;
|
91
|
-
let exports, pages;
|
92
91
|
try {
|
93
|
-
|
92
|
+
const { exports, pages } = compile(toRun, process.argv.includes('--module') ? [ 'module' ] : [], {}, str => {
|
94
93
|
if (shouldPrint) process.stdout.write(str);
|
95
94
|
if (str === '-4919') shouldPrint = true;
|
96
95
|
});
|
97
|
-
} catch (e) {
|
98
|
-
console.log(e);
|
99
|
-
callback();
|
100
|
-
return;
|
101
|
-
}
|
102
96
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
let ret = run ? exports.main() : undefined;
|
109
|
-
let value, type;
|
110
|
-
if (ret?.type != null) {
|
111
|
-
value = ret.value;
|
112
|
-
type = ret.type;
|
113
|
-
ret = ret.js;
|
114
|
-
}
|
97
|
+
if (run && exports.$) {
|
98
|
+
lastMemory = exports.$;
|
99
|
+
lastPages = [...pages.keys()];
|
100
|
+
}
|
115
101
|
|
116
|
-
|
102
|
+
let ret = run ? exports.main() : undefined;
|
103
|
+
let value, type;
|
104
|
+
if (ret?.type != null) {
|
105
|
+
value = ret.value;
|
106
|
+
type = ret.type;
|
107
|
+
ret = ret.js;
|
108
|
+
}
|
117
109
|
|
118
|
-
|
110
|
+
console.log(util.inspect(ret, false, 2, true), (value != null ? `\x1B[34m\x1B[3m(value: ${value}, type: ${TYPE_NAMES[type]})\x1B[0m` : ''));
|
119
111
|
|
120
|
-
|
112
|
+
prev = prev + ';\n' + source.trim();
|
113
|
+
} catch (e) {
|
114
|
+
console.log('Uncaught', e.stack);
|
115
|
+
}
|
121
116
|
|
122
117
|
callback();
|
123
118
|
};
|