diff --git a/Makefile b/Makefile index d0a9949..28cc613 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +test-analyzer: + raco make -v --disable-inline test-analyzer.rkt + racket test-analyzer.rkt + test-all: raco make -v --disable-inline tests/test-all.rkt racket tests/test-all.rkt diff --git a/analyzer-structs.rkt b/analyzer-structs.rkt index d177084..1c63d5a 100644 --- a/analyzer-structs.rkt +++ b/analyzer-structs.rkt @@ -33,3 +33,11 @@ + + +(define-struct: Analysis ([ht : (HashTable Expression CompileTimeEnvironmentEntry)])) + + +(: empty-analysis (-> Analysis)) +(define (empty-analysis) + (make-Analysis (make-hash))) \ No newline at end of file diff --git a/analyzer.rkt b/analyzer.rkt index 6075839..6dfb5ac 100644 --- a/analyzer.rkt +++ b/analyzer.rkt @@ -21,12 +21,12 @@ -(: -analyze (Expression -> (HashTable Expression CompileTimeEnvironmentEntry))) +(: -analyze (Expression -> Analysis)) (define (-analyze exp) (parameterize ([current-expression-map ((inst make-hasheq Expression CompileTimeEnvironmentEntry))]) (analyze exp '()) - (current-expression-map))) + (make-Analysis (current-expression-map)))) diff --git a/compiler.rkt b/compiler.rkt index ac110c1..9dd5ac7 100644 --- a/compiler.rkt +++ b/compiler.rkt @@ -9,6 +9,7 @@ "parameters.rkt" "sets.rkt" "analyzer-structs.rkt" + "analyzer.rkt" racket/match racket/bool racket/list) @@ -19,6 +20,9 @@ +(: current-analysis (Parameterof Analysis)) +(define current-analysis (make-parameter (empty-analysis))) + (: -compile (Expression Target Linkage -> (Listof Statement))) @@ -26,32 +30,35 @@ ;; Note: the toplevel generates the lambda body streams at the head, and then the ;; rest of the instruction stream. (define (-compile exp target linkage) - (let* ([after-lam-bodies (make-label 'afterLamBodies)] - [before-pop-prompt-multiple (make-label 'beforePopPromptMultiple)] - [before-pop-prompt (make-LinkedLabel (make-label 'beforePopPrompt) before-pop-prompt-multiple)]) - (optimize-il - (statements - (append-instruction-sequences - - ;; Layout the lambda bodies... - (make-instruction-sequence - `(,(make-GotoStatement (make-Label after-lam-bodies)))) - (compile-lambda-bodies (collect-all-lambdas-with-bodies exp)) - after-lam-bodies - - ;; Begin a prompted evaluation: - (make-instruction-sequence - `(,(make-PushControlFrame/Prompt default-continuation-prompt-tag - before-pop-prompt))) - (compile exp '() 'val return-linkage/nontail) - before-pop-prompt-multiple - (make-instruction-sequence - `(,(make-PopEnvironment (make-Reg 'argcount) (make-Const 0)))) - before-pop-prompt - (if (eq? target 'val) - empty-instruction-sequence - (make-instruction-sequence - `(,(make-AssignImmediateStatement target (make-Reg 'val)))))))))) + (parameterize ([current-analysis (analyze exp)]) + (let* ([after-lam-bodies (make-label 'afterLamBodies)] + [before-pop-prompt-multiple (make-label 'beforePopPromptMultiple)] + [before-pop-prompt (make-LinkedLabel + (make-label 'beforePopPrompt) + before-pop-prompt-multiple)]) + (optimize-il + (statements + (append-instruction-sequences + + ;; Layout the lambda bodies... + (make-instruction-sequence + `(,(make-GotoStatement (make-Label after-lam-bodies)))) + (compile-lambda-bodies (collect-all-lambdas-with-bodies exp)) + after-lam-bodies + + ;; Begin a prompted evaluation: + (make-instruction-sequence + `(,(make-PushControlFrame/Prompt default-continuation-prompt-tag + before-pop-prompt))) + (compile exp '() 'val return-linkage/nontail) + before-pop-prompt-multiple + (make-instruction-sequence + `(,(make-PopEnvironment (make-Reg 'argcount) (make-Const 0)))) + before-pop-prompt + (if (eq? target 'val) + empty-instruction-sequence + (make-instruction-sequence + `(,(make-AssignImmediateStatement target (make-Reg 'val))))))))))) (define-struct: lam+cenv ([lam : (U Lam CaseLam)] [cenv : CompileTimeEnvironment])) diff --git a/test-analyzer.rkt b/test-analyzer.rkt new file mode 100644 index 0000000..aaa4ed7 --- /dev/null +++ b/test-analyzer.rkt @@ -0,0 +1,9 @@ +#lang racket/base +(require "make-dependencies.rkt" + "make-structs.rkt") + + +;; For some reason, this is breaking. Why? +(make/dependencies + (list (build-path "make-dependencies.rkt")) + debug-configuration) \ No newline at end of file