mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 01:30:27 +02:00
Implement struct built-ins.
* module/language/js-il/runtime.js (struct?): New primitive. (<applicable-struct-vtable>, record-type-vtable, set-struct-vtable-name!, make-struct): Implement built-ins.
This commit is contained in:
parent
2273eb4d06
commit
ebe9d00153
1 changed files with 28 additions and 0 deletions
|
@ -443,6 +443,10 @@ scheme.Struct = function (vtable, nfields) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
scheme.primitives["struct?"] = function (obj) {
|
||||||
|
return coerce_bool(obj instanceof scheme.Struct);
|
||||||
|
};
|
||||||
|
|
||||||
scheme.primitives["allocate-struct/immediate"] = function (vtable, nfields) {
|
scheme.primitives["allocate-struct/immediate"] = function (vtable, nfields) {
|
||||||
return new scheme.Struct(vtable, nfields);
|
return new scheme.Struct(vtable, nfields);
|
||||||
};
|
};
|
||||||
|
@ -908,3 +912,27 @@ def_guile0("struct-vtable?", function (self, cont, obj) {
|
||||||
var bool = coerce_bool(obj instanceof scheme.Struct && obj.is_vtable);
|
var bool = coerce_bool(obj instanceof scheme.Struct && obj.is_vtable);
|
||||||
return cont(bool);
|
return cont(bool);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var applicable_vtable = scm_make_struct(scm_standard_vtable, [new scheme.Symbol(vtable_base_layout.s)]);
|
||||||
|
applicable_vtable.children_applicable_vtables = true;
|
||||||
|
|
||||||
|
def_guile_val("<applicable-struct-vtable>", applicable_vtable);
|
||||||
|
|
||||||
|
def_guile_val("record-type-vtable", scm_standard_vtable); // FIXME:
|
||||||
|
|
||||||
|
def_guile0("set-struct-vtable-name!", function (self, cont, val, args) {
|
||||||
|
// FIXME:
|
||||||
|
return cont(scheme.FALSE);
|
||||||
|
});
|
||||||
|
|
||||||
|
def_guile0("make-struct", function (self, cont, vtable, tailsize) {
|
||||||
|
if (tailsize === 0) {
|
||||||
|
// make-struct/no-tail
|
||||||
|
var args = Array.prototype.slice.call(arguments, 4);
|
||||||
|
return cont(scm_make_struct(vtable, args));
|
||||||
|
} else {
|
||||||
|
console.log("make-struct with tail", arguments);
|
||||||
|
not_implemented_yet();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue