diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 521c414684..16b5b4cd0e 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1691,9 +1691,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, unwind_and_find_exception_handler: { frame_sp -= 2; - void * exnref = (void*) GET_REF_FROM_ADDR(frame_sp); + WASMExceptionReference exnref = (void*) GET_REF_FROM_ADDR(frame_sp); - LOG_REE("THROW_REF is lookung for try-table frame and catch clauses for exnref %p", exnref); + LOG_REE("THROW_REF is looking for try-table frame and catch clauses for exnref %p", exnref); do { LOG_REE("frame_csp is a label of type %d", (frame_csp-1)->label_type); @@ -1701,13 +1701,42 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, case LABEL_TYPE_IF: case LABEL_TYPE_BLOCK: case LABEL_TYPE_LOOP: - /* that frame type have no excn handlers */ + /* that frame types do not have excn handlers */ break; case LABEL_TYPE_TRY_TABLE: /* look for clauses */ + { + uint32 num_clauses = *(int32 *)((frame_csp-1)->frame_sp); + LOG_REE("there are %d clauses in the frame", num_clauses); + + } /* to be implemented */ + uint32 handler_clause = 0; + uint32 handler_depth = 0; + switch (handler_clause) { + case EXCN_HANDLER_CLAUSE_CATCH: + /* put values */ + /* release excn instance */ + free_exnref(module, exnref); + break; + + case EXCN_HANDLER_CLAUSE_CATCH_REF: + /* put values and ref */ + break; + + case EXCN_HANDLER_CLAUSE_CATCH_ALL: + /* put nothing */ + /* release excn instance */ + free_exnref(module, exnref); + break; + + case EXCN_HANDLER_CLAUSE_CATCH_ALL_REF: + /* put ref */ + break; + } + break; case LABEL_TYPE_FUNCTION: /* return exnref to caller */ @@ -1728,6 +1757,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, goto got_exception; } + /* unwind */ POP_CSP(); } while (frame_csp > frame->csp_bottom); /* ... */ @@ -1742,10 +1772,28 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, { read_leb_int32(frame_ip, frame_ip_end, exception_tag_index); + /* get tag address */ + WASMTagInstance * ti = & module->e->tags[exception_tag_index]; + WASMFuncType * tag_type = ti->is_import_tag ? + ti->u.tag_import->tag_type : + ti->u.tag->tag_type; + /* create exception instance */ + LOG_REE("throw tag index %d, ref %p", exception_tag_index, ti); + WASMExceptionReference exnref = allocate_exnref(module, ti); + if (!exnref) { + wasm_set_exception( + module, "WASM_OP_THROW allocating an exception instance failed."); + goto got_exception; + } + + /* collect tag values */ + LOG_REE("tag has %d cells, exn has %d cells allocated", + tag_type->param_cell_num, + exnref->cells); - /* create exception ref */ - void * exnref = (void*) 0xdeadbeef; + frame_sp-=tag_type->param_cell_num; + word_copy(exnref->vals, frame_sp, tag_type->param_cell_num); /* push excnref to stack */ PUT_REF_TO_ADDR(frame_sp, exnref); @@ -2108,13 +2156,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint32 handler_tagindex; uint32 handler_targetlabel; read_leb_int32(frame_ip, frame_ip_end, handler_count); + for (i=0; i