Experimenting with receiving a compound-proc back from compiled code

This commit is contained in:
Justin Ethier 2015-03-03 13:34:31 -05:00
parent 917c6c00b3
commit 132f669659
2 changed files with 12 additions and 8 deletions

View file

@ -358,11 +358,13 @@
((begin? exp) (analyze-sequence (begin-actions exp))) ((begin? exp) (analyze-sequence (begin-actions exp)))
((cond? exp) (analyze (cond->if exp))) ((cond? exp) (analyze (cond->if exp)))
;; END derived expression processing ;; END derived expression processing
;; experimenting with passing these back to eval
((compound-procedure? exp)
(lambda (env) exp)) ;; TODO: good enough? update env?
;; END experimental code
((application? exp) (analyze-application exp)) ((application? exp) (analyze-application exp))
;; TODO: ;; JAE - testing with these next 3
;; TODO: ((primitive-procedure? exp) exp)
;; TODO: ((compound-procedure? exp) exp)
;; TODO: ((procedure? exp) exp)
(else (else
(error "Unknown expression type -- ANALYZE" exp)))) (error "Unknown expression type -- ANALYZE" exp))))
;(lambda () 'TODO-unknown-exp-type)))) ; JAE - this is a debug line ;(lambda () 'TODO-unknown-exp-type)))) ; JAE - this is a debug line

View file

@ -1,17 +1,19 @@
;; Temporary testing, delete this once it works ;; Temporary testing, delete this once it works
(define (mywrite x) (define (call2 fn x y)
(write x)) (write
(fn x y)))
(define (call fn a) (define (call fn a)
(fn a)) (fn a))
(call write 'hello) (call write 'hello)
call2 ;; TODO: or would be optimized out... need to fix that
;; Demonstrate sending an interpreted function to compiled code ;; Demonstrate sending an interpreted function to compiled code
;; I think in order for this to work, the compiled code would have to ;; I think in order for this to work, the compiled code would have to
;; detect an interpreted proc, and use eval to execute it ;; detect an interpreted proc, and use eval to execute it
;; TODO: to debug this, may try placing printfs in runtime's apply ;; TODO: to debug this, may try placing printfs in runtime's apply
(eval '(call (lambda (x) x) (display (+ 1 1)))) (eval '(call2 (lambda (x y) (+ y x)) 2 3))
;(eval '(call (lambda (x) (+ 1 x)) (display (+ 1 1))))
;(eval '(call write 1)) ;(eval '(call write 1))
;(eval '(call mywrite 1)) ;(eval '(call mywrite 1))