trying to simplify structures some more.

This commit is contained in:
Danny Yoo 2011-04-24 18:51:10 -04:00
parent 7b014aab5b
commit 7f6ed34b95
5 changed files with 36 additions and 12 deletions

View File

@ -69,7 +69,7 @@
(define (make-bootstrapped-primitive-code name src)
(parameterize ([current-defined-name name])
(append
(compile (parse src) (make-PrimitivesReference name) next-linkage))))
(compile (parse src) (make-PrimitivesReference name) next-linkage/drop-multiple))))

View File

@ -189,7 +189,10 @@
(append-instruction-sequences
(make-instruction-sequence
`(,(make-PerformStatement (make-ExtendEnvironment/Prefix! names))))
(compile (Top-code top) (cons (Top-prefix top) cenv) target next-linkage)
(compile (Top-code top)
(cons (Top-prefix top) cenv)
target
next-linkage/drop-multiple)
(make-instruction-sequence
`(,(make-PopEnvironment (make-Const 1)
(make-Const 0))))))))
@ -373,8 +376,9 @@
;; All but the last will use next-linkage linkage.
(if (last-exp? seq)
(compile (first-exp seq) cenv target linkage)
(append-instruction-sequences (compile (first-exp seq) cenv target next-linkage)
(compile-sequence (rest-exps seq) cenv target linkage))))
(append-instruction-sequences
(compile (first-exp seq) cenv target next-linkage/drop-multiple)
(compile-sequence (rest-exps seq) cenv target linkage))))
(: compile-splice ((Listof Expression) CompileTimeEnvironment Target Linkage -> InstructionSequence))
@ -573,7 +577,10 @@
next-linkage-expects-single)]
[operand-codes (map (lambda: ([operand : Expression]
[target : Target])
(compile operand extended-cenv target next-linkage-expects-single))
(compile operand
extended-cenv
target
next-linkage-expects-single))
(App-operands exp)
(build-list (length (App-operands exp))
(lambda: ([i : Natural])
@ -724,7 +731,10 @@
(apply append-instruction-sequences
(map (lambda: ([operand : Expression]
[target : Target])
(compile operand extended-cenv target next-linkage-expects-single))
(compile operand
extended-cenv
target
next-linkage-expects-single))
rest-operands
rest-operand-poss))])
@ -875,7 +885,10 @@
next-linkage-expects-single)]
[operand-codes (map (lambda: ([operand : Expression]
[target : Target])
(compile operand extended-cenv target next-linkage-expects-single))
(compile operand
extended-cenv
target
next-linkage-expects-single))
(App-operands exp)
(build-list (length (App-operands exp))
(lambda: ([i : Natural])
@ -1502,9 +1515,9 @@
-> InstructionSequence))
(define (in-other-context linkage)
(let ([body-next-linkage (cond [(NextLinkage? linkage)
next-linkage]
next-linkage/drop-multiple]
[(LabelLinkage? linkage)
next-linkage]
next-linkage/drop-multiple]
[(NextLinkage/Expects? linkage)
linkage]
[(LabelLinkage/Expects? linkage)

View File

@ -402,11 +402,22 @@
;; A ValuesContext describes if a context either
;; * accepts any number multiple values by dropping them from the stack.
;; * accepts any number of multiple values by maintaining them on the stack.
;; * accepts exactly n values, erroring out
(define-type ValuesContext (U 'drop-multiple
'keep-multiple
Natural))
;; Linkage
(define-struct: NextLinkage ())
(define next-linkage (make-NextLinkage))
(define next-linkage/drop-multiple (make-NextLinkage))
;; NextLinkage/Expects works like NextLinkage, but should check that
;; it is returning 'expects' values back.

View File

@ -19,7 +19,7 @@
(assemble/write-invoke (append (get-bootstrapping-code)
(compile (parse source-code)
'val
next-linkage))
next-linkage/drop-multiple))
op)
(fprintf op ";\n"))

View File

@ -9,7 +9,7 @@
(define (run-compiler code)
(compile (parse code) 'val next-linkage))
(compile (parse code) 'val next-linkage/drop-multiple))
;; Test out the compiler, using the simulator.