working on the printer so we can get constructor-style output based on print-mode parameter
This commit is contained in:
parent
44308b643b
commit
602086e46b
|
@ -166,7 +166,7 @@ var withIeHack = function(canvas, f) {
|
|||
|
||||
// Images are expected to define a render() method, which is used
|
||||
// here to draw to the canvas.
|
||||
BaseImage.prototype.toDomNode = function(cache) {
|
||||
BaseImage.prototype.toDomNode = function(params) {
|
||||
var that = this;
|
||||
var width = that.getWidth();
|
||||
var height = that.getHeight();
|
||||
|
@ -365,7 +365,7 @@ FileImage.prototype.getHeight = function() {
|
|||
};
|
||||
|
||||
// Override toDomNode: we don't need a full-fledged canvas here.
|
||||
FileImage.prototype.toDomNode = function(cache) {
|
||||
FileImage.prototype.toDomNode = function(params) {
|
||||
return this.img.cloneNode(true);
|
||||
};
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@
|
|||
return "#&" + baselib.format.toDisplayedString(this.val, cache);
|
||||
};
|
||||
|
||||
Box.prototype.toDomNode = function(cache) {
|
||||
cache.put(this, true);
|
||||
Box.prototype.toDomNode = function(params) {
|
||||
params.put(this, true);
|
||||
var parent = document.createElement("span");
|
||||
parent.appendChild(document.createTextNode('#&'));
|
||||
parent.appendChild(baselib.format.toDomNode(this.val, cache));
|
||||
parent.appendChild(baselib.format.toDomNode(this.val, params));
|
||||
return parent;
|
||||
};
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
this.kvlists = kvlists;
|
||||
};
|
||||
|
||||
ContinuationMarkSet.prototype.toDomNode = function(cache) {
|
||||
ContinuationMarkSet.prototype.toDomNode = function(params) {
|
||||
var dom = document.createElement("span");
|
||||
dom.appendChild(document.createTextNode('#<continuation-mark-set>'));
|
||||
return dom;
|
||||
|
|
|
@ -76,9 +76,9 @@
|
|||
}
|
||||
|
||||
var returnVal;
|
||||
if (typeof(x.toWrittenString) !== 'undefined') {
|
||||
if (x.toWrittenString) {
|
||||
returnVal = x.toWrittenString(cache);
|
||||
} else if (typeof(x.toDisplayedString) !== 'undefined') {
|
||||
} else if (x.toDisplayedString) {
|
||||
returnVal = x.toDisplayedString(cache);
|
||||
} else {
|
||||
returnVal = x.toString();
|
||||
|
@ -119,9 +119,9 @@
|
|||
}
|
||||
|
||||
var returnVal;
|
||||
if (typeof(x.toDisplayedString) !== 'undefined') {
|
||||
if (x.toDisplayedString) {
|
||||
returnVal = x.toDisplayedString(cache);
|
||||
} else if (typeof(x.toWrittenString) !== 'undefined') {
|
||||
} else if (x.toWrittenString) {
|
||||
returnVal = x.toWrittenString(cache);
|
||||
} else {
|
||||
returnVal = x.toString();
|
||||
|
@ -220,6 +220,10 @@
|
|||
return 'print';
|
||||
};
|
||||
|
||||
ToDomNodeParameters.prototype.getDepth = function(x) {
|
||||
return this.depth;
|
||||
};
|
||||
|
||||
ToDomNodeParameters.prototype.containsKey = function(x) {
|
||||
return this.cache.containsKey(x);
|
||||
};
|
||||
|
@ -324,6 +328,8 @@
|
|||
params = new ToDomNodeParameters({'mode' : 'print'});
|
||||
} else if (params === 'display') {
|
||||
params = new ToDomNodeParameters({'mode' : 'display'});
|
||||
} else if (params === 'constructor') {
|
||||
params = new ToDomNodeParameters({'mode' : 'constructor'});
|
||||
} else {
|
||||
params = params || new ToDomNodeParameters({'mode' : 'display'});
|
||||
}
|
||||
|
@ -333,40 +339,6 @@
|
|||
$(node).addClass("number");
|
||||
return node;
|
||||
}
|
||||
|
||||
if (x === null) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("null"));
|
||||
$(node).addClass("null");
|
||||
return node;
|
||||
}
|
||||
|
||||
if (x === true) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("true"));
|
||||
$(node).addClass("boolean");
|
||||
return node;
|
||||
}
|
||||
|
||||
if (x === false) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("false"));
|
||||
$(node).addClass("boolean");
|
||||
return node;
|
||||
}
|
||||
|
||||
if (typeof(x) === 'object') {
|
||||
if (params.containsKey(x)) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("#" + params.get(x)));
|
||||
return node;
|
||||
}
|
||||
}
|
||||
if (x === undefined || x === null) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("#<undefined>"));
|
||||
return node;
|
||||
}
|
||||
|
||||
if (typeof(x) === 'string') {
|
||||
var wrapper = document.createElement("span");
|
||||
|
@ -381,6 +353,35 @@
|
|||
return wrapper;
|
||||
}
|
||||
|
||||
if (x === true || x === false) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode(x ? "true" : "false"));
|
||||
$(node).addClass("boolean");
|
||||
return node;
|
||||
}
|
||||
|
||||
if (x === null) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("null"));
|
||||
$(node).addClass("null");
|
||||
return node;
|
||||
}
|
||||
|
||||
if (x === undefined) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("#<undefined>"));
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
if (typeof(x) === 'object') {
|
||||
if (params.containsKey(x)) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("#" + params.get(x)));
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
if (baselib.functions.isProcedure(x)) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode('#<procedure: ' + x.displayName + '>'));
|
||||
|
@ -397,15 +398,13 @@
|
|||
var returnVal;
|
||||
if (x.nodeType) {
|
||||
returnVal = x;
|
||||
} else if (typeof(x.toDomNode) !== 'undefined') {
|
||||
} else if (x.toDomNode) {
|
||||
returnVal = x.toDomNode(params);
|
||||
} else if (params.getMode() === 'write' &&
|
||||
typeof(x.toWrittenString) !== 'undefined') {
|
||||
} else if (params.getMode() === 'write' && x.toWrittenString) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode(x.toWrittenString(params)));
|
||||
returnVal = node;
|
||||
} else if (params.getMode() === 'display' &&
|
||||
typeof(x.toDisplayedString) !== 'undefined') {
|
||||
} else if (params.getMode() === 'display' && x.toDisplayedString) {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode(x.toDisplayedString(params)));
|
||||
returnVal = node;
|
||||
|
|
|
@ -185,7 +185,7 @@
|
|||
|
||||
|
||||
|
||||
var defaultCurrentPrintImplementation = function defaultCurrentPrintImplementation(MACHINE) {
|
||||
var defaultCurrentPrintImplementation = function (MACHINE) {
|
||||
if(--MACHINE.cbt < 0) {
|
||||
throw defaultCurrentPrintImplementation;
|
||||
}
|
||||
|
@ -195,7 +195,9 @@
|
|||
var outputPort =
|
||||
MACHINE.params.currentOutputPort;
|
||||
if (elt !== VOID) {
|
||||
outputPort.writeDomNode(MACHINE, toDomNode(elt, 'print'));
|
||||
outputPort.writeDomNode(
|
||||
MACHINE,
|
||||
toDomNode(elt, MACHINE.params['print-mode']));
|
||||
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
||||
}
|
||||
MACHINE.a = oldArgcount;
|
||||
|
@ -225,6 +227,10 @@
|
|||
// print-as-expression: boolean
|
||||
'print-as-expression' : true,
|
||||
|
||||
// print-mode: (one-of "write" "print" "constructor")
|
||||
'print-mode' : 'write',
|
||||
|
||||
|
||||
// currentDisplayer: DomNode -> Void
|
||||
// currentDisplayer is responsible for displaying to the browser.
|
||||
'currentDisplayer': function(MACHINE, domNode) {
|
||||
|
@ -245,7 +251,7 @@
|
|||
'currentErrorHandler': function(MACHINE, exn) {
|
||||
MACHINE.params.currentErrorDisplayer(
|
||||
MACHINE,
|
||||
toDomNode(exn));
|
||||
toDomNode(exn, MACHINE.params['print-mode']));
|
||||
},
|
||||
|
||||
'currentNamespace': {},
|
||||
|
|
Loading…
Reference in New Issue
Block a user