diff options
author | Justus Winter <justus@g10code.com> | 2017-04-05 17:30:44 +0200 |
---|---|---|
committer | Justus Winter <justus@g10code.com> | 2017-05-03 15:31:55 +0200 |
commit | 9c6407d17e0cb9f4a370b1b83e7816577ec7d29d (patch) | |
tree | 76fbd84622abb48f718082af49bafe08a30b66c7 /tests/gpgscm | |
parent | speedo,w32: Allow installation as normal user (diff) | |
download | gnupg2-9c6407d17e0cb9f4a370b1b83e7816577ec7d29d.tar.xz gnupg2-9c6407d17e0cb9f4a370b1b83e7816577ec7d29d.zip |
gpgscm: Merge opexe_0.
* tests/gpgscm/scheme-private.h (struct scheme): Remove field 'op'.
* tests/gpgscm/scheme.c (opexe_0): Inline into 'Eval_Cycle'.
(_Error_1): Return the opcode to evaluate next.
(Error_1): Do not return, but set the opcode and goto dispatch.
(Error_0): Likewise.
(s_goto): Likewise.
(s_return): Likewise.
(s_return_enable_gc): Likewise.
(s_thread_to): Remove superfluous cast.
(_s_return): Return the opcode to evaluate next.
(scheme_init_custom_alloc): Adapt to removal of field 'op'.
Signed-off-by: Justus Winter <justus@g10code.com>
Diffstat (limited to 'tests/gpgscm')
-rw-r--r-- | tests/gpgscm/scheme-private.h | 1 | ||||
-rw-r--r-- | tests/gpgscm/scheme.c | 86 |
2 files changed, 38 insertions, 49 deletions
diff --git a/tests/gpgscm/scheme-private.h b/tests/gpgscm/scheme-private.h index bc0269ad2..0ba9a53a5 100644 --- a/tests/gpgscm/scheme-private.h +++ b/tests/gpgscm/scheme-private.h @@ -196,7 +196,6 @@ FILE *tmpfp; int tok; int print_flag; pointer value; -int op; unsigned int flags; void *ext_data; /* For the benefit of foreign functions */ diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c index 811c51fcd..47051f209 100644 --- a/tests/gpgscm/scheme.c +++ b/tests/gpgscm/scheme.c @@ -437,7 +437,6 @@ static pointer reverse(scheme *sc, pointer term, pointer list); static pointer reverse_in_place(scheme *sc, pointer term, pointer list); static pointer revappend(scheme *sc, pointer a, pointer b); static void dump_stack_mark(scheme *); -static pointer opexe_0(scheme *sc, enum scheme_opcodes op); struct op_code_info { char name[31]; /* strlen ("call-with-current-continuation") + 1 */ unsigned char min_arity; @@ -2834,7 +2833,8 @@ static INLINE pointer slot_value_in_env(pointer slot) /* ========== Evaluation Cycle ========== */ -static pointer _Error_1(scheme *sc, const char *s, pointer a) { +static enum scheme_opcodes +_Error_1(scheme *sc, const char *s, pointer a) { const char *str = s; pointer history; #if USE_ERROR_HOOK @@ -2892,8 +2892,7 @@ static pointer _Error_1(scheme *sc, const char *s, pointer a) { sc->code = cons(sc, mk_string(sc, str), sc->code); setimmutable(car(sc->code)); sc->code = cons(sc, slot_value_in_env(x), sc->code); - sc->op = (int)OP_EVAL; - return sc->T; + return OP_EVAL; } #endif @@ -2904,11 +2903,10 @@ static pointer _Error_1(scheme *sc, const char *s, pointer a) { } sc->args = cons(sc, mk_string(sc, str), sc->args); setimmutable(car(sc->args)); - sc->op = (int)OP_ERR0; - return sc->T; + return OP_ERR0; } -#define Error_1(sc,s, a) return _Error_1(sc,s,a) -#define Error_0(sc,s) return _Error_1(sc,s,0) +#define Error_1(sc,s, a) { op = _Error_1(sc,s,a); goto dispatch; } +#define Error_0(sc,s) { op = _Error_1(sc,s,0); goto dispatch; } /* Too small to turn into function */ # define BEGIN do { @@ -2949,9 +2947,7 @@ static pointer _Error_1(scheme *sc, const char *s, pointer a) { /* Bounce back to Eval_Cycle and execute A. */ -#define s_goto(sc,a) BEGIN \ - sc->op = (int)(a); \ - return sc->T; END +#define s_goto(sc, a) { op = (a); goto dispatch; } #if USE_THREADED_CODE @@ -2959,7 +2955,7 @@ static pointer _Error_1(scheme *sc, const char *s, pointer a) { * to it. */ #define s_thread_to(sc, a) \ BEGIN \ - op = (int) (a); \ + op = (a); \ goto a; \ END @@ -2975,11 +2971,11 @@ static pointer _Error_1(scheme *sc, const char *s, pointer a) { /* Return to the previous frame on the dump stack, setting the current * value to A. */ -#define s_return(sc, a) return _s_return(sc, a, 0) +#define s_return(sc, a) s_goto(sc, _s_return(sc, a, 0)) /* Return to the previous frame on the dump stack, setting the current * value to A, and re-enable the garbage collector. */ -#define s_return_enable_gc(sc, a) return _s_return(sc, a, 1) +#define s_return_enable_gc(sc, a) s_goto(sc, _s_return(sc, a, 1)) static INLINE void dump_stack_reset(scheme *sc) { @@ -2996,18 +2992,20 @@ static void dump_stack_free(scheme *sc) sc->dump = sc->NIL; } -static pointer _s_return(scheme *sc, pointer a, int enable_gc) { +static enum scheme_opcodes +_s_return(scheme *sc, pointer a, int enable_gc) { pointer dump = sc->dump; pointer op; unsigned long v; + enum scheme_opcodes next_op; sc->value = (a); if (enable_gc) gc_enable(sc); if (dump == sc->NIL) - return sc->NIL; + return OP_QUIT; free_cons(sc, dump, &op, &dump); v = (unsigned long) ivalue_unchecked(op); - sc->op = (int) (v & S_OP_MASK); + next_op = (int) (v & S_OP_MASK); sc->flags = v & S_FLAG_MASK; #ifdef USE_SMALL_INTEGERS if (v < MAX_SMALL_INTEGER) { @@ -3019,7 +3017,7 @@ static pointer _s_return(scheme *sc, pointer a, int enable_gc) { free_cons(sc, dump, &sc->args, &dump); free_cons(sc, dump, &sc->envir, &dump); free_cons(sc, dump, &sc->code, &sc->dump); - return sc->T; + return next_op; } static void s_save(scheme *sc, enum scheme_opcodes op, pointer args, pointer code) { @@ -3357,7 +3355,10 @@ int list_length(scheme *sc, pointer a) { #define s_retbool(tf) s_return(sc,(tf) ? sc->T : sc->F) -static pointer opexe_0(scheme *sc, enum scheme_opcodes op) { +/* kernel of this interpreter */ +static void +Eval_Cycle(scheme *sc, enum scheme_opcodes op) { + for (;;) { pointer x, y; pointer callsite; num v; @@ -3365,6 +3366,21 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) { double dd; #endif int (*comp_func)(num, num) = NULL; + const struct op_code_info *pcd = &dispatch_table[op]; + + dispatch: + if (pcd->name[0] != 0) { /* if built-in function, check arguments */ + char msg[STRBUFFSIZE]; + if (! check_arguments (sc, pcd, msg, sizeof msg)) { + s_goto(sc, _Error_1(sc, msg, 0)); + } + } + + if(sc->no_memory) { + fprintf(stderr,"No memory!\n"); + exit(1); + } + ok_to_freely_gc(sc); switch (op) { CASE(OP_LOAD): /* load */ @@ -4693,7 +4709,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) { if(sc->interactive_repl) { s_thread_to(sc,OP_T0LVL); } else { - return sc->NIL; + return; } } @@ -4760,7 +4776,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) { if(is_pair(sc->args)) { sc->retcode=ivalue(car(sc->args)); } - return (sc->NIL); + return; CASE(OP_GC): /* gc */ gc(sc, sc->NIL, sc->NIL); @@ -5206,7 +5222,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) { snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", op); Error_0(sc,sc->strbuff); } - return sc->T; /* NOTREACHED */ + } } typedef int (*test_predicate)(pointer); @@ -5335,31 +5351,6 @@ check_arguments (scheme *sc, const struct op_code_info *pcd, char *msg, size_t m return ok; } -/* kernel of this interpreter */ -static void Eval_Cycle(scheme *sc, enum scheme_opcodes op) { - sc->op = op; - for (;;) { - const struct op_code_info *pcd=dispatch_table+sc->op; - if (pcd->name[0] != 0) { /* if built-in function, check arguments */ - char msg[STRBUFFSIZE]; - if (! check_arguments (sc, pcd, msg, sizeof msg)) { - if(_Error_1(sc,msg,0)==sc->NIL) { - return; - } - pcd=dispatch_table+sc->op; - } - } - ok_to_freely_gc(sc); - if (opexe_0(sc, (enum scheme_opcodes)sc->op) == sc->NIL) { - return; - } - if(sc->no_memory) { - fprintf(stderr,"No memory!\n"); - exit(1); - } - } -} - /* ========== Initialization of internal keywords ========== */ /* Symbols representing syntax are tagged with (OP . '()). */ @@ -5551,7 +5542,6 @@ int scheme_init_custom_alloc(scheme *sc, func_alloc malloc, func_dealloc free) { dump_stack_initialize(sc); sc->code = sc->NIL; sc->tracing=0; - sc->op = -1; sc->flags = 0; /* init sc->NIL */ |