mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-18 14:17:03 +01:00
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>
This commit is contained in:
parent
cacfd4bce9
commit
9c6407d17e
@ -196,7 +196,6 @@ FILE *tmpfp;
|
|||||||
int tok;
|
int tok;
|
||||||
int print_flag;
|
int print_flag;
|
||||||
pointer value;
|
pointer value;
|
||||||
int op;
|
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
|
||||||
void *ext_data; /* For the benefit of foreign functions */
|
void *ext_data; /* For the benefit of foreign functions */
|
||||||
|
@ -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 reverse_in_place(scheme *sc, pointer term, pointer list);
|
||||||
static pointer revappend(scheme *sc, pointer a, pointer b);
|
static pointer revappend(scheme *sc, pointer a, pointer b);
|
||||||
static void dump_stack_mark(scheme *);
|
static void dump_stack_mark(scheme *);
|
||||||
static pointer opexe_0(scheme *sc, enum scheme_opcodes op);
|
|
||||||
struct op_code_info {
|
struct op_code_info {
|
||||||
char name[31]; /* strlen ("call-with-current-continuation") + 1 */
|
char name[31]; /* strlen ("call-with-current-continuation") + 1 */
|
||||||
unsigned char min_arity;
|
unsigned char min_arity;
|
||||||
@ -2834,7 +2833,8 @@ static INLINE pointer slot_value_in_env(pointer slot)
|
|||||||
/* ========== Evaluation Cycle ========== */
|
/* ========== 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;
|
const char *str = s;
|
||||||
pointer history;
|
pointer history;
|
||||||
#if USE_ERROR_HOOK
|
#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);
|
sc->code = cons(sc, mk_string(sc, str), sc->code);
|
||||||
setimmutable(car(sc->code));
|
setimmutable(car(sc->code));
|
||||||
sc->code = cons(sc, slot_value_in_env(x), sc->code);
|
sc->code = cons(sc, slot_value_in_env(x), sc->code);
|
||||||
sc->op = (int)OP_EVAL;
|
return OP_EVAL;
|
||||||
return sc->T;
|
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
sc->args = cons(sc, mk_string(sc, str), sc->args);
|
||||||
setimmutable(car(sc->args));
|
setimmutable(car(sc->args));
|
||||||
sc->op = (int)OP_ERR0;
|
return OP_ERR0;
|
||||||
return sc->T;
|
|
||||||
}
|
}
|
||||||
#define Error_1(sc,s, a) return _Error_1(sc,s,a)
|
#define Error_1(sc,s, a) { op = _Error_1(sc,s,a); goto dispatch; }
|
||||||
#define Error_0(sc,s) return _Error_1(sc,s,0)
|
#define Error_0(sc,s) { op = _Error_1(sc,s,0); goto dispatch; }
|
||||||
|
|
||||||
/* Too small to turn into function */
|
/* Too small to turn into function */
|
||||||
# define BEGIN do {
|
# 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. */
|
/* Bounce back to Eval_Cycle and execute A. */
|
||||||
#define s_goto(sc,a) BEGIN \
|
#define s_goto(sc, a) { op = (a); goto dispatch; }
|
||||||
sc->op = (int)(a); \
|
|
||||||
return sc->T; END
|
|
||||||
|
|
||||||
#if USE_THREADED_CODE
|
#if USE_THREADED_CODE
|
||||||
|
|
||||||
@ -2959,7 +2955,7 @@ static pointer _Error_1(scheme *sc, const char *s, pointer a) {
|
|||||||
* to it. */
|
* to it. */
|
||||||
#define s_thread_to(sc, a) \
|
#define s_thread_to(sc, a) \
|
||||||
BEGIN \
|
BEGIN \
|
||||||
op = (int) (a); \
|
op = (a); \
|
||||||
goto a; \
|
goto a; \
|
||||||
END
|
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
|
/* Return to the previous frame on the dump stack, setting the current
|
||||||
* value to A. */
|
* 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
|
/* Return to the previous frame on the dump stack, setting the current
|
||||||
* value to A, and re-enable the garbage collector. */
|
* 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)
|
static INLINE void dump_stack_reset(scheme *sc)
|
||||||
{
|
{
|
||||||
@ -2996,18 +2992,20 @@ static void dump_stack_free(scheme *sc)
|
|||||||
sc->dump = sc->NIL;
|
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 dump = sc->dump;
|
||||||
pointer op;
|
pointer op;
|
||||||
unsigned long v;
|
unsigned long v;
|
||||||
|
enum scheme_opcodes next_op;
|
||||||
sc->value = (a);
|
sc->value = (a);
|
||||||
if (enable_gc)
|
if (enable_gc)
|
||||||
gc_enable(sc);
|
gc_enable(sc);
|
||||||
if (dump == sc->NIL)
|
if (dump == sc->NIL)
|
||||||
return sc->NIL;
|
return OP_QUIT;
|
||||||
free_cons(sc, dump, &op, &dump);
|
free_cons(sc, dump, &op, &dump);
|
||||||
v = (unsigned long) ivalue_unchecked(op);
|
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;
|
sc->flags = v & S_FLAG_MASK;
|
||||||
#ifdef USE_SMALL_INTEGERS
|
#ifdef USE_SMALL_INTEGERS
|
||||||
if (v < MAX_SMALL_INTEGER) {
|
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->args, &dump);
|
||||||
free_cons(sc, dump, &sc->envir, &dump);
|
free_cons(sc, dump, &sc->envir, &dump);
|
||||||
free_cons(sc, dump, &sc->code, &sc->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) {
|
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)
|
#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 x, y;
|
||||||
pointer callsite;
|
pointer callsite;
|
||||||
num v;
|
num v;
|
||||||
@ -3365,6 +3366,21 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
|
|||||||
double dd;
|
double dd;
|
||||||
#endif
|
#endif
|
||||||
int (*comp_func)(num, num) = NULL;
|
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) {
|
switch (op) {
|
||||||
CASE(OP_LOAD): /* load */
|
CASE(OP_LOAD): /* load */
|
||||||
@ -4693,7 +4709,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
|
|||||||
if(sc->interactive_repl) {
|
if(sc->interactive_repl) {
|
||||||
s_thread_to(sc,OP_T0LVL);
|
s_thread_to(sc,OP_T0LVL);
|
||||||
} else {
|
} else {
|
||||||
return sc->NIL;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4760,7 +4776,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
|
|||||||
if(is_pair(sc->args)) {
|
if(is_pair(sc->args)) {
|
||||||
sc->retcode=ivalue(car(sc->args));
|
sc->retcode=ivalue(car(sc->args));
|
||||||
}
|
}
|
||||||
return (sc->NIL);
|
return;
|
||||||
|
|
||||||
CASE(OP_GC): /* gc */
|
CASE(OP_GC): /* gc */
|
||||||
gc(sc, sc->NIL, sc->NIL);
|
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);
|
snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", op);
|
||||||
Error_0(sc,sc->strbuff);
|
Error_0(sc,sc->strbuff);
|
||||||
}
|
}
|
||||||
return sc->T; /* NOTREACHED */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*test_predicate)(pointer);
|
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;
|
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 ========== */
|
/* ========== Initialization of internal keywords ========== */
|
||||||
|
|
||||||
/* Symbols representing syntax are tagged with (OP . '()). */
|
/* 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);
|
dump_stack_initialize(sc);
|
||||||
sc->code = sc->NIL;
|
sc->code = sc->NIL;
|
||||||
sc->tracing=0;
|
sc->tracing=0;
|
||||||
sc->op = -1;
|
|
||||||
sc->flags = 0;
|
sc->flags = 0;
|
||||||
|
|
||||||
/* init sc->NIL */
|
/* init sc->NIL */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user