From 11bf96d749381be3d763d89b8dd72778cdeebfbb Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Wed, 9 Mar 2011 17:43:23 +0900 Subject: cleanup --- hieroglyph/hgoperator.c | 1378 ++++++++++++++------------------------ hieroglyph/hgoperator.h | 17 +- hieroglyph/hgvm.c | 1376 +++++++++++++++---------------------- hieroglyph/hgvm.h | 424 ++++++------ plugins/libedit/libedit-main.c | 8 +- plugins/unittest/unittest-main.c | 16 +- 6 files changed, 1293 insertions(+), 1926 deletions(-) diff --git a/hieroglyph/hgoperator.c b/hieroglyph/hgoperator.c index 33df25c..9786a29 100644 --- a/hieroglyph/hgoperator.c +++ b/hieroglyph/hgoperator.c @@ -502,17 +502,14 @@ DEFUNC_OPER (private_applyparams) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QDICT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } d = HG_VM_LOCK (vm, arg0); if (d == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } keys = g_hash_table_get_keys(vm->params); @@ -593,8 +590,7 @@ DEFUNC_OPER (private_currentpagedevice) _hg_operator_pdev_name_lookup, vm, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } hg_vm_quark_set_default_acl(vm, &q); @@ -644,12 +640,11 @@ DEFUNC_OPER (private_exit) hg_stack_drop(estack); break; } else if (HG_IS_QFILE (q)) { - hg_vm_set_error(vm, qself, HG_e_invalidexit); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidexit); } } if (i == edepth) { - hg_vm_set_error(vm, qself, HG_e_invalidexit); + hg_error_return (HG_STATUS_FAILED, HG_e_invalidexit); } else { retval = TRUE; } @@ -669,7 +664,6 @@ DEFUNC_OPER (private_findlibfile) arg0 = hg_stack_index(ostack, 0); cstr = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -681,8 +675,7 @@ DEFUNC_OPER (private_findlibfile) filename); g_free(filename); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } ret = TRUE; SET_EXPECTED_OSTACK_SIZE (1); @@ -718,19 +711,16 @@ DEFUNC_OPER (private_forceput) hg_usize_t index; if (!HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } index = HG_INT (arg1); retval = hg_vm_array_set(vm, arg0, arg2, index, TRUE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } } else if (HG_IS_QDICT (arg0)) { retval = hg_vm_dict_add(vm, arg0, arg1, arg2, TRUE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } } else if (HG_IS_QSTRING (arg0)) { @@ -738,20 +728,17 @@ DEFUNC_OPER (private_forceput) if (!HG_IS_QINT (arg1) || !HG_IS_QINT (arg2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_string_overwrite_c(s, arg2, arg1); HG_VM_UNLOCK (vm, arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_stack_drop(ostack); @@ -785,8 +772,7 @@ DEFUNC_OPER (private_odef) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QNAME (arg0) || !HG_IS_QARRAY (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (hg_vm_quark_is_executable(vm, &arg1)) { hg_array_t *a = HG_VM_LOCK (vm, arg1); @@ -812,7 +798,6 @@ DEFUNC_OPER (private_product) q = HG_QSTRING (hg_vm_get_mem(vm), "Hieroglyph PostScript Interpreter"); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_vm_quark_set_acl(vm, &q, HG_ACL_READABLE|HG_ACL_ACCESSIBLE); @@ -832,8 +817,7 @@ DEFUNC_OPER (private_quit) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_vm_shutdown(vm, HG_INT (arg0)); @@ -866,8 +850,7 @@ DEFUNC_OPER (private_setglobal) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QBOOL(arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_vm_use_global_mem(vm, HG_BOOL (arg0)); @@ -896,7 +879,6 @@ DEFUNC_OPER (private_stringcvs) q = HG_QSTRING (hg_vm_get_mem(vm), "--nostringval--"); } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -918,7 +900,6 @@ DEFUNC_OPER (private_undef) arg1 = hg_stack_index(ostack, 0); hg_vm_dict_remove(vm, arg0, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -942,19 +923,16 @@ DEFUNC_OPER (private_write_eqeq_only) arg0 = hg_stack_index(ostack, 1); arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } q = hg_vm_quark_to_string(vm, arg1, TRUE, (hg_pointer_t *)&s); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } f = HG_VM_LOCK (vm, arg0); if (f == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); hg_string_free(s, TRUE); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } cstr = hg_string_get_cstr(s); hg_file_write(f, cstr, @@ -964,7 +942,6 @@ DEFUNC_OPER (private_write_eqeq_only) g_free(cstr); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -1010,14 +987,12 @@ DEFUNC_OPER (protected_dicttomark) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { hg_stack_drop(ostack); - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } j = HG_INT (arg0); if ((j % 2) != 0) { hg_stack_drop(ostack); - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } qd = hg_dict_new(hg_vm_get_mem(vm), j / 2, @@ -1025,8 +1000,7 @@ DEFUNC_OPER (protected_dicttomark) (hg_pointer_t *)&dict); if (qd == Qnil) { hg_stack_drop(ostack); - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } hg_vm_quark_set_default_acl(vm, &qd); for (i = j; i > 0; i -= 2) { @@ -1079,7 +1053,6 @@ DEFUNC_OPER (protected_for_yield_int_continue) qq = hg_vm_quark_copy(vm, proc, NULL); if (qq == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -1126,7 +1099,6 @@ DEFUNC_OPER (protected_for_yield_real_continue) qq = hg_vm_quark_copy(vm, proc, NULL); if (qq == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -1154,7 +1126,6 @@ DEFUNC_OPER (protected_forall_array_continue) a = HG_VM_LOCK (vm, val); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } i = HG_INT (*n); @@ -1178,7 +1149,6 @@ DEFUNC_OPER (protected_forall_array_continue) q = hg_vm_quark_copy(vm, proc, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -1205,7 +1175,6 @@ DEFUNC_OPER (protected_forall_dict_continue) d = HG_VM_LOCK (vm, val); if (d == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } i = HG_INT (*n); @@ -1225,17 +1194,15 @@ DEFUNC_OPER (protected_forall_dict_continue) *n = HG_QINT (i + 1); if (!hg_dict_first_item(d, &qk, &qv)) { - hg_vm_set_error(vm, qself, HG_e_VMerror); HG_VM_UNLOCK (vm, val); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } hg_dict_remove(d, qk); HG_VM_UNLOCK (vm, val); q = hg_vm_quark_copy(vm, proc, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -1263,7 +1230,6 @@ DEFUNC_OPER (protected_forall_string_continue) s = HG_VM_LOCK (vm, val); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } i = HG_INT (*n); @@ -1287,7 +1253,6 @@ DEFUNC_OPER (protected_forall_string_continue) q = hg_vm_quark_copy(vm, proc, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -1309,7 +1274,6 @@ DEFUNC_OPER (protected_loop_continue) q = hg_vm_quark_copy(vm, qproc, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -1336,7 +1300,6 @@ DEFUNC_OPER (protected_repeat_continue) q = hg_vm_quark_copy(vm, arg1, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } STACK_PUSH (estack, q); @@ -1363,7 +1326,6 @@ DEFUNC_OPER (protected_stopped_continue) dict = HG_VM_LOCK (vm, vm->qerror); if (dict == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } qn = HG_QNAME (".stopped"); @@ -1428,8 +1390,7 @@ DEFUNC_OPER (abs) } else if (HG_IS_QREAL (arg0)) { *ret = HG_QREAL (fabs(HG_REAL (arg0))); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -1453,8 +1414,7 @@ DEFUNC_OPER (add) d1 = HG_REAL (arg0); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { d2 = HG_INT (arg1); @@ -1462,8 +1422,7 @@ DEFUNC_OPER (add) d2 = HG_REAL (arg1); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } dr = d1 + d2; @@ -1491,16 +1450,13 @@ DEFUNC_OPER (aload) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_stack_pop(ostack); @@ -1509,7 +1465,6 @@ DEFUNC_OPER (aload) for (i = 0; i < len; i++) { q = hg_array_get(a, i); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto error; } STACK_PUSH (ostack, q); @@ -1540,8 +1495,7 @@ DEFUNC_OPER (and) HG_IS_QINT (arg1)) { *ret = HG_QINT (HG_INT (arg0) & HG_INT (arg1)); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_stack_drop(ostack); @@ -1570,45 +1524,39 @@ DEFUNC_OPER (arc) } else if (HG_IS_QREAL (arg0)) { dx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { dr = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { dr = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg3)) { dangle1 = HG_INT (arg3); } else if (HG_IS_QREAL (arg3)) { dangle1 = HG_REAL (arg3); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg4)) { dangle2 = HG_INT (arg4); } else if (HG_IS_QREAL (arg4)) { dangle2 = HG_REAL (arg4); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_arc(gstate, dx, dy, dr, @@ -1647,45 +1595,39 @@ DEFUNC_OPER (arcn) } else if (HG_IS_QREAL (arg0)) { dx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { dr = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { dr = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg3)) { dangle1 = HG_INT (arg3); } else if (HG_IS_QREAL (arg3)) { dangle1 = HG_REAL (arg3); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg4)) { dangle2 = HG_INT (arg4); } else if (HG_IS_QREAL (arg4)) { dangle2 = HG_REAL (arg4); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_arcn(gstate, dx, dy, dr, @@ -1724,45 +1666,39 @@ DEFUNC_OPER (arct) } else if (HG_IS_QREAL (arg0)) { dx1 = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy1 = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy1 = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { dx2 = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { dx2 = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg3)) { dy2 = HG_INT (arg3); } else if (HG_IS_QREAL (arg3)) { dy2 = HG_REAL (arg3); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg4)) { dr = HG_INT (arg4); } else if (HG_IS_QREAL (arg4)) { dr = HG_REAL (arg4); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_arcto(gstate, dx1, dy1, dx2, dy2, dr, NULL); @@ -1799,45 +1735,39 @@ DEFUNC_OPER (arcto) } else if (HG_IS_QREAL (arg0)) { dx1 = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy1 = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy1 = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { dx2 = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { dx2 = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg3)) { dy2 = HG_INT (arg3); } else if (HG_IS_QREAL (arg3)) { dy2 = HG_REAL (arg3); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg4)) { dr = HG_INT (arg4); } else if (HG_IS_QREAL (arg4)) { dr = HG_REAL (arg4); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_arcto(gstate, dx1, dy1, dx2, dy2, dr, dt); @@ -1870,18 +1800,15 @@ DEFUNC_OPER (array) ret = hg_stack_peek(ostack, 0); arg0 = *ret; if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_INT (arg0) < 0 || HG_INT (arg0) > 65535) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } m = hg_vm_get_mem(vm); q = hg_array_new(m, HG_INT (arg0), NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } *ret = q; @@ -1903,28 +1830,27 @@ DEFUNC_OPER (astore) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } len = hg_array_maxlength(a); SET_EXPECTED_OSTACK_SIZE (-len); if (hg_stack_depth(ostack) < (len + 1)) { - hg_vm_set_error(vm, qself, HG_e_stackunderflow); - goto error; + HG_VM_UNLOCK (vm, arg0); + hg_error_return (HG_STATUS_FAILED, HG_e_stackunderflow); } for (i = 0; i < len; i++) { q = hg_stack_index(ostack, len - i); - if (!hg_array_set(a, q, i, FALSE)) - goto error; + if (!hg_array_set(a, q, i, FALSE)) { + HG_VM_UNLOCK (vm, arg0); + return FALSE; + } } for (i = 0; i <= len; i++) { if (i == 0) @@ -1936,7 +1862,6 @@ DEFUNC_OPER (astore) STACK_PUSH (ostack, arg0); retval = TRUE; - error: HG_VM_UNLOCK (vm, arg0); } DEFUNC_OPER_END @@ -1955,20 +1880,17 @@ DEFUNC_OPER (atan) } else if (HG_IS_QREAL (arg0)) { num = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { den = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { den = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_REAL_IS_ZERO (num) && HG_REAL_IS_ZERO (den)) { - hg_vm_set_error(vm, qself, HG_e_undefinedresult); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefinedresult); } angle = atan2(num, den) / (2 * M_PI / 360); if (angle < 0) @@ -1993,12 +1915,10 @@ DEFUNC_OPER (begin) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QDICT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } hg_stack_pop(ostack); @@ -2019,8 +1939,7 @@ DEFUNC_OPER (bind) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0)) { /* ignore it */ @@ -2029,7 +1948,7 @@ DEFUNC_OPER (bind) } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); goto error; } len = hg_array_maxlength(a); @@ -2070,8 +1989,7 @@ DEFUNC_OPER (bitshift) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0) || !HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_INT (arg1) < 0) { *ret = HG_QINT (HG_INT (arg0) >> -HG_INT (arg1)); @@ -2096,12 +2014,10 @@ DEFUNC_OPER (bytesavailable) ret = hg_stack_peek(ostack, 0); arg0 = *ret; if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); @@ -2130,8 +2046,7 @@ DEFUNC_OPER (ceiling) } else if (HG_IS_QREAL (arg0)) { *ret = HG_QREAL (ceil(HG_REAL (arg0))); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; } DEFUNC_OPER_END @@ -2184,7 +2099,7 @@ DEFUNC_OPER (cleartomark) } } if (i == depth) - hg_vm_set_error(vm, qself, HG_e_unmatchedmark); + hg_error_return (HG_STATUS_FAILED, HG_e_unmatchedmark); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (clip); @@ -2196,7 +2111,6 @@ DEFUNC_OPER (clippath) hg_gstate_t *gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_clippath(gstate); @@ -2213,17 +2127,14 @@ DEFUNC_OPER (closefile) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } f = HG_VM_LOCK (vm, arg0); if (f == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_file_close(f); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); HG_VM_UNLOCK (vm, arg0); return FALSE; @@ -2244,7 +2155,6 @@ DEFUNC_OPER (closepath) gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_closepath(gstate); @@ -2266,15 +2176,14 @@ DEFUNC_OPER (concat) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a = HG_VM_LOCK (vm, arg0); if (!a) return FALSE; if (!hg_array_is_matrix(a)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto finalize; + HG_VM_UNLOCK (vm, arg0); + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } hg_array_to_matrix(a, &m1); gstate = HG_VM_LOCK (vm, qg); @@ -2303,6 +2212,7 @@ DEFUNC_OPER (concatmatrix) hg_quark_t arg0, arg1, arg2; hg_array_t *a1, *a2, *a3; hg_matrix_t m1, m2, m3; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 3); @@ -2313,14 +2223,12 @@ DEFUNC_OPER (concatmatrix) if (!HG_IS_QARRAY (arg0) || !HG_IS_QARRAY (arg1) || !HG_IS_QARRAY (arg2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_readable(vm, &arg1) || !hg_vm_quark_is_writable(vm, &arg2)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } a1 = HG_VM_LOCK (vm, arg0); @@ -2330,12 +2238,12 @@ DEFUNC_OPER (concatmatrix) if (hg_array_maxlength(a1) != 6 || hg_array_maxlength(a2) != 6 || hg_array_maxlength(a3) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto error; } if (!hg_array_is_matrix(a1) || !hg_array_is_matrix(a2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); + e = HG_e_typecheck; goto error; } hg_array_to_matrix(a1, &m1); @@ -2353,6 +2261,8 @@ DEFUNC_OPER (concatmatrix) HG_VM_UNLOCK (vm, arg2); HG_VM_UNLOCK (vm, arg1); HG_VM_UNLOCK (vm, arg0); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (condition); @@ -2387,14 +2297,12 @@ DEFUNC_OPER (copy) hg_usize_t n = HG_INT (arg0); if (n < 0 || n >= hg_stack_depth(ostack)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } hg_stack_drop(ostack); for (i = 0; i < n; i++) { if (!hg_stack_push(ostack, hg_stack_index(ostack, n - 1))) { - hg_vm_set_error(vm, qself, HG_e_stackoverflow); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_stackoverflow); } } retval = TRUE; @@ -2411,21 +2319,21 @@ DEFUNC_OPER (copy) if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } a1 = HG_VM_LOCK (vm, arg0); a2 = HG_VM_LOCK (vm, arg1); if (a1 == NULL || a2 == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto a_error; } len1 = hg_array_maxlength(a1); len2 = hg_array_maxlength(a2); if (len1 > len2) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto a_error; + HG_VM_UNLOCK (vm, arg0); + HG_VM_UNLOCK (vm, arg1); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } for (i = 0; i < len1; i++) { hg_quark_t qq; @@ -2439,8 +2347,13 @@ DEFUNC_OPER (copy) q = hg_array_make_subarray(a2, 0, len1 - 1, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - goto a_error; + hg_error_t e = hg_errno; + + HG_VM_UNLOCK (vm, arg0); + HG_VM_UNLOCK (vm, arg1); + hg_errno = e; + + return FALSE; } if (hg_vm_quark_is_readable(vm, &arg1)) acl |= HG_ACL_READABLE; @@ -2466,21 +2379,21 @@ DEFUNC_OPER (copy) if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } d1 = HG_VM_LOCK (vm, arg0); d2 = HG_VM_LOCK (vm, arg1); if (d1 == NULL || d2 == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto d_error; } if (hg_vm_get_language_level(vm) == HG_LANG_LEVEL_1) { if (hg_dict_length(d2) != 0 || hg_dict_maxlength(d1) != hg_dict_maxlength(d2)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto d_error; + HG_VM_UNLOCK (vm, arg0); + HG_VM_UNLOCK (vm, arg1); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } } hg_dict_foreach(d1, _hg_operator_copy_real_traverse_dict, d2); @@ -2499,22 +2412,22 @@ DEFUNC_OPER (copy) if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } s1 = HG_VM_LOCK (vm, arg0); s2 = HG_VM_LOCK (vm, arg1); if (s1 == NULL || s2 == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto s_error; } len1 = hg_string_length(s1); mlen1 = hg_string_maxlength(s1); mlen2 = hg_string_maxlength(s2); if (mlen1 > mlen2) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto s_error; + HG_VM_UNLOCK (vm, arg0); + HG_VM_UNLOCK (vm, arg1); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } for (i = 0; i < len1; i++) { hg_char_t c = hg_string_index(s1, i); @@ -2526,7 +2439,6 @@ DEFUNC_OPER (copy) q = hg_string_make_substring(s2, 0, len1 - 1, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto s_error; } if (hg_vm_quark_is_readable(vm, &arg1)) @@ -2548,8 +2460,7 @@ DEFUNC_OPER (copy) if (s2) HG_VM_UNLOCK (vm, arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (retval) { @@ -2579,8 +2490,7 @@ DEFUNC_OPER (cos) } else if (HG_IS_QREAL (arg0)) { angle = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = HG_QREAL (cos(angle / 180 * M_PI)); @@ -2629,8 +2539,7 @@ DEFUNC_OPER (counttomark) } } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_unmatchedmark); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_unmatchedmark); } STACK_PUSH (ostack, q); @@ -2715,16 +2624,16 @@ DEFUNC_OPER (currentmatrix) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a = HG_VM_LOCK (vm, arg0); if (!a) return FALSE; if (hg_array_maxlength(a) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto finalize; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } gstate = HG_VM_LOCK (vm, qg); if (!gstate) @@ -2785,8 +2694,7 @@ DEFUNC_OPER (currentuserparams) q = hg_vm_get_user_params(vm, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } STACK_PUSH (ostack, q); @@ -2816,54 +2724,47 @@ DEFUNC_OPER (curveto) } else if (HG_IS_QREAL (arg0)) { dx1 = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy1 = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy1 = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { dx2 = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { dx2 = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg3)) { dy2 = HG_INT (arg3); } else if (HG_IS_QREAL (arg3)) { dy2 = HG_REAL (arg3); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg4)) { dx3 = HG_INT (arg4); } else if (HG_IS_QREAL (arg4)) { dx3 = HG_REAL (arg4); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg5)) { dy3 = HG_INT (arg5); } else if (HG_IS_QREAL (arg5)) { dy3 = HG_REAL (arg5); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } retval = hg_gstate_curveto(gstate, dx1, dy1, dx2, dy2, dx3, dy3); if (!retval) @@ -2898,12 +2799,10 @@ DEFUNC_OPER (cvi) hg_real_t d = HG_REAL (arg0); if (d > HG_MAXINT || d < HG_MININT) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } if (isinf(d)) { - hg_vm_set_error(vm, qself, HG_e_limitcheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } *ret = HG_QINT (d); @@ -2912,8 +2811,7 @@ DEFUNC_OPER (cvi) hg_string_t *s; if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } s = HG_VM_LOCK (vm, arg0); q = hg_file_new_with_string(hg_vm_get_mem(vm), @@ -2930,12 +2828,10 @@ DEFUNC_OPER (cvi) qq = hg_stack_pop(ostack); if (!HG_IS_QBOOL (qq)) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } if (!HG_BOOL (qq)) { - hg_vm_set_error(vm, qself, HG_e_syntaxerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_syntaxerror); } qv = hg_stack_pop(ostack); if (HG_IS_QINT (qv)) { @@ -2945,13 +2841,11 @@ DEFUNC_OPER (cvi) if (d < HG_MININT || d > HG_MAXINT) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } *ret = HG_QINT ((hg_int_t)d); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -2961,8 +2855,7 @@ DEFUNC_OPER (cvi) STACK_PUSH (ostack, qself); } } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } } DEFUNC_OPER_END @@ -2991,16 +2884,13 @@ DEFUNC_OPER (cvn) arg0 = *ret; cstr = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (hg_vm_string_length(vm, arg0) > 127) { - hg_vm_set_error(vm, qself, HG_e_limitcheck); g_free(cstr); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -3034,8 +2924,7 @@ DEFUNC_OPER (cvr) hg_string_t *s; if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } s = HG_VM_LOCK (vm, arg0); q = hg_file_new_with_string(hg_vm_get_mem(vm), @@ -3052,36 +2941,38 @@ DEFUNC_OPER (cvr) qq = hg_stack_pop(ostack); if (!HG_IS_QBOOL (qq)) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } if (!HG_BOOL (qq)) { - hg_vm_set_error(vm, qself, HG_e_syntaxerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_syntaxerror); } qv = hg_stack_pop(ostack); if (HG_IS_QINT (qv)) { qv = HG_QREAL (HG_INT (qv)); } else if (HG_IS_QREAL (qv)) { if (isinf(HG_REAL (qv))) { - hg_vm_set_error(vm, qself, HG_e_limitcheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = qv; retval = TRUE; } else { + /* drop -file- */ + hg_stack_exch(ostack); + hg_stack_drop(ostack); + /* We want to notify the place + * where the error happened as in cvr operator + * but not in -token- + */ hg_stack_drop(ostack); STACK_PUSH (ostack, qself); } } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } } DEFUNC_OPER_END @@ -3094,6 +2985,7 @@ DEFUNC_OPER (cvrs) hg_string_t *s; hg_bool_t is_real = FALSE; hg_char_t *cstr = NULL; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 3); @@ -3106,22 +2998,18 @@ DEFUNC_OPER (cvrs) } else if (HG_IS_QINT (arg0)) { d1 = HG_INT (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!HG_IS_QINT (arg1) || !HG_IS_QSTRING (arg2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } radix = HG_INT (arg1); if (radix < 2 || radix > 36) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } if (!hg_vm_quark_is_writable(vm, &arg2)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (radix == 10) { if (is_real) { @@ -3149,11 +3037,11 @@ DEFUNC_OPER (cvrs) } s = HG_VM_LOCK (vm, arg2); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_ERROR_GET_REASON (hg_errno); goto error; } if (strlen(cstr) > hg_string_maxlength(s)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto error; } hg_string_append(s, cstr, -1); @@ -3162,7 +3050,7 @@ DEFUNC_OPER (cvrs) q = hg_string_make_substring(s, 0, hg_string_length(s) - 1, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto error; } if (hg_vm_quark_is_readable(vm, &arg2)) @@ -3192,6 +3080,8 @@ DEFUNC_OPER (cvrs) if (s) HG_VM_UNLOCK (vm, arg2); g_free(cstr); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END /* cvx */ @@ -3220,7 +3110,6 @@ DEFUNC_OPER (def) retval = hg_vm_dict_add(vm, qd, arg0, arg1, FALSE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -3241,26 +3130,25 @@ DEFUNC_OPER (defaultmatrix) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } if (hg_array_maxlength(a) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto finalize; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } if (!hg_device_get_ctm(vm->device, &m) || !hg_array_from_matrix(a, &m)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto finalize; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } retval = TRUE; - finalize: HG_VM_UNLOCK (vm, arg0); } DEFUNC_OPER_END @@ -3280,23 +3168,19 @@ DEFUNC_OPER (dict) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_INT (arg0) < 0) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } if (HG_INT (arg0) > G_MAXUSHORT) { - hg_vm_set_error(vm, qself, HG_e_limitcheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } ret = hg_dict_new(hg_vm_get_mem(vm), HG_INT (arg0), hg_vm_get_language_level(vm) == HG_LANG_LEVEL_1, NULL); if (ret == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_vm_quark_set_default_acl(vm, &ret); @@ -3318,23 +3202,21 @@ DEFUNC_OPER (dictstack) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } ddepth = hg_stack_depth(dstack); len = hg_array_maxlength(a); if (ddepth > len) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto error; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } for (i = 0; i < ddepth; i++) { q = hg_stack_index(dstack, ddepth - i - 1); @@ -3346,7 +3228,6 @@ DEFUNC_OPER (dictstack) q = hg_array_make_subarray(a, 0, ddepth - 1, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto error; } if (hg_vm_quark_is_readable(vm, &arg0)) @@ -3389,20 +3270,17 @@ DEFUNC_OPER (div) } else if (HG_IS_QREAL (arg0)) { d1 = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { d2 = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { d2 = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_REAL_IS_ZERO (d2)) { - hg_vm_set_error(vm, qself, HG_e_undefinedresult); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefinedresult); } *ret = HG_QREAL (d1 / d2); @@ -3440,8 +3318,7 @@ DEFUNC_OPER (end) if ((lang >= HG_LANG_LEVEL_2 && ddepth <= 3) || (lang == HG_LANG_LEVEL_1 && ddepth <= 2)) { - hg_vm_set_error(vm, qself, HG_e_dictstackunderflow); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_dictstackunderflow); } hg_stack_drop(dstack); @@ -3458,20 +3335,17 @@ DEFUNC_OPER (eofill) hg_gstate_t *gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } if (!hg_device_eofill(vm->device, gstate)) { - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } else { - hg_vm_set_error(vm, qself, HG_e_limitcheck); + HG_VM_UNLOCK (vm, qg); + if (HG_ERROR_IS_SUCCESS0 ()) { + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } - goto finalize; + return FALSE; } - retval = TRUE; - finalize: HG_VM_UNLOCK (vm, qg); + retval = TRUE; } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (eoviewclip); @@ -3492,8 +3366,7 @@ DEFUNC_OPER (eq) !hg_vm_quark_is_readable(vm, &arg0)) || (HG_IS_QSTRING (arg1) && !hg_vm_quark_is_readable(vm, &arg1))) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } ret = hg_vm_quark_compare(vm, arg0, arg1); @@ -3512,7 +3385,6 @@ DEFUNC_OPER (eq) } else { s1 = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } } @@ -3522,7 +3394,6 @@ DEFUNC_OPER (eq) } else { s2 = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } } @@ -3581,13 +3452,11 @@ DEFUNC_OPER (exec) if (hg_vm_quark_is_executable(vm, &arg0)) { if (!HG_IS_QOPER (arg0) && !hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } q = hg_vm_quark_copy(vm, arg0, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_stack_drop(ostack); @@ -3614,23 +3483,21 @@ DEFUNC_OPER (execstack) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } edepth = hg_stack_depth(estack); len = hg_array_maxlength(a); if (edepth > len) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto error; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } /* do not include the last node */ for (i = 0; i < edepth - 1; i++) { @@ -3643,7 +3510,6 @@ DEFUNC_OPER (execstack) q = hg_array_make_subarray(a, 0, edepth - 2, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto error; } if (hg_vm_quark_is_readable(vm, &arg0)) @@ -3688,15 +3554,13 @@ DEFUNC_OPER (executeonly) HG_IS_QFILE (*arg0) || HG_IS_QSTRING (*arg0)) { if (!hg_vm_quark_is_accessible(vm, arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } hg_vm_quark_set_readable(vm, arg0, FALSE); hg_vm_quark_set_writable(vm, arg0, FALSE); hg_vm_quark_set_accessible(vm, arg0, TRUE); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -3736,8 +3600,7 @@ DEFUNC_OPER (exit) hg_stack_drop(estack); SET_EXPECTED_ESTACK_SIZE (-(i + 3)); } else if (HG_OPER (q) == HG_enc_protected_stopped_continue) { - hg_vm_set_error(vm, qself, HG_e_invalidexit); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidexit); } else { continue; } @@ -3745,12 +3608,11 @@ DEFUNC_OPER (exit) hg_stack_drop(estack); break; } else if (HG_IS_QFILE (q)) { - hg_vm_set_error(vm, qself, HG_e_invalidexit); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidexit); } } if (i == edepth) { - hg_vm_set_error(vm, qself, HG_e_invalidexit); + hg_error_return (HG_STATUS_FAILED, HG_e_invalidexit); } else { retval = TRUE; } @@ -3773,21 +3635,18 @@ DEFUNC_OPER (exp) } else if (HG_IS_QREAL (arg0)) { base = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { exponent = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { exponent = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_REAL_IS_ZERO (base) && HG_REAL_IS_ZERO (exponent)) { - hg_vm_set_error(vm, qself, HG_e_undefinedresult); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefinedresult); } *ret = HG_QREAL (pow(base, exponent)); @@ -3804,6 +3663,7 @@ DEFUNC_OPER (file) hg_file_io_t iotype; hg_file_mode_t iomode; hg_char_t *filename = NULL, *fmode = NULL; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -3811,18 +3671,16 @@ DEFUNC_OPER (file) arg1 = hg_stack_index(ostack, 0); filename = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto error; } fmode = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto error; } iotype = hg_file_get_io_type(filename); if (fmode == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto error; } switch (fmode[0]) { @@ -3836,7 +3694,7 @@ DEFUNC_OPER (file) iomode = HG_FILE_IO_MODE_APPEND; break; default: - hg_vm_set_error(vm, qself, HG_e_invalidfileaccess); + e = HG_e_invalidfileaccess; goto error; } if (fmode[1] == '+') { @@ -3849,21 +3707,20 @@ DEFUNC_OPER (file) iomode |= HG_FILE_IO_MODE_READWRITE; break; default: - hg_vm_set_error(vm, qself, HG_e_invalidfileaccess); + e = HG_e_invalidfileaccess; goto error; } } else if (fmode[1] != 0) { - hg_vm_set_error(vm, qself, HG_e_invalidfileaccess); + e = HG_e_invalidfileaccess; goto error; } if (iotype != HG_FILE_IO_FILE) { q = hg_vm_get_io(vm, iotype); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto error; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefinedfilename); + e = HG_e_undefinedfilename; goto error; } } else { @@ -3872,11 +3729,10 @@ DEFUNC_OPER (file) q = hg_file_new(hg_vm_get_mem(vm), filename, iomode, NULL); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto error; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefinedfilename); + e = HG_e_undefinedfilename; goto error; } if (iomode & (HG_FILE_IO_MODE_READ|HG_FILE_IO_MODE_APPEND)) @@ -3894,6 +3750,8 @@ DEFUNC_OPER (file) error: g_free(filename); g_free(fmode); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (filenameforall); @@ -3906,19 +3764,20 @@ DEFUNC_OPER (fill) hg_gstate_t *gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } if (!hg_device_fill(vm->device, gstate)) { - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } else { - hg_vm_set_error(vm, qself, HG_e_limitcheck); + hg_error_t e = hg_errno; + + HG_VM_UNLOCK (vm, qg); + if (HG_ERROR_IS_SUCCESS (e)) { + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } - goto finalize; + hg_errno = e; + + return FALSE; } retval = TRUE; - finalize: HG_VM_UNLOCK (vm, qg); } DEFUNC_OPER_END @@ -3936,7 +3795,6 @@ DEFUNC_OPER (flush) q = hg_vm_get_io(vm, HG_FILE_IO_STDOUT); stdout_ = HG_VM_LOCK (vm, q); if (stdout_ == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -3961,13 +3819,11 @@ DEFUNC_OPER (flushfile) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } f = HG_VM_LOCK (vm, arg0); if (!hg_file_flush(f)) { - hg_vm_set_error0(vm, qself); goto error; } retval = TRUE; @@ -3996,8 +3852,7 @@ DEFUNC_OPER (for) (!HG_IS_QINT (arg2) && !HG_IS_QREAL (arg2)) || (!HG_IS_QINT (arg1) && !HG_IS_QREAL (arg1)) || (!HG_IS_QINT (arg0) && !HG_IS_QREAL (arg0))) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QREAL (arg0) || HG_IS_QREAL (arg1) || @@ -4026,12 +3881,10 @@ DEFUNC_OPER (for) arg2 = HG_QREAL (dlimit); } if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefined); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); } STACK_PUSH (estack, arg0); @@ -4077,39 +3930,32 @@ DEFUNC_OPER (forall) arg0 = hg_stack_index(ostack, 1); arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_executable(vm, &arg1) || !hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_IS_QARRAY (arg0)) { q = hg_vm_dict_lookup(vm, vm->qsystemdict, HG_QNAME ("%forall_array_continue"), FALSE); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - return FALSE; - } } else if (HG_IS_QDICT (arg0)) { hg_quark_acl_t acl = 0; dict = HG_VM_LOCK (vm, arg0); - if (dict == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + if (dict == NULL) return FALSE; - } qd = hg_dict_new(dict->o.mem, hg_dict_maxlength(dict), dict->raise_dictfull, (hg_pointer_t *)&new_dict); if (qd == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); HG_VM_UNLOCK (vm, arg0); - goto d_error; + HG_VM_UNLOCK (vm, qd); + + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } if (hg_vm_quark_is_readable(vm, &arg0)) acl |= HG_ACL_READABLE; @@ -4128,27 +3974,16 @@ DEFUNC_OPER (forall) q = hg_vm_dict_lookup(vm, vm->qsystemdict, HG_QNAME ("%forall_dict_continue"), FALSE); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } - d_error: HG_VM_UNLOCK (vm, qd); } else if (HG_IS_QSTRING (arg0)) { q = hg_vm_dict_lookup(vm, vm->qsystemdict, HG_QNAME ("%forall_string_continue"), FALSE); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - return FALSE; - } } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (q == Qnil) { - if (!hg_vm_has_error(vm)) - hg_vm_set_error(vm, qself, HG_e_undefined); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); } STACK_PUSH (estack, HG_QINT (0)); @@ -4221,12 +4056,10 @@ DEFUNC_OPER (ge) cs1 = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } cs2 = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } q = HG_QBOOL (strcmp(cs1, cs2) >= 0); @@ -4235,8 +4068,7 @@ DEFUNC_OPER (ge) g_free(cs1); g_free(cs2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (q != Qnil) { *ret = q; @@ -4262,42 +4094,37 @@ DEFUNC_OPER (get) arg1 = hg_stack_index(ostack, 0); if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_IS_QARRAY (arg0)) { hg_array_t *a; hg_size_t index, len; if (!HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } index = HG_INT (arg1); len = hg_array_maxlength(a); if (index < 0 || index >= len) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto a_error; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } q = hg_array_get(a, index); retval = TRUE; - a_error: HG_VM_UNLOCK (vm, arg0); } else if (HG_IS_QDICT (arg0)) { q = hg_vm_dict_lookup(vm, arg0, arg1, TRUE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefined); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); } retval = TRUE; } else if (HG_IS_QSTRING (arg0)) { @@ -4306,29 +4133,26 @@ DEFUNC_OPER (get) hg_char_t c; if (!HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } index = HG_INT (arg1); len = hg_string_length(s); if (index < 0 || index >= len) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto s_error; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } c = hg_string_index(s, index); q = HG_QINT (c); retval = TRUE; - s_error: HG_VM_UNLOCK (vm, arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (retval) { hg_stack_drop(ostack); @@ -4348,6 +4172,7 @@ DEFUNC_OPER (getinterval) hg_quark_t arg0, arg1, arg2, q = Qnil; hg_size_t len, index, count; hg_quark_acl_t acl = 0; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 3); @@ -4356,12 +4181,10 @@ DEFUNC_OPER (getinterval) arg2 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg1) || !HG_IS_QINT (arg2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } index = HG_INT (arg1); @@ -4371,13 +4194,12 @@ DEFUNC_OPER (getinterval) hg_array_t *a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } len = hg_array_maxlength(a); if (index >= len || (len - index) < count) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto error; } q = hg_array_make_subarray(a, index, index + count - 1, NULL); @@ -4385,22 +4207,20 @@ DEFUNC_OPER (getinterval) hg_string_t *s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } len = hg_string_maxlength(s); if (index >= len || (len - index) < count) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto error; } q = hg_string_make_substring(s, index, index + count - 1, NULL); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto error; } if (hg_vm_quark_is_readable(vm, &arg0)) @@ -4423,6 +4243,8 @@ DEFUNC_OPER (getinterval) SET_EXPECTED_OSTACK_SIZE (-2); error: HG_VM_UNLOCK (vm, arg0); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (glyphshow); @@ -4438,7 +4260,6 @@ DEFUNC_OPER (grestore) g = HG_VM_LOCK (vm, q); if (g == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_vm_set_gstate(vm, q); @@ -4461,7 +4282,6 @@ DEFUNC_OPER (grestoreall) g = HG_VM_LOCK (vm, q); if (g == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_vm_set_gstate(vm, q); @@ -4481,7 +4301,6 @@ DEFUNC_OPER (gsave) q = hg_vm_quark_copy(vm, qg, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } STACK_PUSH (vm->stacks[HG_VM_STACK_GSTATE], qg); @@ -4524,12 +4343,10 @@ DEFUNC_OPER (gt) cs1 = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } cs2 = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } q = HG_QBOOL (strcmp(cs1, cs2) > 0); @@ -4538,8 +4355,7 @@ DEFUNC_OPER (gt) g_free(cs1); g_free(cs2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (q != Qnil) { *ret = q; @@ -4562,26 +4378,23 @@ DEFUNC_OPER (identmatrix) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a = HG_VM_LOCK (vm, arg0); if (!a) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - goto error; + return FALSE; } if (hg_array_maxlength(a) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto error; + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } hg_matrix_init_identity(&m); hg_array_from_matrix(a, &m); retval = TRUE; - error: - if (a) - HG_VM_UNLOCK (vm, arg0); + HG_VM_UNLOCK (vm, arg0); } DEFUNC_OPER_END /* idiv */ @@ -4596,8 +4409,7 @@ DEFUNC_OPER (idiv) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0) || !HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = HG_QINT (HG_INT (arg0) / HG_INT (arg1)); @@ -4619,22 +4431,18 @@ DEFUNC_OPER (if) arg0 = hg_stack_index(ostack, 1); arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QBOOL (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!HG_IS_QARRAY (arg1) || !hg_vm_quark_is_executable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_BOOL (arg0)) { q = hg_vm_quark_copy(vm, arg1, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } STACK_PUSH (estack, q); @@ -4659,26 +4467,21 @@ DEFUNC_OPER (ifelse) arg1 = hg_stack_index(ostack, 1); arg2 = hg_stack_index(ostack, 0); if (!HG_IS_QBOOL (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!HG_IS_QARRAY (arg1) || !hg_vm_quark_is_executable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (!HG_IS_QARRAY (arg2) || !hg_vm_quark_is_executable(vm, &arg2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg2)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_BOOL (arg0)) { q = hg_vm_quark_copy(vm, arg1, NULL); @@ -4686,7 +4489,6 @@ DEFUNC_OPER (ifelse) q = hg_vm_quark_copy(vm, arg2, NULL); } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } STACK_PUSH (estack, q); @@ -4713,14 +4515,12 @@ DEFUNC_OPER (index) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } n = HG_INT (arg0); if (n < 0 || (n + 1) >= hg_stack_depth(ostack)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } q = hg_stack_index(ostack, n + 1); hg_stack_drop(ostack); @@ -4763,6 +4563,7 @@ DEFUNC_OPER (invertmatrix) hg_quark_t arg0, arg1; hg_array_t *a1 = NULL, *a2 = NULL; hg_matrix_t m1, m2; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -4771,28 +4572,27 @@ DEFUNC_OPER (invertmatrix) if (!HG_IS_QARRAY (arg0) || !HG_IS_QARRAY (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a1 = HG_VM_LOCK (vm, arg0); a2 = HG_VM_LOCK (vm, arg1); if (!a1 || !a2) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto error; } if (!hg_array_is_matrix(a1)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto error; } if (hg_array_maxlength(a2) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto error; } hg_array_to_matrix(a1, &m1); if (!hg_matrix_invert(&m1, &m2)) { - hg_vm_set_error(vm, qself, HG_e_undefinedresult); + e = HG_e_undefinedresult; goto error; } hg_array_from_matrix(a2, &m2); @@ -4807,6 +4607,8 @@ DEFUNC_OPER (invertmatrix) HG_VM_UNLOCK (vm, arg0); if (a2) HG_VM_UNLOCK (vm, arg1); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (itransform); @@ -4824,16 +4626,13 @@ DEFUNC_OPER (known) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QDICT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } q = hg_vm_dict_lookup(vm, arg0, arg1, TRUE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -4887,12 +4686,10 @@ DEFUNC_OPER (le) cs1 = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } cs2 = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } q = HG_QBOOL (strcmp(cs1, cs2) <= 0); @@ -4901,8 +4698,7 @@ DEFUNC_OPER (le) g_free(cs1); g_free(cs2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (q != Qnil) { *ret = q; @@ -4929,14 +4725,12 @@ DEFUNC_OPER (length) arg0 = *ret; if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_IS_QARRAY (arg0)) { hg_array_t *a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } *ret = HG_QINT (hg_array_maxlength(a)); @@ -4945,7 +4739,6 @@ DEFUNC_OPER (length) hg_dict_t *d = HG_VM_LOCK (vm, arg0); if (d == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } *ret = HG_QINT (hg_dict_length(d)); @@ -4954,7 +4747,6 @@ DEFUNC_OPER (length) hg_string_t *s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } *ret = HG_QINT (hg_string_maxlength(s)); @@ -4963,13 +4755,11 @@ DEFUNC_OPER (length) const hg_char_t *n = hg_name_lookup(arg0); if (n == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } *ret = HG_QINT (strlen(n)); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -4992,21 +4782,18 @@ DEFUNC_OPER (lineto) } else if (HG_IS_QREAL (arg0)) { dx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_lineto(gstate, dx, dy); @@ -5035,13 +4822,11 @@ DEFUNC_OPER (ln) } else if (HG_IS_QREAL (arg0)) { d = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_REAL_LE (d, 0)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } *ret = HG_QREAL (log(d)); @@ -5065,13 +4850,11 @@ DEFUNC_OPER (log) } else if (HG_IS_QREAL (arg0)) { d = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_REAL_LE (d, 0)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } *ret = HG_QREAL (log10(d)); @@ -5087,24 +4870,20 @@ DEFUNC_OPER (loop) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_executable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } q = hg_vm_dict_lookup(vm, vm->qsystemdict, HG_QNAME ("%loop_continue"), FALSE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefined); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); } STACK_PUSH (estack, arg0); @@ -5149,12 +4928,10 @@ DEFUNC_OPER (lt) cs1 = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } cs2 = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } q = HG_QBOOL (strcmp(cs1, cs2) < 0); @@ -5163,8 +4940,7 @@ DEFUNC_OPER (lt) g_free(cs1); g_free(cs2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (q != Qnil) { *ret = q; @@ -5189,12 +4965,10 @@ DEFUNC_OPER (maxlength) ret = hg_stack_peek(ostack, 0); arg0 = *ret; if (!HG_IS_QDICT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } dict = HG_VM_LOCK (vm, arg0); if (dict == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } *ret = HG_QINT (hg_dict_maxlength(dict)); @@ -5215,12 +4989,10 @@ DEFUNC_OPER (mod) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0) || !HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_INT (arg1) == 0) { - hg_vm_set_error(vm, qself, HG_e_undefinedresult); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefinedresult); } *ret = HG_QINT (HG_INT (arg0) % HG_INT (arg1)); @@ -5249,21 +5021,18 @@ DEFUNC_OPER (moveto) } else if (HG_IS_QREAL (arg0)) { dx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_moveto(gstate, dx, dy); @@ -5295,8 +5064,7 @@ DEFUNC_OPER (mul) d1 = HG_REAL (arg0); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { d2 = HG_INT (arg1); @@ -5304,8 +5072,7 @@ DEFUNC_OPER (mul) d2 = HG_REAL (arg1); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } dr = d1 * d2; @@ -5335,8 +5102,7 @@ DEFUNC_OPER (ne) arg1 = hg_stack_index(ostack, 0); if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } ret = !hg_vm_quark_compare(vm, arg0, arg1); if (ret) { @@ -5354,7 +5120,6 @@ DEFUNC_OPER (ne) } else { s1 = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } } @@ -5364,7 +5129,6 @@ DEFUNC_OPER (ne) } else { s2 = hg_vm_string_get_cstr(vm, arg1); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); goto s_error; } } @@ -5417,8 +5181,7 @@ DEFUNC_OPER (neg) d = -HG_REAL (arg0); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (is_int && @@ -5440,8 +5203,7 @@ DEFUNC_OPER (newpath) gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } retval = hg_gstate_newpath(gstate); @@ -5467,8 +5229,7 @@ DEFUNC_OPER (noaccess) HG_IS_QDICT (*arg0)) { hg_vm_quark_set_acl(vm, arg0, 0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -5490,8 +5251,7 @@ DEFUNC_OPER (not) } else if (HG_IS_QINT (arg0)) { *ret = HG_QINT (-HG_INT (arg0)); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -5519,8 +5279,7 @@ DEFUNC_OPER (or) HG_IS_QINT (arg1)) { *ret = HG_QINT (HG_INT (arg0) | HG_INT (arg1)); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_stack_drop(ostack); @@ -5539,7 +5298,6 @@ DEFUNC_OPER (pathbbox) hg_gstate_t *gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_pathbbox(gstate, @@ -5583,22 +5341,18 @@ DEFUNC_OPER (print) arg0 = hg_stack_index(ostack, 0); cstr = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } qstdout = hg_vm_get_io(vm, HG_FILE_IO_STDOUT); stdout = HG_VM_LOCK (vm, qstdout); if (stdout == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); goto error; } hg_file_write(stdout, cstr, sizeof (hg_char_t), hg_vm_string_length(vm, arg0)); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } else { + if (HG_ERROR_IS_SUCCESS0 ()) { hg_stack_drop(ostack); retval = TRUE; @@ -5627,33 +5381,28 @@ DEFUNC_OPER (put) arg1 = hg_stack_index(ostack, 1); arg2 = hg_stack_index(ostack, 0); if (!hg_vm_quark_is_writable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } is_in_global = hg_quark_has_mem_id(arg0, vm->mem_id[HG_VM_MEM_GLOBAL]); if (is_in_global && !hg_quark_is_simple_object(arg2) && hg_quark_has_mem_id(arg2, vm->mem_id[HG_VM_MEM_LOCAL])) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_IS_QARRAY (arg0)) { hg_usize_t index; if (!HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } index = HG_INT (arg1); retval = hg_vm_array_set(vm, arg0, arg2, index, FALSE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } } else if (HG_IS_QDICT (arg0)) { retval = hg_vm_dict_add(vm, arg0, arg1, arg2, FALSE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } } else if (HG_IS_QSTRING (arg0)) { @@ -5661,20 +5410,17 @@ DEFUNC_OPER (put) if (!HG_IS_QINT (arg1) || !HG_IS_QINT (arg2)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_string_overwrite_c(s, arg2, arg1); HG_VM_UNLOCK (vm, arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (retval) { @@ -5716,8 +5462,7 @@ DEFUNC_OPER (rcheck) !HG_IS_QDICT (arg0) && !HG_IS_QFILE (arg0) && !HG_IS_QSTRING (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = HG_QBOOL (hg_vm_quark_is_readable(vm, &arg0)); @@ -5745,53 +5490,46 @@ DEFUNC_OPER (rcurveto) } else if (HG_IS_QREAL (arg0)) { dx1 = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy1 = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { dy1 = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { dx2 = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { dx2 = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg3)) { dy2 = HG_INT (arg3); } else if (HG_IS_QREAL (arg3)) { dy2 = HG_REAL (arg3); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg4)) { dx3 = HG_INT (arg4); } else if (HG_IS_QREAL (arg4)) { dx3 = HG_REAL (arg4); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg5)) { dy3 = HG_INT (arg5); } else if (HG_IS_QREAL (arg5)) { dy3 = HG_REAL (arg5); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_rcurveto(gstate, dx1, dy1, dx2, dy2, dx3, dy3); @@ -5823,16 +5561,13 @@ DEFUNC_OPER (read) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); if (f == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_file_read(f, c, sizeof (hg_char_t), 1); @@ -5844,9 +5579,7 @@ DEFUNC_OPER (read) STACK_PUSH (ostack, HG_QBOOL (FALSE)); retval = TRUE; - } else if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } else { + } else if (HG_ERROR_IS_SUCCESS0 ()) { hg_stack_drop(ostack); STACK_PUSH (ostack, HG_QINT ((guchar)c[0])); @@ -5865,6 +5598,7 @@ DEFUNC_OPER (readhexstring) hg_char_t c[2], hex = 0; hg_int_t shift = 4; hg_size_t ret; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -5872,32 +5606,28 @@ DEFUNC_OPER (readhexstring) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!HG_IS_QSTRING (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); if (f == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } s = HG_VM_LOCK (vm, arg1); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } if (hg_string_maxlength(s) == 0) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto finalize; } hg_string_clear(s); @@ -5907,7 +5637,7 @@ DEFUNC_OPER (readhexstring) if (ret == 0) { break; } else if (ret < 0) { - hg_vm_set_error(vm, qself, HG_e_ioerror); + e = HG_e_ioerror; goto finalize; } if (c[0] >= '0' && c[0] <= '9') { @@ -5931,7 +5661,7 @@ DEFUNC_OPER (readhexstring) q = HG_QBOOL (FALSE); qs = hg_string_make_substring(s, 0, hg_string_length(s) - 1, NULL); if (qs == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } if (hg_vm_quark_is_readable(vm, &arg1)) @@ -5962,6 +5692,8 @@ DEFUNC_OPER (readhexstring) HG_VM_UNLOCK (vm, arg0); if (s) HG_VM_UNLOCK (vm, arg1); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END /* readline */ @@ -5974,6 +5706,7 @@ DEFUNC_OPER (readline) hg_bool_t eol = FALSE; hg_size_t ret; hg_quark_acl_t acl = 0; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -5981,27 +5714,23 @@ DEFUNC_OPER (readline) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!HG_IS_QSTRING (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); if (f == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } s = HG_VM_LOCK (vm, arg1); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } @@ -6009,7 +5738,7 @@ DEFUNC_OPER (readline) while (!hg_file_is_eof(f)) { if (hg_string_length(s) >= hg_string_maxlength(s)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto finalize; } retry: @@ -6017,7 +5746,7 @@ DEFUNC_OPER (readline) if (ret == 0) { break; } else if (ret < 0) { - hg_vm_set_error(vm, qself, HG_e_ioerror); + e = HG_e_ioerror; goto finalize; } if (c[0] == '\r') { @@ -6042,7 +5771,7 @@ DEFUNC_OPER (readline) } qs = hg_string_make_substring(s, 0, hg_string_length(s) - 1, NULL); if (qs == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } if (hg_vm_quark_is_readable(vm, &arg1)) @@ -6067,6 +5796,8 @@ DEFUNC_OPER (readline) HG_VM_UNLOCK (vm, arg0); if (s) HG_VM_UNLOCK (vm, arg1); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END /* -array- readonly -array- @@ -6086,8 +5817,7 @@ DEFUNC_OPER (readonly) !HG_IS_QDICT (*arg0) && !HG_IS_QFILE (*arg0) && !HG_IS_QSTRING (*arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_vm_quark_set_writable(vm, arg0, FALSE); @@ -6102,6 +5832,7 @@ DEFUNC_OPER (readstring) hg_string_t *s = NULL; hg_char_t c[2]; hg_size_t ret; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -6109,32 +5840,28 @@ DEFUNC_OPER (readstring) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!HG_IS_QSTRING (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_writable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); if (f == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } s = HG_VM_LOCK (vm, arg1); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } if (hg_string_maxlength(s) == 0) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto finalize; } hg_string_clear(s); @@ -6144,7 +5871,7 @@ DEFUNC_OPER (readstring) if (ret == 0) { break; } else if (ret < 0) { - hg_vm_set_error(vm, qself, HG_e_ioerror); + e = HG_e_ioerror; goto finalize; } hg_string_append_c(s, c[0]); @@ -6155,7 +5882,7 @@ DEFUNC_OPER (readstring) q = HG_QBOOL (FALSE); qs = hg_string_make_substring(s, 0, hg_string_length(s) - 1, NULL); if (qs == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } if (hg_vm_quark_is_readable(vm, &arg1)) @@ -6186,6 +5913,8 @@ DEFUNC_OPER (readstring) HG_VM_UNLOCK (vm, arg0); if (s) HG_VM_UNLOCK (vm, arg1); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (realtime); @@ -6209,28 +5938,23 @@ DEFUNC_OPER (repeat) if (!HG_IS_QINT (arg0) || !HG_IS_QARRAY (arg1) || !hg_vm_quark_is_executable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (HG_INT (arg0) < 0) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } q = hg_vm_dict_lookup(vm, vm->qsystemdict, HG_QNAME ("%repeat_continue"), FALSE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefined); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); } STACK_PUSH (estack, arg0); @@ -6259,7 +5983,6 @@ DEFUNC_OPER (restore) arg0 = hg_stack_index(ostack, 0); if (!hg_vm_snapshot_restore(vm, arg0)) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -6287,21 +6010,18 @@ DEFUNC_OPER (rlineto) } else if (HG_IS_QREAL (arg0)) { dx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy = HG_INT (arg0); } else if (HG_IS_QREAL (arg1)) { dy = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } retval = hg_gstate_rlineto(gstate, dx, dy); @@ -6332,22 +6052,19 @@ DEFUNC_OPER (rmoveto) } else if (HG_IS_QREAL (arg0)) { dx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { dy = HG_INT (arg0); } else if (HG_IS_QREAL (arg1)) { dy = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } retval = hg_gstate_rmoveto(gstate, dx, dy); if (!retval) @@ -6372,12 +6089,10 @@ DEFUNC_OPER (roll) if (!HG_IS_QINT (arg0) || !HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_INT (arg0) < 0) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } CHECK_STACK (ostack, HG_INT (arg0) + 2); @@ -6416,9 +6131,9 @@ DEFUNC_OPER (rotate) if (!a) return FALSE; if (hg_array_maxlength(a) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); HG_VM_UNLOCK (vm, arg1); - return FALSE; + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } HG_VM_UNLOCK (vm, arg1); ctm.mtx.xx = 1; @@ -6439,8 +6154,7 @@ DEFUNC_OPER (rotate) } else if (HG_IS_QREAL (arg0)) { angle = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_matrix_rotate(&ctm, angle); @@ -6497,8 +6211,7 @@ DEFUNC_OPER (round) *ret = HG_QREAL (dr); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -6517,8 +6230,6 @@ DEFUNC_OPER (rrand) DEFUNC_OPER (save) { if (!hg_vm_snapshot_save(vm)) { - hg_vm_set_error0(vm, qself); - return FALSE; } @@ -6538,6 +6249,7 @@ DEFUNC_OPER (search) hg_string_t *s = NULL, *seek = NULL; hg_usize_t len0, len1; hg_char_t *cs0 = NULL, *cs1 = NULL, *p; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -6546,19 +6258,18 @@ DEFUNC_OPER (search) if (!HG_IS_QSTRING (arg0) || !HG_IS_QSTRING (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); return FALSE; } if (!hg_vm_quark_is_readable(vm, &arg0) || !hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } s = HG_VM_LOCK (vm, arg0); seek = HG_VM_LOCK (vm, arg1); if (!s || !seek) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } @@ -6579,7 +6290,7 @@ DEFUNC_OPER (search) if (qpre == Qnil || qmatch == Qnil || qpost == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } @@ -6608,6 +6319,8 @@ DEFUNC_OPER (search) HG_VM_UNLOCK (vm, arg0); if (seek) HG_VM_UNLOCK (vm, arg1); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (selectfont); @@ -6639,25 +6352,21 @@ DEFUNC_OPER (setdash) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { offset = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { offset = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } if (!hg_gstate_set_dash(gstate, arg0, offset)) { - hg_vm_set_error0(vm, qself); goto finalize; } @@ -6691,8 +6400,7 @@ DEFUNC_OPER (setgray) } else if (HG_IS_QREAL (arg0)) { d = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (d > 1.0) d = 1.0; @@ -6700,7 +6408,6 @@ DEFUNC_OPER (setgray) d = 0.0; gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_gstate_set_graycolor(gstate, d); @@ -6734,24 +6441,21 @@ DEFUNC_OPER (sethsbcolor) } else if (HG_IS_QREAL (arg0)) { h = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { s = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { s = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg2)) { b = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { b = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (!gstate) @@ -6781,17 +6485,14 @@ DEFUNC_OPER (setlinecap) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } i = HG_INT (arg0); if (i < 0 || i > 2) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_gstate_set_linecap(gstate, i); @@ -6815,17 +6516,14 @@ DEFUNC_OPER (setlinejoin) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } i = HG_INT (arg0); if (i < 0 || i > 2) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_gstate_set_linejoin(gstate, i); @@ -6853,12 +6551,10 @@ DEFUNC_OPER (setlinewidth) } else if (HG_IS_QREAL (arg0)) { d = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_gstate_set_linewidth(gstate, d); @@ -6878,28 +6574,27 @@ DEFUNC_OPER (setmatrix) hg_array_t *a; hg_matrix_t m; hg_gstate_t *gstate = NULL; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 1); arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QARRAY (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } a = HG_VM_LOCK (vm, arg0); if (a == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto finalize; } if (!hg_array_is_matrix(a) || !hg_array_to_matrix(a, &m)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); + e = HG_e_rangecheck; goto finalize; } hg_gstate_set_ctm(gstate, &m); @@ -6912,6 +6607,8 @@ DEFUNC_OPER (setmatrix) if (gstate) HG_VM_UNLOCK (vm, qg); HG_VM_UNLOCK (vm, arg0); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END /* setmiterlimit - */ @@ -6930,24 +6627,22 @@ DEFUNC_OPER (setmiterlimit) } else if (HG_IS_QREAL (arg0)) { miterlen = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } if (!hg_gstate_set_miterlimit(gstate, miterlen)) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - goto finalize; + HG_VM_UNLOCK (vm, qg); + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } hg_stack_drop(ostack); retval = TRUE; SET_EXPECTED_OSTACK_SIZE (-1); - finalize: HG_VM_UNLOCK (vm, qg); } DEFUNC_OPER_END @@ -6974,28 +6669,24 @@ DEFUNC_OPER (setrgbcolor) } else if (HG_IS_QREAL (arg0)) { r = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } if (HG_IS_QINT (arg1)) { g = HG_INT (arg1); } else if (HG_IS_QREAL (arg0)) { g = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } if (HG_IS_QINT (arg2)) { b = HG_INT (arg2); } else if (HG_IS_QREAL (arg2)) { b = HG_REAL (arg2); } else { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_gstate_set_rgbcolor(gstate, r, g, b); @@ -7029,7 +6720,6 @@ DEFUNC_OPER (setuserparams) hg_vm_set_user_params(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -7059,8 +6749,7 @@ DEFUNC_OPER (sin) } else if (HG_IS_QREAL (arg0)) { angle = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = HG_QREAL (sin(angle / 180 * M_PI)); @@ -7082,8 +6771,7 @@ DEFUNC_OPER (sqrt) } else if (HG_IS_QREAL (arg0)) { d = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = HG_QREAL (sqrt(d)); @@ -7100,8 +6788,7 @@ DEFUNC_OPER (srand) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_vm_set_rand_seed(vm, HG_INT (arg0)); @@ -7130,7 +6817,6 @@ DEFUNC_OPER (status) hg_file_t *f = HG_VM_LOCK (vm, arg0); if (!f) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } q = HG_QBOOL (!hg_file_is_closed(f)); @@ -7148,7 +6834,6 @@ DEFUNC_OPER (status) filename = hg_vm_string_get_cstr(vm, arg0); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } @@ -7168,8 +6853,7 @@ DEFUNC_OPER (status) SET_EXPECTED_OSTACK_SIZE (5 - 1); } } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } retval = TRUE; @@ -7199,7 +6883,6 @@ DEFUNC_OPER (stop) HG_QNAME (".stopped"), HG_QBOOL (TRUE), FALSE)) { - hg_vm_set_error0(vm, qself); return FALSE; } for (; i > 1; i--) { @@ -7222,20 +6905,17 @@ DEFUNC_OPER (stopped) if (!hg_quark_is_simple_object(arg0) && !HG_IS_QOPER (arg0) && !hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } if (hg_vm_quark_is_executable(vm, &arg0)) { q = hg_vm_dict_lookup(vm, vm->qsystemdict, HG_QNAME ("%stopped_continue"), FALSE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_undefined); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); } STACK_PUSH (estack, q); @@ -7264,17 +6944,14 @@ DEFUNC_OPER (string) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } len = HG_INT (arg0); if (len < 0 || len > 65535) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } q = hg_string_new(hg_vm_get_mem(vm), len, NULL); if (q == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } @@ -7294,19 +6971,20 @@ DEFUNC_OPER (stroke) hg_gstate_t *gstate = HG_VM_LOCK (vm, qg); if (gstate == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } if (!hg_device_stroke(vm->device, gstate)) { - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } else { - hg_vm_set_error(vm, qself, HG_e_limitcheck); + hg_error_t e = hg_errno; + + HG_VM_UNLOCK (vm, qg); + if (HG_ERROR_IS_SUCCESS (e)) { + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); } - goto finalize; + hg_errno = e; + + return FALSE; } retval = TRUE; - finalize: HG_VM_UNLOCK (vm, qg); } DEFUNC_OPER_END @@ -7330,8 +7008,7 @@ DEFUNC_OPER (sub) d1 = HG_REAL (arg0); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { d2 = HG_INT (arg1); @@ -7339,8 +7016,7 @@ DEFUNC_OPER (sub) d2 = HG_REAL (arg1); is_int = FALSE; } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (is_int) { @@ -7362,59 +7038,57 @@ DEFUNC_OPER (sub) DEFUNC_OPER (token) { hg_quark_t arg0, qt; - hg_bool_t is_proceeded = FALSE; CHECK_STACK (ostack, 1); arg0 = hg_stack_index(ostack, 0); if (HG_IS_QFILE (arg0)) { if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } hg_quark_set_executable(&arg0, TRUE); STACK_PUSH (estack, arg0); - hg_vm_stepi(vm, &is_proceeded); - if (hg_vm_has_error(vm)) { - hg_stack_drop(ostack); /* the object where the error happened */ - /* We want to notify the place - * where the error happened as in token operator - * but not in --file-- - */ - STACK_PUSH (ostack, qself); - - return FALSE; - } else { - hg_quark_t q; - - if (is_proceeded) { - /* EOF may detected */ + if (!hg_vm_translate(vm, HG_TRANS_FLAG_TOKEN)) { + if (!hg_vm_has_error(vm)) { + /* EOF detected */ + qt = hg_stack_index(ostack, 0); hg_stack_drop(ostack); /* the file object given for token operator */ STACK_PUSH (ostack, HG_QBOOL (FALSE)); SET_EXPECTED_OSTACK_SIZE (0); } else { - qt = hg_stack_index(estack, 0); - if (HG_IS_QFILE (qt)) { - /* scanner may detected the procedure. - * in this case, the scanned object doesn't appear in the exec stack. - */ - q = hg_stack_pop(ostack); - } else { - q = hg_stack_pop(estack); - } - - hg_stack_drop(estack); /* the file object executed above */ - hg_stack_drop(ostack); /* the file object given for token operator */ + hg_stack_drop(ostack); /* the object where the error happened */ + /* We want to notify the place + * where the error happened as in token operator + * but not in --file-- + */ + STACK_PUSH (ostack, qself); - STACK_PUSH (ostack, q); - STACK_PUSH (ostack, HG_QBOOL (TRUE)); + return FALSE; + } + } else { + hg_quark_t q; - SET_EXPECTED_OSTACK_SIZE (1); + qt = hg_stack_index(estack, 0); + if (HG_IS_QFILE (qt)) { + /* scanner may detected the procedure. + * in this case, the scanned object doesn't appear in the exec stack. + */ + q = hg_stack_pop(ostack); + } else { + q = hg_stack_pop(estack); } + + hg_stack_drop(estack); /* the file object executed above */ + hg_stack_drop(ostack); /* the file object given for token operator */ + + STACK_PUSH (ostack, q); + STACK_PUSH (ostack, HG_QBOOL (TRUE)); + + SET_EXPECTED_OSTACK_SIZE (1); } retval = TRUE; @@ -7423,12 +7097,10 @@ DEFUNC_OPER (token) hg_quark_t qf; if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } s = HG_VM_LOCK (vm, arg0); if (!s) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } qf = hg_file_new_with_string(hg_vm_get_mem(vm), @@ -7439,31 +7111,15 @@ DEFUNC_OPER (token) NULL); HG_VM_UNLOCK (vm, arg0); if (qf == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } hg_quark_set_executable(&qf, TRUE); STACK_PUSH (estack, qf); - hg_vm_stepi(vm, &is_proceeded); - if (hg_vm_has_error(vm)) { - hg_stack_drop(ostack); /* the object where the error happened */ - /* We want to notify the place - * where the error happened as in token operator - * but not in --file-- - */ - STACK_PUSH (ostack, qself); - - return FALSE; - } else { - hg_quark_t q, qs; - hg_file_t *f; - hg_size_t pos; - hg_uint_t length; - - if (is_proceeded) { - /* EOF may detected */ + if (!hg_vm_translate(vm, HG_TRANS_FLAG_TOKEN)) { + if (!hg_vm_has_error(vm)) { + /* EOF detected */ hg_stack_drop(ostack); /* the string object given for token operator */ STACK_PUSH (ostack, HG_QBOOL (FALSE)); @@ -7471,57 +7127,66 @@ DEFUNC_OPER (token) retval = TRUE; SET_EXPECTED_OSTACK_SIZE (0); } else { - qt = hg_stack_index(estack, 0); - if (HG_IS_QFILE (qt)) { - /* scanner may detected the procedure. - * in this case, the scanned object doesn't appear in the exec stack. - */ - q = hg_stack_pop(ostack); - } else { - q = hg_stack_pop(estack); - } - - f = HG_VM_LOCK (vm, qf); - if (!f) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; - } + hg_stack_drop(ostack); /* the object where the error happened */ + /* We want to notify the place + * where the error happened as in token operator + * but not in --file-- + */ + STACK_PUSH (ostack, qself); - pos = hg_file_seek(f, 0, HG_FILE_POS_CURRENT); - HG_VM_UNLOCK (vm, qf); + return FALSE; + } + } else { + hg_quark_t q, qs; + hg_file_t *f; + hg_size_t pos; + hg_uint_t length; - /* safely drop the file object from the stack here. - * shouldn't do that during someone is referring it because it may be destroyed by GC. + qt = hg_stack_index(estack, 0); + if (HG_IS_QFILE (qt)) { + /* scanner may detected the procedure. + * in this case, the scanned object doesn't appear in the exec stack. */ - hg_stack_drop(estack); /* the file object executed above */ + q = hg_stack_pop(ostack); + } else { + q = hg_stack_pop(estack); + } - s = HG_VM_LOCK (vm, arg0); - if (!s) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; - } + f = HG_VM_LOCK (vm, qf); + if (!f) + return FALSE; + pos = hg_file_seek(f, 0, HG_FILE_POS_CURRENT); + HG_VM_UNLOCK (vm, qf); - length = hg_string_maxlength(s) - 1; - qs = hg_string_make_substring(s, pos, length, NULL); - if (qs == Qnil) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - goto s_finalize; - } - hg_stack_drop(ostack); /* the string object given for token operator */ + /* safely drop the file object from the stack here. + * shouldn't do that during someone is referring it because it may be destroyed by GC. + */ + hg_stack_drop(estack); /* the file object executed above */ - STACK_PUSH (ostack, qs); - STACK_PUSH (ostack, q); - STACK_PUSH (ostack, HG_QBOOL (TRUE)); + s = HG_VM_LOCK (vm, arg0); + if (!s) { + return FALSE; + } - retval = TRUE; - SET_EXPECTED_OSTACK_SIZE (2); - s_finalize: + length = hg_string_maxlength(s) - 1; + qs = hg_string_make_substring(s, pos, length, NULL); + if (qs == Qnil) { HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } + hg_stack_drop(ostack); /* the string object given for token operator */ + + STACK_PUSH (ostack, qs); + STACK_PUSH (ostack, q); + STACK_PUSH (ostack, HG_QBOOL (TRUE)); + + retval = TRUE; + SET_EXPECTED_OSTACK_SIZE (2); + HG_VM_UNLOCK (vm, arg0); } } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } } DEFUNC_OPER_END @@ -7553,9 +7218,9 @@ DEFUNC_OPER (translate) if (!a) return FALSE; if (hg_array_maxlength(a) != 6) { - hg_vm_set_error(vm, qself, HG_e_rangecheck); HG_VM_UNLOCK (vm, arg2); - return FALSE; + + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } HG_VM_UNLOCK (vm, arg2); ctm.mtx.xx = 1; @@ -7576,16 +7241,14 @@ DEFUNC_OPER (translate) } else if (HG_IS_QREAL (arg0)) { tx = HG_REAL (arg0); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (HG_IS_QINT (arg1)) { ty = HG_INT (arg1); } else if (HG_IS_QREAL (arg1)) { ty = HG_REAL (arg1); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_matrix_translate(&ctm, tx, ty); @@ -7663,8 +7326,7 @@ DEFUNC_OPER (vmreclaim) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QINT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } switch (HG_INT (arg0)) { case -2: @@ -7683,8 +7345,7 @@ DEFUNC_OPER (vmreclaim) hg_mem_spool_run_gc(vm->mem[HG_VM_MEM_LOCAL]); break; default: - hg_vm_set_error(vm, qself, HG_e_rangecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_rangecheck); } hg_stack_drop(ostack); @@ -7726,8 +7387,7 @@ DEFUNC_OPER (wcheck) !HG_IS_QDICT (arg0) && !HG_IS_QFILE (arg0) && !HG_IS_QSTRING (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } *ret = HG_QBOOL (hg_vm_quark_is_writable(vm, &arg0)); @@ -7749,7 +7409,6 @@ DEFUNC_OPER (where) q = hg_stack_index(dstack, i); qq = hg_vm_dict_lookup(vm, q, arg0, TRUE); if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); return FALSE; } if (qq != Qnil) @@ -7785,23 +7444,17 @@ DEFUNC_OPER (write) if (!HG_IS_QFILE (arg0) || !HG_IS_QINT (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); if (!f) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } c[0] = HG_INT (arg1) % 256; retval = (hg_file_write(f, c, sizeof (hg_char_t), 1) > 0); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } HG_VM_UNLOCK (vm, arg0); hg_stack_drop(ostack); @@ -7817,6 +7470,7 @@ DEFUNC_OPER (writehexstring) hg_string_t *s; hg_char_t *cstr; hg_usize_t length, i; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 2); @@ -7824,26 +7478,24 @@ DEFUNC_OPER (writehexstring) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0) || !HG_IS_QSTRING (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0) || !hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); s = HG_VM_LOCK (vm, arg1); if (f == NULL || s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); + e = HG_e_VMerror; goto error; } cstr = hg_string_get_cstr(s); length = hg_string_maxlength(s); for (i = 0; i < length; i++) { if (hg_file_append_printf(f, "%x", cstr[i] & 0xff) < 0) { - hg_vm_set_error(vm, qself, HG_e_ioerror); + e = HG_e_ioerror; goto error; } } @@ -7855,6 +7507,8 @@ DEFUNC_OPER (writehexstring) error: HG_VM_UNLOCK (vm, arg0); HG_VM_UNLOCK (vm, arg1); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END DEFUNC_UNIMPLEMENTED_OPER (writeobject); @@ -7873,33 +7527,30 @@ DEFUNC_OPER (writestring) arg1 = hg_stack_index(ostack, 0); if (!HG_IS_QFILE (arg0) || !HG_IS_QSTRING (arg1)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_writable(vm, &arg0) || !hg_vm_quark_is_readable(vm, &arg1)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } f = HG_VM_LOCK (vm, arg0); + if (!f) + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); s = HG_VM_LOCK (vm, arg1); - if (f == NULL || - s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - goto error; + if (!s) { + HG_VM_UNLOCK (vm, arg0); + + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } cstr = hg_string_get_cstr(s); hg_file_write(f, cstr, sizeof (hg_char_t), hg_string_length(s)); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error0(vm, qself); - } else { + if (HG_ERROR_IS_SUCCESS0 ()) { retval = TRUE; hg_stack_drop(ostack); hg_stack_drop(ostack); } SET_EXPECTED_OSTACK_SIZE (-2); - error: HG_VM_UNLOCK (vm, arg0); HG_VM_UNLOCK (vm, arg1); } DEFUNC_OPER_END @@ -7940,8 +7591,7 @@ DEFUNC_OPER (xor) HG_IS_QINT (arg1)) { *ret = HG_QINT (HG_INT (arg0) ^ HG_INT (arg1)); } else { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } hg_stack_drop(ostack); diff --git a/hieroglyph/hgoperator.h b/hieroglyph/hgoperator.h index dc9e019..c84de04 100644 --- a/hieroglyph/hgoperator.h +++ b/hieroglyph/hgoperator.h @@ -168,10 +168,7 @@ typedef hg_bool_t (* hg_operator_func_t) (hg_vm_t *vm); OPER_FUNC_NAME (_n_) (hg_vm_t *vm) \ { \ hg_warning("%s isn't yet implemented.", #_n_); \ - hg_vm_set_error(vm, \ - hg_stack_index(vm->stacks[HG_VM_STACK_ESTACK], 0), \ - HG_e_VMerror); \ - return FALSE; \ + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); \ } #define DEFUNC_OPER_END \ HG_STMT_END; \ @@ -183,23 +180,21 @@ typedef hg_bool_t (* hg_operator_func_t) (hg_vm_t *vm); #define CHECK_STACK(_s_,_n_) \ HG_STMT_START { \ if (hg_stack_depth((_s_)) < (_n_)) { \ - hg_vm_set_error(vm, qself, HG_e_stackunderflow); \ - return FALSE; \ + hg_error_return (HG_STATUS_FAILED, HG_e_stackunderflow); \ } \ } HG_STMT_END #define STACK_PUSH(_s_,_q_) \ HG_STMT_START { \ if (!hg_stack_push((_s_), (_q_))) { \ if ((_s_) == ostack) { \ - hg_vm_set_error(vm, qself, HG_e_stackoverflow); \ + hg_error_return (HG_STATUS_FAILED, HG_e_stackoverflow); \ } else if ((_s_) == estack) { \ - hg_vm_set_error(vm, qself, HG_e_execstackoverflow); \ + hg_error_return (HG_STATUS_FAILED, HG_e_execstackoverflow); \ } else if ((_s_) == dstack) { \ - hg_vm_set_error(vm, qself, HG_e_dictstackoverflow); \ + hg_error_return (HG_STATUS_FAILED, HG_e_dictstackoverflow); \ } else { \ - hg_vm_set_error(vm, qself, HG_e_limitcheck); \ + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); \ } \ - return FALSE; \ } \ } HG_STMT_END diff --git a/hieroglyph/hgvm.c b/hieroglyph/hgvm.c index 94092a9..e9d3d5e 100644 --- a/hieroglyph/hgvm.c +++ b/hieroglyph/hgvm.c @@ -51,9 +51,9 @@ #define HG_VM_GLOBAL_MEM_SIZE 24000000 #define HG_VM_LOCAL_MEM_SIZE 1000000 #define _HG_VM_LOCK(_v_,_q_) \ - (_hg_vm_real_lock_object((_v_),(_q_),__PRETTY_FUNCTION__)) + (_hg_vm_quark_lock_object((_v_),(_q_),__PRETTY_FUNCTION__)) #define _HG_VM_UNLOCK(_v_,_q_) \ - (_hg_vm_real_unlock_object((_v_),(_q_))) + (_hg_vm_quark_unlock_object((_v_),(_q_))) #undef HG_VM_DEBUG @@ -86,11 +86,24 @@ hg_bool_t __hg_vm_is_initialized = FALSE; /*< private >*/ HG_INLINE_FUNC hg_mem_t * -_hg_vm_get_mem(hg_vm_t *vm, - hg_quark_t quark) +_hg_vm_get_mem(hg_vm_t *vm) +{ + hg_return_val_if_fail (vm != NULL, NULL, HG_e_VMerror); + hg_return_val_if_fail (vm->vm_state->current_mem_index < HG_VM_MEM_END, NULL, HG_e_VMerror); + + return vm->mem[vm->vm_state->current_mem_index]; +} + +HG_INLINE_FUNC hg_mem_t * +_hg_vm_quark_get_mem(hg_vm_t *vm, + hg_quark_t quark) { hg_mem_t *retval = NULL; - hg_int_t id = hg_quark_get_mem_id(quark); + hg_int_t id; + + hg_return_val_if_fail (vm != NULL, NULL, HG_e_VMerror); + + id = hg_quark_get_mem_id(quark); if (vm->mem_id[HG_VM_MEM_GLOBAL] == id) { retval = vm->mem[HG_VM_MEM_GLOBAL]; @@ -98,26 +111,36 @@ _hg_vm_get_mem(hg_vm_t *vm, retval = vm->mem[HG_VM_MEM_LOCAL]; } else { hg_warning("Unknown memory spooler id: %d, quark: %lx", id, quark); + hg_error_return_val (NULL, HG_STATUS_FAILED, HG_e_VMerror); } return retval; } +HG_INLINE_FUNC void +_hg_vm_quark_free(hg_vm_t *vm, + hg_quark_t qdata) +{ + hg_mem_t *m = _hg_vm_quark_get_mem(vm, qdata); + + hg_mem_free(m, qdata); +} + HG_INLINE_FUNC hg_pointer_t -_hg_vm_real_lock_object(hg_vm_t *vm, - hg_quark_t qdata, - const hg_char_t *pretty_function) +_hg_vm_quark_lock_object(hg_vm_t *vm, + hg_quark_t qdata, + const hg_char_t *pretty_function) { - return _hg_mem_lock_object(_hg_vm_get_mem(vm, qdata), + return _hg_mem_lock_object(_hg_vm_quark_get_mem(vm, qdata), qdata, pretty_function); } HG_INLINE_FUNC void -_hg_vm_real_unlock_object(hg_vm_t *vm, - hg_quark_t qdata) +_hg_vm_quark_unlock_object(hg_vm_t *vm, + hg_quark_t qdata) { - hg_mem_unlock_object(_hg_vm_get_mem(vm, qdata), + hg_mem_unlock_object(_hg_vm_quark_get_mem(vm, qdata), qdata); } @@ -206,7 +229,7 @@ _hg_vm_stack_real_dump(hg_mem_t *mem, } else { hg_uint_t id; - id = hg_mem_get_id(hg_vm_get_mem_from_quark(ddata->vm, qdata)); + id = hg_quark_get_mem_id(qdata); mc = (id == ddata->vm->mem_id[HG_VM_MEM_GLOBAL] ? 'G' : id == ddata->vm->mem_id[HG_VM_MEM_LOCAL] ? 'L' : '?'); } hg_file_append_printf(ddata->ofile, "0x%016lx|%-12s|%c| %c%c%c|%s\n", @@ -240,199 +263,285 @@ _hg_vm_rs_real_dump(hg_quark_t qdata, } static hg_bool_t -hg_vm_stepi_in_exec_array(hg_vm_t *vm, - hg_quark_t qparent) +_hg_vm_translate(hg_vm_t *vm, + hg_vm_trans_flags_t flags) { - hg_stack_t *ostack, *estack; - hg_quark_t qexecobj, qresult; - hg_file_t *file; - hg_bool_t retval = TRUE; - const hg_char_t *name; + hg_stack_t *estack, *ostack; + hg_quark_t qdata, qresult; + hg_int_t clock_count = 0; + hg_bool_t translate_block = (flags & HG_TRANS_FLAG_BLOCK); + hg_bool_t translate_token = (flags & HG_TRANS_FLAG_TOKEN); + hg_bool_t translated, block_terminated = (translate_block ? FALSE : TRUE); ostack = vm->stacks[HG_VM_STACK_OSTACK]; estack = vm->stacks[HG_VM_STACK_ESTACK]; - qexecobj = hg_stack_index(estack, 0); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error(vm, qparent, HG_e_stackunderflow); - goto finalize; + if (hg_stack_depth(estack) == 0) { + hg_warning("No objects in the exec stack"); + return TRUE; } - switch (hg_quark_get_type(qexecobj)) { - case HG_TYPE_EVAL_NAME: - if (hg_vm_quark_is_executable(vm, &qexecobj)) { - qresult = hg_vm_dstack_lookup(vm, qexecobj); - if (qresult == Qnil) { - hg_vm_set_error(vm, qparent, - HG_e_undefined); - return FALSE; + do { + translated = FALSE; + qdata = hg_stack_index(estack, 0); + if (!HG_ERROR_IS_SUCCESS0 ()) + return FALSE; + + hg_debug(HG_MSGCAT_VM, "Processing 0x%lx [%d]", qdata, clock_count); + clock_count++; + + evaluate: + switch (hg_quark_get_type(qdata)) { + case HG_TYPE_REAL: + if (isinf(HG_REAL (qdata))) + hg_error_return (HG_STATUS_FAILED, HG_e_limitcheck); + case HG_TYPE_NULL: + case HG_TYPE_INT: + case HG_TYPE_BOOL: + case HG_TYPE_DICT: + case HG_TYPE_MARK: + case HG_TYPE_SNAPSHOT: + case HG_TYPE_GSTATE: + push_stack: + if (!hg_stack_push(ostack, qdata)) + hg_error_return (HG_STATUS_FAILED, HG_e_stackoverflow); + hg_stack_drop(estack); + translated = TRUE; + break; + case HG_TYPE_EVAL_NAME: + if (hg_vm_quark_is_executable(vm, &qdata)) { + qresult = hg_vm_dstack_lookup(vm, qdata); + if (qresult == Qnil) + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); + + /* Re-evaluate the object immediately */ + qdata = qresult; + hg_debug(HG_MSGCAT_VM, "Re-processing 0x%lx", qdata); + if (translate_block || + translate_token) + goto push_stack; + goto evaluate; } - qexecobj = qresult; - } else { - hg_warning("Immediately evaluated name object somehow doesn't have a exec bit turned on: %s", hg_name_lookup(qexecobj)); - } - case HG_TYPE_NULL: - case HG_TYPE_INT: - goto push_stack; - case HG_TYPE_REAL: - if (isinf(HG_REAL (qexecobj))) { - hg_vm_set_error(vm, qparent, - HG_e_limitcheck); - return FALSE; - } - case HG_TYPE_BOOL: - case HG_TYPE_DICT: - case HG_TYPE_MARK: - case HG_TYPE_NAME: - case HG_TYPE_ARRAY: - case HG_TYPE_STRING: - case HG_TYPE_OPER: - push_stack: - if (!hg_stack_push(ostack, qexecobj)) { - hg_vm_set_error(vm, qparent, - HG_e_stackoverflow); - return FALSE; - } - hg_stack_drop(estack); - break; - case HG_TYPE_FILE: - if (!hg_vm_quark_is_executable(vm, &qexecobj)) { + hg_warning("Immediately evaluated name object somehow does not have an exec bit turned on: %s", hg_name_lookup(qdata)); goto push_stack; - } else { - file = _HG_VM_LOCK (vm, qexecobj); - if (file == NULL) - break; - hg_scanner_attach_file(vm->scanner, file); - _HG_VM_UNLOCK (vm, qexecobj); + case HG_TYPE_NAME: + if (translate_block || + translate_token) + goto push_stack; + if (hg_vm_quark_is_executable(vm, &qdata)) { + hg_quark_t q; + + qresult = hg_vm_dstack_lookup(vm, qdata); + if (qresult == Qnil) + hg_error_return (HG_STATUS_FAILED, HG_e_undefined); + + if (hg_vm_quark_is_executable(vm, &qresult)) { + q = hg_vm_quark_copy(vm, qresult, NULL); + if (q == Qnil) + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); + } else { + q = qresult; + } + if (!hg_stack_push(estack, q)) + hg_error_return (HG_STATUS_FAILED, HG_e_execstackoverflow); - if (!hg_scanner_scan(vm->scanner, vm)) { - hg_vm_set_error(vm, qparent, - HG_e_syntaxerror); - retval = FALSE; + hg_stack_exch(estack); + hg_stack_drop(estack); break; } - qresult = hg_scanner_get_token(vm->scanner); - hg_vm_quark_set_default_acl(vm, &qresult); -#if defined (HG_DEBUG) && defined (HG_VM_DEBUG) - HG_STMT_START { - hg_quark_t qs; - hg_string_t *s; - - qs = hg_vm_quark_to_string(vm, qresult, TRUE, (hg_pointer_t *)&s); - if (qs == Qnil) { - hg_warning("Unable to lookup the scanned object: %lx", qresult); - } else { - hg_char_t *cstr = hg_string_get_cstr(s); - - hg_debug(HG_MSGCAT_SCAN, "[%d] scanning... %s [%s:%c%c%c]", - vm->n_nest_scan, cstr, - hg_quark_get_type_name(qresult), - hg_quark_is_readable(qresult) ? 'r' : '-', - hg_quark_is_writable(qresult) ? 'w' : '-', - hg_quark_is_executable(qresult) ? 'x' : '-'); - g_free(cstr); - /* this is an instant object. - * surely no reference to the container. - * so it can be safely destroyed. - */ - hg_string_free(s, TRUE); - } - } HG_STMT_END; -#endif - /* exception for processing the executable array */ - if (HG_IS_QNAME (qresult) && - (name = hg_name_lookup(qresult)) != NULL) { - if (!strcmp(name, "{")) { - qresult = hg_vm_step_in_exec_array(vm, qparent); - if (qresult == Qnil) - return FALSE; -#if defined (HG_DEBUG) && defined (HG_VM_DEBUG) - HG_STMT_START { - hg_quark_t qs; - hg_string_t *s; - - qs = hg_vm_quark_to_string(vm, qresult, TRUE, (hg_pointer_t *)&s); - if (qs == Qnil) { - hg_warning("Unable to look up the scanned object: %lx", qresult); + goto push_stack; + case HG_TYPE_ARRAY: + if (translate_block || + translate_token) + goto push_stack; + if (hg_vm_quark_is_executable(vm, &qdata)) { + hg_array_t *a = _HG_VM_LOCK (vm, qdata); + hg_error_reason_t e = 0; + + if (!a) + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); + if (hg_array_length(a) > 0) { + hg_stack_t *s; + + qresult = hg_array_get(a, 0); + if (!HG_ERROR_IS_SUCCESS0 ()) { + e = HG_ERROR_GET_REASON (hg_errno); + goto a_error; + } + if (hg_vm_quark_is_executable(vm, &qresult) && + (HG_IS_QNAME (qresult) || + HG_IS_QOPER (qresult))) { + e = HG_e_execstackoverflow; + s = estack; + } else { + e = HG_e_stackoverflow; + s = ostack; + translated = TRUE; + } + if (hg_stack_push(s, qresult)) { + e = 0; + if (hg_array_length(a) == 1) { + if (s == estack) + hg_stack_exch(estack); + hg_stack_drop(estack); + translated = TRUE; } else { - hg_char_t *cstr = hg_string_get_cstr(s); - - hg_debug(HG_MSGCAT_SCAN, "[%d] scanned result %s [%s:%c%c%c]", - vm->n_nest_scan, cstr, - hg_quark_get_type_name(qresult), - hg_quark_is_readable(qresult) ? 'r' : '-', - hg_quark_is_writable(qresult) ? 'w' : '-', - hg_quark_is_executable(qresult) ? 'x' : '-'); - g_free(cstr); - /* this is an instant object. - * surely no reference to the container. - * so it can be safely destroyed. - */ - hg_string_free(s, TRUE); + hg_array_remove(a, 0); } - } HG_STMT_END; + } + } else { + hg_stack_drop(estack); + translated = TRUE; + } + a_error: + _HG_VM_UNLOCK (vm, qdata); + if (e != 0) + hg_error_return (HG_STATUS_FAILED, e); + break; + } + goto push_stack; + case HG_TYPE_STRING: + if (translate_block || + translate_token) + goto push_stack; + if (hg_vm_quark_is_executable(vm, &qdata)) { + hg_string_t *s = _HG_VM_LOCK (vm, qdata); + + if (!s) + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); + qresult = hg_file_new_with_string(_hg_vm_get_mem(vm), + "%sfile", + HG_FILE_IO_MODE_READ, + s, + NULL, + NULL); + if (qresult == Qnil) + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); + hg_vm_quark_set_executable(vm, &qresult, TRUE); + _HG_VM_UNLOCK (vm, qdata); + hg_stack_drop(estack); + if (!hg_stack_push(estack, qresult)) + hg_error_return (HG_STATUS_FAILED, HG_e_execstackoverflow); + break; + } + goto push_stack; + case HG_TYPE_OPER: + if (translate_block || + translate_token) + goto push_stack; + if (hg_operator_invoke(qdata, vm)) { + hg_stack_drop(estack); +#ifdef HG_DEBUG + if (!HG_ERROR_IS_SUCCESS0 ()) { + hg_warning("status conflict in hg_errno"); + } #endif - } else if (!strcmp(name, "}")) { - hg_size_t i, idx = 0; - hg_quark_t q; - hg_array_t *a; - - idx = hg_stack_depth(ostack); - qresult = hg_array_new(hg_vm_get_mem(vm), - idx, - (hg_pointer_t *)&a); - if (qresult == Qnil) { - hg_vm_set_error(vm, qparent, - HG_e_VMerror); + } else { + if (HG_ERROR_IS_SUCCESS0 () && !hg_vm_has_error(vm)) { + hg_critical("No error set."); + hg_operator_invoke(HG_QOPER (HG_enc_private_abort), vm); + } + } + translated = TRUE; + break; + case HG_TYPE_FILE: + if (!hg_vm_quark_is_executable(vm, &qdata)) { + goto push_stack; + } else { + hg_file_t *f = _HG_VM_LOCK (vm, qdata); + const hg_char_t *name; + + if (!f) + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); + hg_scanner_attach_file(vm->scanner, f); + if (!hg_scanner_scan(vm->scanner, vm)) { + hg_bool_t is_eof = hg_file_is_eof(f); + + _HG_VM_UNLOCK (vm, qdata); + if (HG_ERROR_IS_SUCCESS0 () && + is_eof && + !translate_block) { + hg_debug(HG_MSGCAT_VM, "EOF detected"); + hg_stack_drop(estack); + return FALSE; } - hg_vm_quark_set_default_acl(vm, &qresult); - hg_vm_quark_set_executable(vm, &qresult, TRUE); - for (i = idx - 1; i >= 0; i--) { - q = hg_stack_index(ostack, i); - if (!HG_ERROR_IS_SUCCESS0 ()) - goto finalize; - if (!hg_array_set(a, q, idx - i - 1, FALSE)) - goto finalize; - } - _HG_VM_UNLOCK (vm, qresult); - - for (i = 0; i <= idx; i++) { - hg_stack_drop(ostack); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error(vm, qparent, - HG_e_stackunderflow); - goto finalize; + hg_error_return (HG_STATUS_FAILED, HG_e_syntaxerror); + } + _HG_VM_UNLOCK (vm, qdata); + qresult = hg_scanner_get_token(vm->scanner); + hg_vm_quark_set_default_acl(vm, &qresult); + + /* exception for processing the executable array */ + if (HG_IS_QNAME (qresult) && + (name = hg_name_lookup(qresult)) != NULL) { + if (!strcmp(name, "{")) { + qresult = _hg_vm_translate_block(vm, flags); + if (qresult == Qnil) { + translated = TRUE; + break; } - } - if (!hg_stack_push(ostack, qresult)) - hg_vm_set_error(vm, qparent, - HG_e_stackoverflow); + if (!hg_stack_push(ostack, qresult)) + hg_error_return (HG_STATUS_FAILED, HG_e_stackoverflow); + translated = TRUE; + break; + } else if (!strcmp(name, "}")) { + hg_size_t i, idx = 0; + hg_quark_t q; + hg_array_t *a; + + if (!translate_block) + hg_error_return (HG_STATUS_FAILED, HG_e_syntaxerror); + + idx = hg_stack_depth(ostack); + qresult = hg_array_new(_hg_vm_get_mem(vm), + idx, + (hg_pointer_t *)&a); + if (qresult == Qnil) + return FALSE; + hg_vm_quark_set_default_acl(vm, &qresult); + hg_vm_quark_set_executable(vm, &qresult, TRUE); + for (i = idx - 1; i >= 0; i--) { + q = hg_stack_index(ostack, i); + if (!HG_ERROR_IS_SUCCESS0 ()) { + _HG_VM_UNLOCK (vm, qresult); + return FALSE; + } + if (!hg_array_set(a, q, idx - i - 1, FALSE)) { + _HG_VM_UNLOCK (vm, qresult); + return FALSE; + } + } + _HG_VM_UNLOCK (vm, qresult); - return FALSE; + for (i = 0; i <= idx; i++) { + hg_stack_drop(ostack); + if (!HG_ERROR_IS_SUCCESS0 ()) + return FALSE; + } + if (!hg_stack_push(ostack, qresult)) + return FALSE; + + translated = TRUE; + block_terminated = TRUE; + break; + } } + hg_stack_push(estack, qresult); } - hg_stack_push(estack, qresult); - } - break; - default: - hg_warning("Unknown object type: %d", hg_quark_get_type(qexecobj)); - return FALSE; - } - - finalize: - if (!HG_ERROR_IS_SUCCESS0 ()) { - if (!hg_vm_has_error(vm)) - hg_vm_set_error(vm, qexecobj, HG_e_VMerror); - retval = FALSE; - } + break; + default: + hg_warning("Unknown object type: %d", hg_quark_get_type(qdata)); + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); + } + } while (!(translated && block_terminated)); - return retval; + return HG_ERROR_IS_SUCCESS0 (); } static hg_quark_t -hg_vm_step_in_exec_array(hg_vm_t *vm, - hg_quark_t qparent) +_hg_vm_translate_block(hg_vm_t *vm, + hg_vm_trans_flags_t flags) { hg_stack_t *old_ostack; hg_quark_t retval = Qnil; @@ -442,17 +551,14 @@ hg_vm_step_in_exec_array(hg_vm_t *vm, old_ostack = vm->stacks[HG_VM_STACK_OSTACK]; vm->stacks[HG_VM_STACK_OSTACK] = hg_vm_stack_new(vm, 65535); if (vm->stacks[HG_VM_STACK_OSTACK] == NULL) { - /* unable to dup the correct stacks in this case */ + /* unable to duplicate the stack */ vm->stacks[HG_VM_STACK_OSTACK] = old_ostack; - hg_vm_set_error(vm, qparent, HG_e_VMerror); - - return FALSE; + hg_error_return_val (Qnil, HG_STATUS_FAILED, HG_e_VMerror); } - while (hg_vm_stepi_in_exec_array(vm, qparent)); - if (!hg_vm_has_error(vm)) { - retval = hg_stack_index(vm->stacks[HG_VM_STACK_OSTACK], - 0); + _hg_vm_translate(vm, flags | HG_TRANS_FLAG_BLOCK); + if (HG_ERROR_IS_SUCCESS0 ()) { + retval = hg_stack_index(vm->stacks[HG_VM_STACK_OSTACK], 0); } hg_stack_free(vm->stacks[HG_VM_STACK_OSTACK]); @@ -759,6 +865,123 @@ _hg_vm_restore_mark(hg_snapshot_t *snapshot, return TRUE; } +static hg_bool_t +_hg_vm_set_error(hg_vm_t *vm, + hg_quark_t qdata, + hg_error_reason_t error) +{ + hg_quark_t qerrordict, qnerrordict, qhandler, q; + hg_usize_t i; + + hg_return_val_if_fail (vm != NULL, FALSE, HG_e_VMerror); + hg_return_val_if_fail (error < HG_e_END, FALSE, HG_e_VMerror); + + if (vm->has_error) { + hg_quark_t qerrorname = HG_QNAME ("errorname"); + hg_quark_t qcommand = HG_QNAME ("command"); + hg_quark_t qresult_err, qresult_cmd, qwhere; + hg_dict_t *derror; + hg_string_t *where; + hg_char_t *scommand, *swhere; + + derror = _HG_VM_LOCK (vm, vm->qerror); + if (derror == NULL) + goto fatal_error; + qresult_err = hg_dict_lookup(derror, qerrorname); + qresult_cmd = hg_dict_lookup(derror, qcommand); + _HG_VM_UNLOCK (vm, vm->qerror); + + if (qresult_cmd == Qnil) { + scommand = g_strdup("-%unknown%-"); + } else { + hg_string_t *s = NULL; + + q = hg_vm_quark_to_string(vm, + qresult_cmd, + TRUE, + (hg_pointer_t *)&s); + if (q == Qnil) + scommand = g_strdup("-%ENOMEM%-"); + else + scommand = hg_string_get_cstr(s); + /* this is an instant object. + * surely no reference to the container. + * so it can be safely destroyed. + */ + hg_string_free(s, TRUE); + } + qwhere = hg_vm_quark_to_string(vm, + qdata, + TRUE, + (hg_pointer_t *)&where); + if (qwhere == Qnil) + swhere = g_strdup("-%ENOMEM%-"); + else + swhere = hg_string_get_cstr(where); + _hg_vm_quark_free(vm, qwhere); + + if (qresult_err == Qnil) { + g_printerr("Multiple errors occurred.\n" + " previous error: unknown or this happened at %s prior to set /errorname\n" + " current error: %s at %s\n", + scommand, + hg_name_lookup(vm->qerror_name[error]), + swhere); + } else { + g_printerr("Multiple errors occurred.\n" + " previous error: %s at %s\n" + " current error: %s at %s\n", + hg_name_lookup(qresult_err), + scommand, + hg_name_lookup(vm->qerror_name[error]), + swhere); + } + g_free(swhere); + g_free(scommand); + + hg_operator_invoke(HG_QOPER (HG_enc_private_abort), vm); + } + for (i = 0; i < HG_VM_STACK_END; i++) { + hg_stack_set_validation(vm->stacks[i], FALSE); + } + qnerrordict = HG_QNAME ("errordict"); + qerrordict = hg_vm_dstack_lookup(vm, qnerrordict); + if (qerrordict == Qnil) { + hg_critical("Unable to lookup errordict"); + + hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_VMerror); + goto fatal_error; + } + qhandler = hg_vm_dict_lookup(vm, qerrordict, vm->qerror_name[error], FALSE); + if (qhandler == Qnil) { + hg_critical("Unable to obtain the error handler for %s", + hg_name_lookup(vm->qerror_name[error])); + hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_VMerror); + goto fatal_error; + } + + q = hg_vm_quark_copy(vm, qhandler, NULL); + if (q == Qnil) + goto fatal_error; + hg_stack_push(vm->stacks[HG_VM_STACK_ESTACK], q); + hg_stack_push(vm->stacks[HG_VM_STACK_OSTACK], qdata); + vm->has_error = TRUE; + + return TRUE; + fatal_error: + G_STMT_START { + const hg_char_t *errname = hg_name_lookup(vm->qerror_name[error]); + + if (errname) { + hg_critical("Fatal error during recovering from /%s", errname); + } else { + hg_critical("Fatal error during recovering from the unknown error"); + } + + return hg_operator_invoke(HG_QOPER (HG_enc_private_abort), vm); + } G_STMT_END; +} + /*< public >*/ /** * hg_vm_init: @@ -774,7 +997,7 @@ hg_vm_init(void) __hg_vm_mem = hg_mem_spool_new(HG_MEM_TYPE_MASTER, HG_VM_MEM_SIZE); if (__hg_vm_mem == NULL) - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); __hg_vm_is_initialized = TRUE; @@ -795,11 +1018,11 @@ hg_vm_init(void) goto error; } - return TRUE; + hg_error_return (HG_STATUS_SUCCESS, 0); error: hg_vm_tini(); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } /** @@ -1033,7 +1256,7 @@ hg_vm_destroy(hg_vm_t *vm) hg_stack_spooler_destroy(vm->stack_spooler); for (i = 0; i < HG_FILE_IO_END; i++) { if (vm->qio[i] != Qnil) - hg_vm_mfree(vm, vm->qio[i]); + _hg_vm_quark_free(vm, vm->qio[i]); } for (i = 0; i < HG_VM_MEM_END; i++) { hg_mem_spool_destroy(vm->mem[i]); @@ -1090,69 +1313,7 @@ hg_vm_realloc(hg_vm_t *vm, { hg_return_val_if_fail (vm != NULL, Qnil, HG_e_VMerror); - return hg_mem_realloc(_hg_vm_get_mem(vm, qdata), qdata, size, ret); -} - -/** - * hg_vm_mfree: - * @vm: - * @qdata: - * - * FIXME - */ -void -hg_vm_mfree(hg_vm_t *vm, - hg_quark_t qdata) -{ - hg_return_if_fail (vm != NULL, HG_e_VMerror); - - if (qdata == Qnil) - return; - - if (!hg_quark_is_simple_object(qdata) && - !HG_IS_QOPER (qdata)) { - hg_object_free(_hg_vm_get_mem(vm, qdata), - qdata); - } else { - hg_mem_free(_hg_vm_get_mem(vm, qdata), qdata); - } -} - -/** - * hg_vm_lock_object: - * @vm: - * @qdata: - * @pretty_function: - * @error: - * - * FIXME - * - * Returns: - */ -hg_pointer_t -hg_vm_lock_object(hg_vm_t *vm, - hg_quark_t qdata, - const hg_char_t *pretty_function) -{ - hg_return_val_if_fail (vm != NULL, NULL, HG_e_VMerror); - - return _hg_vm_real_lock_object(vm, qdata, pretty_function); -} - -/** - * hg_vm_unlock_object: - * @vm: - * @qdata: - * - * FIXME - */ -void -hg_vm_unlock_object(hg_vm_t *vm, - hg_quark_t qdata) -{ - hg_return_if_fail (vm != NULL, HG_e_VMerror); - - _hg_vm_real_unlock_object(vm, qdata); + return hg_mem_realloc(_hg_vm_quark_get_mem(vm, qdata), qdata, size, ret); } /** @@ -1182,26 +1343,7 @@ hg_vm_set_default_acl(hg_vm_t *vm, hg_mem_t * hg_vm_get_mem(hg_vm_t *vm) { - hg_return_val_if_fail (vm != NULL, NULL, HG_e_VMerror); - hg_return_val_if_fail (vm->vm_state->current_mem_index < HG_VM_MEM_END, NULL, HG_e_VMerror); - - return vm->mem[vm->vm_state->current_mem_index]; -} - -/** - * hg_vm_get_mem_from_quark: - * @vm: - * @qdata: - * - * FIXME - * - * Returns: - */ -hg_mem_t * -hg_vm_get_mem_from_quark(hg_vm_t *vm, - hg_quark_t qdata) -{ - return _hg_vm_get_mem(vm, qdata); + return _hg_vm_get_mem(vm); } /** @@ -1258,7 +1400,7 @@ hg_vm_get_io(hg_vm_t *vm, hg_return_val_if_fail (type < HG_FILE_IO_END, Qnil, HG_e_invalidfileaccess); if (type == HG_FILE_IO_LINEEDIT) { - ret = hg_file_new_with_vtable(hg_vm_get_mem(vm), + ret = hg_file_new_with_vtable(_hg_vm_get_mem(vm), "%lineedit", HG_FILE_IO_MODE_READ, hg_file_get_lineedit_vtable(), @@ -1267,7 +1409,7 @@ hg_vm_get_io(hg_vm_t *vm, if (ret != Qnil) hg_vm_quark_set_acl(vm, &ret, HG_ACL_READABLE|HG_ACL_ACCESSIBLE); } else if (type == HG_FILE_IO_STATEMENTEDIT) { - ret = hg_file_new_with_vtable(hg_vm_get_mem(vm), + ret = hg_file_new_with_vtable(_hg_vm_get_mem(vm), "%statementedit", HG_FILE_IO_MODE_READ, hg_file_get_lineedit_vtable(), @@ -1338,7 +1480,7 @@ hg_vm_setup(hg_vm_t *vm, /* initialize I/O */ if (stdin == Qnil) { - qf = hg_file_new(hg_vm_get_mem(vm), + qf = hg_file_new(_hg_vm_get_mem(vm), "%stdin", HG_FILE_IO_MODE_READ, (hg_pointer_t *)&fstdin); @@ -1348,7 +1490,7 @@ hg_vm_setup(hg_vm_t *vm, hg_vm_quark_set_acl(vm, &qf, HG_ACL_READABLE|HG_ACL_ACCESSIBLE); vm->qio[HG_FILE_IO_STDIN] = qf; if (stdout == Qnil) { - qf = hg_file_new(hg_vm_get_mem(vm), + qf = hg_file_new(_hg_vm_get_mem(vm), "%stdout", HG_FILE_IO_MODE_WRITE, (hg_pointer_t *)&fstdout); @@ -1358,7 +1500,7 @@ hg_vm_setup(hg_vm_t *vm, hg_vm_quark_set_acl(vm, &qf, HG_ACL_WRITABLE|HG_ACL_ACCESSIBLE); vm->qio[HG_FILE_IO_STDOUT] = qf; if (stderr == Qnil) { - qf = hg_file_new(hg_vm_get_mem(vm), + qf = hg_file_new(_hg_vm_get_mem(vm), "%stderr", HG_FILE_IO_MODE_WRITE, NULL); @@ -1374,7 +1516,7 @@ hg_vm_setup(hg_vm_t *vm, goto error; } - vm->lineedit = hg_lineedit_new(hg_vm_get_mem(vm), + vm->lineedit = hg_lineedit_new(_hg_vm_get_mem(vm), hg_lineedit_get_default_vtable(), fstdin, fstdout); @@ -1515,19 +1657,19 @@ hg_vm_finish(hg_vm_t *vm) hg_return_if_fail (vm->is_initialized, HG_e_VMerror); if (vm->qsystemdict != Qnil) { - hg_vm_mfree(vm, vm->qsystemdict); + _hg_vm_quark_free(vm, vm->qsystemdict); vm->qsystemdict = Qnil; } if (vm->qglobaldict != Qnil) { - hg_vm_mfree(vm, vm->qglobaldict); + _hg_vm_quark_free(vm, vm->qglobaldict); vm->qglobaldict = Qnil; } if (vm->qinternaldict != Qnil) { - hg_vm_mfree(vm, vm->qinternaldict); + _hg_vm_quark_free(vm, vm->qinternaldict); vm->qinternaldict = Qnil; } if (vm->qgstate != Qnil) { - hg_vm_mfree(vm, vm->qgstate); + _hg_vm_quark_free(vm, vm->qgstate); vm->qgstate = Qnil; } for (i = 0; i < HG_VM_STACK_END; i++) { @@ -1547,408 +1689,89 @@ hg_vm_finish(hg_vm_t *vm) /** * hg_vm_get_language_level: - * @vm: - * - * FIXME - * - * Returns: - */ -hg_vm_langlevel_t -hg_vm_get_language_level(hg_vm_t *vm) -{ - hg_return_val_if_fail (vm != NULL, HG_LANG_LEVEL_END, HG_e_VMerror); - - return vm->language_level; -} - -/** - * hg_vm_set_language_level: - * @vm: - * @level: - * - * FIXME - * - * Returns: - */ -hg_bool_t -hg_vm_set_language_level(hg_vm_t *vm, - hg_vm_langlevel_t level) -{ - hg_return_val_if_fail (vm != NULL, FALSE, HG_e_VMerror); - hg_return_val_if_fail (level < HG_LANG_LEVEL_END, FALSE, HG_e_VMerror); - - if (vm->is_initialized && !vm->hold_lang_level) { - if (hg_vm_get_language_level(vm) >= level) - return FALSE; - - /* re-initialize operators */ - return hg_vm_startjob(vm, level, "", FALSE); - } - - return FALSE; -} - -/** - * hg_vm_hold_language_level: - * @vm: - * @flag: - * - * FIXME - */ -void -hg_vm_hold_language_level(hg_vm_t *vm, - hg_bool_t flag) -{ - hg_return_if_fail (vm != NULL, HG_e_VMerror); - - vm->hold_lang_level = (flag == TRUE); -} - -/** - * hg_vm_stepi: - * @vm: - * @is_proceeded: - * - * FIXME - * - * Returns: - */ -hg_bool_t -hg_vm_stepi(hg_vm_t *vm, - hg_bool_t *is_proceeded) -{ - hg_stack_t *estack, *ostack; - hg_quark_t qexecobj, qresult; - hg_file_t *file; - hg_bool_t retval = TRUE; - const hg_char_t *name; - - hg_return_val_if_fail (vm != NULL, FALSE, HG_e_VMerror); - hg_return_val_if_fail (is_proceeded != NULL, FALSE, HG_e_VMerror); - - ostack = vm->stacks[HG_VM_STACK_OSTACK]; - estack = vm->stacks[HG_VM_STACK_ESTACK]; - - qexecobj = hg_stack_index(estack, 0); - *is_proceeded = FALSE; - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error(vm, Qnil, HG_e_stackunderflow); - return FALSE; - } - - evaluate: - hg_debug(HG_MSGCAT_VM, "Executing %lx", qexecobj); -#if defined (HG_DEBUG) && defined (HG_VM_DEBUG) - HG_STMT_START { - hg_quark_t qs; - hg_string_t *s; - - qs = hg_vm_quark_to_string(vm, qexecobj, TRUE, (hg_pointer_t *)&s); - if (qs == Qnil) { - hg_warning("Unable to look up the object being executed: %lx", qexecobj); - } else { - hg_char_t *cstr = hg_string_get_cstr(s); - - hg_debug(HG_MSGCAT_VM, "executing... %s [%s:%c%c%c]", - cstr, hg_quark_get_type_name(qexecobj), - hg_quark_is_readable(qexecobj) ? 'r' : '-', - hg_quark_is_writable(qexecobj) ? 'w' : '-', - hg_quark_is_executable(qexecobj) ? 'x' : '-'); - g_free(cstr); - /* this is an instant object. - * surely no reference to the container. - * so it can be safely destroyed. - */ - hg_string_free(s, TRUE); - } - } HG_STMT_END; -#endif - switch (hg_quark_get_type(qexecobj)) { - case HG_TYPE_NULL: - case HG_TYPE_INT: - goto push_stack; - case HG_TYPE_REAL: - if (isinf(HG_REAL (qexecobj))) { - hg_vm_set_error(vm, qexecobj, HG_e_limitcheck); - return TRUE; - } - case HG_TYPE_BOOL: - case HG_TYPE_DICT: - case HG_TYPE_MARK: - case HG_TYPE_SNAPSHOT: - case HG_TYPE_GSTATE: - push_stack: - if (!hg_stack_push(ostack, qexecobj)) { - hg_vm_set_error(vm, qexecobj, HG_e_stackoverflow); - return TRUE; - } - hg_stack_drop(estack); - *is_proceeded = TRUE; - break; - case HG_TYPE_EVAL_NAME: - if (hg_vm_quark_is_executable(vm, &qexecobj)) { - qresult = hg_vm_dstack_lookup(vm, qexecobj); - if (qresult == Qnil) { - hg_vm_set_error(vm, qexecobj, - HG_e_undefined); - - return TRUE; - } - qexecobj = qresult; - goto evaluate; - } - hg_warning("Immediately evaluated name object somehow doesn't have a exec bit turned on: %s", hg_name_lookup(qexecobj)); - goto push_stack; - case HG_TYPE_NAME: - /* /foo ... nope - * foo ... exec bit - */ - if (hg_vm_quark_is_executable(vm, &qexecobj)) { - hg_quark_t q; - - qresult = hg_vm_dstack_lookup(vm, qexecobj); - if (qresult == Qnil) { - hg_vm_set_error(vm, qexecobj, - HG_e_undefined); - - return TRUE; - } - if (hg_vm_quark_is_executable(vm, &qresult)) { - q = hg_vm_quark_copy(vm, qresult, NULL); - if (q == Qnil) { - hg_vm_set_error(vm, qexecobj, - HG_e_VMerror); - return TRUE; - } - } else { - q = qresult; - } - if (!hg_stack_push(estack, q)) { - hg_vm_set_error(vm, qexecobj, - HG_e_execstackoverflow); - - return TRUE; - } - hg_stack_roll(estack, 2, 1); - hg_stack_drop(estack); - break; - } - goto push_stack; - case HG_TYPE_ARRAY: - /* [ ... ] ... nope - * { ... } ... exec bit - */ - if (hg_vm_quark_is_executable(vm, &qexecobj)) { - hg_array_t *a = _HG_VM_LOCK (vm, qexecobj); - - if (a == NULL) { - hg_vm_set_error(vm, qexecobj, HG_e_VMerror); - return TRUE; - } - if (hg_array_length(a) > 0) { - qresult = hg_array_get(a, 0); - if (!HG_ERROR_IS_SUCCESS0 ()) { - hg_vm_set_error(vm, qexecobj, HG_e_VMerror); - goto a_error; - } - if (hg_vm_quark_is_executable(vm, &qresult) && - (HG_IS_QNAME (qresult) || - HG_IS_QOPER (qresult))) { - if (hg_array_length(a) == 1) { - hg_stack_drop(estack); - } else { - hg_array_remove(a, 0); - } - if (!hg_stack_push(estack, qresult)) { - hg_vm_set_error(vm, qexecobj, - HG_e_execstackoverflow); - goto a_error; - } - } else { - if (!hg_stack_push(ostack, qresult)) { - hg_vm_set_error(vm, qexecobj, - HG_e_stackoverflow); - goto a_error; - } - if (hg_array_length(a) == 1) { - hg_stack_drop(estack); - } else { - hg_array_remove(a, 0); - } - } - } else { - hg_stack_drop(estack); - } - a_error: - _HG_VM_UNLOCK (vm, qexecobj); - break; - } - goto push_stack; - case HG_TYPE_STRING: - if (hg_vm_quark_is_executable(vm, &qexecobj)) { - hg_string_t *s; - - s = _HG_VM_LOCK (vm, qexecobj); - if (s == NULL) - break; - qresult = hg_file_new_with_string(hg_vm_get_mem(vm), - "%sfile", - HG_FILE_IO_MODE_READ, - s, - NULL, - NULL); - hg_vm_quark_set_executable(vm, &qresult, TRUE); - _HG_VM_UNLOCK (vm, qexecobj); - hg_stack_drop(estack); - if (!hg_stack_push(estack, qresult)) { - hg_vm_set_error(vm, qexecobj, - HG_e_execstackoverflow); - - return TRUE; - } - break; - } - goto push_stack; - case HG_TYPE_OPER: - retval = hg_operator_invoke(qexecobj, - vm); - if (retval) { - hg_stack_drop(estack); -#ifdef HG_DEBUG - if (!HG_ERROR_IS_SUCCESS0 ()) { - g_print("hg_errno wasn't cleaned up\n"); - } -#endif - } - *is_proceeded = TRUE; - break; - case HG_TYPE_FILE: - if (!hg_vm_quark_is_executable(vm, &qexecobj)) { - goto push_stack; - } else { - file = _HG_VM_LOCK (vm, qexecobj); - if (file == NULL) - break; - hg_scanner_attach_file(vm->scanner, file); - if (!hg_scanner_scan(vm->scanner, vm)) { - hg_bool_t is_eof = hg_file_is_eof(file); + * @vm: + * + * FIXME + * + * Returns: + */ +hg_vm_langlevel_t +hg_vm_get_language_level(hg_vm_t *vm) +{ + hg_return_val_if_fail (vm != NULL, HG_LANG_LEVEL_END, HG_e_VMerror); - _HG_VM_UNLOCK (vm, qexecobj); - if (HG_ERROR_IS_SUCCESS0 () && is_eof) { - hg_debug(HG_MSGCAT_VM, "EOF detected"); - hg_stack_drop(estack); - *is_proceeded = TRUE; - break; - } - hg_vm_set_error(vm, qexecobj, - HG_e_syntaxerror); + return vm->language_level; +} - return TRUE; - } - _HG_VM_UNLOCK (vm, qexecobj); - qresult = hg_scanner_get_token(vm->scanner); - hg_vm_quark_set_default_acl(vm, &qresult); -#if defined (HG_DEBUG) && defined (HG_VM_DEBUG) - HG_STMT_START { - hg_quark_t qs; - hg_string_t *s; - - qs = hg_vm_quark_to_string(vm, qresult, TRUE, (hg_pointer_t *)&s); - if (qs == Qnil) { - hg_warning("Unable to look up the scanned object: %lx", qresult); - } else { - hg_char_t *cstr = hg_string_get_cstr(s); +/** + * hg_vm_set_language_level: + * @vm: + * @level: + * + * FIXME + * + * Returns: + */ +hg_bool_t +hg_vm_set_language_level(hg_vm_t *vm, + hg_vm_langlevel_t level) +{ + hg_return_val_if_fail (vm != NULL, FALSE, HG_e_VMerror); + hg_return_val_if_fail (level < HG_LANG_LEVEL_END, FALSE, HG_e_VMerror); - hg_debug(HG_MSGCAT_SCAN, "scanning... %s [%s:%c%c%c]", - cstr, hg_quark_get_type_name(qresult), - hg_quark_is_readable(qresult) ? 'r' : '-', - hg_quark_is_writable(qresult) ? 'w' : '-', - hg_quark_is_executable(qresult) ? 'x' : '-'); - g_free(cstr); - /* this is an instant object. - * surely no reference to the container. - * so it can be safely destroyed. - */ - hg_string_free(s, TRUE); - } - } HG_STMT_END; -#endif - /* exception for processing the executable array */ - if (HG_IS_QNAME (qresult) && - (name = hg_name_lookup(qresult)) != NULL) { - if (!strcmp(name, "{")) { - qresult = hg_vm_step_in_exec_array(vm, qexecobj); - if (qresult == Qnil) - break; -#if defined (HG_DEBUG) && defined (HG_VM_DEBUG) - HG_STMT_START { - hg_quark_t qs; - hg_string_t *s; - - qs = hg_vm_quark_to_string(vm, qresult, TRUE, (hg_pointer_t *)&s); - if (qs == Qnil) { - hg_warning("Unable to look up the scanned object: %lx", qresult); - } else { - hg_char_t *cstr = hg_string_get_cstr(s); - - hg_debug(HG_MSGCAT_SCAN, "scanned result %s [%s:%c%c%c]", - cstr, - hg_quark_get_type_name(qresult), - hg_quark_is_readable(qresult) ? 'r' : '-', - hg_quark_is_writable(qresult) ? 'w' : '-', - hg_quark_is_executable(qresult) ? 'x' : '-'); - g_free(cstr); - /* this is an instant object. - * surely no reference to the container. - * so it can be safely destroyed. - */ - hg_string_free(s, TRUE); - } - } HG_STMT_END; -#endif - if (!hg_stack_push(ostack, qresult)) { - hg_vm_set_error(vm, qexecobj, - HG_e_stackoverflow); - } - return TRUE; - } else if (!strcmp(name, "}")) { - hg_vm_set_error(vm, qexecobj, HG_e_syntaxerror); - return TRUE; - } - } - hg_stack_push(estack, qresult); - } - break; - default: - hg_warning("Unknown object type: %d", hg_quark_get_type(qexecobj)); - return FALSE; - } + if (vm->is_initialized && !vm->hold_lang_level) { + if (hg_vm_get_language_level(vm) >= level) + return FALSE; - if (!HG_ERROR_IS_SUCCESS0 ()) { - if (!hg_vm_has_error(vm)) - hg_vm_set_error0(vm, qexecobj); - retval = FALSE; + /* re-initialize operators */ + return hg_vm_startjob(vm, level, "", FALSE); } - return retval; + return FALSE; +} + +/** + * hg_vm_hold_language_level: + * @vm: + * @flag: + * + * FIXME + */ +void +hg_vm_hold_language_level(hg_vm_t *vm, + hg_bool_t flag) +{ + hg_return_if_fail (vm != NULL, HG_e_VMerror); + + vm->hold_lang_level = (flag == TRUE); } /** - * hg_vm_step: + * hg_vm_translate: * @vm: + * @flags: * * FIXME * * Returns: */ hg_bool_t -hg_vm_step(hg_vm_t *vm) +hg_vm_translate(hg_vm_t *vm, + hg_vm_trans_flags_t flags) { - hg_bool_t retval, is_proceeded; + hg_bool_t retval; - while ((retval = hg_vm_stepi(vm, &is_proceeded))) { - if (is_proceeded) - break; + hg_return_val_if_fail (vm != NULL, FALSE, HG_e_VMerror); + + /* drop a HG_TRANS_FLAG_BLOCK from flags */ + flags &= ~HG_TRANS_FLAG_BLOCK; + + retval = _hg_vm_translate(vm, flags); + + if (!HG_ERROR_IS_SUCCESS0 ()) { + hg_quark_t q = hg_stack_index(vm->stacks[HG_VM_STACK_ESTACK], 0); + + _hg_vm_set_error(vm, q, HG_ERROR_GET_REASON (hg_errno)); } return retval; @@ -1976,12 +1799,7 @@ hg_vm_main_loop(hg_vm_t *vm) if (depth == 0) break; - if (!hg_vm_step(vm)) { - if (!hg_vm_has_error(vm)) { - hg_critical("[BUG] detected an infinite loop in the exec stack."); - hg_operator_invoke(HG_QOPER (HG_enc_private_abort), vm); - } - } + hg_vm_translate(vm, HG_TRANS_FLAG_NONE); if (vm->device && hg_device_is_pending_draw(vm->device)) hg_device_draw(vm->device); } @@ -2189,7 +2007,7 @@ hg_vm_eval_from_cstring(hg_vm_t *vm, memcpy(str, cstring, clen); str[clen] = '\n'; str[clen + 1] = 0; - qstring = HG_QSTRING_LEN (hg_vm_get_mem(vm), + qstring = HG_QSTRING_LEN (_hg_vm_get_mem(vm), str, clen + 1); g_free(str); if (qstring == Qnil) { @@ -2242,7 +2060,7 @@ hg_vm_eval_from_file(hg_vm_t *vm, if (filename) { hg_quark_t qfile; - qfile = hg_file_new(hg_vm_get_mem(vm), + qfile = hg_file_new(_hg_vm_get_mem(vm), filename, HG_FILE_IO_MODE_READ, NULL); @@ -2489,7 +2307,7 @@ hg_vm_get_user_params(hg_vm_t *vm, hg_return_val_if_fail (vm != NULL, Qnil, HG_e_VMerror); - retval = hg_dict_new(hg_vm_get_mem(vm), + retval = hg_dict_new(_hg_vm_get_mem(vm), sizeof (hg_vm_user_params_t) / sizeof (hg_int_t) + 1, hg_vm_get_language_level(vm) == HG_LANG_LEVEL_1, (hg_pointer_t *)&d); @@ -2722,152 +2540,6 @@ hg_vm_reset_error(hg_vm_t *vm) hg_critical("Unable to reset entries in $error dict"); } -/** - * hg_vm_set_error: - * @vm: - * @qdata: - * @error: - * - * FIXME - * - * Returns: - */ -hg_bool_t -hg_vm_set_error(hg_vm_t *vm, - hg_quark_t qdata, - hg_error_reason_t error) -{ - hg_quark_t qerrordict, qnerrordict, qhandler, q; - hg_usize_t i; - - hg_return_val_if_fail (vm != NULL, FALSE, HG_e_VMerror); - hg_return_val_if_fail (error < HG_e_END, FALSE, HG_e_VMerror); - - if (vm->has_error) { - hg_quark_t qerrorname = HG_QNAME ("errorname"); - hg_quark_t qcommand = HG_QNAME ("command"); - hg_quark_t qresult_err, qresult_cmd, qwhere; - hg_dict_t *derror; - hg_string_t *where; - hg_char_t *scommand, *swhere; - - derror = _HG_VM_LOCK (vm, vm->qerror); - if (derror == NULL) - goto fatal_error; - qresult_err = hg_dict_lookup(derror, qerrorname); - qresult_cmd = hg_dict_lookup(derror, qcommand); - _HG_VM_UNLOCK (vm, vm->qerror); - - if (qresult_cmd == Qnil) { - scommand = g_strdup("-%unknown%-"); - } else { - hg_string_t *s = NULL; - - q = hg_vm_quark_to_string(vm, - qresult_cmd, - TRUE, - (hg_pointer_t *)&s); - if (q == Qnil) - scommand = g_strdup("-%ENOMEM%-"); - else - scommand = hg_string_get_cstr(s); - /* this is an instant object. - * surely no reference to the container. - * so it can be safely destroyed. - */ - hg_string_free(s, TRUE); - } - qwhere = hg_vm_quark_to_string(vm, - qdata, - TRUE, - (hg_pointer_t *)&where); - if (qwhere == Qnil) - swhere = g_strdup("-%ENOMEM%-"); - else - swhere = hg_string_get_cstr(where); - hg_vm_mfree(vm, qwhere); - - if (qresult_err == Qnil) { - g_printerr("Multiple errors occurred.\n" - " previous error: unknown or this happened at %s prior to set /errorname\n" - " current error: %s at %s\n", - scommand, - hg_name_lookup(vm->qerror_name[error]), - swhere); - } else { - g_printerr("Multiple errors occurred.\n" - " previous error: %s at %s\n" - " current error: %s at %s\n", - hg_name_lookup(qresult_err), - scommand, - hg_name_lookup(vm->qerror_name[error]), - swhere); - } - g_free(swhere); - g_free(scommand); - - hg_operator_invoke(HG_QOPER (HG_enc_private_abort), vm); - } - for (i = 0; i < HG_VM_STACK_END; i++) { - hg_stack_set_validation(vm->stacks[i], FALSE); - } - qnerrordict = HG_QNAME ("errordict"); - qerrordict = hg_vm_dstack_lookup(vm, qnerrordict); - if (qerrordict == Qnil) { - hg_critical("Unable to lookup errordict"); - - hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_VMerror); - goto fatal_error; - } - qhandler = hg_vm_dict_lookup(vm, qerrordict, vm->qerror_name[error], FALSE); - if (qhandler == Qnil) { - hg_critical("Unable to obtain the error handler for %s", - hg_name_lookup(vm->qerror_name[error])); - hg_errno = HG_ERROR_ (HG_STATUS_FAILED, HG_e_VMerror); - goto fatal_error; - } - - q = hg_vm_quark_copy(vm, qhandler, NULL); - if (q == Qnil) - goto fatal_error; - hg_stack_push(vm->stacks[HG_VM_STACK_ESTACK], q); - hg_stack_push(vm->stacks[HG_VM_STACK_OSTACK], qdata); - vm->has_error = TRUE; - - return TRUE; - fatal_error: - G_STMT_START { - const hg_char_t *errname = hg_name_lookup(vm->qerror_name[error]); - - if (errname) { - hg_critical("Fatal error during recovering from /%s", errname); - } else { - hg_critical("Fatal error during recovering from the unknown error"); - } - - return hg_operator_invoke(HG_QOPER (HG_enc_private_abort), vm); - } G_STMT_END; -} - -/** - * hg_vm_set_error0: - * @error: - * - * FIXME - * - * Returns: - */ -hg_bool_t -hg_vm_set_error0(hg_vm_t *vm, - hg_quark_t qdata) -{ - if (!HG_ERROR_IS_SUCCESS0 ()) { - return hg_vm_set_error(vm, qdata, HG_ERROR_GET_REASON (hg_errno)); - } - - return TRUE; -} - /** * hg_vm_reserved_spool_dump: * @vm: @@ -2888,7 +2560,7 @@ hg_vm_reserved_spool_dump(hg_vm_t *vm, hg_return_if_fail (ofile != NULL, HG_e_VMerror); /* to avoid unusable result when OOM */ - hg_mem_spool_set_resizable(hg_vm_get_mem(vm), TRUE); + hg_mem_spool_set_resizable(_hg_vm_get_mem(vm), TRUE); data.vm = vm; data.mem = mem; @@ -3419,6 +3091,54 @@ hg_vm_dict_lookup(hg_vm_t *vm, /* hg_quark_t */ +/** + * hg_vm_quark_get_mem: + * @vm: + * @qdata: + * + * FIXME + * + * Returns: + */ +hg_mem_t * +hg_vm_quark_get_mem(hg_vm_t *vm, + hg_quark_t qdata) +{ + return _hg_vm_quark_get_mem(vm, qdata); +} + +/** + * hg_vm_quark_lock_object: + * @vm: + * @qdata: + * @pretty_function: + * + * FIXME + * + * Returns: + */ +hg_pointer_t +hg_vm_quark_lock_object(hg_vm_t *vm, + hg_quark_t qdata, + const hg_char_t *pretty_function) +{ + return _hg_vm_quark_lock_object(vm, qdata, pretty_function); +} + +/** + * hg_vm_quark_unlock_object: + * @vm: + * @qdata: + * + * FIXME + */ +void +hg_vm_quark_unlock_object(hg_vm_t *vm, + hg_quark_t qdata) +{ + _hg_vm_quark_unlock_object(vm, qdata); +} + /** * hg_vm_quark_gc_mark: * @vm: @@ -3549,7 +3269,7 @@ hg_vm_quark_to_string(hg_vm_t *vm, hg_return_val_if_fail (vm != NULL, Qnil, HG_e_VMerror); - retval = hg_string_new(hg_vm_get_mem(vm), + retval = hg_string_new(_hg_vm_get_mem(vm), 65535, (hg_pointer_t *)&s); if (retval == Qnil) return Qnil; @@ -4119,7 +3839,7 @@ hg_vm_stack_dump(hg_vm_t *vm, hg_return_if_fail (stack != NULL, HG_e_VMerror); hg_return_if_fail (output != NULL, HG_e_VMerror); - m = hg_vm_get_mem(vm); + m = _hg_vm_get_mem(vm); /* to avoid unusable result when OOM */ hg_mem_spool_set_resizable(m, TRUE); diff --git a/hieroglyph/hgvm.h b/hieroglyph/hgvm.h index 1d75092..a2ba83b 100644 --- a/hieroglyph/hgvm.h +++ b/hieroglyph/hgvm.h @@ -39,13 +39,14 @@ HG_BEGIN_DECLS #define HG_VM_LOCK(_v_,_q_) \ - (hg_vm_lock_object((_v_),(_q_),__PRETTY_FUNCTION__)) -#define HG_VM_UNLOCK(_v_,_q_) \ - (hg_vm_unlock_object((_v_),(_q_))) + (hg_vm_quark_lock_object((_v_),(_q_),__PRETTY_FUNCTION__)) +#define HG_VM_UNLOCK(_v_,_q_) \ + (hg_vm_quark_unlock_object((_v_),(_q_))) typedef enum _hg_vm_mem_type_t hg_vm_mem_type_t; typedef struct _hg_vm_state_t hg_vm_state_t; typedef enum _hg_vm_langlevel_t hg_vm_langlevel_t; +typedef enum _hg_vm_trans_flags_t hg_vm_trans_flags_t; typedef struct _hg_vm_user_params_t hg_vm_user_params_t; typedef struct _hg_vm_sys_params_t hg_vm_sys_params_t; typedef struct _hg_vm_value_t hg_vm_value_t; @@ -83,25 +84,31 @@ enum _hg_vm_langlevel_t { HG_LANG_LEVEL_3, HG_LANG_LEVEL_END }; +enum _hg_vm_trans_flags_t { + HG_TRANS_FLAG_NONE = 0, + HG_TRANS_FLAG_TOKEN = (1 << 0), + HG_TRANS_FLAG_BLOCK = (1 << 1), /* For internal */ + HG_TRANS_FLAG_END +}; struct _hg_vm_user_params_t { - gsize max_op_stack; - gsize max_exec_stack; - gsize max_dict_stack; - gsize max_gstate_stack; + hg_usize_t max_op_stack; + hg_usize_t max_exec_stack; + hg_usize_t max_dict_stack; + hg_usize_t max_gstate_stack; }; struct _hg_vm_sys_params_t { }; struct _hg_vm_state_t { hg_quark_t self; hg_vm_mem_type_t current_mem_index; - gint n_save_objects; + hg_int_t n_save_objects; }; struct _hg_vm_t { hg_quark_t self; hg_vm_state_t *vm_state; hg_vm_user_params_t user_params; hg_mem_t *mem[HG_VM_MEM_END]; - gint mem_id[HG_VM_MEM_END]; + hg_int_t mem_id[HG_VM_MEM_END]; hg_quark_t qio[HG_FILE_IO_END]; hg_stack_spool_t *stack_spooler; hg_stack_t *stacks[HG_VM_STACK_END]; @@ -118,218 +125,217 @@ struct _hg_vm_t { hg_scanner_t *scanner; hg_lineedit_t *lineedit; hg_vm_langlevel_t language_level; - gboolean is_initialized:1; - gboolean hold_lang_level:1; - gboolean shutdown:1; - gboolean has_error:1; - gint error_code; - guint n_nest_scan; + hg_bool_t is_initialized:1; + hg_bool_t hold_lang_level:1; + hg_bool_t shutdown:1; + hg_bool_t has_error:1; + hg_int_t error_code; + hg_uint_t n_nest_scan; hg_quark_acl_t default_acl; GHashTable *params; GHashTable *plugin_table; GList *plugin_list; GRand *rand_; - guint32 rand_seed; + hg_uint_t rand_seed; GTimeVal initiation_time; hg_device_t *device; }; struct _hg_vm_value_t { - gint type; + hg_int_t type; union { - gboolean bool; - gint32 integer; - gdouble real; - gchar *string; + hg_bool_t bool; + hg_int_t integer; + hg_real_t real; + hg_char_t *string; } u; }; /* hg_vm_t */ -gboolean hg_vm_init (void); -void hg_vm_tini (void); -hg_vm_t *hg_vm_new (void); -void hg_vm_destroy (hg_vm_t *vm); -hg_quark_t hg_vm_malloc (hg_vm_t *vm, - gsize size, - gpointer *ret); -hg_quark_t hg_vm_realloc (hg_vm_t *vm, - hg_quark_t qdata, - gsize size, - gpointer *ret); -void hg_vm_mfree (hg_vm_t *vm, - hg_quark_t qdata); -gpointer hg_vm_lock_object (hg_vm_t *vm, - hg_quark_t qdata, - const gchar *pretty_function); -void hg_vm_unlock_object (hg_vm_t *vm, - hg_quark_t qdata); -void hg_vm_set_default_acl (hg_vm_t *vm, - hg_quark_acl_t acl); -hg_mem_t *hg_vm_get_mem (hg_vm_t *vm); -hg_mem_t *hg_vm_get_mem_from_quark (hg_vm_t *vm, - hg_quark_t qdata); -void hg_vm_use_global_mem (hg_vm_t *vm, - gboolean flag); -gboolean hg_vm_is_global_mem_used (hg_vm_t *vm); -hg_quark_t hg_vm_get_io (hg_vm_t *vm, - hg_file_io_t type); -void hg_vm_set_io (hg_vm_t *vm, - hg_file_io_t type, - hg_quark_t file); -gboolean hg_vm_setup (hg_vm_t *vm, - hg_vm_langlevel_t lang_level, - hg_quark_t stdin, - hg_quark_t stdout, - hg_quark_t stderr); -void hg_vm_finish (hg_vm_t *vm); -hg_vm_langlevel_t hg_vm_get_language_level (hg_vm_t *vm); -gboolean hg_vm_set_language_level (hg_vm_t *vm, - hg_vm_langlevel_t level); -void hg_vm_hold_language_level (hg_vm_t *vm, - gboolean flag); -gboolean hg_vm_stepi (hg_vm_t *vm, - gboolean *is_proceeded); -gboolean hg_vm_step (hg_vm_t *vm); -gboolean hg_vm_main_loop (hg_vm_t *vm); -gchar *hg_vm_find_libfile (hg_vm_t *vm HG_GNUC_UNUSED, - const gchar *filename); -gboolean hg_vm_eval (hg_vm_t *vm, - hg_quark_t qeval, - hg_stack_t *ostack, - hg_stack_t *estack, - hg_stack_t *dstack, - gboolean protect_systemdict); -gboolean hg_vm_eval_from_cstring (hg_vm_t *vm, - const gchar *cstring, - gssize clen, - hg_stack_t *ostack, - hg_stack_t *estack, - hg_stack_t *dstack, - gboolean protect_systemdict); -gboolean hg_vm_eval_from_file (hg_vm_t *vm, - const gchar *initfile, - hg_stack_t *ostack, - hg_stack_t *estack, - hg_stack_t *dstack, - gboolean protect_systemdict); -gint hg_vm_get_error_code (hg_vm_t *vm); -void hg_vm_set_error_code (hg_vm_t *vm, - gint error_code); -gboolean hg_vm_startjob (hg_vm_t *vm, - hg_vm_langlevel_t lang_level, - const gchar *initfile, - gboolean encapsulated); -void hg_vm_shutdown (hg_vm_t *vm, - gint error_code); -gboolean hg_vm_is_finished (hg_vm_t *vm); -hg_quark_t hg_vm_get_gstate (hg_vm_t *vm); -void hg_vm_set_gstate (hg_vm_t *vm, - hg_quark_t qgstate); -hg_quark_t hg_vm_get_user_params (hg_vm_t *vm, - gpointer *ret); -hg_bool_t hg_vm_set_user_params (hg_vm_t *vm, - hg_quark_t qdict); -void hg_vm_set_rand_seed (hg_vm_t *vm, - guint32 seed); -guint32 hg_vm_get_rand_seed (hg_vm_t *vm); -guint32 hg_vm_rand_int (hg_vm_t *vm); -guint32 hg_vm_get_current_time (hg_vm_t *vm); -gboolean hg_vm_has_error (hg_vm_t *vm); -void hg_vm_clear_error (hg_vm_t *vm); -void hg_vm_reset_error (hg_vm_t *vm); -gboolean hg_vm_set_error (hg_vm_t *vm, - hg_quark_t qdata, - hg_error_reason_t error); -gboolean hg_vm_set_error0 (hg_vm_t *vm, - hg_quark_t qdata); -void hg_vm_reserved_spool_dump (hg_vm_t *vm, - hg_mem_t *mem, - hg_file_t *ofile); -gboolean hg_vm_add_plugin (hg_vm_t *vm, - const gchar *name); -void hg_vm_load_plugins (hg_vm_t *vm); -gboolean hg_vm_remove_plugin (hg_vm_t *vm, - const gchar *name); -void hg_vm_unload_plugins (hg_vm_t *vm); -gboolean hg_vm_set_device (hg_vm_t *vm, - const gchar *name); -void hg_vm_add_param (hg_vm_t *vm, - const gchar *name, - hg_vm_value_t *value); +hg_bool_t hg_vm_init (void); +void hg_vm_tini (void); +hg_vm_t *hg_vm_new (void); +void hg_vm_destroy (hg_vm_t *vm); +hg_quark_t hg_vm_malloc (hg_vm_t *vm, + hg_usize_t size, + hg_pointer_t *ret); +hg_quark_t hg_vm_realloc (hg_vm_t *vm, + hg_quark_t qdata, + hg_usize_t size, + hg_pointer_t *ret); +void hg_vm_set_default_acl (hg_vm_t *vm, + hg_quark_acl_t acl); +hg_mem_t *hg_vm_get_mem (hg_vm_t *vm); +void hg_vm_use_global_mem (hg_vm_t *vm, + hg_bool_t flag); +hg_bool_t hg_vm_is_global_mem_used (hg_vm_t *vm); +hg_quark_t hg_vm_get_io (hg_vm_t *vm, + hg_file_io_t type); +void hg_vm_set_io (hg_vm_t *vm, + hg_file_io_t type, + hg_quark_t file); +hg_bool_t hg_vm_setup (hg_vm_t *vm, + hg_vm_langlevel_t lang_level, + hg_quark_t stdin, + hg_quark_t stdout, + hg_quark_t stderr); +void hg_vm_finish (hg_vm_t *vm); +hg_vm_langlevel_t hg_vm_get_language_level (hg_vm_t *vm); +hg_bool_t hg_vm_set_language_level (hg_vm_t *vm, + hg_vm_langlevel_t level); +void hg_vm_hold_language_level(hg_vm_t *vm, + hg_bool_t flag); +hg_bool_t hg_vm_translate (hg_vm_t *vm, + hg_vm_trans_flags_t flags); +hg_bool_t hg_vm_main_loop (hg_vm_t *vm); +hg_char_t *hg_vm_find_libfile (hg_vm_t *vm HG_GNUC_UNUSED, + const hg_char_t *filename); +hg_bool_t hg_vm_eval (hg_vm_t *vm, + hg_quark_t qeval, + hg_stack_t *ostack, + hg_stack_t *estack, + hg_stack_t *dstack, + hg_bool_t protect_systemdict); +hg_bool_t hg_vm_eval_from_cstring (hg_vm_t *vm, + const hg_char_t *cstring, + hg_size_t clen, + hg_stack_t *ostack, + hg_stack_t *estack, + hg_stack_t *dstack, + hg_bool_t protect_systemdict); +hg_bool_t hg_vm_eval_from_file (hg_vm_t *vm, + const hg_char_t *initfile, + hg_stack_t *ostack, + hg_stack_t *estack, + hg_stack_t *dstack, + hg_bool_t protect_systemdict); +hg_int_t hg_vm_get_error_code (hg_vm_t *vm); +void hg_vm_set_error_code (hg_vm_t *vm, + hg_int_t error_code); +hg_bool_t hg_vm_startjob (hg_vm_t *vm, + hg_vm_langlevel_t lang_level, + const hg_char_t *initfile, + hg_bool_t encapsulated); +void hg_vm_shutdown (hg_vm_t *vm, + hg_int_t error_code); +hg_bool_t hg_vm_is_finished (hg_vm_t *vm); +hg_quark_t hg_vm_get_gstate (hg_vm_t *vm); +void hg_vm_set_gstate (hg_vm_t *vm, + hg_quark_t qgstate); +hg_quark_t hg_vm_get_user_params (hg_vm_t *vm, + hg_pointer_t *ret); +hg_bool_t hg_vm_set_user_params (hg_vm_t *vm, + hg_quark_t qdict); +void hg_vm_set_rand_seed (hg_vm_t *vm, + hg_uint_t seed); +hg_uint_t hg_vm_get_rand_seed (hg_vm_t *vm); +hg_uint_t hg_vm_rand_int (hg_vm_t *vm); +hg_uint_t hg_vm_get_current_time (hg_vm_t *vm); +hg_bool_t hg_vm_has_error (hg_vm_t *vm); +void hg_vm_clear_error (hg_vm_t *vm); +void hg_vm_reset_error (hg_vm_t *vm); +#if 0 +hg_bool_t hg_vm_set_error (hg_vm_t *vm, + hg_quark_t qdata, + hg_error_reason_t error); +hg_bool_t hg_vm_set_error0 (hg_vm_t *vm, + hg_quark_t qdata); +#endif +void hg_vm_reserved_spool_dump(hg_vm_t *vm, + hg_mem_t *mem, + hg_file_t *ofile); +hg_bool_t hg_vm_add_plugin (hg_vm_t *vm, + const hg_char_t *name); +void hg_vm_load_plugins (hg_vm_t *vm); +hg_bool_t hg_vm_remove_plugin (hg_vm_t *vm, + const hg_char_t *name); +void hg_vm_unload_plugins (hg_vm_t *vm); +hg_bool_t hg_vm_set_device (hg_vm_t *vm, + const hg_char_t *name); +void hg_vm_add_param (hg_vm_t *vm, + const hg_char_t *name, + hg_vm_value_t *value); /* hg_array_t */ -gboolean hg_vm_array_set(hg_vm_t *vm, - hg_quark_t qarray, - hg_quark_t qdata, - gsize index, - gboolean force); -hg_quark_t hg_vm_array_get(hg_vm_t *vm, - hg_quark_t qarray, - gsize index, - gboolean force); +hg_bool_t hg_vm_array_set(hg_vm_t *vm, + hg_quark_t qarray, + hg_quark_t qdata, + hg_usize_t index, + hg_bool_t force); +hg_quark_t hg_vm_array_get(hg_vm_t *vm, + hg_quark_t qarray, + hg_usize_t index, + hg_bool_t force); /* hg_dict_t */ -hg_quark_t hg_vm_dstack_lookup (hg_vm_t *vm, - hg_quark_t qname); -gboolean hg_vm_dstack_remove (hg_vm_t *vm, - hg_quark_t qname, - gboolean remove_all); -hg_quark_t hg_vm_dstack_get_dict(hg_vm_t *vm); -gboolean hg_vm_dict_add (hg_vm_t *vm, - hg_quark_t qdict, - hg_quark_t qkey, - hg_quark_t qval, - gboolean force); -gboolean hg_vm_dict_remove (hg_vm_t *vm, - hg_quark_t qdict, - hg_quark_t qkey); -hg_quark_t hg_vm_dict_lookup (hg_vm_t *vm, - hg_quark_t qdict, - hg_quark_t qkey, - gboolean check_perms); +hg_quark_t hg_vm_dstack_lookup (hg_vm_t *vm, + hg_quark_t qname); +hg_bool_t hg_vm_dstack_remove (hg_vm_t *vm, + hg_quark_t qname, + hg_bool_t remove_all); +hg_quark_t hg_vm_dstack_get_dict(hg_vm_t *vm); +hg_bool_t hg_vm_dict_add (hg_vm_t *vm, + hg_quark_t qdict, + hg_quark_t qkey, + hg_quark_t qval, + hg_bool_t force); +hg_bool_t hg_vm_dict_remove (hg_vm_t *vm, + hg_quark_t qdict, + hg_quark_t qkey); +hg_quark_t hg_vm_dict_lookup (hg_vm_t *vm, + hg_quark_t qdict, + hg_quark_t qkey, + hg_bool_t check_perms); /* hg_quark_t */ -hg_error_t hg_vm_quark_gc_mark (hg_vm_t *vm, - hg_quark_t qdata); -hg_quark_t hg_vm_quark_copy (hg_vm_t *vm, - hg_quark_t qdata, - hg_pointer_t *ret); -hg_quark_t hg_vm_quark_to_string (hg_vm_t *vm, - hg_quark_t qdata, - gboolean ps_like_syntax, - gpointer *ret); -gboolean hg_vm_quark_compare (hg_vm_t *vm, - hg_quark_t qdata1, - hg_quark_t qdata2); -gboolean hg_vm_quark_compare_content (hg_vm_t *vm, - hg_quark_t qdata1, - hg_quark_t qdata2); -void hg_vm_quark_set_default_acl (hg_vm_t *vm, - hg_quark_t *qdata); -void hg_vm_quark_set_acl (hg_vm_t *vm, - hg_quark_t *qdata, - hg_quark_acl_t acl); -void hg_vm_quark_set_readable (hg_vm_t *vm, - hg_quark_t *qdata, - gboolean flag); -gboolean hg_vm_quark_is_readable (hg_vm_t *vm, - hg_quark_t *qdata); -void hg_vm_quark_set_writable (hg_vm_t *vm, - hg_quark_t *qdata, - gboolean flag); -gboolean hg_vm_quark_is_writable (hg_vm_t *vm, - hg_quark_t *qdata); -void hg_vm_quark_set_executable (hg_vm_t *vm, - hg_quark_t *qdata, - gboolean flag); -gboolean hg_vm_quark_is_executable (hg_vm_t *vm, - hg_quark_t *qdata); -void hg_vm_quark_set_accessible (hg_vm_t *vm, - hg_quark_t *qdata, - gboolean flag); -gboolean hg_vm_quark_is_accessible (hg_vm_t *vm, - hg_quark_t *qdata); +hg_mem_t *hg_vm_quark_get_mem (hg_vm_t *vm, + hg_quark_t qdata); +hg_pointer_t hg_vm_quark_lock_object (hg_vm_t *vm, + hg_quark_t qdata, + const hg_char_t *pretty_function); +void hg_vm_quark_unlock_object (hg_vm_t *vm, + hg_quark_t qdata); +hg_bool_t hg_vm_quark_gc_mark (hg_vm_t *vm, + hg_quark_t qdata); +hg_quark_t hg_vm_quark_copy (hg_vm_t *vm, + hg_quark_t qdata, + hg_pointer_t *ret); +hg_quark_t hg_vm_quark_to_string (hg_vm_t *vm, + hg_quark_t qdata, + hg_bool_t ps_like_syntax, + hg_pointer_t *ret); +hg_bool_t hg_vm_quark_compare (hg_vm_t *vm, + hg_quark_t qdata1, + hg_quark_t qdata2); +hg_bool_t hg_vm_quark_compare_content(hg_vm_t *vm, + hg_quark_t qdata1, + hg_quark_t qdata2); +void hg_vm_quark_set_default_acl(hg_vm_t *vm, + hg_quark_t *qdata); +void hg_vm_quark_set_acl (hg_vm_t *vm, + hg_quark_t *qdata, + hg_quark_acl_t acl); +void hg_vm_quark_set_readable (hg_vm_t *vm, + hg_quark_t *qdata, + hg_bool_t flag); +hg_bool_t hg_vm_quark_is_readable (hg_vm_t *vm, + hg_quark_t *qdata); +void hg_vm_quark_set_writable (hg_vm_t *vm, + hg_quark_t *qdata, + hg_bool_t flag); +hg_bool_t hg_vm_quark_is_writable (hg_vm_t *vm, + hg_quark_t *qdata); +void hg_vm_quark_set_executable (hg_vm_t *vm, + hg_quark_t *qdata, + hg_bool_t flag); +hg_bool_t hg_vm_quark_is_executable (hg_vm_t *vm, + hg_quark_t *qdata); +void hg_vm_quark_set_accessible (hg_vm_t *vm, + hg_quark_t *qdata, + hg_bool_t flag); +hg_bool_t hg_vm_quark_is_accessible (hg_vm_t *vm, + hg_quark_t *qdata); /* hg_snapshot_t */ hg_error_t hg_vm_snapshot_save (hg_vm_t *vm); @@ -338,23 +344,23 @@ hg_error_t hg_vm_snapshot_restore(hg_vm_t *vm, /* hg_stack_t */ hg_stack_t *hg_vm_stack_new (hg_vm_t *vm, - gsize size); + hg_usize_t size); void hg_vm_stack_dump(hg_vm_t *vm, hg_stack_t *stack, hg_file_t *output); /* hg_string_t */ -gchar *hg_vm_string_get_cstr(hg_vm_t *vm, - hg_quark_t qstring); -guint hg_vm_string_length (hg_vm_t *vm, - hg_quark_t qstring); +hg_char_t *hg_vm_string_get_cstr(hg_vm_t *vm, + hg_quark_t qstring); +hg_uint_t hg_vm_string_length (hg_vm_t *vm, + hg_quark_t qstring); /* hg_vm_value_t */ -void hg_vm_value_free (gpointer data); -hg_vm_value_t *hg_vm_value_boolean_new(gboolean value); -hg_vm_value_t *hg_vm_value_integer_new(gint32 value); -hg_vm_value_t *hg_vm_value_real_new (gdouble value); -hg_vm_value_t *hg_vm_value_string_new (const gchar *value); +void hg_vm_value_free (hg_pointer_t data); +hg_vm_value_t *hg_vm_value_boolean_new(hg_bool_t value); +hg_vm_value_t *hg_vm_value_integer_new(hg_int_t value); +hg_vm_value_t *hg_vm_value_real_new (hg_real_t value); +hg_vm_value_t *hg_vm_value_string_new (const hg_char_t *value); HG_END_DECLS diff --git a/plugins/libedit/libedit-main.c b/plugins/libedit/libedit-main.c index 881a78c..7c6e2b1 100644 --- a/plugins/libedit/libedit-main.c +++ b/plugins/libedit/libedit-main.c @@ -130,12 +130,10 @@ DEFUNC_OPER (private_loadhistory) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QSTRING (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } cstr = hg_string_get_cstr(s); @@ -170,12 +168,10 @@ DEFUNC_OPER (private_savehistory) arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QSTRING (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } s = HG_VM_LOCK (vm, arg0); if (s == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); return FALSE; } cstr = hg_string_get_cstr(s); diff --git a/plugins/unittest/unittest-main.c b/plugins/unittest/unittest-main.c index 58c2e80..139038e 100644 --- a/plugins/unittest/unittest-main.c +++ b/plugins/unittest/unittest-main.c @@ -47,22 +47,20 @@ DEFUNC_OPER (private_validatetestresult) hg_bool_t verbose = FALSE, result = TRUE; hg_int_t attrs = 0; hg_char_t *cexp; + hg_error_reason_t e = 0; CHECK_STACK (ostack, 1); arg0 = hg_stack_index(ostack, 0); if (!HG_IS_QDICT (arg0)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_typecheck); } if (!hg_vm_quark_is_readable(vm, &arg0)) { - hg_vm_set_error(vm, qself, HG_e_invalidaccess); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_invalidaccess); } d = HG_VM_LOCK (vm, arg0); if (d == NULL) { - hg_vm_set_error(vm, qself, HG_e_VMerror); - return FALSE; + hg_error_return (HG_STATUS_FAILED, HG_e_VMerror); } qverbose = hg_dict_lookup(d, HG_QNAME ("verbose")); if (qverbose != Qnil && HG_IS_QBOOL (qverbose)) { @@ -86,7 +84,7 @@ DEFUNC_OPER (private_validatetestresult) qeerror = hg_dict_lookup(d, HG_QNAME ("expectederror")); qerrorat = hg_dict_lookup(d, HG_QNAME ("errorat")); if (qaerror == Qnil || qeerror == Qnil || qerrorat == Qnil) { - hg_vm_set_error(vm, qself, HG_e_typecheck); + e = HG_e_typecheck; goto error; } else if (!hg_vm_quark_compare(vm, qaerror, qeerror)) { if (verbose) { @@ -134,7 +132,7 @@ DEFUNC_OPER (private_validatetestresult) if (qastack == Qnil || qestack == Qnil || !HG_IS_QARRAY (qastack) || !HG_IS_QARRAY (qestack)) { - hg_vm_set_error(vm, qself, HG_e_typecheck); + e = HG_e_typecheck; goto error; } else { hg_string_t *sa, *se; @@ -178,6 +176,8 @@ DEFUNC_OPER (private_validatetestresult) hg_stack_drop(ostack); STACK_PUSH (ostack, HG_QBOOL (result && retval)); + if (e) + hg_error_return (HG_STATUS_FAILED, e); } DEFUNC_OPER_END static hg_bool_t -- cgit v1.2.3