Permalink
Browse files

moving javascript-specific functions off to the js module

  • Loading branch information...
1 parent 06aaf51 commit 619abb1fca213730b83292641fb115f7af48bdc6 Danny Yoo committed Jul 14, 2011
Showing with 86 additions and 69 deletions.
  1. +2 −1 Makefile
  2. +2 −0 examples/window-size.rkt
  3. +14 −34 js-assembler/runtime-src/runtime.js
  4. +30 −1 js/js-impl.js
  5. +6 −1 js/main.rkt
  6. +25 −1 js/racket-impl.rkt
  7. +1 −30 lang/kernel.rkt
  8. +6 −1 tests/test-browser-evaluate.rkt
View
@@ -6,7 +6,7 @@ launcher:
raco make -v --disable-inline whalesong.rkt
racket make-launcher.rkt
-whalesong:
+whalesong:
raco make -v --disable-inline whalesong.rkt
test-all:
@@ -39,5 +39,6 @@ test-conform:
+
doc:
scribble ++xref-in setup/xref load-collections-xref --redirect-main http://docs.racket-lang.org/ --dest generated-docs --dest-name index.html scribblings/manual.scrbl
@@ -1,5 +1,7 @@
#lang planet dyoo/whalesong
+(require (planet dyoo/whalesong/js))
+
(when (in-javascript-context?)
(viewport-width))
@@ -568,7 +568,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) {
var args = [], i, formatString;
- formatString = checkString(MACHINE, 'format', 0);
+ formatString = checkString(MACHINE, 'format', 0).toString();
for(i = 1; i < MACHINE.argcount; i++) {
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
}
@@ -581,7 +581,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) {
var args = [], i, formatString, result, outputPort;
- formatString = checkString(MACHINE, 'printf', 0);
+ formatString = checkString(MACHINE, 'printf', 0).toString();
for(i = 1; i < MACHINE.argcount; i++) {
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
}
@@ -598,7 +598,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) {
var args = [], i, formatString, outputPort, result;
outputPort = checkOutputPort(MACHINE, 'fprintf', 0);
- formatString = checkString(MACHINE, 'fprintf', 1);
+ formatString = checkString(MACHINE, 'fprintf', 1).toString();
for(i = 2; i < MACHINE.argcount; i++) {
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
}
@@ -1001,7 +1001,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var buffer = [];
var i;
for (i = 0; i < MACHINE.argcount; i++) {
- buffer.push(checkString(MACHINE, 'string-append', i));
+ buffer.push(checkString(MACHINE, 'string-append', i).toString());
}
return buffer.join('');
});
@@ -1010,7 +1010,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'string-length',
1,
function(MACHINE) {
- var firstArg = checkString(MACHINE, 'string-length', 0);
+ var firstArg = checkString(MACHINE, 'string-length', 0).toString();
return firstArg.length;
});
@@ -1486,11 +1486,19 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure(
+ 'string->symbol',
+ 1,
+ function(MACHINE) {
+ return makeSymbol(checkString(MACHINE, 'string->symbol', 0).toString());
+ });
+
+
+ installPrimitiveProcedure(
'string->number',
1,
function(MACHINE) {
return plt.baselib.numbers.fromString(
- checkString(MACHINE, 'string->number', 0));
+ checkString(MACHINE, 'string->number', 0).toString());
});
@@ -1663,34 +1671,6 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
-
-
- // Javascript-specific extensions. A small experiment.
- installPrimitiveProcedure(
- 'viewport-width',
- 0,
- function(MACHINE) {
- return $(window).width();
- });
-
- installPrimitiveProcedure(
- 'viewport-height',
- 0,
- function(MACHINE) {
- return $(window).height();
- });
-
-
- installPrimitiveProcedure(
- 'in-javascript-context?',
- 0,
- function(MACHINE) {
- return true;
- });
-
-
-
-
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
View
@@ -23,7 +23,7 @@ EXPORTS['$'] =
EXPORTS['call-method'] =
RUNTIME.makePrimitiveProcedure(
'call-method',
- new RUNTIME.ArityAtLeast(2),
+ plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) {
var obj = MACHINE.env[MACHINE.env.length - 1];
var methodName = MACHINE.env[MACHINE.env.length - 2];
@@ -34,3 +34,32 @@ EXPORTS['call-method'] =
var result = obj[methodName].apply(obj, args);
return result;
});
+
+
+
+
+// Javascript-specific extensions. A small experiment.
+EXPORTS['viewport-width'] =
+ RUNTIME.makePrimitiveProcedure(
+ 'viewport-width',
+ 0,
+ function(MACHINE) {
+ return $(window).width();
+ });
+
+EXPORTS['viewport-height'] =
+ RUNTIME.makePrimitiveProcedure(
+ 'viewport-height',
+ 0,
+ function(MACHINE) {
+ return $(window).height();
+ });
+
+
+EXPORTS['in-javascript-context?'] =
+ RUNTIME.makePrimitiveProcedure(
+ 'in-javascript-context?',
+ 0,
+ function(MACHINE) {
+ return true;
+ });
View
@@ -6,4 +6,9 @@
#:provided-values (alert
body
call-method
- $))
+ $
+
+ viewport-width
+ viewport-height
+ in-javascript-context?
+ ))
View
@@ -1,6 +1,9 @@
#lang s-exp "../lang/base.rkt"
-(provide alert body call-method $)
+(provide alert body call-method $
+ in-javascript-context?
+ viewport-width
+ viewport-height)
(define (alert x)
(display x)
@@ -13,3 +16,24 @@
(define ($ name)
'not-done-yet)
+
+
+
+
+;; in-javascript-context: -> boolean
+;; Produces true if we're in a JavaScript context.
+(define (in-javascript-context?)
+ #f)
+
+
+;; viewport-width: -> natural
+;; The viewport width in pixels.
+(define (viewport-width)
+ (error 'viewport-width "Not available outside JavaScript context."))
+
+
+;; viewport-height: -> natural
+;; The viewport height in pixels.
+(define (viewport-height)
+ (error 'viewport-width "Not available outside JavaScript context."))
+
View
@@ -342,7 +342,7 @@ memq
;; string->list
;; list->string
;; string-copy
-;; string->symbol
+string->symbol
symbol->string
format
printf
@@ -412,35 +412,6 @@ symbol->string
-(provide
- ;; FIXME:
- ;; Extensions: these may need to be hidden in a JavaScript-implemented module
- in-javascript-context?
- viewport-width
- viewport-height)
-
-
-
-;; in-javascript-context: -> boolean
-;; Produces true if we're in a JavaScript context.
-(define (in-javascript-context?)
- #f)
-
-
-;; viewport-width: -> natural
-;; The viewport width in pixels.
-(define (viewport-width)
- (error 'viewport-width "Not available outside JavaScript context."))
-
-
-;; viewport-height: -> natural
-;; The viewport height in pixels.
-(define (viewport-height)
- (error 'viewport-width "Not available outside JavaScript context."))
-
-
-
-
(provide set-car! set-cdr!)
@@ -271,7 +271,12 @@ EOF
(displayln (fib 5))
(displayln (fib 6)))
"2\n3\n5\n8\n")
-
+
+
+(test '(displayln (eq? (string->symbol "hello")
+ 'hello))
+ "true\n")
+
(test '(begin (define (tak x y z)
(if (>= y x)

0 comments on commit 619abb1

Please sign in to comment.