Skip to content
Browse files

forward

  • Loading branch information...
1 parent ad8ba22 commit e2c5082342dc34a86409ddebe12e4c46c194cfa3 @drewlesueur committed Apr 21, 2012
Showing with 72 additions and 25 deletions.
  1. +72 −25 thumbs.js
View
97 thumbs.js
@@ -28,9 +28,11 @@ var codeToTree = function (code, fileName) {
"ten double 5"
return [ 0, fileName, "do",
- [0, fileName, "double", [0, fileName, ".", [0, fileName, "x"],
- [1, fileName, "mult", "x", "2"]]],
- [2, fileName, "ten", "double", "5"]
+ [0, fileName, ".",
+ [0, fileName, "double", [0, fileName, ".", [0, fileName, "args", "x"],
+ [1, fileName, "mult", "x", "2"]]],
+ [2, fileName, "ten", "double", "5"]
+ ]
]
}
@@ -40,31 +42,75 @@ var getId = function (prefix) {
return prefix + id;
}
+var separateFunctions = function (tree, trees) {
+ var trees = trees || [];
+ var childTree, lineNumber, fileName, bagOfSand, goldStatue;
+ for (var i = 2; i < tree.length; i++) {
+ childTree = tree[i];
+ if (childTree[2] == ".") {
+ lineNumber = childTree[0];
+ fileName = childTree[1];
+ bagOfSand = [lineNumber, fileName, "fn", trees.length+1]; //we add one because we are going to be unshifting
+ goldStatue = tree.splice(i, 1, bagOfSand)[0].slice(3);
+ trees.push(goldStatue);
+ }
+ separateFunctions(childTree, trees);
+ }
+}
+
+var branchToLines = function (branch, lines) {
+ var lineNumber = branch[0]
+ var fileName = branch[1]
+ var lineNumberByteCode = getCachedLineNumberByteCode(lineNumber)
+ var fileNameByteCode = getCachedFileNameByteCode(fileName)
+ lines.push(lineNumberByteCode)
+ lines.push(fileNameByteCode)
+ var twig;
+ for (var i = 2; i < branch.length; i++) {
+ twig = branch[i]
+ if (isString(twig)) {
+ lines.push(getCachedGetByteCode(twig))
+ } else if (isArray(twig)) {
+ branchesToLines(twig, lines)
+ }
+ }
+ var lineNumberByteCode = getCachedLineNumberByteCode(lineNumber)
+ var fileNameByteCode = getCachedFileNameByteCode(fileName)
+
+}
+var branchesToLines = function (branches, lines) {
+ lines = lines || [];
+ var branch;
+ for (var i = 0; i < branches.length; i++) {
+ branch = branches[i]
+ branchToLines(branch, lines)
+ }
+}
+
var treeToLines = function (tree, fileName, codeLines) {
+ var trees = [];
+ separateFunctions(tree, trees);
+ trees.unshift([tree]);
+ console.log("debranched trees are")
+ console.log(trees)
+ console.log("original tree is")
+ console.log(tree)
+ var braches;
+ var lines = [];
+ for (var i = 0; i < trees.length; i++) {
+ branches = trees[i];
+ branchesToLines(branches, lines);
+ }
+
+ return lines;
+ return;
+
codeLines = codeLines || [];
var childTree, lineNumber, fileName, getBytecode;
lineNumber = tree[0]
fileName = tree[1]
var lineNumberByteCode = getCachedLineNumberByteCode(lineNumber)
var fileNameByteCode = getCachedFileNameByteCode(fileName)
- //codeLines.push(lineNumberByteCode);
- //codeLines.push(fileNameByteCode);
-
- while (true) {
-
- }
-
- //for (var i = 2; i < tree.length; i++) {
- // childTree = tree[i];
- // if (isString(childTree)) {
- // getBytecode = getCachedGetByteCode(childTree);
- // codeLines.push(getBytecode);
- // codeLines.push(rawCall);
- // } else if (isArray(childTree)) {
- // treeToLines(childTree, fileName, codeLines);
- // }
- //}
- return codeLines;
}
@@ -76,11 +122,13 @@ var funcBag = [];
var funcBagStack = [funcBag];
var args = [];
-var rawCall = function () { }
-var rawPushToCall = function () {}
+var rawStart = function () { return "starting function call"}
+var rawEnd = function () { return "endin function call"}
+var rawAdd = function () { return "adding to args" }
+
var rawSetLineNumber = function (lineNumber) { currentLineNumber = lineNumber; }
var rawSetFileName = function (fileName) { currentFileName = fileName }
-var rawGet = function (arg) { console.log("getting " + arg + "(" + pc + ")") }
+var rawGet = function (arg) { return ("getting " + arg + "(" + pc + ")") }
var makeCachingSystem = function (fn, name) {
//just caches the func, arg pair so i don't new up a bunch of arrays
@@ -119,7 +167,6 @@ var runFile = function (file) {
return ran;
}
-
thumbs.runScripts = runScripts
thumbs.run = run //runs raw code
thumbs.runFile = runFile

0 comments on commit e2c5082

Please sign in to comment.
Something went wrong with that request. Please try again.