From 380890b13dd9aa72bbbe3bb3839ec4198b41eb6e Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Wed, 25 May 2011 17:50:16 -0400 Subject: [PATCH] fixing bug with print-values --- compiler.rkt | 74 +++++++++++++++++++----------------- js-assembler/mini-runtime.js | 5 ++- js-assembler/package.rkt | 5 ++- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/compiler.rkt b/compiler.rkt index f02fa6d..67532dd 100644 --- a/compiler.rkt +++ b/compiler.rkt @@ -326,41 +326,45 @@ [names : (Listof (U False Symbol GlobalBucket ModuleVariable)) (Prefix-names prefix)] [module-cenv : CompileTimeEnvironment (list prefix)]) - - (end-with-linkage - linkage cenv - (append-instruction-sequences - (make-instruction-sequence - `(,(make-PerformStatement (make-InstallModuleEntry! name path module-entry)) - ,(make-GotoStatement (make-Label after-module-body)))) - - - module-entry - (make-PerformStatement (make-MarkModuleInvoked! path)) - ;; Module body definition: - ;; 1. First invoke all the modules that this requires. - (apply append-instruction-sequences (map compile-module-invoke (Module-requires mod))) - - ;; 2. Next, evaluate the module body. - (make-instruction-sequence - `(,(make-PerformStatement (make-ExtendEnvironment/Prefix! names)))) + + (end-with-linkage + linkage cenv + (append-instruction-sequences + (make-PerformStatement (make-InstallModuleEntry! name path module-entry)) + (make-GotoStatement (make-Label after-module-body)) - (make-AssignImmediateStatement (make-ModulePrefixTarget path) - (make-EnvWholePrefixReference 0)) - ;; TODO: we need to sequester the prefix of the module with the record. - (compile (Module-code mod) - (cons (Module-prefix mod) module-cenv) - 'val - next-linkage/drop-multiple) - - ;; 3. Finally, cleanup and return. - (make-instruction-sequence - `(,(make-PopEnvironment (make-Const 1) (make-Const 0)) - ,(make-AssignImmediateStatement 'proc (make-ControlStackLabel)) - ,(make-PopControlFrame) - ,(make-GotoStatement (make-Reg 'proc)))) - - after-module-body)))])) + + module-entry + (make-PerformStatement (make-MarkModuleInvoked! path)) + ;; Module body definition: + ;; 1. First invoke all the modules that this requires. + (make-DebugPrint (make-Const "handling internal requires")) + (apply append-instruction-sequences + (map compile-module-invoke (Module-requires mod))) + + ;; 2. Next, evaluate the module body. + (make-DebugPrint (make-Const (format "evaluating module body of ~s" path))) + (make-PerformStatement (make-ExtendEnvironment/Prefix! names)) + + (make-AssignImmediateStatement (make-ModulePrefixTarget path) + (make-EnvWholePrefixReference 0)) + ;; TODO: we need to sequester the prefix of the module with the record. + (compile (Module-code mod) + (cons (Module-prefix mod) module-cenv) + 'val + next-linkage/drop-multiple) + + (make-DebugPrint (make-Const (format "About to clean up ~s" path))) + + ;; 3. Finally, cleanup and return. + (make-PopEnvironment (make-Const 1) (make-Const 0)) + (make-AssignImmediateStatement 'proc (make-ControlStackLabel)) + (make-PopControlFrame) + (make-DebugPrint (make-Const "Returning from module invokation.")) + (make-DebugPrint (make-Reg 'proc)) + (make-GotoStatement (make-Reg 'proc)) + + after-module-body)))])) (: compile-require (Require CompileTimeEnvironment Target Linkage -> InstructionSequence)) (define (compile-require exp cenv target linkage) @@ -399,6 +403,7 @@ ,(make-TestAndBranchStatement (make-TestTrue (make-IsModuleInvoked a-module-name)) already-loaded) + ,(make-DebugPrint (make-Const (format "entering module ~s" a-module-name))) ,(make-PushControlFrame/Call on-return) ,(make-GotoStatement (ModuleEntry a-module-name)) ,on-return-multiple @@ -406,6 +411,7 @@ (make-Const 1)) (make-Const 0)) ,on-return + ,(make-DebugPrint (make-Const (format "coming back from module ~s" a-module-name))) ,already-loaded)))])) diff --git a/js-assembler/mini-runtime.js b/js-assembler/mini-runtime.js index cbfd6e0..eae16fd 100644 --- a/js-assembler/mini-runtime.js +++ b/js-assembler/mini-runtime.js @@ -496,8 +496,9 @@ } outputPort.write(MACHINE, "\n"); } - MACHINE.env.length = MACHINE.env.length - (MACHINE.argcount - 1); - throw MACHINE.control.pop(); + MACHINE.env.length = MACHINE.env.length - MACHINE.argcount; + var frame = MACHINE.control.pop(); + return frame.label(MACHINE); }, new ArityAtLeast(0), [], diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index 18256c3..a19875c 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -99,15 +99,18 @@ var invokeMainModule = function() { MACHINE.modules['*main*'].invoke( MACHINE, function() { + console.log("done with main module invokation"); // On main module invokation success }, - function() { + function(MACHINE, e) { + console.log(e.stack); // On main module invokation failure })}, function() {}, { currentDisplayer : function(v) { document.body.appendChild(document.createTextNode(String(v))); + document.body.appendChild(document.createElement("br")); } }); };