trying to simplify structures some more.
This commit is contained in:
parent
7b014aab5b
commit
7f6ed34b95
|
@ -69,7 +69,7 @@
|
||||||
(define (make-bootstrapped-primitive-code name src)
|
(define (make-bootstrapped-primitive-code name src)
|
||||||
(parameterize ([current-defined-name name])
|
(parameterize ([current-defined-name name])
|
||||||
(append
|
(append
|
||||||
(compile (parse src) (make-PrimitivesReference name) next-linkage))))
|
(compile (parse src) (make-PrimitivesReference name) next-linkage/drop-multiple))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
29
compiler.rkt
29
compiler.rkt
|
@ -189,7 +189,10 @@
|
||||||
(append-instruction-sequences
|
(append-instruction-sequences
|
||||||
(make-instruction-sequence
|
(make-instruction-sequence
|
||||||
`(,(make-PerformStatement (make-ExtendEnvironment/Prefix! names))))
|
`(,(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-instruction-sequence
|
||||||
`(,(make-PopEnvironment (make-Const 1)
|
`(,(make-PopEnvironment (make-Const 1)
|
||||||
(make-Const 0))))))))
|
(make-Const 0))))))))
|
||||||
|
@ -373,8 +376,9 @@
|
||||||
;; All but the last will use next-linkage linkage.
|
;; All but the last will use next-linkage linkage.
|
||||||
(if (last-exp? seq)
|
(if (last-exp? seq)
|
||||||
(compile (first-exp seq) cenv target linkage)
|
(compile (first-exp seq) cenv target linkage)
|
||||||
(append-instruction-sequences (compile (first-exp seq) cenv target next-linkage)
|
(append-instruction-sequences
|
||||||
(compile-sequence (rest-exps seq) cenv target linkage))))
|
(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))
|
(: compile-splice ((Listof Expression) CompileTimeEnvironment Target Linkage -> InstructionSequence))
|
||||||
|
@ -573,7 +577,10 @@
|
||||||
next-linkage-expects-single)]
|
next-linkage-expects-single)]
|
||||||
[operand-codes (map (lambda: ([operand : Expression]
|
[operand-codes (map (lambda: ([operand : Expression]
|
||||||
[target : Target])
|
[target : Target])
|
||||||
(compile operand extended-cenv target next-linkage-expects-single))
|
(compile operand
|
||||||
|
extended-cenv
|
||||||
|
target
|
||||||
|
next-linkage-expects-single))
|
||||||
(App-operands exp)
|
(App-operands exp)
|
||||||
(build-list (length (App-operands exp))
|
(build-list (length (App-operands exp))
|
||||||
(lambda: ([i : Natural])
|
(lambda: ([i : Natural])
|
||||||
|
@ -724,7 +731,10 @@
|
||||||
(apply append-instruction-sequences
|
(apply append-instruction-sequences
|
||||||
(map (lambda: ([operand : Expression]
|
(map (lambda: ([operand : Expression]
|
||||||
[target : Target])
|
[target : Target])
|
||||||
(compile operand extended-cenv target next-linkage-expects-single))
|
(compile operand
|
||||||
|
extended-cenv
|
||||||
|
target
|
||||||
|
next-linkage-expects-single))
|
||||||
rest-operands
|
rest-operands
|
||||||
rest-operand-poss))])
|
rest-operand-poss))])
|
||||||
|
|
||||||
|
@ -875,7 +885,10 @@
|
||||||
next-linkage-expects-single)]
|
next-linkage-expects-single)]
|
||||||
[operand-codes (map (lambda: ([operand : Expression]
|
[operand-codes (map (lambda: ([operand : Expression]
|
||||||
[target : Target])
|
[target : Target])
|
||||||
(compile operand extended-cenv target next-linkage-expects-single))
|
(compile operand
|
||||||
|
extended-cenv
|
||||||
|
target
|
||||||
|
next-linkage-expects-single))
|
||||||
(App-operands exp)
|
(App-operands exp)
|
||||||
(build-list (length (App-operands exp))
|
(build-list (length (App-operands exp))
|
||||||
(lambda: ([i : Natural])
|
(lambda: ([i : Natural])
|
||||||
|
@ -1502,9 +1515,9 @@
|
||||||
-> InstructionSequence))
|
-> InstructionSequence))
|
||||||
(define (in-other-context linkage)
|
(define (in-other-context linkage)
|
||||||
(let ([body-next-linkage (cond [(NextLinkage? linkage)
|
(let ([body-next-linkage (cond [(NextLinkage? linkage)
|
||||||
next-linkage]
|
next-linkage/drop-multiple]
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? linkage)
|
||||||
next-linkage]
|
next-linkage/drop-multiple]
|
||||||
[(NextLinkage/Expects? linkage)
|
[(NextLinkage/Expects? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(LabelLinkage/Expects? linkage)
|
[(LabelLinkage/Expects? linkage)
|
||||||
|
|
|
@ -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
|
;; Linkage
|
||||||
(define-struct: NextLinkage ())
|
(define-struct: NextLinkage ())
|
||||||
(define next-linkage (make-NextLinkage))
|
(define next-linkage/drop-multiple (make-NextLinkage))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; NextLinkage/Expects works like NextLinkage, but should check that
|
;; NextLinkage/Expects works like NextLinkage, but should check that
|
||||||
;; it is returning 'expects' values back.
|
;; it is returning 'expects' values back.
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
(assemble/write-invoke (append (get-bootstrapping-code)
|
(assemble/write-invoke (append (get-bootstrapping-code)
|
||||||
(compile (parse source-code)
|
(compile (parse source-code)
|
||||||
'val
|
'val
|
||||||
next-linkage))
|
next-linkage/drop-multiple))
|
||||||
op)
|
op)
|
||||||
(fprintf op ";\n"))
|
(fprintf op ";\n"))
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
|
|
||||||
(define (run-compiler code)
|
(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.
|
;; Test out the compiler, using the simulator.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user