experiment: viewport width and viewport height are accessible.
This commit is contained in:
parent
71f356a100
commit
25a33e54ce
|
@ -112,7 +112,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
var elt = MACHINE.env.pop();
|
var elt = MACHINE.env.pop();
|
||||||
var outputPort =
|
var outputPort =
|
||||||
MACHINE.params.currentOutputPort;
|
MACHINE.params.currentOutputPort;
|
||||||
if (elt !== undefined) {
|
if (elt !== VOID) {
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode(elt, 'print'));
|
outputPort.writeDomNode(MACHINE, toDomNode(elt, 'print'));
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'print'));
|
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'print'));
|
||||||
}
|
}
|
||||||
|
@ -520,7 +520,24 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
// are coded here; several of them (including call/cc) are injected by
|
// are coded here; several of them (including call/cc) are injected by
|
||||||
// the bootstrapping code.
|
// the bootstrapping code.
|
||||||
var Primitives = {};
|
var Primitives = {};
|
||||||
Primitives['display'] = function(MACHINE) {
|
|
||||||
|
var installPrimitiveProcedure = function(name, arity, f) {
|
||||||
|
Primitives[name] = f;
|
||||||
|
Primitives[name].arity = arity;
|
||||||
|
Primitives[name].displayName = name;
|
||||||
|
};
|
||||||
|
|
||||||
|
var installPrimitiveConstant = function(name, v) {
|
||||||
|
Primitives[name] = v;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
installPrimitiveConstant('pi', jsnums.pi);
|
||||||
|
installPrimitiveConstant('e', jsnums.e);
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
|
'display', makeList(1, 2),
|
||||||
|
function(MACHINE) {
|
||||||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||||
var outputPort = MACHINE.params.currentOutputPort;
|
var outputPort = MACHINE.params.currentOutputPort;
|
||||||
if (MACHINE.argcount === 2) {
|
if (MACHINE.argcount === 2) {
|
||||||
|
@ -534,12 +551,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
}
|
}
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode(firstArg, 'display'));
|
outputPort.writeDomNode(MACHINE, toDomNode(firstArg, 'display'));
|
||||||
return VOID;
|
return VOID;
|
||||||
};
|
});
|
||||||
Primitives['display'].arity = makeList(1, 2);
|
|
||||||
Primitives['display'].displayName = 'display';
|
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
Primitives['newline'] = function(MACHINE) {
|
'newline', makeList(0, 1),
|
||||||
|
function(MACHINE) {
|
||||||
var outputPort = MACHINE.params.currentOutputPort;
|
var outputPort = MACHINE.params.currentOutputPort;
|
||||||
if (MACHINE.argcount === 1) {
|
if (MACHINE.argcount === 1) {
|
||||||
testArgument(MACHINE,
|
testArgument(MACHINE,
|
||||||
|
@ -552,12 +568,12 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
}
|
}
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
||||||
return VOID;
|
return VOID;
|
||||||
};
|
});
|
||||||
Primitives['newline'].arity = makeList(0, 1);
|
|
||||||
Primitives['newline'].displayName = 'newline';
|
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
Primitives['displayln'] = function(MACHINE){
|
'displayln',
|
||||||
|
makeList(1, 2),
|
||||||
|
function(MACHINE){
|
||||||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||||
var outputPort = MACHINE.params.currentOutputPort;
|
var outputPort = MACHINE.params.currentOutputPort;
|
||||||
if (MACHINE.argcount === 2) {
|
if (MACHINE.argcount === 2) {
|
||||||
|
@ -572,23 +588,26 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode(firstArg, 'display'));
|
outputPort.writeDomNode(MACHINE, toDomNode(firstArg, 'display'));
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
||||||
return VOID;
|
return VOID;
|
||||||
};
|
});
|
||||||
Primitives['displayln'].arity = makeList(1, 2);
|
|
||||||
Primitives['displayln'].displayName = 'displayln';
|
|
||||||
|
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
Primitives['current-print'] = function(MACHINE) {
|
'current-print',
|
||||||
|
makeList(0, 1),
|
||||||
|
function(MACHINE) {
|
||||||
|
if (MACHINE.argcount === 1) {
|
||||||
|
MACHINE.params['current-print'] = MACHINE.env[MACHINE.env.length - 1];
|
||||||
|
return VOID;
|
||||||
|
} else {
|
||||||
return MACHINE.params['current-print'];
|
return MACHINE.params['current-print'];
|
||||||
};
|
}
|
||||||
Primitives['current-print'].arity = makeList(0, 1);
|
});
|
||||||
Primitives['current-print'].displayName = "current-print";
|
|
||||||
|
|
||||||
Primitives['pi'] = jsnums.pi;
|
|
||||||
|
|
||||||
Primitives['e'] = jsnums.e;
|
installPrimitiveProcedure(
|
||||||
|
'=',
|
||||||
Primitives['='] = function(MACHINE) {
|
new ArityAtLeast(2),
|
||||||
|
function(MACHINE) {
|
||||||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||||
testArgument(MACHINE, 'number', isNumber, firstArg, 0, '=');
|
testArgument(MACHINE, 'number', isNumber, firstArg, 0, '=');
|
||||||
for (var i = 0; i < MACHINE.argcount - 1; i++) {
|
for (var i = 0; i < MACHINE.argcount - 1; i++) {
|
||||||
|
@ -604,11 +623,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
});
|
||||||
Primitives['='].arity = new ArityAtLeast(2);
|
|
||||||
Primitives['='].displayName = '=';
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: use installPrimitiveProcedure for the rest...
|
||||||
|
|
||||||
Primitives['<'] = function(MACHINE) {
|
Primitives['<'] = function(MACHINE) {
|
||||||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||||
testArgument(MACHINE,
|
testArgument(MACHINE,
|
||||||
|
@ -1161,6 +1180,24 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Extensions. A small experiment.
|
||||||
|
installPrimitiveProcedure(
|
||||||
|
'viewport-width',
|
||||||
|
0,
|
||||||
|
function(MACHINE) {
|
||||||
|
return $(window).width();
|
||||||
|
});
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
|
'viewport-height',
|
||||||
|
0,
|
||||||
|
function(MACHINE) {
|
||||||
|
return $(window).height();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// recomputeGas: state number -> number
|
// recomputeGas: state number -> number
|
||||||
|
@ -1342,6 +1379,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
exports['currentMachine'] = new Machine();
|
exports['currentMachine'] = new Machine();
|
||||||
exports['invokeMains'] = invokeMains;
|
exports['invokeMains'] = invokeMains;
|
||||||
|
|
||||||
|
|
||||||
|
// installing new primitives
|
||||||
|
exports['installPrimitiveProcedure'] = installPrimitiveProcedure;
|
||||||
exports['Primitives'] = Primitives;
|
exports['Primitives'] = Primitives;
|
||||||
|
|
||||||
exports['ready'] = ready;
|
exports['ready'] = ready;
|
||||||
|
@ -1417,5 +1457,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
exports['HaltError'] = HaltError;
|
exports['HaltError'] = HaltError;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
scope.link.announceReady('runtime');
|
scope.link.announceReady('runtime');
|
||||||
})(this['plt']);
|
})(this['plt']);
|
|
@ -148,7 +148,7 @@
|
||||||
display
|
display
|
||||||
newline
|
newline
|
||||||
|
|
||||||
#;displayln
|
;; displayln
|
||||||
|
|
||||||
;; current-print
|
;; current-print
|
||||||
;; current-continuation-marks
|
;; current-continuation-marks
|
||||||
|
@ -394,6 +394,27 @@
|
||||||
;; make-reader-graph
|
;; make-reader-graph
|
||||||
;; make-placeholder
|
;; make-placeholder
|
||||||
;; placeholder-set!
|
;; placeholder-set!
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(provide
|
||||||
|
;; FIXME:
|
||||||
|
;; Extensions: these may need to be hidden in a JavaScript-implemented module
|
||||||
|
viewport-width
|
||||||
|
viewport-height)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; 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."))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user