making instructions explicit types so we can get better error trapping.
This commit is contained in:
parent
120895c624
commit
03b2a0eae8
|
@ -1,5 +1,5 @@
|
|||
#lang racket/base
|
||||
(require "structs.rkt"
|
||||
#lang typed/racket/base
|
||||
(require "typed-structs.rkt"
|
||||
racket/string
|
||||
racket/list)
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#lang typed/racket/base
|
||||
|
||||
(require "typed-structs.rkt"
|
||||
#;"assemble.rkt"
|
||||
racket/list)
|
||||
|
||||
(provide compile)
|
|
@ -31,10 +31,31 @@
|
|||
|
||||
|
||||
;; instruction sequences
|
||||
(define-type Statement (U Symbol ;; label
|
||||
AssignStatement
|
||||
PerformStatement
|
||||
TestStatement
|
||||
BranchStatement
|
||||
GotoStatement
|
||||
SaveStatement
|
||||
RestoreStatement))
|
||||
(define-struct: AssignStatement () #:transparent)
|
||||
(define-struct: PerformStatement () #:transparent)
|
||||
(define-struct: TestStatement () #:transparent)
|
||||
(define-struct: BranchStatement () #:transparent)
|
||||
(define-struct: GotoStatement () #:transparent)
|
||||
(define-struct: SaveStatement () #:transparent)
|
||||
(define-struct: RestoreStatement () #:transparent)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(define-type InstructionSequence (U Symbol instruction-sequence))
|
||||
(define-struct: instruction-sequence ([needs : (Listof Symbol)]
|
||||
[modifies : (Listof Symbol)]
|
||||
[statements : (Listof Any)]) #:transparent)
|
||||
[statements : (Listof Statement)]) #:transparent)
|
||||
(define empty-instruction-sequence (make-instruction-sequence '() '() '()))
|
||||
|
||||
(: make-label (Symbol -> Symbol))
|
||||
|
@ -53,7 +74,7 @@
|
|||
(define (registers-modified s)
|
||||
(if (symbol? s) '() (instruction-sequence-modifies s)))
|
||||
|
||||
(: statements (InstructionSequence -> (Listof Any)))
|
||||
(: statements (InstructionSequence -> (Listof Statement)))
|
||||
(define (statements s)
|
||||
(if (symbol? s) (list s) (instruction-sequence-statements s)))
|
||||
|
||||
|
@ -63,4 +84,8 @@
|
|||
(define-type Target Symbol)
|
||||
|
||||
;; Linkage
|
||||
(define-type Linkage (U 'return 'next Symbol))
|
||||
(define-type Linkage (U 'return 'next Symbol))
|
||||
|
||||
|
||||
|
||||
(define-struct: basic-block ([name : Symbol] [stmts : (Listof Statement)]) #:transparent)
|
||||
|
|
Loading…
Reference in New Issue
Block a user