From 8fe85d2e7c1ebf0cb4f2077a64b500f2d277ba60 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Wed, 25 Feb 2009 19:11:28 +0100 Subject: [PATCH] Introduce ECL_STACK_INDEX macro --- src/c/compiler.d | 4 ++-- src/c/interpreter.d | 9 +-------- src/c/read.d | 8 ++++---- src/c/stacks.d | 2 +- src/c/string.d | 4 ++-- src/cmp/cmpcatch.lsp | 2 +- src/h/external.h | 2 +- src/h/internal.h | 1 - 8 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/c/compiler.d b/src/c/compiler.d index 0734242db..eaa9a8ef2 100644 --- a/src/c/compiler.d +++ b/src/c/compiler.d @@ -59,9 +59,9 @@ /********************* PRIVATE ********************/ -#define asm_begin() ecl_stack_index(ecl_process_env()) +#define asm_begin() current_pc() #define asm_clear(h) ecl_stack_set_index(ecl_process_env(), h) -#define current_pc() ecl_stack_index(ecl_process_env()) +#define current_pc() ECL_STACK_INDEX(ecl_process_env()) #define set_pc(n) ecl_stack_set_index(ecl_process_env(), n) #define asm_op(o) ecl_stack_push(ecl_process_env(), (cl_object)((cl_fixnum)(o))) #define asm_ref(n) (cl_fixnum)(ecl_process_env()->stack[n]) diff --git a/src/c/interpreter.d b/src/c/interpreter.d index 36b7d694a..4e6fa3ad2 100644 --- a/src/c/interpreter.d +++ b/src/c/interpreter.d @@ -66,7 +66,7 @@ FEstack_advance(void) FEerror("Internal error: stack advance beyond current point.",0); } -static void +void ecl_stack_grow(cl_env_ptr env) { ecl_stack_set_size(env, env->stack_size + env->stack_size / 2); @@ -86,13 +86,6 @@ ecl_stack_pop(cl_env_ptr env) { return *(--env->stack_top); } -#undef ecl_stack_index - -cl_index -ecl_stack_index(cl_env_ptr env) { - return env->stack_top - env->stack; -} - void ecl_stack_set_index(cl_env_ptr env, cl_index index) { cl_object *new_top = env->stack + index; diff --git a/src/c/read.d b/src/c/read.d index e0a5ae9ec..d3f722826 100644 --- a/src/c/read.d +++ b/src/c/read.d @@ -976,7 +976,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_index dim, dimcount, i; cl_object rtbl = ecl_current_readtable(); @@ -1001,7 +1001,7 @@ sharp_asterisk_reader(cl_object in, cl_object c, cl_object d) FEreader_error("Character ~:C is not allowed after #*", in, 1, CODE_CHAR(x)); } - ecl_stack_push(env, MAKE_FIXNUM(x == '1')); + ECL_STACK_PUSH(env, MAKE_FIXNUM(x == '1')); } if (Null(d)) { dim = dimcount; @@ -1011,7 +1011,7 @@ sharp_asterisk_reader(cl_object in, cl_object c, cl_object d) FEreader_error("Too many elements in #*....", in, 0); if (dim && (dimcount == 0)) FEreader_error("Cannot fill the bit-vector #*.", in, 0); - else last = env->stack_top[-1]; + else last = ECL_STACK_REF(env,-1); } x = ecl_alloc_simple_vector(dim, aet_bit); for (i = 0; i < dim; i++) { @@ -1021,7 +1021,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(env, dimcount); + ECL_STACK_POP_N_UNSAFE(env, dimcount); @(return x) } diff --git a/src/c/stacks.d b/src/c/stacks.d index 47d14b251..07c7c4d5f 100644 --- a/src/c/stacks.d +++ b/src/c/stacks.d @@ -394,7 +394,7 @@ _ecl_frs_push(register cl_env_ptr env, register cl_object val) output->frs_bds_top_index = env->bds_top - env->bds_org; output->frs_val = val; output->frs_ihs = env->ihs_top; - output->frs_sp = ecl_stack_index(env); + output->frs_sp = ECL_STACK_INDEX(env); return output; } diff --git a/src/c/string.d b/src/c/string.d index 7259182b7..f83a8833f 100644 --- a/src/c/string.d +++ b/src/c/string.d @@ -953,14 +953,14 @@ nstring_case(cl_narg narg, cl_object fun, ecl_casefun casefun, cl_va_list ARGS) for (i = 0, l = 0; i < narg; i++) { cl_object s = si_coerce_to_base_string(cl_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 = cl_alloc_simple_base_string(l); while (l) { - cl_object s = ecl_stack_pop(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/cmp/cmpcatch.lsp b/src/cmp/cmpcatch.lsp index 765a960a4..133007e39 100644 --- a/src/cmp/cmpcatch.lsp +++ b/src/cmp/cmpcatch.lsp @@ -61,7 +61,7 @@ (*unwind-exit* `((STACK ,sp) ,@*unwind-exit*))) (wt-nl "{") (wt-nl "volatile bool unwinding = FALSE;") - (wt-nl "cl_index " sp "=ecl_stack_index(cl_env_copy)," nargs ";") + (wt-nl "cl_index " sp "=ECL_STACK_INDEX(cl_env_copy)," nargs ";") (wt-nl "ecl_frame_ptr next_fr;") ;; Here we compile the form which is protected. When this form ;; is aborted, it continues at the ecl_frs_pop() with unwinding=TRUE. diff --git a/src/h/external.h b/src/h/external.h index 85096b358..1f18055ce 100644 --- a/src/h/external.h +++ b/src/h/external.h @@ -475,9 +475,9 @@ extern ECL_API void ecl_stack_frame_close(cl_object f); extern ECL_API void FEstack_underflow(void); extern ECL_API void FEstack_advance(void); +extern ECL_API void ecl_stack_grow(cl_env_ptr env); extern ECL_API void ecl_stack_push(cl_env_ptr env, cl_object o); extern ECL_API cl_object ecl_stack_pop(cl_env_ptr env); -extern ECL_API cl_index ecl_stack_index(cl_env_ptr env); extern ECL_API void ecl_stack_set_size(cl_env_ptr env, cl_index new_size); extern ECL_API void ecl_stack_set_index(cl_env_ptr env, cl_index sp); extern ECL_API void ecl_stack_pop_n(cl_env_ptr env, cl_index n); diff --git a/src/h/internal.h b/src/h/internal.h index 171e7edd1..902f09e04 100644 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -92,7 +92,6 @@ typedef struct cl_compiler_env *cl_compiler_env_ptr; /* interpreter.d */ #define ecl_stack_ref(env,n) (env)->stack[n] -#define ecl_stack_index(env) ((env)->stack_top-(env)->stack) #define ECL_BUILD_STACK_FRAME(env,name,frame) \ struct ecl_stack_frame frame;\