55#if WEB49_USE_SWTICH
66#define OPCODE (n ) (n)
77#else
8- #define OPCODE (n ) ({size_t x = (n); if (ptrs[x] == NULL) {__builtin_trap ();} ptrs[x]; })
8+ #define OPCODE (n ) ({size_t x = (n); if (ptrs[x] == NULL) {web49_die ();} ptrs[x]; })
99#endif
1010
1111web49_env_t * web49_env_new (void * state , web49_env_func_t func ) {
@@ -375,10 +375,7 @@ uint32_t web49_interp_read_instr(web49_read_block_state_t *state, web49_instr_t
375375 args [i ] = n ;
376376 uint32_t end = state -> depth ;
377377 if (begin + 1 != end ) {
378- fprintf (stderr , "error: the below instruction (%s ...) did not yield exactly 1 value (debug: %" PRIu32 "+1 != %" PRIu32 ")\n" , web49_opcode_to_name (cur .args [i ].opcode ), begin , end );
379- web49_debug_print_instr (stderr , cur .args [i ]);
380- __builtin_trap ();
381- // state->depth = begin + 1;
378+ web49_error ("error: the instruction (%s ...) did not yield exactly 1 value (debug: %" PRIu32 "+1 != %" PRIu32 ")\n" , web49_opcode_to_name (cur .args [i ].opcode ), begin , end );
382379 }
383380 }
384381 // puts(web49_opcode_to_name(cur.opcode));
@@ -388,12 +385,10 @@ uint32_t web49_interp_read_instr(web49_read_block_state_t *state, web49_instr_t
388385 }
389386 uint32_t outer_end = state -> depth ;
390387 if (outer_begin + cur .nargs != outer_end ) {
391- fprintf (stderr , "error: stack should have been at %zu, but was at %zu\n" , (size_t )(outer_begin + cur .nargs ), (size_t )outer_end );
392- web49_debug_print_instr (stderr , cur );
393- __builtin_trap ();
388+ web49_error ("error: stack should have been at %zu, but was at %zu\n" , (size_t )(outer_begin + cur .nargs ), (size_t )outer_end );
394389 }
395390 if (state -> depth < cur .nargs ) {
396- __builtin_trap ( );
391+ web49_error ( "error: bad number of arguments" );
397392 }
398393 state -> depth -= cur .nargs ;
399394 if (cur .opcode == WEB49_OPCODE_NOP || cur .opcode == WEB49_OPCODE_UNREACHABLE ) {
@@ -516,8 +511,7 @@ uint32_t web49_interp_read_instr(web49_read_block_state_t *state, web49_instr_t
516511 build -> code [build -> ncode ++ ].data .v128 = WEB49_INTERP_V128 (cur .immediate .u128 );
517512 break ;
518513 default :
519- fprintf (stderr , "bad immediate: %zu\n" , (size_t )cur .immediate .id );
520- __builtin_trap ();
514+ web49_error ("bad immediate: %zu\n" , (size_t )cur .immediate .id );
521515 }
522516 return ret ;
523517}
@@ -579,8 +573,7 @@ static void web49_interp_block_run_comp(web49_interp_block_t *block, void **ptrs
579573 } else if (block -> nreturns == 1 ) {
580574 instrs [0 ].opcode = OPCODE (WEB49_OPCODE_FFI_CALL1 );
581575 } else {
582- fprintf (stderr , "error: import returns too many things\n" );
583- __builtin_trap ();
576+ web49_error ("error: import returns too many things\n" );
584577 }
585578 web49_env_t * env = NULL ;
586579 for (size_t nimport = 0 ; nimport < interp .num_env ; nimport ++ ) {
@@ -593,8 +586,7 @@ static void web49_interp_block_run_comp(web49_interp_block_t *block, void **ptrs
593586 }
594587 }
595588 if (env == NULL ) {
596- fprintf (stderr , "not implemented: %s.%s\n" , block -> module_str , block -> field_str );
597- __builtin_trap ();
589+ web49_error ("not implemented: %s.%s\n" , block -> module_str , block -> field_str );
598590 }
599591 instrs [1 ].func = env ;
600592 web49_free (block -> module_str );
0 commit comments