diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-12-11 12:44:29 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-12-11 13:03:45 +0100 |
commit | bd91ecce14c8df1022d4f7225888906541556570 (patch) | |
tree | 577a83b49d4ddd46556faa5060be16c88a71350e /libguile/vm-i-scheme.c | |
parent | 6c20a0b34b3c79c999213320eabf3d46eddd1c6e (diff) | |
download | guile-bd91ecce14c8df1022d4f7225888906541556570.tar.gz |
Add opcodes for `struct?', `struct-vtable', and `make-struct'.
* libguile/vm-engine.c (VM_NAME)[vm_error_not_a_struct]: New label.
* libguile/vm-i-scheme.c (VM_VALIDATE_STRUCT): New macro.
(struct_p, struct_vtable, make_struct): New instructions.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Add
`struct?', `struct-vtable', and `make-struct'.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*,
*effect-free-primitives*): Likewise.
Diffstat (limited to 'libguile/vm-i-scheme.c')
-rw-r--r-- | libguile/vm-i-scheme.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libguile/vm-i-scheme.c b/libguile/vm-i-scheme.c index c9b40ee56..6faab9be1 100644 --- a/libguile/vm-i-scheme.c +++ b/libguile/vm-i-scheme.c @@ -621,6 +621,40 @@ BV_FLOAT_SET (f64, ieee_double, double, 8) #undef BV_INT_SET #undef BV_FLOAT_SET +#define VM_VALIDATE_STRUCT(obj) \ + if (SCM_UNLIKELY (!SCM_STRUCTP (obj))) \ + { \ + finish_args = (obj); \ + goto vm_error_not_a_struct; \ + } + +VM_DEFINE_FUNCTION (174, struct_p, "struct?", 1) +{ + ARGS1 (obj); + RETURN (scm_from_bool (SCM_STRUCTP (obj))); +} + +VM_DEFINE_FUNCTION (175, struct_vtable, "struct-vtable", 1) +{ + ARGS1 (obj); + VM_VALIDATE_STRUCT (obj); + RETURN (SCM_STRUCT_VTABLE (obj)); +} + +VM_DEFINE_INSTRUCTION (176, make_struct, "make-struct", 2, -1, 1) +{ + unsigned h = FETCH (); + unsigned l = FETCH (); + int n_args = ((h << 8U) + l); + SCM vtable = sp[1 - n_args], n_tail = sp[2 - n_args]; + const SCM *inits = sp - n_args + 3; + + sp -= n_args - 1; + + RETURN (scm_c_make_structv (vtable, scm_to_size_t (n_tail), + n_args - 2, (scm_t_bits *) inits)); +} + /* (defun renumber-ops () "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences" |