Make call/cc a global definition

This commit is contained in:
Justin Ethier 2015-03-23 13:04:58 -04:00
parent dc6ba643e1
commit 573f049d5e
2 changed files with 21 additions and 14 deletions

View file

@ -66,11 +66,18 @@
(trace:info "---------------- after alpha conversion:")
(trace:info input-program) ;pretty-print
(set! globals (cons 'call/cc globals))
(set! input-program
(map
(lambda (expr)
(cps-convert expr))
input-program))
(cons
;; Add call/cc here because it is already in CPS form
;; TODO: prevents this from being optimized-out
;; TODO: will this cause issues if another var is assigned to call/cc?
'(define call/cc
(lambda (k f) (f k (lambda (_ result) (k result)))))
(map
(lambda (expr)
(cps-convert expr))
input-program)))
(trace:info "---------------- after CPS:")
(trace:info input-program) ;pretty-print

View file

@ -1472,16 +1472,16 @@
;; TODO: this is very broken if call/cc is used by a global function!!!
;; TODO: if needed, should call/cc be added as a global?
;; may need a separate scanning phase to detect call/cc and add the def
(if (member 'call/cc (free-vars ast))
; add this definition for call/cc if call/cc is needed
(list
(list
'lambda
(list 'call/cc)
ast-cps)
'(lambda (k f)
(f k (lambda (_ result) (k result)))))
ast-cps)
;(if (member 'call/cc (free-vars ast))
; ; add this definition for call/cc if call/cc is needed
; (list
; (list
; 'lambda
; (list 'call/cc)
; ast-cps)
; '(lambda (k f)
; (f k (lambda (_ result) (k result)))))
ast-cps;)
))