@@ -66,9 +66,10 @@ let decref_closure_ident = Ident.create_persistent("GRAIN$EXPORT$decRef");
6666
6767/* Exceptions */
6868let exception_mod = "GRAIN$MODULE$runtime/exception" ;
69- let print_exception_ident = Ident . create_persistent("printException" );
70- let print_exception_closure_ident =
71- Ident . create_persistent("GRAIN$EXPORT$printException" );
69+ let panic_with_exception_ident =
70+ Ident . create_persistent("panicWithException" );
71+ let panic_with_exception_closure_ident =
72+ Ident . create_persistent("GRAIN$EXPORT$panicWithException" );
7273let assertion_error_ident = Ident . create_persistent("AssertionError" );
7374let assertion_error_closure_ident =
7475 Ident . create_persistent("GRAIN$EXPORT$AssertionError" );
@@ -109,9 +110,9 @@ let required_global_imports = [
109110 mimp_used: false ,
110111 },
111112 {
112- mimp_id: print_exception_closure_ident ,
113+ mimp_id: panic_with_exception_closure_ident ,
113114 mimp_mod: exception_mod,
114- mimp_name: Ident . name(print_exception_closure_ident ),
115+ mimp_name: Ident . name(panic_with_exception_closure_ident ),
115116 mimp_type: MGlobalImport (Types . Unmanaged (WasmI32 ), true ),
116117 mimp_kind: MImportWasm ,
117118 mimp_setup: MSetupNone ,
@@ -190,9 +191,9 @@ let runtime_global_imports =
190191
191192let required_function_imports = [
192193 {
193- mimp_id: print_exception_ident ,
194+ mimp_id: panic_with_exception_ident ,
194195 mimp_mod: exception_mod,
195- mimp_name: Ident . name(print_exception_ident ),
196+ mimp_name: Ident . name(panic_with_exception_ident ),
196197 mimp_type:
197198 MFuncImport (
198199 [ Types . Unmanaged (WasmI32 ), Types . Unmanaged (WasmI32 )] ,
@@ -346,18 +347,21 @@ let get_wasm_imported_name = (~runtime_import=true, mod_, name) => {
346347
347348let get_grain_imported_name = (mod_, name) => Ident . unique_name(name);
348349
349- let call_exception_printer = (wasm_mod, env, args) => {
350+ let call_panic_handler = (wasm_mod, env, args) => {
350351 let args = [
351352 Expression . Global_get . make(
352353 wasm_mod,
353- get_wasm_imported_name(exception_mod, print_exception_closure_ident),
354+ get_wasm_imported_name(
355+ exception_mod,
356+ panic_with_exception_closure_ident,
357+ ),
354358 Type . int32,
355359 ),
356360 ... args,
357361 ] ;
358362 Expression . Call . make(
359363 wasm_mod,
360- get_wasm_imported_name(exception_mod, print_exception_ident ),
364+ get_wasm_imported_name(exception_mod, panic_with_exception_ident ),
361365 args,
362366 Type . int32,
363367 );
@@ -1028,17 +1032,7 @@ let call_error_handler = (wasm_mod, env, err, args) => {
10281032 Type . int32,
10291033 );
10301034 };
1031- Expression . Block . make(
1032- wasm_mod,
1033- gensym_label("call_error_handler" ),
1034- [
1035- Expression . Drop . make(
1036- wasm_mod,
1037- call_exception_printer(wasm_mod, env, [ err] ),
1038- ),
1039- Expression . Unreachable . make(wasm_mod),
1040- ] ,
1041- );
1035+ call_panic_handler(wasm_mod, env, [ err] );
10421036};
10431037
10441038let error_if_true = (wasm_mod, env, cond, err, args) =>
@@ -2367,6 +2361,7 @@ let compile_prim0 = (wasm_mod, env, p0): Expression.t => {
23672361 allocate_number_uninitialized(wasm_mod, env, BoxedFloat64 )
23682362 | AllocateRational =>
23692363 allocate_number_uninitialized(wasm_mod, env, BoxedRational )
2364+ | Unreachable => Expression . Unreachable . make(wasm_mod)
23702365 };
23712366};
23722367
@@ -2486,7 +2481,7 @@ let compile_prim1 = (wasm_mod, env, p1, arg, loc): Expression.t => {
24862481 [
24872482 Expression . Drop . make(
24882483 wasm_mod,
2489- call_exception_printer (wasm_mod, env, [ compiled_arg] ),
2484+ call_panic_handler (wasm_mod, env, [ compiled_arg] ),
24902485 ),
24912486 Expression . Unreachable . make(wasm_mod),
24922487 ] ,
0 commit comments