hacking in structs
This commit is contained in:
parent
35054f8b18
commit
48c8d067ce
|
@ -40,6 +40,8 @@
|
||||||
(define-runtime-path baselib_symbol.js "runtime-src/baselib_symbol.js")
|
(define-runtime-path baselib_symbol.js "runtime-src/baselib_symbol.js")
|
||||||
(define-runtime-path baselib_structs.js "runtime-src/baselib_structs.js")
|
(define-runtime-path baselib_structs.js "runtime-src/baselib_structs.js")
|
||||||
(define-runtime-path baselib_arity.js "runtime-src/baselib_arity.js")
|
(define-runtime-path baselib_arity.js "runtime-src/baselib_arity.js")
|
||||||
|
(define-runtime-path baselib_inspectors.js "runtime-src/baselib_inspectors.js")
|
||||||
|
(define-runtime-path baselib_exceptions.js "runtime-src/baselib_exceptions.js")
|
||||||
|
|
||||||
|
|
||||||
(define-runtime-path jshashtable.js "runtime-src/jshashtable-2.1_src.js")
|
(define-runtime-path jshashtable.js "runtime-src/jshashtable-2.1_src.js")
|
||||||
|
@ -73,6 +75,9 @@
|
||||||
baselib_symbol.js
|
baselib_symbol.js
|
||||||
baselib_structs.js
|
baselib_structs.js
|
||||||
baselib_arity.js
|
baselib_arity.js
|
||||||
|
baselib_inspectors.js
|
||||||
|
baselib_exceptions.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
link.js
|
link.js
|
||||||
|
|
22
js-assembler/runtime-src/baselib_inspectors.js
Normal file
22
js-assembler/runtime-src/baselib_inspectors.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Structure types
|
||||||
|
|
||||||
|
(function(baselib) {
|
||||||
|
var exports = {};
|
||||||
|
baselib.inspectors = exports;
|
||||||
|
|
||||||
|
|
||||||
|
var Inspector = function() {
|
||||||
|
};
|
||||||
|
var DEFAULT_INSPECTOR = new Inspector();
|
||||||
|
|
||||||
|
Inspector.prototype.toString = function() {
|
||||||
|
return "#<inspector>";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exports.Inspector = Inspector;
|
||||||
|
exports.DEFAULT_INSPECTOR = DEFAULT_INSPECTOR;
|
||||||
|
|
||||||
|
|
||||||
|
})(this['plt'].baselib);
|
|
@ -163,16 +163,16 @@
|
||||||
return plt.helpers.toWrittenString(this, cache);
|
return plt.helpers.toWrittenString(this, cache);
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct.prototype.toDomNode = function(cache) {
|
Struct.prototype.toDomNode = function(params) {
|
||||||
cache.put(this, true);
|
params.put(this, true);
|
||||||
var node = document.createElement("div");
|
var node = document.createElement("div");
|
||||||
node.appendChild(document.createTextNode("("));
|
$(node).append(document.createTextNode("("));
|
||||||
node.appendChild(document.createTextNode(this._constructorName));
|
$(node).append(document.createTextNode(this._constructorName));
|
||||||
for(var i = 0; i < this._fields.length; i++) {
|
for(var i = 0; i < this._fields.length; i++) {
|
||||||
node.appendChild(document.createTextNode(" "));
|
$(node).append(document.createTextNode(" "));
|
||||||
appendChild(node, plt.helpers.toDomNode(this._fields[i], cache));
|
$(node).append(plt.helpers.toDomNode(this._fields[i], params));
|
||||||
}
|
}
|
||||||
node.appendChild(document.createTextNode(")"));
|
$(node).append(document.createTextNode(")"));
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
$(domNode).appendTo(document.body);
|
$(domNode).appendTo(document.body);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'currentInspector': plt.baselib.inspectors.DEFAULT_INSPECTOR,
|
||||||
|
|
||||||
'currentOutputPort': new StandardOutputPort(),
|
'currentOutputPort': new StandardOutputPort(),
|
||||||
'currentErrorPort': new StandardErrorPort(),
|
'currentErrorPort': new StandardErrorPort(),
|
||||||
|
@ -383,10 +384,10 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
|
|
||||||
|
|
||||||
var raise = function(MACHINE, e) {
|
var raise = function(MACHINE, e) {
|
||||||
if (typeof(window.console) !== 'undefined' &&
|
if (typeof(window['console']) !== 'undefined' &&
|
||||||
typeof(console.log) === 'function') {
|
typeof(console['log']) === 'function') {
|
||||||
console.log(MACHINE);
|
console.log(MACHINE);
|
||||||
if (e.stack) { console.log(e.stack); }
|
if (e['stack']) { console.log(e['stack']); }
|
||||||
else { console.log(e); }
|
else { console.log(e); }
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -556,7 +557,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
vs,
|
vs,
|
||||||
f) {
|
f) {
|
||||||
var args = [];
|
var args = [];
|
||||||
for (var i = 0; i < MACHINE.argcount.length; i++) {
|
for (var i = 0; i < MACHINE.argcount; i++) {
|
||||||
if (i < mandatoryArgCount) {
|
if (i < mandatoryArgCount) {
|
||||||
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2078,16 +2079,74 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
procSpec, // FIXME: currently ignored
|
procSpec, // FIXME: currently ignored
|
||||||
immutables, // FIXME: currently ignored
|
immutables, // FIXME: currently ignored
|
||||||
guard, // FIXME: currently ignored
|
guard, // FIXME: currently ignored
|
||||||
constructorName // FIXME, currently ignored
|
constructorName
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// FIXME: we need to return those five values back.
|
// FIXME: typechecks.
|
||||||
|
|
||||||
|
var structType = plt.baselib.structs.makeStructureType(
|
||||||
|
name,
|
||||||
|
superType,
|
||||||
|
initFieldCount,
|
||||||
|
autoFieldCount,
|
||||||
|
autoV,
|
||||||
|
//props,
|
||||||
|
//inspector,
|
||||||
|
//procSpec,
|
||||||
|
//immutables,
|
||||||
|
guard);
|
||||||
|
|
||||||
|
console.log('constructor', name, superType, initFieldCount);
|
||||||
|
var constructorValue =
|
||||||
|
makePrimitiveProcedure(
|
||||||
|
constructorName,
|
||||||
|
jsnums.toFixnum(initFieldCount),
|
||||||
|
function(MACHINE) {
|
||||||
|
var args = [];
|
||||||
|
for(var i = 0; i < initFieldCount; i++) {
|
||||||
|
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
|
||||||
|
}
|
||||||
|
return structType.constructor.apply(null, args);
|
||||||
|
});
|
||||||
|
|
||||||
|
var predicateValue =
|
||||||
|
makePrimitiveProcedure(
|
||||||
|
String(name) + "?",
|
||||||
|
1,
|
||||||
|
function(MACHINE) {
|
||||||
|
return structType.predicate(MACHINE.env[MACHINE.env.length - 1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
var accessorValue =
|
||||||
|
makePrimitiveProcedure(
|
||||||
|
String(name) + "-accessor",
|
||||||
|
2,
|
||||||
|
function(MACHINE) {
|
||||||
|
// FIXME: typechecks
|
||||||
|
return structType.accessor(
|
||||||
|
MACHINE.env[MACHINE.env.length - 1],
|
||||||
|
jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2]));
|
||||||
|
});
|
||||||
|
|
||||||
|
var mutatorValue =
|
||||||
|
makePrimitiveProcedure(
|
||||||
|
String(name) + "-mutator",
|
||||||
|
3,
|
||||||
|
function(MACHINE) {
|
||||||
|
// FIXME: typechecks
|
||||||
|
return structType.mutator(
|
||||||
|
MACHINE.env[MACHINE.env.length - 1],
|
||||||
|
jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2]),
|
||||||
|
MACHINE.env[MACHINE.env.length - 3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
finalizeClosureCall(MACHINE,
|
finalizeClosureCall(MACHINE,
|
||||||
"type",
|
structType,
|
||||||
"constructor",
|
constructorValue,
|
||||||
"predicate",
|
predicateValue,
|
||||||
"accessor",
|
accessorValue,
|
||||||
"mutator");
|
mutatorValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2095,17 +2154,67 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
'current-inspector',
|
'current-inspector',
|
||||||
makeList(0, 1),
|
makeList(0, 1),
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
return "inspector gadget";
|
if (MACHINE.argcount === 1) {
|
||||||
|
MACHINE.params['currentInspector'] = MACHINE.env[MACHINE.env.length - 1];
|
||||||
|
return VOID;
|
||||||
|
} else {
|
||||||
|
return MACHINE.params['currentInspector'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
installPrimitiveProcedure(
|
installPrimitiveProcedure(
|
||||||
'make-struct-field-accessor',
|
'make-struct-field-accessor',
|
||||||
makeList(2, 3),
|
makeList(2, 3),
|
||||||
function(MACHINE){
|
function(MACHINE){
|
||||||
return 'a procedure';
|
// FIXME: typechecks
|
||||||
|
var structType = MACHINE.env[MACHINE.env.length - 1];
|
||||||
|
var index = MACHINE.env[MACHINE.env.length - 2];
|
||||||
|
var name;
|
||||||
|
if (MACHINE.argcount === 3) {
|
||||||
|
name = String(MACHINE.env[MACHINE.env.length - 3]);
|
||||||
|
} else {
|
||||||
|
name = 'field' + index;
|
||||||
|
}
|
||||||
|
return makePrimitiveProcedure(
|
||||||
|
name,
|
||||||
|
1,
|
||||||
|
function(MACHINE) {
|
||||||
|
return structType.accessor(
|
||||||
|
MACHINE.env[MACHINE.env.length - 1],
|
||||||
|
jsnums.toFixnum(index));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
installPrimitiveProcedure(
|
||||||
|
'make-struct-field-mutator',
|
||||||
|
makeList(2, 3),
|
||||||
|
function(MACHINE){
|
||||||
|
// FIXME: typechecks
|
||||||
|
var structType = MACHINE.env[MACHINE.env.length - 1];
|
||||||
|
var index = MACHINE.env[MACHINE.env.length - 2];
|
||||||
|
var name;
|
||||||
|
if (MACHINE.argcount === 3) {
|
||||||
|
name = String(MACHINE.env[MACHINE.env.length - 3]);
|
||||||
|
} else {
|
||||||
|
name = 'field' + index;
|
||||||
|
}
|
||||||
|
return makePrimitiveProcedure(
|
||||||
|
name,
|
||||||
|
2,
|
||||||
|
function(MACHINE) {
|
||||||
|
return structType.mutator(
|
||||||
|
MACHINE.env[MACHINE.env.length - 1],
|
||||||
|
jsnums.toFixnum(index),
|
||||||
|
MACHINE.env[MACHINE.env.length - 2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user