From 428882af6ac26216acd85a1de5ecaa79fd11cae4 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 11 Apr 2011 16:16:10 -0400 Subject: [PATCH] in the middle of debugging the javascript implementation --- assemble.rkt | 8 +++++++- runtime.js | 15 +++++++++++++++ test-assemble.rkt | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/assemble.rkt b/assemble.rkt index e9f66ae..00e2132 100644 --- a/assemble.rkt +++ b/assemble.rkt @@ -173,6 +173,8 @@ EOF empty] [(SpliceListIntoStack!? op) empty] + [(UnspliceRestFromStack!? op) + empty] [(FixClosureShellMap!? op) empty])) @@ -501,7 +503,11 @@ EOF (assemble-oparg (SetFrameCallee!-proc op)))] [(SpliceListIntoStack!? op) (format "RUNTIME.spliceListIntoStack(MACHINE, ~a);" - (assemble-oparg (SpliceListIntoStack!-depth op)))])) + (assemble-oparg (SpliceListIntoStack!-depth op)))] + [(UnspliceRestFromStack!? op) + (format "RUNTIME.unspliceRestFromStack(MACHINE, ~a, ~a);" + (assemble-oparg (UnspliceRestFromStack!-depth op)) + (assemble-oparg (UnspliceRestFromStack!-length op)))])) diff --git a/runtime.js b/runtime.js index 2c98cfb..81659a2 100644 --- a/runtime.js +++ b/runtime.js @@ -261,6 +261,20 @@ MACHINE.argcount = MACHINE.argcount + vals.length - 1; }; + var unspliceRestFromStack = function(MACHINE, depth, length) { + console.log(depth, length); + var lst = NULL; + var i; + for (i = 0; i < length; i++) { + lst = [MACHINE.env[MACHINE.env.length - depth - length + i], lst]; + } + console.log(lst); + MACHINE.env.splice(MACHINE.env.length - 1 - depth - length, + length, + lst); + MACHINE.argcount = MACHINE.argcount - length + 1; + }; + // An arity is either a primitive number, an ArityAtLeast instance, @@ -877,6 +891,7 @@ exports['trampoline'] = trampoline; exports['spliceListIntoStack'] = spliceListIntoStack; + exports['unspliceRestFromStack'] = unspliceRestFromStack; exports['isNumber'] = isNumber; diff --git a/test-assemble.rkt b/test-assemble.rkt index 5f2d3e4..f132224 100644 --- a/test-assemble.rkt +++ b/test-assemble.rkt @@ -390,4 +390,38 @@ ,(make-AssignImmediateStatement 'argcount (make-Const 3)) ,(make-PerformStatement (make-SpliceListIntoStack! (make-Const 2)))) "MACHINE.argcount + ',' + MACHINE.env[0] + ',' + MACHINE.env[1] + ',' + MACHINE.env[2] + ',' + MACHINE.env[3] + ',' + MACHINE.env[4]") - "5,3,2,1,world,hello") \ No newline at end of file + "5,3,2,1,world,hello") + + + + + + + +;; testing rest splicing +(test (E-many `(,(make-PushEnvironment 1 #f) + ,(make-AssignImmediateStatement (make-EnvLexicalReference 0 #f) + (make-Const "hello")) + ,(make-AssignImmediateStatement 'argcount (make-Const 1)) + ,(make-PerformStatement (make-UnspliceRestFromStack! (make-Const 0) + (make-Const 1)))) + "MACHINE.argcount + ',' + plt.runtime.isList(MACHINE.env[0])") + "1,true") + + +(test (E-many + `(,(make-PushEnvironment 5 #f) + ,(make-AssignImmediateStatement (make-EnvLexicalReference 0 #f) + (make-Const "hello")) + ,(make-AssignImmediateStatement (make-EnvLexicalReference 1 #f) + (make-Const "world")) + ,(make-AssignImmediateStatement (make-EnvLexicalReference 2 #f) + (make-Const 'x)) + ,(make-AssignImmediateStatement (make-EnvLexicalReference 3 #f) + (make-Const 'y)) + ,(make-AssignImmediateStatement (make-EnvLexicalReference 4 #f) + (make-Const 'z)) + ,(make-AssignImmediateStatement 'argcount (make-Const 5)) + ,(make-PerformStatement (make-UnspliceRestFromStack! (make-Const 2) (make-Const 3)))) + "MACHINE.argcount + ',' + MACHINE.env.length + ',' + plt.runtime.isList(MACHINE.env[0]) + ',' + MACHINE.env[2] + ',' + MACHINE.env[1]") + "3,3,true,hello,world") \ No newline at end of file