From 2ebb4a88f956ef47efcc0cbfaf37f9f060556120 Mon Sep 17 00:00:00 2001 From: "chris.double" Date: Fri, 15 Dec 2006 07:49:42 +0000 Subject: [PATCH] fjsc: add run-file and ability to have bootstrap factor code --- apps/furnace-fjsc/resources/bootstrap.factor | 4 ++ apps/furnace-fjsc/resources/bootstrap.js | 47 ++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 apps/furnace-fjsc/resources/bootstrap.factor diff --git a/apps/furnace-fjsc/resources/bootstrap.factor b/apps/furnace-fjsc/resources/bootstrap.factor new file mode 100644 index 0000000000..090b395dcb --- /dev/null +++ b/apps/furnace-fjsc/resources/bootstrap.factor @@ -0,0 +1,4 @@ +: alert + window { } "alert" { "string" } alien-invoke ; + +"Bootstrap code loaded" alert \ No newline at end of file diff --git a/apps/furnace-fjsc/resources/bootstrap.js b/apps/furnace-fjsc/resources/bootstrap.js index be64a23435..3c50767a89 100644 --- a/apps/furnace-fjsc/resources/bootstrap.js +++ b/apps/furnace-fjsc/resources/bootstrap.js @@ -1,5 +1,6 @@ function Factor() { var self = this; + this.form = false; this.data_stack = [ ]; this.words = { dup: function() { self.fjsc_dup(); }, @@ -20,11 +21,13 @@ function Factor() { "f": function() { self.fjsc_false(); }, "t": function() { self.fjsc_true(); }, "empty?": function() { self.fjsc_is_empty(); }, - alert: function() { self.fjsc_alert(); } + "window": function() { self.fjsc_window(); }, + "run-file": function() { self.fjsc_run_file(); }, + "bootstrap": function() { self.fjsc_bootstrap(); } }; } -Factor.prototype.fjsc_eval = function(form) { +Factor.prototype.server_eval = function(text) { var self = this; var callback = { success: function(o) { @@ -33,13 +36,18 @@ Factor.prototype.fjsc_eval = function(form) { self.display_datastack(); document.getElementById('compiled').innerHTML="
" + v + "
"; document.getElementById('code').value=""; - } }; - YAHOO.util.Connect.setForm(form); + this.form.code.value=text; + YAHOO.util.Connect.setForm(this.form); YAHOO.util.Connect.asyncRequest('POST', "/responder/fjsc/compile", callback); } +Factor.prototype.fjsc_eval = function(form) { + this.form = form; + this.server_eval(form.code.value); +} + Factor.prototype.display_datastack = function() { var html=[]; html.push("") @@ -148,10 +156,6 @@ Factor.prototype.fjsc_equals = function() { this.data_stack.push(v1==v2); } -Factor.prototype.fjsc_alert = function() { - alert(this.data_stack.pop()); -} - Factor.prototype.fjsc_clear = function() { factor.data_stack = [ ] } @@ -173,4 +177,31 @@ Factor.prototype.fjsc_over = function() { stack.push(stack[stack.length-2]); } +Factor.prototype.fjsc_window = function() { + var stack = this.data_stack; + stack.push(window); +} + +Factor.prototype.fjsc_run_file = function() { + var self = this; + var stack = this.data_stack; + var url = stack.pop(); + var callback = { + success: function(o) { + var result = o.responseText; + self.server_eval(result); + }, + failure: function(o) { + alert('run-file failed'); + } + }; + + YAHOO.util.Connect.asyncRequest('GET', url, callback, null); +} + +Factor.prototype.fjsc_bootstrap = function() { + this.data_stack.push("/responder/fjsc-resources/bootstrap.factor"); + this.fjsc_run_file(); +} + var factor = new Factor(); \ No newline at end of file