fixing the runtime library
This commit is contained in:
parent
9afc4accdc
commit
3f5c2b459f
|
@ -62,11 +62,14 @@
|
|||
baselib-placeholders.js
|
||||
baselib-keywords.js
|
||||
baselib-structs.js
|
||||
|
||||
baselib-ports.js
|
||||
|
||||
baselib-arity.js
|
||||
baselib-inspectors.js
|
||||
baselib-exceptions.js
|
||||
baselib-readergraph.js
|
||||
|
||||
baselib-check.js
|
||||
|
||||
runtime.js))
|
||||
|
||||
|
|
56
js-assembler/runtime-src/baselib-check.js
Normal file
56
js-assembler/runtime-src/baselib-check.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Helper functions for argument checking.
|
||||
|
||||
(function(baselib) {
|
||||
var exports = {};
|
||||
baselib.check = exports;
|
||||
|
||||
|
||||
var makeCheckArgumentType = function(predicate, predicateName) {
|
||||
return function(MACHINE, callerName, position) {
|
||||
testArgument(
|
||||
MACHINE,
|
||||
predicateName,
|
||||
predicate,
|
||||
MACHINE.env[MACHINE.env.length - 1 - position],
|
||||
position,
|
||||
callerName);
|
||||
return MACHINE.env[MACHINE.env.length - 1 - position];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// testArgument: (X -> boolean) X number string string -> boolean
|
||||
// Produces true if val is true, and otherwise raises an error.
|
||||
var testArgument = function(MACHINE,
|
||||
expectedTypeName,
|
||||
predicate,
|
||||
val,
|
||||
index,
|
||||
callerName) {
|
||||
if (predicate(val)) {
|
||||
return true;
|
||||
} else {
|
||||
plt.baselib.exceptions.raiseArgumentTypeError(MACHINE,
|
||||
callerName,
|
||||
expectedTypeName,
|
||||
index,
|
||||
val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//var checkOutputPort = makeCheckArgumentType()
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
exports.testArgument = testArgument;
|
||||
exports.makeCheckArgumentType = makeCheckArgumentType;
|
||||
//exports.checkOutputPort = checkOutputPort;
|
||||
|
||||
|
||||
|
||||
})(this['plt'].baselib);
|
57
js-assembler/runtime-src/baselib-ports.js
Normal file
57
js-assembler/runtime-src/baselib-ports.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Arity structure
|
||||
(function(baselib) {
|
||||
var exports = {};
|
||||
baselib.ports = exports;
|
||||
|
||||
|
||||
// Output Ports
|
||||
|
||||
var OutputPort = function() {};
|
||||
var isOutputPort = baselib.makeClassPredicate(OutputPort);
|
||||
|
||||
|
||||
var StandardOutputPort = function() {
|
||||
OutputPort.call(this);
|
||||
};
|
||||
StandardOutputPort.prototype = baselib.heir(OutputPort.prototype);
|
||||
StandardOutputPort.prototype.writeDomNode = function(MACHINE, domNode) {
|
||||
MACHINE.params['currentDisplayer'](MACHINE, domNode);
|
||||
};
|
||||
|
||||
var StandardErrorPort = function() {
|
||||
OutputPort.call(this);
|
||||
};
|
||||
StandardErrorPort.prototype = baselib.heir(OutputPort.prototype);
|
||||
StandardErrorPort.prototype.writeDomNode = function(MACHINE, domNode) {
|
||||
MACHINE.params['currentErrorDisplayer'](MACHINE, domNode);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var OutputStringPort = function() {
|
||||
this.buf = [];
|
||||
};
|
||||
OutputStringPort.prototype = baselib.heir(OutputPort.prototype);
|
||||
OutputStringPort.prototype.writeDomNode = function(MACHINE, v) {
|
||||
this.buf.push($(v).text());
|
||||
};
|
||||
OutputStringPort.prototype.getOutputString = function() {
|
||||
return this.buf.join('');
|
||||
};
|
||||
var isOutputStringPort = baselib.makeClassPredicate(OutputStringPort);
|
||||
|
||||
|
||||
|
||||
|
||||
exports.OutputPort = OutputPort;
|
||||
exports.isOutputPort = isOutputPort;
|
||||
exports.StandardOutputPort = StandardOutputPort;
|
||||
exports.StandardErrorPort = StandardErrorPort;
|
||||
exports.OutputStringPort = OutputStringPort;
|
||||
exports.isOutputStringPort = isOutputStringPort;
|
||||
|
||||
|
||||
})(this['plt'].baselib);
|
|
@ -33,10 +33,15 @@ if (! this['plt']) { this['plt'] = {}; }
|
|||
};
|
||||
|
||||
|
||||
// Consumes a class and creates a predicate that recognizes subclasses.
|
||||
var makeClassPredicate = function(aClass) {
|
||||
return function(x) { return x instanceof aClass; };
|
||||
};
|
||||
|
||||
|
||||
baselib.heir = heir;
|
||||
baselib.clone = clone;
|
||||
baselib.makeClassPredicate = makeClassPredicate;
|
||||
|
||||
|
||||
})(this['plt']);
|
||||
|
|
|
@ -12,11 +12,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
var types = plt.types;
|
||||
|
||||
|
||||
var makeClassPredicate = plt.baselib.makeClassPredicate;
|
||||
|
||||
// Consumes a class and creates a predicate that recognizes subclasses.
|
||||
var makeClassPredicate = function(aClass) {
|
||||
return function(x) { return x instanceof aClass; };
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -67,6 +64,20 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
var CallFrame = plt.baselib.frames.CallFrame;
|
||||
var PromptFrame = plt.baselib.frames.PromptFrame;
|
||||
|
||||
|
||||
// Ports
|
||||
var OutputPort = plt.baselib.ports.OutputPort;
|
||||
var isOutputPort = plt.baselib.ports.isOutputPort;
|
||||
var StandardOutputPort = plt.baselib.ports.StandardOutputPort;
|
||||
var StandardErrorPort = plt.baselib.ports.StandardErrorPort;
|
||||
var OutputStringPort = plt.baselib.ports.OutputStringPort;
|
||||
var isOutputStringPort = plt.baselib.ports.isOutputStringPort;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////]
|
||||
|
||||
|
||||
|
@ -259,45 +270,6 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
|
||||
|
||||
|
||||
// Output Ports
|
||||
|
||||
var OutputPort = function() {};
|
||||
var isOutputPort = makeClassPredicate(OutputPort);
|
||||
|
||||
|
||||
var StandardOutputPort = function() {
|
||||
OutputPort.call(this);
|
||||
};
|
||||
StandardOutputPort.prototype = heir(OutputPort.prototype);
|
||||
StandardOutputPort.prototype.writeDomNode = function(MACHINE, domNode) {
|
||||
MACHINE.params['currentDisplayer'](MACHINE, domNode);
|
||||
};
|
||||
|
||||
var StandardErrorPort = function() {
|
||||
OutputPort.call(this);
|
||||
};
|
||||
StandardErrorPort.prototype = heir(OutputPort.prototype);
|
||||
StandardErrorPort.prototype.writeDomNode = function(MACHINE, domNode) {
|
||||
MACHINE.params['currentErrorDisplayer'](MACHINE, domNode);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var OutputStringPort = function() {
|
||||
this.buf = [];
|
||||
};
|
||||
OutputStringPort.prototype = heir(OutputPort.prototype);
|
||||
OutputStringPort.prototype.writeDomNode = function(MACHINE, v) {
|
||||
this.buf.push($(v).text());
|
||||
};
|
||||
OutputStringPort.prototype.getOutputString = function() {
|
||||
return this.buf.join('');
|
||||
};
|
||||
var isOutputStringPort = makeClassPredicate(OutputStringPort);
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -363,40 +335,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
var raiseUnimplementedPrimitiveError = plt.baselib.exceptions.raiseUnimplementedPrimitiveError;
|
||||
|
||||
|
||||
|
||||
|
||||
// testArgument: (X -> boolean) X number string string -> boolean
|
||||
// Produces true if val is true, and otherwise raises an error.
|
||||
var testArgument = function(MACHINE,
|
||||
expectedTypeName,
|
||||
predicate,
|
||||
val,
|
||||
index,
|
||||
callerName) {
|
||||
if (predicate(val)) {
|
||||
return true;
|
||||
} else {
|
||||
raiseArgumentTypeError(MACHINE,
|
||||
callerName,
|
||||
expectedTypeName,
|
||||
index,
|
||||
val);
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function for argument checking.
|
||||
var makeCheckArgumentType = function(predicate, predicateName) {
|
||||
return function(MACHINE, callerName, position) {
|
||||
testArgument(
|
||||
MACHINE,
|
||||
predicateName,
|
||||
predicate,
|
||||
MACHINE.env[MACHINE.env.length - 1 - position],
|
||||
position,
|
||||
callerName);
|
||||
return MACHINE.env[MACHINE.env.length - 1 - position];
|
||||
}
|
||||
};
|
||||
var testArgument = plt.baselib.check.testArgument;
|
||||
var makeCheckArgumentType = plt.baselib.check.makeCheckArgumentType;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user