in the middle
This commit is contained in:
parent
a1aa14885a
commit
4f2e6f8546
29
parse.rkt
29
parse.rkt
|
@ -147,6 +147,12 @@
|
||||||
(parse (set!-value exp) cenv #f))])
|
(parse (set!-value exp) cenv #f))])
|
||||||
(make-Constant (void)))))]
|
(make-Constant (void)))))]
|
||||||
|
|
||||||
|
[(with-continuation-mark? exp)
|
||||||
|
(make-WithContMark (parse (with-continuation-mark-key exp) cenv #f)
|
||||||
|
(parse (with-continuation-mark-value exp) cenv #f)
|
||||||
|
(parse (with-continuation-mark-body exp) cenv #f))]
|
||||||
|
|
||||||
|
|
||||||
;; Remember, this needs to be the last case.
|
;; Remember, this needs to be the last case.
|
||||||
[(application? exp)
|
[(application? exp)
|
||||||
(let ([cenv-with-scratch-space
|
(let ([cenv-with-scratch-space
|
||||||
|
@ -272,6 +278,11 @@
|
||||||
(cons (set!-name exp)
|
(cons (set!-name exp)
|
||||||
(loop (set!-value exp)))]
|
(loop (set!-value exp)))]
|
||||||
|
|
||||||
|
[(with-continuation-mark? exp)
|
||||||
|
(append (loop (with-continuation-mark-key exp))
|
||||||
|
(loop (with-continuation-mark-value exp))
|
||||||
|
(loop (with-continuation-mark-body exp)))]
|
||||||
|
|
||||||
;; Remember: this needs to be the last case.
|
;; Remember: this needs to be the last case.
|
||||||
[(application? exp)
|
[(application? exp)
|
||||||
(append (loop (operator exp))
|
(append (loop (operator exp))
|
||||||
|
@ -335,6 +346,11 @@
|
||||||
(cons (set!-name exp)
|
(cons (set!-name exp)
|
||||||
(loop (set!-value exp)))]
|
(loop (set!-value exp)))]
|
||||||
|
|
||||||
|
[(with-continuation-mark? exp)
|
||||||
|
(append (loop (with-continuation-mark-key exp))
|
||||||
|
(loop (with-continuation-mark-value exp))
|
||||||
|
(loop (with-continuation-mark-body exp)))]
|
||||||
|
|
||||||
;; Remember, this needs to be the last case.
|
;; Remember, this needs to be the last case.
|
||||||
[(application? exp)
|
[(application? exp)
|
||||||
(append (loop (operator exp))
|
(append (loop (operator exp))
|
||||||
|
@ -465,6 +481,19 @@
|
||||||
,(loop (cdr clauses))))])))
|
,(loop (cdr clauses))))])))
|
||||||
|
|
||||||
|
|
||||||
|
(define (with-continuation-mark? exp)
|
||||||
|
(tagged-list? exp 'with-continuation-mark))
|
||||||
|
|
||||||
|
(define (with-continuation-mark-key exp)
|
||||||
|
(cadr exp))
|
||||||
|
(define (with-continuation-mark-value exp)
|
||||||
|
(caddr exp))
|
||||||
|
(define (with-continuation-mark-body exp)
|
||||||
|
(cadddr exp))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Fixme: see if the parameter is mutated. If so, box it.
|
;; Fixme: see if the parameter is mutated. If so, box it.
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(require "simulator-structs.rkt"
|
(require "simulator-structs.rkt"
|
||||||
"il-structs.rkt"
|
"il-structs.rkt"
|
||||||
racket/math
|
racket/math
|
||||||
|
racket/list
|
||||||
(for-syntax racket/base))
|
(for-syntax racket/base))
|
||||||
|
|
||||||
(provide lookup-primitive set-primitive!)
|
(provide lookup-primitive set-primitive!)
|
||||||
|
@ -133,6 +134,28 @@
|
||||||
the-void-value))
|
the-void-value))
|
||||||
|
|
||||||
|
|
||||||
|
(define current-continuation-marks
|
||||||
|
(letrec ([f (case-lambda [(a-machine)
|
||||||
|
(f a-machine default-continuation-prompt-tag-value)]
|
||||||
|
[(a-machine tag)
|
||||||
|
(make-ContinuationMarkSet
|
||||||
|
(let loop ([frames (machine-control a-machine)])
|
||||||
|
(cond
|
||||||
|
[(empty? frames)
|
||||||
|
empty]
|
||||||
|
[(eq? tag (frame-tag (first frames)))
|
||||||
|
empty]
|
||||||
|
[else
|
||||||
|
(append (hash-map (frame-marks (first frames))
|
||||||
|
cons)
|
||||||
|
(loop (rest frames)))])))])])
|
||||||
|
(make-primitive-proc (lambda args (apply f args))
|
||||||
|
'(1 2)
|
||||||
|
'current-continuation-marks)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define lookup-primitive (make-lookup #:functions (+ - * / = < <= > >=
|
(define lookup-primitive (make-lookup #:functions (+ - * / = < <= > >=
|
||||||
sub1
|
sub1
|
||||||
not
|
not
|
||||||
|
@ -182,6 +205,7 @@
|
||||||
|
|
||||||
|
|
||||||
symbol?)
|
symbol?)
|
||||||
#:constants (null pi e)))
|
#:constants (null pi e
|
||||||
|
current-continuation-marks)))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,34 @@
|
||||||
[marks : (HashTable PrimitiveValue PrimitiveValue)])
|
[marks : (HashTable PrimitiveValue PrimitiveValue)])
|
||||||
#:transparent)
|
#:transparent)
|
||||||
|
|
||||||
|
|
||||||
|
(: frame-temps (frame -> (HashTable Symbol PrimitiveValue)))
|
||||||
|
(define (frame-temps a-frame)
|
||||||
|
(cond
|
||||||
|
[(CallFrame? a-frame)
|
||||||
|
(CallFrame-temps a-frame)]
|
||||||
|
[(PromptFrame? a-frame)
|
||||||
|
(PromptFrame-temps a-frame)]))
|
||||||
|
|
||||||
|
|
||||||
|
(: frame-marks (frame -> (HashTable PrimitiveValue PrimitiveValue)))
|
||||||
|
(define (frame-marks a-frame)
|
||||||
|
(cond
|
||||||
|
[(CallFrame? a-frame)
|
||||||
|
(CallFrame-marks a-frame)]
|
||||||
|
[(PromptFrame? a-frame)
|
||||||
|
(PromptFrame-marks a-frame)]))
|
||||||
|
|
||||||
|
(: frame-tag (frame -> (U ContinuationPromptTagValue #f)))
|
||||||
|
(define (frame-tag a-frame)
|
||||||
|
(cond
|
||||||
|
[(CallFrame? a-frame)
|
||||||
|
#f]
|
||||||
|
[(PromptFrame? a-frame)
|
||||||
|
(PromptFrame-tag a-frame)]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define-struct: ContinuationPromptTagValue ([name : Symbol])
|
(define-struct: ContinuationPromptTagValue ([name : Symbol])
|
||||||
#:transparent)
|
#:transparent)
|
||||||
|
|
||||||
|
@ -82,6 +110,15 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(define-struct: ContinuationMarkSet ([marks : (Listof (Pairof PrimitiveValue PrimitiveValue))])
|
||||||
|
#:transparent)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define-struct: toplevel ([names : (Listof (U #f Symbol ModuleVariable))]
|
(define-struct: toplevel ([names : (Listof (U #f Symbol ModuleVariable))]
|
||||||
[vals : (Listof PrimitiveValue)])
|
[vals : (Listof PrimitiveValue)])
|
||||||
#:transparent
|
#:transparent
|
||||||
|
|
|
@ -457,22 +457,6 @@
|
||||||
(ensure-primitive-value v))
|
(ensure-primitive-value v))
|
||||||
'ok))]))
|
'ok))]))
|
||||||
|
|
||||||
(: frame-temps (frame -> (HashTable Symbol PrimitiveValue)))
|
|
||||||
(define (frame-temps a-frame)
|
|
||||||
(cond
|
|
||||||
[(CallFrame? a-frame)
|
|
||||||
(CallFrame-temps a-frame)]
|
|
||||||
[(PromptFrame? a-frame)
|
|
||||||
(PromptFrame-temps a-frame)]))
|
|
||||||
|
|
||||||
|
|
||||||
(: frame-marks (frame -> (HashTable PrimitiveValue PrimitiveValue)))
|
|
||||||
(define (frame-marks a-frame)
|
|
||||||
(cond
|
|
||||||
[(CallFrame? a-frame)
|
|
||||||
(CallFrame-marks a-frame)]
|
|
||||||
[(PromptFrame? a-frame)
|
|
||||||
(PromptFrame-marks a-frame)]))
|
|
||||||
|
|
||||||
|
|
||||||
(: step-assign-primitive-operation! (machine AssignPrimOpStatement -> 'ok))
|
(: step-assign-primitive-operation! (machine AssignPrimOpStatement -> 'ok))
|
||||||
|
|
|
@ -1082,6 +1082,11 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(test '(with-continuation-mark 'name "danny"
|
||||||
|
(continuation-mark-set->list (current-continuation-marks)))
|
||||||
|
'("danny"))
|
||||||
|
|
||||||
|
|
||||||
#;(test (read (open-input-file "tests/conform/program0.sch"))
|
#;(test (read (open-input-file "tests/conform/program0.sch"))
|
||||||
(port->string (open-input-file "tests/conform/expected0.txt")))
|
(port->string (open-input-file "tests/conform/expected0.txt")))
|
||||||
|
|
||||||
|
|
|
@ -479,3 +479,11 @@
|
||||||
'lamEntry1))
|
'lamEntry1))
|
||||||
(make-App (make-ToplevelRef 0 3) '())
|
(make-App (make-ToplevelRef 0 3) '())
|
||||||
(make-App (make-ToplevelRef 2 2) (list (make-ToplevelRef 2 0) (make-ToplevelRef 2 1)))))))
|
(make-App (make-ToplevelRef 2 2) (list (make-ToplevelRef 2 0) (make-ToplevelRef 2 1)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(test (parse '(with-continuation-mark x y z))
|
||||||
|
(make-Top (make-Prefix '(x y z))
|
||||||
|
(make-WithContMark (make-ToplevelRef 0 0)
|
||||||
|
(make-ToplevelRef 0 1)
|
||||||
|
(make-ToplevelRef 0 2))))
|
Loading…
Reference in New Issue
Block a user