diff --git a/examples/alert.rkt b/examples/alert.rkt new file mode 100644 index 0000000..367abd0 --- /dev/null +++ b/examples/alert.rkt @@ -0,0 +1,3 @@ +#lang planet dyoo/whalesong +(require (planet dyoo/whalesong/js)) +(alert "hello world") diff --git a/examples/dom-play.rkt b/examples/dom-play.rkt new file mode 100644 index 0000000..1917796 --- /dev/null +++ b/examples/dom-play.rkt @@ -0,0 +1,25 @@ +#lang planet dyoo/whalesong + +(require (planet dyoo/whalesong/js)) + + +;; insert-break: -> void +(define (insert-break) + (call ($ "
") "appendTo" body) + (void)) + + +(void (call ($ "

Hello world

") "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 ($ "This is another thing that has been added.") + "appendTo" + body)) diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index 6f5442a..dd4d853 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -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])) diff --git a/js.rkt b/js.rkt new file mode 100644 index 0000000..121fc34 --- /dev/null +++ b/js.rkt @@ -0,0 +1,3 @@ +#lang s-exp "lang/base.rkt" +(require "js/main.rkt") +(provide (all-from-out "js/main.rkt")) \ No newline at end of file diff --git a/js/js-impl.js b/js/js-impl.js new file mode 100644 index 0000000..a79a95f --- /dev/null +++ b/js/js-impl.js @@ -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; + }); diff --git a/js/main.rkt b/js/main.rkt new file mode 100644 index 0000000..35d16af --- /dev/null +++ b/js/main.rkt @@ -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 + $)) \ No newline at end of file diff --git a/js/racket-impl.rkt b/js/racket-impl.rkt new file mode 100644 index 0000000..a9c55af --- /dev/null +++ b/js/racket-impl.rkt @@ -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) \ No newline at end of file diff --git a/lang/kernel.rkt b/lang/kernel.rkt index 1b4e293..47654b9 100644 --- a/lang/kernel.rkt +++ b/lang/kernel.rkt @@ -175,7 +175,7 @@ ;; compose ;; current-inexact-milliseconds ;; current-seconds -;; void + void ;; random ;; sleep ;; (identity -identity)