mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 01:07:34 +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 "---------------- after alpha conversion:")
|
||||||
(trace:info input-program) ;pretty-print
|
(trace:info input-program) ;pretty-print
|
||||||
|
|
||||||
|
(set! globals (cons 'call/cc globals))
|
||||||
(set! input-program
|
(set! input-program
|
||||||
(map
|
(cons
|
||||||
(lambda (expr)
|
;; Add call/cc here because it is already in CPS form
|
||||||
(cps-convert expr))
|
;; TODO: prevents this from being optimized-out
|
||||||
input-program))
|
;; 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 "---------------- after CPS:")
|
||||||
(trace:info input-program) ;pretty-print
|
(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: this is very broken if call/cc is used by a global function!!!
|
||||||
;; TODO: if needed, should call/cc be added as a global?
|
;; 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
|
;; may need a separate scanning phase to detect call/cc and add the def
|
||||||
(if (member 'call/cc (free-vars ast))
|
;(if (member 'call/cc (free-vars ast))
|
||||||
; add this definition for call/cc if call/cc is needed
|
; ; add this definition for call/cc if call/cc is needed
|
||||||
(list
|
; (list
|
||||||
(list
|
; (list
|
||||||
'lambda
|
; 'lambda
|
||||||
(list 'call/cc)
|
; (list 'call/cc)
|
||||||
ast-cps)
|
; ast-cps)
|
||||||
'(lambda (k f)
|
; '(lambda (k f)
|
||||||
(f k (lambda (_ result) (k result)))))
|
; (f k (lambda (_ result) (k result)))))
|
||||||
ast-cps)
|
ast-cps;)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue