From 815e0daa056473e0451861019af14e82d533aa7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Thu, 4 Apr 2024 17:01:07 +0200 Subject: [PATCH] stacks: make runtime stack accessors inline functions Also remove an unused operator FEstack_advance. --- src/c/compiler.d | 10 ++--- src/c/ffi.d | 6 +-- src/c/interpreter.d | 96 ++++++++++++++++++++++----------------------- src/c/read.d | 6 +-- src/c/stacks.d | 12 ++---- src/c/string.d | 4 +- src/h/external.h | 1 - src/h/stacks.h | 86 ++++++++++++++++++++++------------------ 8 files changed, 112 insertions(+), 109 deletions(-) diff --git a/src/c/compiler.d b/src/c/compiler.d index f3c054576..0c2f7b3eb 100644 --- a/src/c/compiler.d +++ b/src/c/compiler.d @@ -53,7 +53,7 @@ typedef struct cl_compiler_env *cl_compiler_ptr; #define asm_begin(env) current_pc(env) -#define current_pc(env) ECL_STACK_INDEX(env) +#define current_pc(env) ecl_stack_index(env) #define set_pc(env,n) asm_clear(env,n) #define asm_ref(env,n) (cl_fixnum)((env)->run_stack.org[n]) static void asm_clear(cl_env_ptr env, cl_index h); @@ -206,12 +206,12 @@ asm_end(cl_env_ptr env, cl_index beginning, cl_object definition) { static void asm_op(cl_env_ptr env, cl_fixnum code) { cl_object v = (cl_object)code; - ECL_STACK_PUSH(env,v); + ecl_stack_push(env,v); } static void asm_clear(cl_env_ptr env, cl_index h) { - ECL_STACK_SET_INDEX(env, h); + ecl_stack_set_index_unsafe(env, h); } static void @@ -2813,7 +2813,7 @@ save_bytecodes(cl_env_ptr env, cl_index start, cl_index end) cl_object bytecodes = ecl_alloc_simple_vector(l, ecl_aet_index); cl_index *p; for (p = bytecodes->vector.self.index; end > start; end--, p++) { - *p = (cl_index)ECL_STACK_POP_UNSAFE(env); + *p = (cl_index)ecl_stack_pop_unsafe(env); } return bytecodes; } @@ -2824,7 +2824,7 @@ restore_bytecodes(cl_env_ptr env, cl_object bytecodes) cl_index *p = bytecodes->vector.self.index; cl_index l; for (l = bytecodes->vector.dim; l; l--) { - ECL_STACK_PUSH(env, (cl_object)p[l-1]); + ecl_stack_push(env, (cl_object)p[l-1]); } ecl_dealloc(bytecodes); } diff --git a/src/c/ffi.d b/src/c/ffi.d index f6b3ff17b..34faf54de 100644 --- a/src/c/ffi.d +++ b/src/c/ffi.d @@ -904,7 +904,7 @@ prepare_cif(cl_env_ptr the_env, ffi_cif *cif, cl_object return_type, /* Push the newly allocated object onto the stack so that it * is reachable by the garbage collector */ if (ECL_CONS_CAR(args) != object) { - ECL_STACK_PUSH(the_env, object); + ecl_stack_push(the_env, object); } } args = ECL_CONS_CDR(args); @@ -937,12 +937,12 @@ prepare_cif(cl_env_ptr the_env, ffi_cif *cif, cl_object return_type, volatile cl_index sp; ffi_cif cif; @ { - sp = ECL_STACK_INDEX(the_env); + sp = ecl_stack_index(the_env); prepare_cif(the_env, &cif, return_type, arg_types, args, cc_type, NULL); ffi_call(&cif, cfun, the_env->ffi_values, (void **)the_env->ffi_values_ptrs); object = ecl_foreign_data_ref_elt(the_env->ffi_values, ecl_foreign_type_code(return_type)); - ECL_STACK_SET_INDEX(the_env, sp); + ecl_stack_set_index_unsafe(the_env, sp); if (object != ECL_NIL) { @(return object); } else { diff --git a/src/c/interpreter.d b/src/c/interpreter.d index b3a8d7413..b187cf14f 100644 --- a/src/c/interpreter.d +++ b/src/c/interpreter.d @@ -421,7 +421,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) Inlined forms for some functions which act on reg0 and stack. */ CASE(OP_CONS); { - cl_object car = ECL_STACK_POP_UNSAFE(the_env); + cl_object car = ecl_stack_pop_unsafe(the_env); reg0 = CONS(car, reg0); THREAD_NEXT; } @@ -447,7 +447,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) cl_index n; GET_OPARG(n, vector); while (--n) { - reg0 = CONS(ECL_STACK_POP_UNSAFE(the_env), reg0); + reg0 = CONS(ecl_stack_pop_unsafe(the_env), reg0); } THREAD_NEXT; } @@ -475,7 +475,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PINT); { cl_fixnum n; GET_OPARG(n, vector); - ECL_STACK_PUSH(the_env, ecl_make_fixnum(n)); + ecl_stack_push(the_env, ecl_make_fixnum(n)); THREAD_NEXT; } @@ -483,7 +483,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) Pushes the object in REG0. */ CASE(OP_PUSH); { - ECL_STACK_PUSH(the_env, reg0); + ecl_stack_push(the_env, reg0); THREAD_NEXT; } /* OP_PUSHV n{lcl} @@ -494,13 +494,13 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PUSHV); { int ndx; GET_OPARG(ndx, vector); - ECL_STACK_PUSH(the_env, ecl_lcl_env_get_var(lcl_env, ndx)); + ecl_stack_push(the_env, ecl_lcl_env_get_var(lcl_env, ndx)); THREAD_NEXT; } CASE(OP_PUSHVC); { int ndx; GET_OPARG(ndx, vector); - ECL_STACK_PUSH(the_env, ecl_lex_env_get_var(lex_env, ndx)); + ecl_stack_push(the_env, ecl_lex_env_get_var(lex_env, ndx)); THREAD_NEXT; } CASE(OP_PUSHVS); { @@ -509,7 +509,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) value = ECL_SYM_VAL(the_env, var_name); if (ecl_unlikely(value == OBJNULL)) VEunbound_variable(var_name); - ECL_STACK_PUSH(the_env, value); + ecl_stack_push(the_env, value); THREAD_NEXT; } /* OP_PUSHQ n{arg} @@ -518,7 +518,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PUSHQ); { cl_object aux; GET_DATA(aux, vector, data); - ECL_STACK_PUSH(the_env, aux); + ecl_stack_push(the_env, aux); THREAD_NEXT; } @@ -540,7 +540,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) the_env->function = ECL_SYM_FUN(s); f = ECL_SYM_FUN(s)->cfun.entry; SETUP_ENV(the_env); - reg0 = f(2, ECL_STACK_POP_UNSAFE(the_env), reg0); + reg0 = f(2, ecl_stack_pop_unsafe(the_env), reg0); THREAD_NEXT; } @@ -584,7 +584,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) the stack (They all have been deposited by OP_PUSHVALUES) */ CASE(OP_MCALL); { - narg = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env)); + narg = ecl_fixnum(ecl_stack_pop_unsafe(the_env)); reg0 = ECL_STACK_REF(the_env,-narg-1); INTERPRET_FUNCALL(reg0, the_env, frame_aux, narg, reg0); THREAD_NEXT; @@ -594,14 +594,14 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) Pops a single value pushed by a OP_PUSH* operator. */ CASE(OP_POP); { - reg0 = ECL_STACK_POP_UNSAFE(the_env); + reg0 = ecl_stack_pop_unsafe(the_env); THREAD_NEXT; } /* OP_POP1 Pops a single value pushed by a OP_PUSH* operator, ignoring it. */ CASE(OP_POP1); { - (void)ECL_STACK_POP_UNSAFE(the_env); + (void)ecl_stack_pop_unsafe(the_env); THREAD_NEXT; } /* OP_POPREQ @@ -624,7 +624,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) if (frame_index >= frame->frame.size) { reg0 = ECL_NIL; } else { - ECL_STACK_PUSH(the_env, ECL_STACK_FRAME_REF(frame, frame_index++)); + ecl_stack_push(the_env, ECL_STACK_FRAME_REF(frame, frame_index++)); reg0 = ECL_T; } THREAD_NEXT; @@ -676,8 +676,8 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) } } } - if (flag != ECL_NIL) ECL_STACK_PUSH(the_env, value); - ECL_STACK_PUSH(the_env, flag); + if (flag != ECL_NIL) ecl_stack_push(the_env, value); + ecl_stack_push(the_env, flag); } if (count && Null(aok)) { cl_object *p = first; @@ -859,7 +859,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) output values are left in VALUES(...). */ CASE(OP_THROW); { - cl_object tag_name = ECL_STACK_POP_UNSAFE(the_env); + cl_object tag_name = ecl_stack_pop_unsafe(the_env); the_env->values[0] = reg0; cl_throw(tag_name); THREAD_NEXT; @@ -954,7 +954,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PBIND); { cl_object var_name; GET_DATA(var_name, vector, data); - bind_var(lcl_env, var_name, ECL_STACK_POP_UNSAFE(the_env)); + bind_var(lcl_env, var_name, ecl_stack_pop_unsafe(the_env)); THREAD_NEXT; } CASE(OP_VBIND); { @@ -975,7 +975,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PBINDS); { cl_object var_name; GET_DATA(var_name, vector, data); - ecl_bds_bind(the_env, var_name, ECL_STACK_POP_UNSAFE(the_env)); + ecl_bds_bind(the_env, var_name, ecl_stack_pop_unsafe(the_env)); THREAD_NEXT; } CASE(OP_VBINDS); { @@ -1027,20 +1027,20 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PSETQ); { int ndx; GET_OPARG(ndx, vector); - ecl_lcl_env_set_var(lcl_env, ndx, ECL_STACK_POP_UNSAFE(the_env)); + ecl_lcl_env_set_var(lcl_env, ndx, ecl_stack_pop_unsafe(the_env)); THREAD_NEXT; } CASE(OP_PSETQC); { int ndx; GET_OPARG(ndx, vector); - ecl_lex_env_set_var(lex_env, ndx, ECL_STACK_POP_UNSAFE(the_env)); + ecl_lex_env_set_var(lex_env, ndx, ecl_stack_pop_unsafe(the_env)); THREAD_NEXT; } CASE(OP_PSETQS); { cl_object var; GET_DATA(var, vector, data); /* INV: Not NIL, and of type t_symbol */ - ECL_SETQ(the_env, var, ECL_STACK_POP_UNSAFE(the_env)); + ECL_SETQ(the_env, var, ecl_stack_pop_unsafe(the_env)); THREAD_NEXT; } CASE(OP_VSETQ); { @@ -1107,8 +1107,8 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_FRAME); { cl_opcode *exit; GET_LABEL(exit, vector); - ECL_STACK_PUSH(the_env, tangle_lcl(lcl_env)); - ECL_STACK_PUSH(the_env, (cl_object)exit); + ecl_stack_push(the_env, tangle_lcl(lcl_env)); + ecl_stack_push(the_env, (cl_object)exit); ecl_frs_push(the_env,reg1); if (__ecl_frs_push_result != 0) { reg0 = the_env->values[0]; @@ -1136,8 +1136,8 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_TAGBODY); { int n; GET_OPARG(n, vector); - ECL_STACK_PUSH(the_env, tangle_lcl(lcl_env)); - ECL_STACK_PUSH(the_env, (cl_object)vector); /* FIXME! */ + ecl_stack_push(the_env, tangle_lcl(lcl_env)); + ecl_stack_push(the_env, (cl_object)vector); /* FIXME! */ vector += n * OPARG_SIZE; ecl_frs_push(the_env,reg1); if (__ecl_frs_push_result != 0) { @@ -1158,7 +1158,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_EXIT_FRAME); { DO_EXIT_FRAME: ecl_frs_pop(the_env); - ECL_STACK_POP_N_UNSAFE(the_env, 2); + ecl_stack_pop_n_unsafe(the_env, 2); THREAD_NEXT; } CASE(OP_NIL); { @@ -1166,7 +1166,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) THREAD_NEXT; } CASE(OP_PUSHNIL); { - ECL_STACK_PUSH(the_env, ECL_NIL); + ecl_stack_push(the_env, ECL_NIL); THREAD_NEXT; } CASE(OP_VALUEREG0); { @@ -1181,7 +1181,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) PUSH_VALUES: CASE(OP_PUSHVALUES); { cl_index i = the_env->nvalues; - ECL_STACK_PUSH_N(the_env, i+1); + ecl_stack_push_n(the_env, i+1); the_env->values[0] = reg0; memcpy(&ECL_STACK_REF(the_env, -(i+1)), the_env->values, i * sizeof(cl_object)); ECL_STACK_REF(the_env, -1) = ecl_make_fixnum(the_env->nvalues); @@ -1193,7 +1193,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PUSHMOREVALUES); { cl_index n = ecl_fixnum(ECL_STACK_REF(the_env,-1)); cl_index i = the_env->nvalues; - ECL_STACK_PUSH_N(the_env, i); + ecl_stack_push_n(the_env, i); the_env->values[0] = reg0; memcpy(&ECL_STACK_REF(the_env, -(i+1)), the_env->values, i * sizeof(cl_object)); ECL_STACK_REF(the_env, -1) = ecl_make_fixnum(n + i); @@ -1204,15 +1204,15 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) */ CASE(OP_POPVALUES); { cl_object *dest = the_env->values; - int n = the_env->nvalues = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env)); + int n = the_env->nvalues = ecl_fixnum(ecl_stack_pop_unsafe(the_env)); if (n == 0) { *dest = reg0 = ECL_NIL; THREAD_NEXT; } else if (n == 1) { - *dest = reg0 = ECL_STACK_POP_UNSAFE(the_env); + *dest = reg0 = ecl_stack_pop_unsafe(the_env); THREAD_NEXT; } else { - ECL_STACK_POP_N_UNSAFE(the_env,n); + ecl_stack_pop_n_unsafe(the_env,n); memcpy(dest, &ECL_STACK_REF(the_env,0), n * sizeof(cl_object)); reg0 = *dest; THREAD_NEXT; @@ -1226,7 +1226,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) cl_fixnum n; GET_OPARG(n, vector); the_env->nvalues = n; - ECL_STACK_POP_N_UNSAFE(the_env, n); + ecl_stack_pop_n_unsafe(the_env, n); memcpy(the_env->values, &ECL_STACK_REF(the_env, 0), n * sizeof(cl_object)); reg0 = the_env->values[0]; THREAD_NEXT; @@ -1236,7 +1236,7 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) The index N-th is extracted from the top of the stack. */ CASE(OP_NTHVAL); { - cl_fixnum n = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env)); + cl_fixnum n = ecl_fixnum(ecl_stack_pop_unsafe(the_env)); if (ecl_unlikely(n < 0)) { VEwrong_arg_type_nth_val(n); } else if ((cl_index)n >= the_env->nvalues) { @@ -1262,15 +1262,15 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PROTECT); { cl_opcode *exit; GET_LABEL(exit, vector); - ECL_STACK_PUSH(the_env, tangle_lcl(lcl_env)); - ECL_STACK_PUSH(the_env, (cl_object)exit); + ecl_stack_push(the_env, tangle_lcl(lcl_env)); + ecl_stack_push(the_env, (cl_object)exit); ecl_frs_push(the_env,ECL_PROTECT_TAG); if (__ecl_frs_push_result != 0) { ecl_frs_pop(the_env); - vector = (cl_opcode *)ECL_STACK_POP_UNSAFE(the_env); - unwind_lcl(lcl_env, ECL_STACK_POP_UNSAFE(the_env)); + vector = (cl_opcode *)ecl_stack_pop_unsafe(the_env); + unwind_lcl(lcl_env, ecl_stack_pop_unsafe(the_env)); reg0 = the_env->values[0]; - ECL_STACK_PUSH(the_env, ecl_make_fixnum(the_env->frs_stack.nlj_fr - the_env->frs_stack.top)); + ecl_stack_push(the_env, ecl_make_fixnum(the_env->frs_stack.nlj_fr - the_env->frs_stack.top)); goto PUSH_VALUES; } THREAD_NEXT; @@ -1278,17 +1278,17 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) CASE(OP_PROTECT_NORMAL); { ecl_bds_unwind(the_env, the_env->frs_stack.top->frs_bds_top_index); ecl_frs_pop(the_env); - (void)ECL_STACK_POP_UNSAFE(the_env); - unwind_lcl(lcl_env, ECL_STACK_POP_UNSAFE(the_env)); - ECL_STACK_PUSH(the_env, ecl_make_fixnum(1)); + (void)ecl_stack_pop_unsafe(the_env); + unwind_lcl(lcl_env, ecl_stack_pop_unsafe(the_env)); + ecl_stack_push(the_env, ecl_make_fixnum(1)); goto PUSH_VALUES; } CASE(OP_PROTECT_EXIT); { - volatile cl_fixnum n = the_env->nvalues = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env)); + volatile cl_fixnum n = the_env->nvalues = ecl_fixnum(ecl_stack_pop_unsafe(the_env)); while (n--) - the_env->values[n] = ECL_STACK_POP_UNSAFE(the_env); + the_env->values[n] = ecl_stack_pop_unsafe(the_env); reg0 = the_env->values[0]; - n = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env)); + n = ecl_fixnum(ecl_stack_pop_unsafe(the_env)); if (n <= 0) ecl_unwind(the_env, the_env->frs_stack.top + n); THREAD_NEXT; @@ -1302,13 +1302,13 @@ ecl_interpret(cl_object frame, cl_object closure, cl_object bytecodes) */ CASE(OP_PROGV); { cl_object values = reg0; - cl_object vars = ECL_STACK_POP_UNSAFE(the_env); + cl_object vars = ecl_stack_pop_unsafe(the_env); cl_index n = ecl_progv(the_env, vars, values); - ECL_STACK_PUSH(the_env, ecl_make_fixnum(n)); + ecl_stack_push(the_env, ecl_make_fixnum(n)); THREAD_NEXT; } CASE(OP_EXIT_PROGV); { - cl_index n = ecl_fixnum(ECL_STACK_POP_UNSAFE(the_env)); + cl_index n = ecl_fixnum(ecl_stack_pop_unsafe(the_env)); ecl_bds_unwind(the_env, n); THREAD_NEXT; } diff --git a/src/c/read.d b/src/c/read.d index dcb124730..1f2c41d9d 100644 --- a/src/c/read.d +++ b/src/c/read.d @@ -910,7 +910,7 @@ static cl_object sharp_asterisk_reader(cl_object in, cl_object c, cl_object d) { cl_env_ptr env = ecl_process_env(); - cl_index sp = ECL_STACK_INDEX(env); + cl_index sp = ecl_stack_index(env); cl_object last, elt, x; cl_fixnum dim, dimcount, i; cl_object rtbl = ecl_current_readtable(); @@ -935,7 +935,7 @@ sharp_asterisk_reader(cl_object in, cl_object c, cl_object d) FEreader_error("Character ~:C is not allowed after #*", in, 1, ECL_CODE_CHAR(x)); } - ECL_STACK_PUSH(env, ecl_make_fixnum(x == '1')); + ecl_stack_push(env, ecl_make_fixnum(x == '1')); } if (Null(d)) { dim = dimcount; @@ -960,7 +960,7 @@ sharp_asterisk_reader(cl_object in, cl_object c, cl_object d) else x->vector.self.bit[i/CHAR_BIT] |= 0200 >> i%CHAR_BIT; } - ECL_STACK_POP_N_UNSAFE(env, dimcount); + ecl_stack_pop_n_unsafe(env, dimcount); @(return x); } diff --git a/src/c/stacks.d b/src/c/stacks.d index a078d04bc..7a1e1da8b 100644 --- a/src/c/stacks.d +++ b/src/c/stacks.d @@ -179,12 +179,6 @@ FEstack_underflow(void) FEerror("Internal error: stack underflow.",0); } -void -FEstack_advance(void) -{ - FEerror("Internal error: stack advance beyond current point.",0); -} - cl_object * ecl_stack_grow(cl_env_ptr env) { @@ -276,7 +270,7 @@ ecl_stack_frame_close(cl_object f) { if (f->frame.opened) { f->frame.opened = 0; - ECL_STACK_SET_INDEX(f->frame.env, f->frame.base); + ecl_stack_set_index_unsafe(f->frame.env, f->frame.base); } } @@ -703,7 +697,7 @@ _ecl_frs_push(cl_env_ptr env) ++env->frs_stack.top; output->frs_bds_top_index = env->bds_stack.top - env->bds_stack.org; output->frs_ihs = env->ihs_stack.top; - output->frs_sp = ECL_STACK_INDEX(env); + output->frs_sp = ecl_stack_index(env); return output; } @@ -718,7 +712,7 @@ ecl_unwind(cl_env_ptr env, ecl_frame_ptr fr) } env->ihs_stack.top = top->frs_ihs; ecl_bds_unwind(env, top->frs_bds_top_index); - ECL_STACK_SET_INDEX(env, top->frs_sp); + ecl_stack_set_index_unsafe(env, top->frs_sp); env->frs_stack.top = top; ecl_longjmp(env->frs_stack.top->frs_jmpbuf, 1); /* never reached */ diff --git a/src/c/string.d b/src/c/string.d index 32093f8b8..6fa76858d 100644 --- a/src/c/string.d +++ b/src/c/string.d @@ -881,14 +881,14 @@ nstring_case(cl_narg narg, cl_object fun, ecl_casefun casefun, ecl_va_list ARGS) for (i = 0, l = 0; i < narg; i++) { cl_object s = si_coerce_to_base_string(ecl_va_arg(args)); if (s->base_string.fillp) { - ECL_STACK_PUSH(the_env, s); + ecl_stack_push(the_env, s); l += s->base_string.fillp; } } /* Do actual copying by recovering those strings */ output = ecl_alloc_simple_base_string(l); while (l) { - cl_object s = ECL_STACK_POP_UNSAFE(the_env); + cl_object s = ecl_stack_pop_unsafe(the_env); size_t bytes = s->base_string.fillp; l -= bytes; memcpy(output->base_string.self + l, s->base_string.self, bytes); diff --git a/src/h/external.h b/src/h/external.h index ca4816f8e..f45137c53 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -543,7 +543,6 @@ extern ECL_API void ecl_stack_frame_close(cl_object f); #define si_apply_from_stack_frame ecl_apply_from_stack_frame extern ECL_API void FEstack_underflow(void) ecl_attr_noreturn; -extern ECL_API void FEstack_advance(void) ecl_attr_noreturn; extern ECL_API cl_object *ecl_stack_grow(cl_env_ptr env); extern ECL_API cl_object *ecl_stack_set_size(cl_env_ptr env, cl_index new_size); extern ECL_API cl_index ecl_stack_push_values(cl_env_ptr env); diff --git a/src/h/stacks.h b/src/h/stacks.h index 27f5cc57a..48558933c 100755 --- a/src/h/stacks.h +++ b/src/h/stacks.h @@ -364,51 +364,61 @@ extern ECL_API ecl_frame_ptr _ecl_frs_push(cl_env_ptr); * LISP STACK *************/ -#define ECL_STACK_INDEX(env) ((env)->run_stack.top - (env)->run_stack.org) - -#define ECL_STACK_PUSH(the_env,o) do { \ - const cl_env_ptr __env = (the_env); \ - cl_object *__new_top = __env->run_stack.top; \ - if (ecl_unlikely(__new_top >= __env->run_stack.limit)) { \ - __new_top = ecl_stack_grow(__env); \ - } \ - __env->run_stack.top = __new_top+1; \ - *__new_top = (o); } while (0) - -#define ECL_STACK_POP_UNSAFE(env) *(--((env)->run_stack.top)) - #define ECL_STACK_REF(env,n) ((env)->run_stack.top[n]) -#define ECL_STACK_SET_INDEX(the_env,ndx) do { \ - const cl_env_ptr __env = (the_env); \ - cl_object *__new_top = __env->run_stack.org + (ndx); \ - if (ecl_unlikely(__new_top > __env->run_stack.top)) \ - FEstack_advance(); \ - __env->run_stack.top = __new_top; } while (0) +static inline void +ecl_stack_push(cl_env_ptr env, cl_object o) { + cl_object *new_top = env->run_stack.top; + if (ecl_unlikely(new_top >= env->run_stack.limit)) { + new_top = ecl_stack_grow(env); + } + env->run_stack.top = new_top+1; + *new_top = (o); +} -#define ECL_STACK_POP_N(the_env,n) do { \ - const cl_env_ptr __env = (the_env); \ - cl_object *__new_top = __env->run_stack.top - (n); \ - if (ecl_unlikely(__new_top < __env->run_stack.org)) \ - FEstack_underflow(); \ - __env->run_stack.top = __new_top; } while (0) +static inline void +ecl_stack_push_n(cl_env_ptr env, cl_index n) { + cl_object *new_top = env->run_stack.top; + while (ecl_unlikely((env->run_stack.limit - new_top) <= n)) { + new_top = ecl_stack_grow(env); + } + env->run_stack.top = new_top + n; +} -#define ECL_STACK_POP_N_UNSAFE(the_env,n) ((the_env)->run_stack.top -= (n)) +static inline cl_object +ecl_stack_pop_unsafe(cl_env_ptr env) +{ + return *(--((env)->run_stack.top)); +} -#define ECL_STACK_PUSH_N(the_env,n) do { \ - const cl_env_ptr __env = (the_env) ; \ - cl_index __aux = (n); \ - cl_object *__new_top = __env->run_stack.top; \ - while (ecl_unlikely((__env->run_stack.limit - __new_top) <= __aux)) { \ - __new_top = ecl_stack_grow(__env); \ - } \ - __env->run_stack.top = __new_top + __aux; } while (0) +static inline void +ecl_stack_pop_n_unsafe(cl_env_ptr env, cl_index n) +{ + env->run_stack.top -= n; +} -#define ECL_STACK_FRAME_REF(f,ndx) ((f)->frame.env->stack[(f)->frame.base+(ndx)]) -#define ECL_STACK_FRAME_SET(f,ndx,o) do { ECL_STACK_FRAME_REF(f,ndx) = (o); } while(0) +static inline cl_index +ecl_stack_index(cl_env_ptr env) { + return (env)->run_stack.top - (env)->run_stack.org; +} -#define ECL_STACK_FRAME_PTR(f) ((f)->frame.env->stack+(f)->frame.base) -#define ECL_STACK_FRAME_TOP(f) ((f)->frame.env->stack+(f)->frame.sp) +static inline void +ecl_stack_set_index_unsafe(cl_env_ptr env, cl_index ndx) +{ + env->run_stack.top = env->run_stack.org + (ndx); +} + +#define ECL_STACK_INDEX(env) ((env)->run_stack.top - (env)->run_stack.org) + +#define ECL_STACK_FRAME_REF(f,ndx) \ + ((f)->frame.env->run_stack.org[(f)->frame.base+(ndx)]) +#define ECL_STACK_FRAME_SET(f,ndx,o) \ + do { ECL_STACK_FRAME_REF(f,ndx) = (o); } while(0) + +#define ECL_STACK_FRAME_PTR(f) \ + ((f)->frame.env->run_stack.org+(f)->frame.base) +#define ECL_STACK_FRAME_TOP(f) \ + ((f)->frame.env->run_stack.org+(f)->frame.sp) #define ECL_STACK_FRAME_COPY(dest,orig) do { \ cl_object __dst = (dest); \