Skip to content

Commit

Permalink
Simple ben.rb, which just does 3 + 4 but has actually executed code i…
Browse files Browse the repository at this point in the history
…n the browser.
  • Loading branch information
matasar committed Apr 15, 2010
1 parent d5a3973 commit ed1673f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
12 changes: 9 additions & 3 deletions 8ball.rb
Expand Up @@ -51,7 +51,7 @@ def visitRootNode(node)
end

def visit_local_asgn_node(node)
gather("var #{node.get_name} = #{node.child_nodes.map { |n| visit(n) }};")
gather("#{node.get_name} = #{node.child_nodes.map { |n| visit(n) }};")
end

def visit_block_node(node)
Expand All @@ -61,6 +61,10 @@ def visit_block_node(node)
def visitNewlineNode(node)
visit(node.nextNode)
end

def visitCallOneArgFixnumNode(node)
visitCallOneArgNode(node)
end

# def visitFCallNode(node)
# raise NotYetImplmented
Expand All @@ -80,6 +84,8 @@ def visitCallOneArgNode(node)
gather("#{visit(node.receiverNode)}.#{ mangle(node.getName)}#{args}".wrap_with("()"))
end



def visitCallNode(node)
if node.class == Java::OrgJrubyAst::CallNode
args = node.argsNode && visit(node.argsNode.getLast).to_comma_list
Expand All @@ -92,7 +98,7 @@ def visitCallNode(node)
end

def visitFixnumNode(node)
"#{node.value}"
"(#{node.value})"
end

def visitStrNode(node)
Expand Down Expand Up @@ -139,7 +145,7 @@ def mangle(method)
end

def compile_function(name, args, body)
gather("function #{name}#{compile_arglist(args)}",
gather("function #{name} (#{compile_arglist(args)})",
compile_function_body(body).wrap_with(["{\n", "\n}\n"]))
end

Expand Down
8 changes: 4 additions & 4 deletions cgi-bin/compile_8ball.cgi
Expand Up @@ -10,10 +10,10 @@ puts "Content-type: text/plain"
puts ""

class EightBallCompiler
def self.cs(ruby)
ast = parse(ruby)
puts ast.accept(EightBallVisitor.new)
end
def self.cs(ruby)
ast = parse(ruby)
puts ast.accept(EightBallVisitor.new)
end
end

begin
Expand Down
5 changes: 4 additions & 1 deletion primitives.js
@@ -1 +1,4 @@
function primplus(x, y) { return x + y; }
Number.prototype.primplus = function(y) { return this + y; };
Number.prototype.times = function (fn) { for (var i = 0; i < this; i++) { fn(i) }}

function puts(string) {console.log(string)};
3 changes: 1 addition & 2 deletions snooker.html
Expand Up @@ -16,7 +16,6 @@
for (elm in data) {
if (data[elm]) {
FilesForm.options.append($("<option value=\"" + data[elm] + "\">" + data[elm] + "</option>"));
console.log(data[elm]);
}
}
},
Expand Down Expand Up @@ -59,7 +58,7 @@
this.submitButton = $("#executeButton");
this.submitButton.bind('click',
function () {
eval(RunForm.code.val());
console.log(eval(RunForm.code.val()));
})
}

Expand Down
1 change: 1 addition & 0 deletions target/ben.rb
@@ -0,0 +1 @@
3 + 4

0 comments on commit ed1673f

Please sign in to comment.