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

@ -7,3 +7,5 @@
</div>
<div id="stack">
</div>
<div id="playground">
</div>

View File

@ -4,9 +4,32 @@
"browser-dom" in
: $ ( string -- result )
: elements ( string -- result )
#! Call JQuery's $ function
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
: 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.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 */
factor.add_word("math", "*", "primitive", function(next) {
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) {
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)
stack.push(v);
factor.call_next(next);
@ -399,6 +418,15 @@ factor.add_word("alien", "alien-property", "primitive", function(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) {
var stack = factor.cont.data_stack;
var result = [];

View File

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