From 35d154345be08159c28cfb66e3a2b8248073159b Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Sun, 3 Mar 2013 15:28:02 -0700 Subject: [PATCH] Right in the middle of getting global references to work. --- whalesong/compiler/compiler.rkt | 19 +++++++++++++++---- whalesong/compiler/il-structs.rkt | 16 +++++++++++++++- whalesong/compiler/optimize-il.rkt | 4 +++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/whalesong/compiler/compiler.rkt b/whalesong/compiler/compiler.rkt index 2ee2d31..d1282e6 100644 --- a/whalesong/compiler/compiler.rkt +++ b/whalesong/compiler/compiler.rkt @@ -448,9 +448,16 @@ (make-EnvPrefixReference (ToplevelRef-depth exp) (ToplevelRef-pos exp) #t))])] + [(GlobalBucket? prefix-element) + (append-instruction-sequences + (if (ToplevelRef-check-defined? exp) + (make-Perform (make-CheckGlobalBound! (GlobalBucket-name prefix-element))) + empty-instruction-sequence) + (make-AssignImmediate + target + (make-GlobalsReference (GlobalBucket-name prefix-element))))] [(or (eq? prefix-element #f) - (symbol? prefix-element) - (GlobalBucket? prefix-element)) + (symbol? prefix-element)) (append-instruction-sequences (if (ToplevelRef-check-defined? exp) (make-Perform (make-CheckToplevelBound! @@ -487,9 +494,13 @@ (ToplevelSet-pos exp) #t) next-linkage/expects-single)] + [(GlobalBucket? prefix-element) + (compile (ToplevelSet-value exp) + cenv + (make-GlobalsReference (GlobalBucket-name prefix-element)) + next-linkage/expects-single)] [(or (eq? prefix-element #f) - (symbol? prefix-element) - (GlobalBucket? prefix-element)) + (symbol? prefix-element)) (compile (ToplevelSet-value exp) cenv (make-EnvPrefixReference (ToplevelSet-depth exp) diff --git a/whalesong/compiler/il-structs.rkt b/whalesong/compiler/il-structs.rkt index b0c4b78..94c2095 100644 --- a/whalesong/compiler/il-structs.rkt +++ b/whalesong/compiler/il-structs.rkt @@ -38,6 +38,7 @@ ModulePredicate PrimitiveKernelValue VariableReference + GlobalsReference )) @@ -45,7 +46,8 @@ (define-type Target (U AtomicRegisterSymbol EnvLexicalReference EnvPrefixReference - PrimitivesReference + PrimitivesReference + GlobalsReference ControlFrameTemporary ModulePrefixTarget )) @@ -152,6 +154,10 @@ (define-struct: PrimitivesReference ([name : Symbol]) #:transparent) +(define-struct: GlobalsReference ([name : Symbol]) + #:transparent) + + ;; Produces the entry point of the module. (define-struct: ModuleEntry ([name : ModuleLocator]) #:transparent) @@ -313,6 +319,7 @@ ModuleVariable PrimitivesReference + GlobalsReference MakeBoxedEnvironmentValue @@ -398,6 +405,12 @@ [pos : Natural]) #:transparent) +;; Check that the global can be defined. +;; If not, raise an error and stop evaluation. +(define-struct: CheckGlobalBound! ([name : Symbol]) + #:transparent) + + ;; Check the closure procedure value in 'proc and make sure it's a closure ;; that can accept the right arguments (stored as a number in the argcount register.). (define-struct: CheckClosureAndArity! () @@ -511,6 +524,7 @@ (define-type PrimitiveCommand (U CheckToplevelBound! + CheckGlobalBound! CheckClosureAndArity! CheckPrimitiveArity! diff --git a/whalesong/compiler/optimize-il.rkt b/whalesong/compiler/optimize-il.rkt index bb1fd77..2276350 100644 --- a/whalesong/compiler/optimize-il.rkt +++ b/whalesong/compiler/optimize-il.rkt @@ -147,7 +147,9 @@ [(PrimitivesReference? op) op] - )) + + [(GlobalsReference? op) + op])) (: rewrite-primcmd (PrimitiveCommand -> PrimitiveCommand))