fjsc: various bug fixes

chris.double 2006-12-17 05:45:59 +00:00
parent 3f73db3538
commit 1cdeb8c343
4 changed files with 57 additions and 4 deletions

View File

@ -6,4 +6,6 @@
<div id="compiled"> <div id="compiled">
</div> </div>
<div id="stack"> <div id="stack">
</div>
<div id="playground">
</div> </div>

View File

@ -4,9 +4,32 @@
"browser-dom" in "browser-dom" in
: $ ( string -- result ) : elements ( string -- result )
#! Call JQuery's $ function #! Call JQuery's $ function
window { "result" } "" "$" { "string" } alien-invoke ; window { "result" } "" "$" { "string" } alien-invoke ;
: html ( string -- element )
#! Set the innerHTML of element using jQuery
{ } "" "html" { "string" } alien-invoke ;
: bind-event ( name element quot -- )
>function swap { } "" "bind" { "string" "function" } alien-invoke ;
"scratchpad" in "scratchpad" in
: example1 ( -- )
"<button id='test'>Press Me</button>" "#playground" elements html ;
: example2 ( -- )
"click" "#test" elements [ "clicked" alert ] bind-event ;
: example3 ( -- )
[
[
>r "click" "#test" elements r> [ continue ] curry bind-event
"Waiting for click on button" alert
continue
] callcc0
drop "Click done!" alert
] callcc0 ;

View File

@ -330,6 +330,25 @@ factor.add_word("kernel", "forget", "primitive", function(next) {
factor.call_next(next); factor.call_next(next);
}); });
factor.add_word("kernel", ">function", "primitive", function(next) {
var stack = factor.cont.data_stack;
var word = stack.pop();
stack.push(function() { word.func(function() { }) });
factor.call_next(next);
});
factor.add_word("kernel", "curry", "primitive", function(next) {
var stack = factor.cont.data_stack;
var quot = stack.pop();
var value = stack.pop();
stack.push(factor.make_quotation("quotation", function(next) {
factor.cont.data_stack.push(value);
quot.execute(factor.cont.next);
}));
factor.call_next(next);
});
/* Math vocabulary */ /* Math vocabulary */
factor.add_word("math", "*", "primitive", function(next) { factor.add_word("math", "*", "primitive", function(next) {
var stack = factor.cont.data_stack; var stack = factor.cont.data_stack;
@ -384,7 +403,7 @@ factor.add_word("alien", "alien-invoke", "primitive", function(next) {
for(var i = 0; i < arg_types.length; ++i) { for(var i = 0; i < arg_types.length; ++i) {
args[i] = stack.pop(); args[i] = stack.pop();
} }
var v = obj[method_name].apply(obj, args); var v = obj[method_name].apply(obj, args.reverse());
if(return_values.length > 0) if(return_values.length > 0)
stack.push(v); stack.push(v);
factor.call_next(next); factor.call_next(next);
@ -399,6 +418,15 @@ factor.add_word("alien", "alien-property", "primitive", function(next) {
factor.call_next(next); factor.call_next(next);
}); });
factor.add_word("alien", "set-alien-property", "primitive", function(next) {
var stack = factor.cont.data_stack;
var obj = stack.pop();
var property_name = stack.pop();
var data = stack.pop();
obj[property_name] = v;
factor.call_next(next);
});
factor.add_word("words", "vocabs", "primitive", function(next) { factor.add_word("words", "vocabs", "primitive", function(next) {
var stack = factor.cont.data_stack; var stack = factor.cont.data_stack;
var result = []; var result = [];

View File

@ -129,9 +129,9 @@ M: ast-number (compile)
"," , ; "," , ;
M: ast-string (literal) M: ast-string (literal)
"'" , "\"" ,
ast-string-value , ast-string-value ,
"'" , ; "\"" , ;
M: ast-string (compile) M: ast-string (compile)
"factor.push_data(" , "factor.push_data(" ,