add scheme apply, rename apply-> apply_env.
This commit is contained in:
parent
08b1a52af2
commit
c1886195e6
36
mes.c
36
mes.c
|
@ -260,16 +260,10 @@ assq (scm *x, scm *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
scm *
|
scm *
|
||||||
eval_quote (scm *fn, scm *x)
|
apply_env_ (scm *fn, scm *x, scm *a)
|
||||||
{
|
|
||||||
return apply (fn, x, &scm_nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
scm *
|
|
||||||
apply_ (scm *fn, scm *x, scm *a)
|
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf ("apply fn=");
|
printf ("apply_env fn=");
|
||||||
display (fn);
|
display (fn);
|
||||||
printf (" x=");
|
printf (" x=");
|
||||||
display (x);
|
display (x);
|
||||||
|
@ -283,12 +277,12 @@ apply_ (scm *fn, scm *x, scm *a)
|
||||||
return call (&scm_call_with_values_env, append2 (x, cons (a, &scm_nil)));
|
return call (&scm_call_with_values_env, append2 (x, cons (a, &scm_nil)));
|
||||||
if (builtin_p (fn) == &scm_t)
|
if (builtin_p (fn) == &scm_t)
|
||||||
return call (fn, x);
|
return call (fn, x);
|
||||||
return apply (eval (fn, a), x, a);
|
return apply_env (eval (fn, a), x, a);
|
||||||
}
|
}
|
||||||
else if (car (fn) == &scm_lambda)
|
else if (car (fn) == &scm_lambda)
|
||||||
return begin_env (cddr (fn), pairlis (cadr (fn), x, a));
|
return begin_env (cddr (fn), pairlis (cadr (fn), x, a));
|
||||||
else if (car (fn) == &scm_label)
|
else if (car (fn) == &scm_label)
|
||||||
return apply (caddr (fn), x, cons (cons (cadr (fn), caddr (fn)), a));
|
return apply_env (caddr (fn), x, cons (cons (cadr (fn), caddr (fn)), a));
|
||||||
return &scm_unspecified;
|
return &scm_unspecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,11 +352,11 @@ eval_ (scm *e, scm *a)
|
||||||
return evcon (cdr (e), a);
|
return evcon (cdr (e), a);
|
||||||
#if MACROS
|
#if MACROS
|
||||||
else if ((macro = assq (car (e), cdr (assq (&scm_macro, a)))) != &scm_f)
|
else if ((macro = assq (car (e), cdr (assq (&scm_macro, a)))) != &scm_f)
|
||||||
return eval (apply_ (cdr (macro), cdr (e), a), a);
|
return eval (apply_env_ (cdr (macro), cdr (e), a), a);
|
||||||
#endif // MACROS
|
#endif // MACROS
|
||||||
return apply (car (e), evlis (cdr (e), a), a);
|
return apply_env (car (e), evlis (cdr (e), a), a);
|
||||||
}
|
}
|
||||||
return apply (car (e), evlis (cdr (e), a), a);
|
return apply_env (car (e), evlis (cdr (e), a), a);
|
||||||
}
|
}
|
||||||
|
|
||||||
scm *
|
scm *
|
||||||
|
@ -633,10 +627,10 @@ values (scm *x/*...*/)
|
||||||
scm *
|
scm *
|
||||||
call_with_values_env (scm *producer, scm *consumer, scm *a)
|
call_with_values_env (scm *producer, scm *consumer, scm *a)
|
||||||
{
|
{
|
||||||
scm *v = apply_ (producer, &scm_nil, a);
|
scm *v = apply_env_ (producer, &scm_nil, a);
|
||||||
if (v->type == VALUES)
|
if (v->type == VALUES)
|
||||||
v = v->cdr;
|
v = v->cdr;
|
||||||
return apply_ (consumer, v, a);
|
return apply_env_ (consumer, v, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
scm *
|
scm *
|
||||||
|
@ -1173,7 +1167,7 @@ loop (scm *r, scm *e, scm *a)
|
||||||
if (e == &scm_nil)
|
if (e == &scm_nil)
|
||||||
return r;
|
return r;
|
||||||
else if (eq_p (e, &scm_symbol_EOF) == &scm_t)
|
else if (eq_p (e, &scm_symbol_EOF) == &scm_t)
|
||||||
return apply (cdr (assq (&scm_symbol_loop2, a)),
|
return apply_env (cdr (assq (&scm_symbol_loop2, a)),
|
||||||
cons (&scm_unspecified, cons (&scm_t, cons (a, &scm_nil))), a);
|
cons (&scm_unspecified, cons (&scm_t, cons (a, &scm_nil))), a);
|
||||||
else if (eq_p (e, &scm_symbol_EOF2) == &scm_t)
|
else if (eq_p (e, &scm_symbol_EOF2) == &scm_t)
|
||||||
return r;
|
return r;
|
||||||
|
@ -1202,18 +1196,18 @@ main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
scm *
|
scm *
|
||||||
apply (scm *fn, scm *x, scm *a)
|
apply_env (scm *fn, scm *x, scm *a)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf ("\nc:apply fn=");
|
printf ("\nc:apply_env fn=");
|
||||||
display (fn);
|
display (fn);
|
||||||
printf (" x=");
|
printf (" x=");
|
||||||
display (x);
|
display (x);
|
||||||
puts ("");
|
puts ("");
|
||||||
#endif
|
#endif
|
||||||
if (fn == &scm_apply_)
|
if (fn == &scm_apply_env_)
|
||||||
return eval_ (x, a);
|
return eval_ (x, a);
|
||||||
return apply_ (fn, x, a);
|
return apply_env_ (fn, x, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool evalling_p = false;
|
bool evalling_p = false;
|
||||||
|
@ -1234,7 +1228,7 @@ eval (scm *e, scm *a)
|
||||||
|| evalling_p)
|
|| evalling_p)
|
||||||
return eval_ (e, a);
|
return eval_ (e, a);
|
||||||
evalling_p = true;
|
evalling_p = true;
|
||||||
scm *r = apply (eval__, cons (e, cons (a, &scm_nil)), a);
|
scm *r = apply_env (eval__, cons (e, cons (a, &scm_nil)), a);
|
||||||
evalling_p = false;
|
evalling_p = false;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
20
mes.mes
20
mes.mes
|
@ -52,7 +52,7 @@
|
||||||
;; ;; Page 13
|
;; ;; Page 13
|
||||||
;; (define (eval-quote fn x)
|
;; (define (eval-quote fn x)
|
||||||
;; ;(debug "eval-quote fn=~a x=~a" fn x)
|
;; ;(debug "eval-quote fn=~a x=~a" fn x)
|
||||||
;; (apply fn x '()))
|
;; (apply-env fn x '()))
|
||||||
|
|
||||||
(define (evcon c a)
|
(define (evcon c a)
|
||||||
;;(debug "evcon c=~a a=~a\n" c a)
|
;;(debug "evcon c=~a a=~a\n" c a)
|
||||||
|
@ -78,8 +78,8 @@
|
||||||
(#t (cons (eval (car m) a) (evlis (cdr m) a)))))
|
(#t (cons (eval (car m) a) (evlis (cdr m) a)))))
|
||||||
|
|
||||||
|
|
||||||
(define (apply fn x a)
|
(define (apply-env fn x a)
|
||||||
;; (display 'mes-apply:)
|
;; (display 'mes-apply-env:)
|
||||||
;; (newline)
|
;; (newline)
|
||||||
;; (display 'fn:)
|
;; (display 'fn:)
|
||||||
;; (display fn)
|
;; (display fn)
|
||||||
|
@ -94,15 +94,15 @@
|
||||||
((atom? fn)
|
((atom? fn)
|
||||||
(cond
|
(cond
|
||||||
((eq? fn 'current-module)
|
((eq? fn 'current-module)
|
||||||
(c:apply current-module '() a))
|
(c:apply-env current-module '() a))
|
||||||
((eq? fn 'call-with-values)
|
((eq? fn 'call-with-values)
|
||||||
(c:apply 'call-with-values x a))
|
(c:apply-env 'call-with-values x a))
|
||||||
((builtin? fn)
|
((builtin? fn)
|
||||||
(call fn x))
|
(call fn x))
|
||||||
(#t (apply (eval fn a) x a))))
|
(#t (apply-env (eval fn a) x a))))
|
||||||
((eq? (car fn) 'lambda)
|
((eq? (car fn) 'lambda)
|
||||||
(begin-env (cddr fn) (pairlis (cadr fn) x a)))
|
(begin-env (cddr fn) (pairlis (cadr fn) x a)))
|
||||||
((eq? (car fn) 'label) (apply (caddr fn) x (cons (cons (cadr fn)
|
((eq? (car fn) 'label) (apply-env (caddr fn) x (cons (cons (cadr fn)
|
||||||
(caddr fn)) a)))))
|
(caddr fn)) a)))))
|
||||||
|
|
||||||
(define (begin-env body a)
|
(define (begin-env body a)
|
||||||
|
@ -142,13 +142,13 @@
|
||||||
((eq? (car e) 'cond) (evcon (cdr e) a))
|
((eq? (car e) 'cond) (evcon (cdr e) a))
|
||||||
((pair? (assq (car e) (cdr (assq '*macro* a))))
|
((pair? (assq (car e) (cdr (assq '*macro* a))))
|
||||||
(c:eval
|
(c:eval
|
||||||
(c:apply
|
(c:apply-env
|
||||||
(cdr (assq (car e) (cdr (assq '*macro* a))))
|
(cdr (assq (car e) (cdr (assq '*macro* a))))
|
||||||
(cdr e)
|
(cdr e)
|
||||||
a)
|
a)
|
||||||
a))
|
a))
|
||||||
(#t (apply (car e) (evlis (cdr e) a) a))))
|
(#t (apply-env (car e) (evlis (cdr e) a) a))))
|
||||||
(#t (apply (car e) (evlis (cdr e) a) a))))
|
(#t (apply-env (car e) (evlis (cdr e) a) a))))
|
||||||
|
|
||||||
(define (eval-quasiquote e a)
|
(define (eval-quasiquote e a)
|
||||||
;; (display 'mes-eval-quasiquote:)
|
;; (display 'mes-eval-quasiquote:)
|
||||||
|
|
11
mes.scm
11
mes.scm
|
@ -58,7 +58,6 @@ exec guile -L $(pwd) -e '(mes)' -s "$0" "$@"
|
||||||
pair?
|
pair?
|
||||||
|
|
||||||
;; ADDITIONAL PRIMITIVES
|
;; ADDITIONAL PRIMITIVES
|
||||||
apply
|
|
||||||
number?
|
number?
|
||||||
procedure?
|
procedure?
|
||||||
<
|
<
|
||||||
|
@ -124,7 +123,7 @@ exec guile -L $(pwd) -e '(mes)' -s "$0" "$@"
|
||||||
(eval e (append a environment)))
|
(eval e (append a environment)))
|
||||||
|
|
||||||
(define (apply-environment fn e a)
|
(define (apply-environment fn e a)
|
||||||
(apply fn e (append a environment)))
|
(apply-env fn e (append a environment)))
|
||||||
|
|
||||||
(define (readenv a)
|
(define (readenv a)
|
||||||
(let ((x (guile:read)))
|
(let ((x (guile:read)))
|
||||||
|
@ -156,7 +155,7 @@ exec guile -L $(pwd) -e '(mes)' -s "$0" "$@"
|
||||||
(assq . ,assq)
|
(assq . ,assq)
|
||||||
|
|
||||||
(eval . ,eval-environment)
|
(eval . ,eval-environment)
|
||||||
(apply . ,apply-environment)
|
(apply-env . ,apply-environment)
|
||||||
|
|
||||||
(readenv . ,readenv)
|
(readenv . ,readenv)
|
||||||
(display . ,guile:display)
|
(display . ,guile:display)
|
||||||
|
@ -205,9 +204,9 @@ exec guile -L $(pwd) -e '(mes)' -s "$0" "$@"
|
||||||
(define (loop r e a)
|
(define (loop r e a)
|
||||||
(cond ((null? e) r)
|
(cond ((null? e) r)
|
||||||
((eq? e 'exit)
|
((eq? e 'exit)
|
||||||
(apply (cdr (assq 'loop a))
|
(apply-env (cdr (assq 'loop a))
|
||||||
(cons *unspecified* (cons #t (cons a '())))
|
(cons *unspecified* (cons #t (cons a '())))
|
||||||
a))
|
a))
|
||||||
((atom? e) (loop (eval e a) (readenv a) a))
|
((atom? e) (loop (eval e a) (readenv a) a))
|
||||||
((eq? (car e) 'define)
|
((eq? (car e) 'define)
|
||||||
(loop *unspecified* (readenv a) (cons (mes-define e a) a)))
|
(loop *unspecified* (readenv a) (cons (mes-define e a) a)))
|
||||||
|
|
Loading…
Reference in a new issue