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