From f7ffa7cfeb59517aa64b31860fa98fea504d368a Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 16 Nov 2019 22:27:48 +0100 Subject: [PATCH] flat->deep variable ref: it boots! --- include/mes/builtins.h | 1 - include/mes/mes.h | 1 + mes/module/mes/boot-module.scm | 13 ++++++------- src/builtins.c | 1 - src/eval-apply.c | 2 +- src/variable.c | 6 ++++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/mes/builtins.h b/include/mes/builtins.h index 3aafbae6..0cb9e5c3 100644 --- a/include/mes/builtins.h +++ b/include/mes/builtins.h @@ -172,7 +172,6 @@ struct scm *struct_ref (struct scm *x, struct scm *i); struct scm *struct_set_x (struct scm *x, struct scm *i, struct scm *e); /* src/variable.c */ struct scm *variable_ref (struct scm *var); -struct scm *flat_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_handle (struct scm *name, struct scm* define_p); diff --git a/include/mes/mes.h b/include/mes/mes.h index a68692b4..6fffb423 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -125,6 +125,7 @@ struct scm *cell_ref (struct scm *cell, long index); struct scm *cstring_to_list (char const *s); struct scm *cstring_to_symbol (char const *s); struct scm *current_module (); +struct scm *deep_variable_ref (struct scm *var); struct scm *fdisplay_ (struct scm *, int, int); struct scm *handle_set_x (struct scm *name, struct scm *value); struct scm *init_symbols (); diff --git a/mes/module/mes/boot-module.scm b/mes/module/mes/boot-module.scm index cd8bfde6..b21b1e23 100644 --- a/mes/module/mes/boot-module.scm +++ b/mes/module/mes/boot-module.scm @@ -44,7 +44,6 @@ (define (module-bound x) (display "core:module-bound?\n")) (define core:variable-ref variable-ref) -(define variable-ref flat-variable-ref) (define (provided? x) #f) @@ -2745,10 +2744,10 @@ (display "\n") -;; (display "===> ZEE\n") -;; (display ZEE-MODULE) -;; (display "\n") +(display "===> ZEE\n") +(display ZEE-MODULE) +(display "\n") -;; (display "===> (ZEE)\n") -;; (display (ZEE-MODULE)) -;; (display "\n") +(display "===> (ZEE)\n") +(display (ZEE-MODULE)) +(display "\n") diff --git a/src/builtins.c b/src/builtins.c index ec87f48f..c234907c 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -282,7 +282,6 @@ mes_builtins (struct scm *a) /*:((internal)) */ a = init_builtin (builtin_type, "struct-set!", 3, &struct_set_x, a); /* src/variable.c */ a = init_builtin (builtin_type, "variable-ref", 1, &variable_ref, a); - a = init_builtin (builtin_type, "flat-variable-ref", 1, &flat_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-handle", 2, &lookup_handle, a); diff --git a/src/eval-apply.c b/src/eval-apply.c index e89b718d..fe4cc8d3 100644 --- a/src/eval-apply.c +++ b/src/eval-apply.c @@ -729,7 +729,7 @@ eval: } else if (t == TVARIABLE) { - R1 = variable_ref (R1); + R1 = deep_variable_ref (R1); goto vm_return; } else if (t == TBROKEN_HEART) diff --git a/src/variable.c b/src/variable.c index 2e9b3e89..09a49bb4 100644 --- a/src/variable.c +++ b/src/variable.c @@ -22,18 +22,20 @@ #include "mes/mes.h" struct scm * -variable_ref (struct scm *var) +deep_variable_ref (struct scm *var) { assert_variable (1, var); struct scm *ref = var->variable; struct scm *value = ref->cdr; if (value == cell_undefined) error (cell_symbol_unbound_variable, var); + if (value->type == TVARIABLE) + value = value->variable; return value; } struct scm * -flat_variable_ref (struct scm *var) +variable_ref (struct scm *var) { assert_variable (1, var); struct scm *value = var->variable;