Skip to content

Commit

Permalink
more features
Browse files Browse the repository at this point in the history
  • Loading branch information
drewlesueur committed May 16, 2010
1 parent e332413 commit 8cd29a0
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions index.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<style> <style>
textarea { textarea {
width: 500px; width: 500px;
height: 400px; height: 200px;
} }


* { * {
Expand Down Expand Up @@ -77,6 +77,9 @@
var funcs = { var funcs = {
equal: function(a, b) { equal: function(a, b) {
return a == b; return a == b;
},
print: function(tokens, line) {
console.log(lookup(tokens[0]))
} }
} }
var returns = []; var returns = [];
Expand Down Expand Up @@ -126,6 +129,8 @@
line_after_equals = line.substr(line.indexOf(" =") + 2); line_after_equals = line.substr(line.indexOf(" =") + 2);
exec_after_equal = exec(tokens_after_equals, line_after_equals); exec_after_equal = exec(tokens_after_equals, line_after_equals);
assign(tokens[0], exec_after_equal) assign(tokens[0], exec_after_equal)
} else if (tokens[0] == "if"){

} else if (tokens[tokens.length-1] == ":") { } else if (tokens[tokens.length-1] == ":") {
assign(tokens[0], pc + 1); assign(tokens[0], pc + 1);
} else if (tokens.length == 1 && _s(tokens[0],-2) == "()") { } else if (tokens.length == 1 && _s(tokens[0],-2) == "()") {
Expand All @@ -134,12 +139,22 @@
returns.push(pc + 1) returns.push(pc + 1)
pc = line - 1 pc = line - 1
on_jump = true; on_jump = true;
console.log("moving pc to " + pc)
console.log("the function we are calling is" + func)
} else if (tokens.length == 1) { } else if (tokens.length == 1) {
return lookup(tokens[0]); return lookup(tokens[0]);
} else { } else { //normal fuction call
console.log("didn't match anything" + tokens[0]) var func = tokens[0];
if (func in funcs) {
sub_token = _s(tokens,1);
sub_line = _s(line, tokens[0].length)
return funcs[func](sub_token, sub_line)
} else if (func in scope) {
assign("args", _s(tokens, 1))
assign("raw_args", _s(line, tokens[0].length))
new_pc = lookup(func);
returns.push(pc + 1)
pc = new_pc - 1
on_jump = true;
}
} }


} }
Expand Down Expand Up @@ -170,10 +185,17 @@
} }
} }
scope[ee] = or scope[ee] = or
if (typeof or == "string" && or.length > 1) if (typeof or == "string" && or.length > 1) {
for (var i = 0; i < or.length; i++) { for (var i = 0; i < or.length; i++) {
assign(ee + "." + i, or.charAt(i)); assign(ee + "." + i, or.charAt(i));
}
} }
if (typeof or == "object") {
for (var i in or) {
assign(ee + "." + i, or[i])
}
}

} }


function parse(txt) { function parse(txt) {
Expand All @@ -186,10 +208,7 @@
function while2() { //comment this out function while2() { //comment this out
iters++ iters++
line = lines[pc] line = lines[pc]

document.getElementById("bar").style.top = 16 * pc + "px" document.getElementById("bar").style.top = 16 * pc + "px"
console.log(pc)
console.log(line)
match = line.match(/^[\s]*/) match = line.match(/^[\s]*/)
space_len = match[0]; space_len = match[0];
tokens = tokenize(trim(line)) tokens = tokenize(trim(line))
Expand All @@ -201,7 +220,6 @@
on_jump = false; on_jump = false;
next_pc = pc next_pc = pc
while (next_pc < lines.length) { while (next_pc < lines.length) {
console.log("inner loop")
next_line = lines[next_pc]; next_line = lines[next_pc];
match = next_line.match(/^[\s]*/) match = next_line.match(/^[\s]*/)
next_space_len = match[0] next_space_len = match[0]
Expand All @@ -219,7 +237,6 @@
next_pc++ next_pc++
} }
} else { } else {
console.log("on_jump is true")
on_jump = false; on_jump = false;
} }


Expand Down

0 comments on commit 8cd29a0

Please sign in to comment.