mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Make call/cc a global definition
This commit is contained in:
parent
dc6ba643e1
commit
573f049d5e
2 changed files with 21 additions and 14 deletions
15
cyclone.scm
15
cyclone.scm
|
@ -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
|
||||
|
||||
|
|
20
trans.scm
20
trans.scm
|
@ -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;)
|
||||
))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue