whalesong/simulator-structs.rkt

87 lines
2.5 KiB
Racket

#lang typed/racket/base
(provide (all-defined-out))
(require "il-structs.rkt")
(define-type PrimitiveValue (Rec PrimitiveValue (U String Number Symbol Boolean
Null Void
undefined
primitive-proc
closure
(Vectorof PrimitiveValue)
MutablePair
)))
(define-type SlotValue (U PrimitiveValue
(Boxof PrimitiveValue)
toplevel
CapturedControl
CapturedEnvironment))
(define-struct: MutablePair ([h : PrimitiveValue]
[t : PrimitiveValue]))
;; For continuation capture:
(define-struct: CapturedControl ([frames : (Listof frame)]))
(define-struct: CapturedEnvironment ([vals : (Listof SlotValue)]))
(define-struct: machine ([val : SlotValue]
[proc : SlotValue]
[env : (Listof SlotValue)]
[control : (Listof frame)]
[pc : Natural] ;; program counter
[text : (Vectorof Statement)] ;; text of the program
;; other metrics for debugging
[stack-size : Natural]
)
#:transparent
#:mutable)
(define-struct: frame ([return : Symbol]
;; The procedure being called. Used to optimize self-application
[proc : (U closure #f)]
;; TODO: add continuation marks
)
#:transparent)
(define-struct: toplevel ([vals : (Listof PrimitiveValue)])
#:transparent
#:mutable)
;; Primitive procedure wrapper
(define-struct: primitive-proc ([f : (machine Symbol PrimitiveValue * -> PrimitiveValue)])
#:transparent)
;; Compiled procedure closures
(define-struct: closure ([label : Symbol]
[arity : Natural]
[vals : (Listof SlotValue)])
#:transparent)
;; undefined value
(define-struct: undefined ()
#:transparent)
(define-predicate PrimitiveValue? PrimitiveValue)