From a455aa8f5b319b2eae8c6b4ba74704e36bc1cf95 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 15 Nov 2019 17:45:27 +0100 Subject: [PATCH] core: Refactor lookup_variable. * src/variable.c (lookup_variable, lookup_variable_, lookup_ref): Drop lookup/env parameter. Update users. * src/builtins.c (mes_builtins): Update registration. * include/mes/builtins.h: Update declarations. * include/mes/mes.h: Likewise. --- include/mes/builtins.h | 4 ++-- include/mes/mes.h | 2 +- mes/module/mes/boot-0.scm | 2 +- mes/module/mes/boot-00.scm | 2 +- mes/module/mes/boot-01.scm | 2 +- mes/module/mes/boot-02.scm | 2 +- mes/module/mes/boot-03.scm | 2 +- scaffold/boot/53-closure-display.scm | 2 +- scaffold/boot/60-let-syntax-expanded.scm | 2 +- src/builtins.c | 4 ++-- src/core.c | 2 +- src/eval-apply.c | 16 ++++++++-------- src/variable.c | 14 ++++++-------- 13 files changed, 27 insertions(+), 29 deletions(-) diff --git a/include/mes/builtins.h b/include/mes/builtins.h index 73c82a26..08b4d844 100644 --- a/include/mes/builtins.h +++ b/include/mes/builtins.h @@ -174,8 +174,8 @@ struct scm *struct_set_x (struct scm *x, struct scm *i, struct scm *e); struct scm *variable_ref (struct scm *var); struct scm *variable_set_x (struct scm *var, struct scm *value); struct scm *variable_bound_p (struct scm *var); -struct scm *lookup_variable (struct scm *lookup, struct scm *name, struct scm *define_p); -struct scm *lookup_ref (struct scm *lookup, struct scm *name); +struct scm *lookup_variable (struct scm *name, struct scm *define_p); +struct scm *lookup_ref (struct scm *name); /* src/vector.c */ struct scm *make_vector (struct scm *x); struct scm *vector_length (struct scm *x); diff --git a/include/mes/mes.h b/include/mes/mes.h index 33ea07f4..beecc2c4 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -127,7 +127,7 @@ struct scm *cell_ref (struct scm *cell, long index); struct scm *fdisplay_ (struct scm *, int, int); struct scm *init_symbols (); struct scm *init_time (struct scm *a); -struct scm *lookup_variable_ (struct scm *lookup, char const* name); +struct scm *lookup_variable_ (char const* name); struct scm *make_builtin_type (); struct scm *make_bytes (char const *s, size_t length); struct scm *make_cell (long type, struct scm *car, struct scm *cdr); diff --git a/mes/module/mes/boot-0.scm b/mes/module/mes/boot-0.scm index c2532864..8aa4a9bf 100644 --- a/mes/module/mes/boot-0.scm +++ b/mes/module/mes/boot-0.scm @@ -30,7 +30,7 @@ (define mes %version) (define (defined? x) - (lookup-variable (current-module) x #f)) + (lookup-variable x #f)) (define (cond-expand-expander clauses) (if (defined? (car (car clauses))) diff --git a/mes/module/mes/boot-00.scm b/mes/module/mes/boot-00.scm index 1e84fee9..7203b231 100644 --- a/mes/module/mes/boot-00.scm +++ b/mes/module/mes/boot-00.scm @@ -20,7 +20,7 @@ (define mes %version) (define (defined? x) - (lookup-variable (current-module) x #f)) + (lookup-variable x #f)) (define (cond-expand-expander clauses) (if (defined? (car (car clauses))) diff --git a/mes/module/mes/boot-01.scm b/mes/module/mes/boot-01.scm index 577d00af..5e1bfa72 100644 --- a/mes/module/mes/boot-01.scm +++ b/mes/module/mes/boot-01.scm @@ -20,7 +20,7 @@ (define mes %version) (define (defined? x) - (lookup-variable (current-module) x #f)) + (lookup-variable x #f)) (define (cond-expand-expander clauses) (if (defined? (car (car clauses))) diff --git a/mes/module/mes/boot-02.scm b/mes/module/mes/boot-02.scm index c6beec8f..4a5a0356 100644 --- a/mes/module/mes/boot-02.scm +++ b/mes/module/mes/boot-02.scm @@ -30,7 +30,7 @@ (define mes %version) (define (defined? x) - (lookup-variable (current-module) x #f)) + (lookup-variable x #f)) (define (cond-expand-expander clauses) (if (defined? (car (car clauses))) diff --git a/mes/module/mes/boot-03.scm b/mes/module/mes/boot-03.scm index 14346201..843dfc1a 100644 --- a/mes/module/mes/boot-03.scm +++ b/mes/module/mes/boot-03.scm @@ -30,7 +30,7 @@ (define mes %version) (define (defined? x) - (lookup-variable (current-module) x #f)) + (lookup-variable x #f)) (define (cond-expand-expander clauses) (if (defined? (car (car clauses))) diff --git a/scaffold/boot/53-closure-display.scm b/scaffold/boot/53-closure-display.scm index 3dc1f7e8..9ba02224 100644 --- a/scaffold/boot/53-closure-display.scm +++ b/scaffold/boot/53-closure-display.scm @@ -28,7 +28,7 @@ (if (null? lst) (list) (cons (f (car lst)) (map f (cdr lst))))) (define (closure x) - (map car (cdr (core:cdr (core:car (core:cdr (cdr (lookup-variable (current-module) 'x #f)))))))))) + (map car (cdr (core:cdr (core:car (core:cdr (cdr (lookup-variable 'x #f)))))))))) (define (x t) #t) (define (xx x1 x2) diff --git a/scaffold/boot/60-let-syntax-expanded.scm b/scaffold/boot/60-let-syntax-expanded.scm index 84e40289..64f85c2e 100644 --- a/scaffold/boot/60-let-syntax-expanded.scm +++ b/scaffold/boot/60-let-syntax-expanded.scm @@ -20,7 +20,7 @@ (define mes %version) (define (defined? x) - (lookup-variable (current-module) x #f)) + (lookup-variable x #f)) (define (cond-expand-expander clauses) (if (defined? (car (car clauses))) diff --git a/src/builtins.c b/src/builtins.c index 4fed3135..d9e5abad 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -284,8 +284,8 @@ mes_builtins (struct scm *a) /*:((internal)) */ a = init_builtin (builtin_type, "variable-ref", 1, &variable_ref, a); a = init_builtin (builtin_type, "variable-set!", 2, &variable_set_x, a); a = init_builtin (builtin_type, "variable-bound?", 1, &variable_bound_p, a); - a = init_builtin (builtin_type, "lookup-variable", 3, &lookup_variable, a); - a = init_builtin (builtin_type, "lookup-ref", 2, &lookup_ref, a); + a = init_builtin (builtin_type, "lookup-variable", 2, &lookup_variable, a); + a = init_builtin (builtin_type, "lookup-ref", 1, &lookup_ref, a); /* src/vector.c */ a = init_builtin (builtin_type, "make-vector", -1, &make_vector, a); a = init_builtin (builtin_type, "vector-length", 1, &vector_length, a); diff --git a/src/core.c b/src/core.c index 6f2a4267..05d32775 100644 --- a/src/core.c +++ b/src/core.c @@ -149,7 +149,7 @@ struct scm * error (struct scm *key, struct scm *x) { #if !__MESC_MES__ && !__M2_PLANET__ - struct scm *throw = lookup_variable (R0, cell_symbol_throw, cell_f); + struct scm *throw = lookup_variable (cell_symbol_throw, cell_f); if (throw != cell_f) return apply (throw->cdr, cons (key, cons (x, cell_nil)), R0); #endif diff --git a/src/eval-apply.c b/src/eval-apply.c index e5e2fe63..097410e9 100644 --- a/src/eval-apply.c +++ b/src/eval-apply.c @@ -120,7 +120,7 @@ set_x (struct scm *x, struct scm *e) /*:((internal)) */ p = x->variable; else { - p = lookup_variable (R0, x, cell_f); + p = lookup_variable (x, cell_f); if (p == cell_f || p-> cdr == cell_undefined) error (cell_symbol_unbound_variable, x); } @@ -264,7 +264,7 @@ expand_variable_ (struct scm *x, struct scm *formals, int top_p) /*:((int && a != cell_symbol_primitive_load && formal_p (x->car, formals) == 0) { - v = lookup_variable (R0, a, cell_f); + v = lookup_variable (a, cell_f); if (v != cell_f) x->car = make_variable (v); } @@ -617,7 +617,7 @@ eval: macro_set_x (name, entry); } else - entry = lookup_variable (R0, name, cell_t); + entry = lookup_variable (name, cell_t); } R2 = R1; aa = R1->cdr->car; @@ -651,7 +651,7 @@ eval: } else if (global_p != 0) { - entry = lookup_variable (R0, name, cell_f); + entry = lookup_variable (name, cell_f); set_cdr_x (entry, R1); } else @@ -660,7 +660,7 @@ eval: aa = cons (entry, cell_nil); set_cdr_x (aa, cdr (R0)); set_cdr_x (R0, aa); - cl = lookup_variable (R0, cell_closure, cell_f); + cl = lookup_variable (cell_closure, cell_f); set_cdr_x (cl, aa); } R1 = cell_unspecified; @@ -685,7 +685,7 @@ eval: goto vm_return; if (R1 == cell_symbol_call_with_current_continuation) goto vm_return; - R1 = lookup_ref (R0, R1); + R1 = lookup_ref (R1); goto vm_return; } else if (t == TVARIABLE) @@ -758,13 +758,13 @@ macro_expand: macro = macro_get_handle (cell_symbol_portable_macro_expand); if (macro != cell_f) { - expanders = lookup_ref (R0, cell_symbol_sc_expander_alist); + expanders = lookup_ref (cell_symbol_sc_expander_alist); if (expanders != cell_f) { macro = assq (R1->car, expanders); if (macro != cell_f) { - sc_expand = lookup_ref (R0, cell_symbol_macro_expand); + sc_expand = lookup_ref (cell_symbol_macro_expand); R2 = R1; if (sc_expand != cell_undefined && sc_expand != cell_f) { diff --git a/src/variable.c b/src/variable.c index 86d2d769..384d403f 100644 --- a/src/variable.c +++ b/src/variable.c @@ -51,11 +51,9 @@ variable_bound_p (struct scm *var) } struct scm * -lookup_variable (struct scm *lookup, struct scm *name, struct scm *define_p) +lookup_variable (struct scm *name, struct scm *define_p) { - struct scm *handle = cell_f; - if (lookup->type = TPAIR) - handle = assq (name, lookup); + struct scm *handle = handle = assq (name, R0); if (handle == cell_f) { @@ -68,15 +66,15 @@ lookup_variable (struct scm *lookup, struct scm *name, struct scm *define_p) } struct scm * -lookup_variable_ (struct scm *lookup, char const* name) +lookup_variable_ (char const* name) { - return lookup_variable (lookup, cstring_to_symbol (name), cell_f); + return lookup_variable (cstring_to_symbol (name), cell_f); } struct scm * -lookup_ref (struct scm *lookup, struct scm *name) +lookup_ref (struct scm *name) { - struct scm *x = lookup_variable (lookup, name, cell_f); + struct scm *x = lookup_variable (name, cell_f); if (x == cell_f) error (cell_symbol_unbound_variable, name); return x->cdr;