From 4f69cb8ec3db6e46ee85075b44e22cb5a5175516 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 16 Jun 2015 22:51:49 +0900 Subject: [PATCH] eval procedure now takes environment object for the second argument --- contrib/05.r7rs/scheme/eval.scm | 10 ++++------ contrib/05.r7rs/scheme/r5rs.scm | 7 ++++--- contrib/20.repl/repl.scm | 5 +++-- extlib/benz/eval.c | 13 +++++-------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/contrib/05.r7rs/scheme/eval.scm b/contrib/05.r7rs/scheme/eval.scm index 54574c03..b93764cd 100644 --- a/contrib/05.r7rs/scheme/eval.scm +++ b/contrib/05.r7rs/scheme/eval.scm @@ -4,14 +4,12 @@ (define environment (let ((counter 0)) (lambda specs - (let ((library-name `(picrin @@my-environment ,counter))) + (let ((library-name `(picrin @@my-environment ,(string->symbol (number->string counter))))) (set! counter (+ counter 1)) (eval `(define-library ,library-name - ,@(map (lambda (spec) - `(import ,spec)) - specs)) - '(scheme base)) - library-name)))) + ,@(map (lambda (spec) `(import ,spec)) specs)) + (library-environment (find-library '(scheme base)))) + (library-environment (find-library library-name)))))) (export environment eval)) diff --git a/contrib/05.r7rs/scheme/r5rs.scm b/contrib/05.r7rs/scheme/r5rs.scm index 9baebe65..e054f3bb 100644 --- a/contrib/05.r7rs/scheme/r5rs.scm +++ b/contrib/05.r7rs/scheme/r5rs.scm @@ -7,7 +7,8 @@ (scheme cxr) (scheme lazy) (scheme eval) - (scheme load)) + (scheme load) + (picrin base)) (define-library (scheme null) (import (scheme base)) @@ -25,12 +26,12 @@ (define (null-environment n) (if (not (= n 5)) (error "unsupported environment version" n) - '(scheme null))) + (library-environment (find-library '(scheme null))))) (define (scheme-report-environment n) (if (not (= n 5)) (error "unsupported environment version" n) - '(scheme r5rs))) + (library-environment (find-library '(scheme r5rs))))) (export * + - / < <= = > >= abs acos and diff --git a/contrib/20.repl/repl.scm b/contrib/20.repl/repl.scm index 3afd70c8..ad1c2e19 100644 --- a/contrib/20.repl/repl.scm +++ b/contrib/20.repl/repl.scm @@ -2,7 +2,8 @@ (import (scheme base) (scheme read) (scheme write) - (scheme eval)) + (scheme eval) + (picrin base)) (cond-expand ((library (picrin readline)) @@ -32,7 +33,7 @@ (picrin macro) (picrin array) (picrin library)) - '(picrin user)) + (library-environment (find-library '(picrin user)))) (define (repl) (let loop ((buf "")) diff --git a/extlib/benz/eval.c b/extlib/benz/eval.c index 34941a61..c81da246 100644 --- a/extlib/benz/eval.c +++ b/extlib/benz/eval.c @@ -17,16 +17,13 @@ pic_eval(pic_state *pic, pic_value program, struct pic_env *env) static pic_value pic_eval_eval(pic_state *pic) { - pic_value program, spec; - struct pic_lib *lib; + pic_value program, env; - pic_get_args(pic, "oo", &program, &spec); + pic_get_args(pic, "oo", &program, &env); - lib = pic_find_library(pic, spec); - if (lib == NULL) { - pic_errorf(pic, "no library found: ~s", spec); - } - return pic_eval(pic, program, lib->env); + pic_assert_type(pic, env, env); + + return pic_eval(pic, program, pic_env_ptr(env)); } void