dom-play example is starting to look cool
This commit is contained in:
parent
dbfe7c3d2c
commit
91c4942ab7
3
examples/alert.rkt
Normal file
3
examples/alert.rkt
Normal file
|
@ -0,0 +1,3 @@
|
|||
#lang planet dyoo/whalesong
|
||||
(require (planet dyoo/whalesong/js))
|
||||
(alert "hello world")
|
25
examples/dom-play.rkt
Normal file
25
examples/dom-play.rkt
Normal file
|
@ -0,0 +1,25 @@
|
|||
#lang planet dyoo/whalesong
|
||||
|
||||
(require (planet dyoo/whalesong/js))
|
||||
|
||||
|
||||
;; insert-break: -> void
|
||||
(define (insert-break)
|
||||
(call ($ "<br/>") "appendTo" body)
|
||||
(void))
|
||||
|
||||
|
||||
(void (call ($ "<h1>Hello world</h1>") "appendTo" body))
|
||||
|
||||
|
||||
(void (call body "append" "hello, this is a test"))
|
||||
(insert-break)
|
||||
(void (call body "append" "hello, this is a test"))
|
||||
(insert-break)
|
||||
(void (call body "css" "background-color" "green"))
|
||||
|
||||
|
||||
|
||||
(void (call ($ "<span>This is another thing that has been added.</span>")
|
||||
"appendTo"
|
||||
body))
|
|
@ -99,7 +99,6 @@
|
|||
(let ([name (rewrite-path (ModuleSource-path src))]
|
||||
[text (query:query `(file ,(path->string (ModuleSource-path src))))]
|
||||
[bytecode (parse-bytecode (ModuleSource-path src))])
|
||||
(printf "bytecode: ~s\n" bytecode)
|
||||
(make-UninterpretedSource
|
||||
(format "
|
||||
MACHINE.modules[~s] =
|
||||
|
@ -109,11 +108,9 @@ MACHINE.modules[~s] =
|
|||
var modrec = MACHINE.modules[~s];
|
||||
var exports = {};
|
||||
modrec.isInvoked = true;
|
||||
(function(MACHINE, EXPORTS){~a})(MACHINE, exports);
|
||||
|
||||
(function(MACHINE, RUNTIME, EXPORTS){~a})(MACHINE, plt.runtime, exports);
|
||||
// FIXME: we need to inject the namespace with the values defined in exports.
|
||||
~a
|
||||
|
||||
return MACHINE.control.pop().label(MACHINE);
|
||||
});
|
||||
"
|
||||
|
@ -156,8 +153,6 @@ MACHINE.modules[~s] =
|
|||
(define (wrap-source src)
|
||||
(cond
|
||||
[(source-is-javascript-module? src)
|
||||
(notify "the module ~s has a javascript implementation.\n"
|
||||
src)
|
||||
(get-javascript-implementation src)]
|
||||
[else
|
||||
src]))
|
||||
|
|
3
js.rkt
Normal file
3
js.rkt
Normal file
|
@ -0,0 +1,3 @@
|
|||
#lang s-exp "lang/base.rkt"
|
||||
(require "js/main.rkt")
|
||||
(provide (all-from-out "js/main.rkt"))
|
36
js/js-impl.js
Normal file
36
js/js-impl.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
EXPORTS['alert'] =
|
||||
RUNTIME.makePrimitiveProcedure(
|
||||
'is-color?',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var elt = MACHINE.env[MACHINE.env.length - 1];
|
||||
alert(String(elt));
|
||||
return RUNTIME.VOID;
|
||||
});
|
||||
|
||||
|
||||
EXPORTS['body'] = $(document.body);
|
||||
|
||||
EXPORTS['$'] =
|
||||
RUNTIME.makePrimitiveProcedure(
|
||||
'$',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var obj = MACHINE.env[MACHINE.env.length - 1];
|
||||
return $(obj);
|
||||
});
|
||||
|
||||
EXPORTS['call'] =
|
||||
RUNTIME.makePrimitiveProcedure(
|
||||
'call',
|
||||
new RUNTIME.ArityAtLeast(2),
|
||||
function(MACHINE) {
|
||||
var obj = MACHINE.env[MACHINE.env.length - 1];
|
||||
var methodName = MACHINE.env[MACHINE.env.length - 2];
|
||||
var args = [];
|
||||
for (var i = 0; i < MACHINE.argcount - 2; i++) {
|
||||
args.push(MACHINE.env[MACHINE.env.length -1 - 2 - i]);
|
||||
}
|
||||
var result = obj[methodName].apply(obj, args);
|
||||
return result;
|
||||
});
|
9
js/main.rkt
Normal file
9
js/main.rkt
Normal file
|
@ -0,0 +1,9 @@
|
|||
#lang s-exp "../lang/js/js.rkt"
|
||||
|
||||
(declare-implementation
|
||||
#:racket "racket-impl.rkt"
|
||||
#:javascript ("js-impl.js")
|
||||
#:provided-values (alert
|
||||
body
|
||||
call
|
||||
$))
|
15
js/racket-impl.rkt
Normal file
15
js/racket-impl.rkt
Normal file
|
@ -0,0 +1,15 @@
|
|||
#lang s-exp "../lang/base.rkt"
|
||||
|
||||
(provide alert body call $)
|
||||
|
||||
(define (alert x)
|
||||
(display x)
|
||||
(newline))
|
||||
|
||||
(define body 'blah)
|
||||
|
||||
(define (call object method . args)
|
||||
'not-done-yet)
|
||||
|
||||
(define ($ name)
|
||||
'not-done-yet)
|
|
@ -175,7 +175,7 @@
|
|||
;; compose
|
||||
;; current-inexact-milliseconds
|
||||
;; current-seconds
|
||||
;; void
|
||||
void
|
||||
;; random
|
||||
;; sleep
|
||||
;; (identity -identity)
|
||||
|
|
Loading…
Reference in New Issue
Block a user