moving javascript-specific functions off to the js module
This commit is contained in:
parent
06aaf51cb8
commit
619abb1fca
3
Makefile
3
Makefile
|
@ -6,7 +6,7 @@ launcher:
|
||||||
raco make -v --disable-inline whalesong.rkt
|
raco make -v --disable-inline whalesong.rkt
|
||||||
racket make-launcher.rkt
|
racket make-launcher.rkt
|
||||||
|
|
||||||
whalesong:
|
whalesong:
|
||||||
raco make -v --disable-inline whalesong.rkt
|
raco make -v --disable-inline whalesong.rkt
|
||||||
|
|
||||||
test-all:
|
test-all:
|
||||||
|
@ -39,5 +39,6 @@ test-conform:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
doc:
|
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
|
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
|
#lang planet dyoo/whalesong
|
||||||
|
|
||||||
|
(require (planet dyoo/whalesong/js))
|
||||||
|
|
||||||
(when (in-javascript-context?)
|
(when (in-javascript-context?)
|
||||||
(viewport-width))
|
(viewport-width))
|
||||||
|
|
||||||
|
|
|
@ -568,7 +568,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
plt.baselib.arity.makeArityAtLeast(1),
|
plt.baselib.arity.makeArityAtLeast(1),
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var args = [], i, formatString;
|
var args = [], i, formatString;
|
||||||
formatString = checkString(MACHINE, 'format', 0);
|
formatString = checkString(MACHINE, 'format', 0).toString();
|
||||||
for(i = 1; i < MACHINE.argcount; i++) {
|
for(i = 1; i < MACHINE.argcount; i++) {
|
||||||
args.push(MACHINE.env[MACHINE.env.length - 1 - 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),
|
plt.baselib.arity.makeArityAtLeast(1),
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var args = [], i, formatString, result, outputPort;
|
var args = [], i, formatString, result, outputPort;
|
||||||
formatString = checkString(MACHINE, 'printf', 0);
|
formatString = checkString(MACHINE, 'printf', 0).toString();
|
||||||
for(i = 1; i < MACHINE.argcount; i++) {
|
for(i = 1; i < MACHINE.argcount; i++) {
|
||||||
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
||||||
}
|
}
|
||||||
|
@ -598,7 +598,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var args = [], i, formatString, outputPort, result;
|
var args = [], i, formatString, outputPort, result;
|
||||||
outputPort = checkOutputPort(MACHINE, 'fprintf', 0);
|
outputPort = checkOutputPort(MACHINE, 'fprintf', 0);
|
||||||
formatString = checkString(MACHINE, 'fprintf', 1);
|
formatString = checkString(MACHINE, 'fprintf', 1).toString();
|
||||||
for(i = 2; i < MACHINE.argcount; i++) {
|
for(i = 2; i < MACHINE.argcount; i++) {
|
||||||
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
||||||
}
|
}
|
||||||
|
@ -1001,7 +1001,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
var buffer = [];
|
var buffer = [];
|
||||||
var i;
|
var i;
|
||||||
for (i = 0; i < MACHINE.argcount; 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('');
|
return buffer.join('');
|
||||||
});
|
});
|
||||||
|
@ -1010,7 +1010,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
'string-length',
|
'string-length',
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var firstArg = checkString(MACHINE, 'string-length', 0);
|
var firstArg = checkString(MACHINE, 'string-length', 0).toString();
|
||||||
return firstArg.length;
|
return firstArg.length;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1485,12 +1485,20 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
|
'string->symbol',
|
||||||
|
1,
|
||||||
|
function(MACHINE) {
|
||||||
|
return makeSymbol(checkString(MACHINE, 'string->symbol', 0).toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
installPrimitiveProcedure(
|
installPrimitiveProcedure(
|
||||||
'string->number',
|
'string->number',
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
return plt.baselib.numbers.fromString(
|
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -23,7 +23,7 @@ EXPORTS['$'] =
|
||||||
EXPORTS['call-method'] =
|
EXPORTS['call-method'] =
|
||||||
RUNTIME.makePrimitiveProcedure(
|
RUNTIME.makePrimitiveProcedure(
|
||||||
'call-method',
|
'call-method',
|
||||||
new RUNTIME.ArityAtLeast(2),
|
plt.baselib.arity.makeArityAtLeast(2),
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var obj = MACHINE.env[MACHINE.env.length - 1];
|
var obj = MACHINE.env[MACHINE.env.length - 1];
|
||||||
var methodName = MACHINE.env[MACHINE.env.length - 2];
|
var methodName = MACHINE.env[MACHINE.env.length - 2];
|
||||||
|
@ -34,3 +34,32 @@ EXPORTS['call-method'] =
|
||||||
var result = obj[methodName].apply(obj, args);
|
var result = obj[methodName].apply(obj, args);
|
||||||
return result;
|
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;
|
||||||
|
});
|
||||||
|
|
|
@ -6,4 +6,9 @@
|
||||||
#:provided-values (alert
|
#:provided-values (alert
|
||||||
body
|
body
|
||||||
call-method
|
call-method
|
||||||
$))
|
$
|
||||||
|
|
||||||
|
viewport-width
|
||||||
|
viewport-height
|
||||||
|
in-javascript-context?
|
||||||
|
))
|
|
@ -1,6 +1,9 @@
|
||||||
#lang s-exp "../lang/base.rkt"
|
#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)
|
(define (alert x)
|
||||||
(display x)
|
(display x)
|
||||||
|
@ -13,3 +16,24 @@
|
||||||
|
|
||||||
(define ($ name)
|
(define ($ name)
|
||||||
'not-done-yet)
|
'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."))
|
||||||
|
|
||||||
|
|
|
@ -342,7 +342,7 @@ memq
|
||||||
;; string->list
|
;; string->list
|
||||||
;; list->string
|
;; list->string
|
||||||
;; string-copy
|
;; string-copy
|
||||||
;; string->symbol
|
string->symbol
|
||||||
symbol->string
|
symbol->string
|
||||||
format
|
format
|
||||||
printf
|
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!)
|
(provide set-car! set-cdr!)
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,12 @@ EOF
|
||||||
(displayln (fib 5))
|
(displayln (fib 5))
|
||||||
(displayln (fib 6)))
|
(displayln (fib 6)))
|
||||||
"2\n3\n5\n8\n")
|
"2\n3\n5\n8\n")
|
||||||
|
|
||||||
|
|
||||||
|
(test '(displayln (eq? (string->symbol "hello")
|
||||||
|
'hello))
|
||||||
|
"true\n")
|
||||||
|
|
||||||
|
|
||||||
(test '(begin (define (tak x y z)
|
(test '(begin (define (tak x y z)
|
||||||
(if (>= y x)
|
(if (>= y x)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user