#lang typed/racket (require "ast.rkt") (struct State ([stack : Stack] [dump : Dump] [heap : Heap] [globals : Globals] [stats : Stats])) (define-type Addr Symbol) (define-type Stack (Listof Addr)) (define-type Dump Null) (define-type Heap (Immutable-HashTable Addr Node)) (define-type Node (∪ (List Addr Addr) CoreScDefn Integer)) (define-type Globals (Immutable-HashTable Name Addr)) (define-type Stats Nonnegative-Integer) (: new-addr (-> Addr)) (define (new-addr) (gensym)) (: initial-dump Dump) (define initial-dump '()) (: initial-stats Stats) (define initial-stats 0) (: incr-stats (-> Stats Stats)) (define incr-stats add1) (: update-stats (-> (-> Stats Stats) State State)) (define (update-stats f mstate) (struct-copy State mstate [stats (f (State-stats mstate))])) (: allocate-node (-> Heap Node (Values Heap Addr))) (define (allocate-node heap node) (let ([addr (new-addr)]) (values (hash-set heap addr node) addr))) (: allocate-sc (-> Heap CoreScDefn (Values Heap (Pair Name Addr)))) (define (allocate-sc heap scdef) (let-values ([(heap addr) (allocate-node heap scdef)]) (values heap (cons (scdefn-name scdef) addr)))) ;; (: initial-heap (-> (Listof CoreScDefn) (Values Heap Globals))) ;; (define (initial-heap scs) ;; (for/fold ([heap ])))