summaryrefslogtreecommitdiff
path: root/libguile/struct.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2018-01-21 21:03:35 +0100
committerAndy Wingo <wingo@pobox.com>2018-01-21 21:03:35 +0100
commit5084fa4858c0fa153c7c9fd5db3625cbc90470df (patch)
tree995fb5f86b8a99facf964bb26bb1bf129b3bd7b0 /libguile/struct.c
parent557acdbbba9e3bcc1108d81cbf8c2f7c14fcb29a (diff)
downloadguile-5084fa4858c0fa153c7c9fd5db3625cbc90470df.tar.gz
Introduce make-struct/simple
* libguile/struct.h: * libguile/struct.c (scm_make_struct_simple): New function. * module/ice-9/boot-9.scm (make-record-type): Recast in terms of make-struct/simple. * module/ice-9/eval.scm (primitive-eval): Remove allocate-struct case. * module/srfi/srfi-9.scm (%%set-fields, %define-record-type): Use make-struct/simple.
Diffstat (limited to 'libguile/struct.c')
-rw-r--r--libguile/struct.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/libguile/struct.c b/libguile/struct.c
index e39f3c720..957776b28 100644
--- a/libguile/struct.c
+++ b/libguile/struct.c
@@ -1,5 +1,5 @@
/* Copyright (C) 1996-2001, 2003-2004, 2006-2013, 2015,
- * 2017 Free Software Foundation, Inc.
+ * 2017-2018 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -413,6 +413,44 @@ SCM_DEFINE (scm_allocate_struct, "allocate-struct", 2, 0, 0,
}
#undef FUNC_NAME
+SCM_DEFINE (scm_make_struct_simple, "make-struct/simple", 1, 0, 1,
+ (SCM vtable, SCM init),
+ "Create a new structure.\n\n"
+ "@var{vtable} must be a vtable structure (@pxref{Vtables}).\n\n"
+ "The @var{init1}, @dots{} arguments supply the initial values\n"
+ "for the structure's fields\n.\n"
+ "This is a restricted variant of @code{make-struct/no-tail}\n"
+ "which applies only if the structure has no unboxed fields.\n"
+ "@code{make-struct/simple} must be called with as many\n"
+ "@var{init} values as the struct has fields. No finalizer is set\n"
+ "on the instance, even if the vtable has a non-zero finalizer\n"
+ "field. No magical vtable fields are inherited.\n\n"
+ "The advantage of using @code{make-struct/simple} is that the\n"
+ "compiler can inline it, so it is faster. When in doubt though,\n"
+ "use @code{make-struct/no-tail}.")
+#define FUNC_NAME s_scm_make_struct_simple
+{
+ long i, n_init;
+ SCM ret;
+
+ SCM_VALIDATE_VTABLE (1, vtable);
+ n_init = scm_ilength (init);
+ if (n_init != SCM_VTABLE_SIZE (vtable))
+ SCM_MISC_ERROR ("Wrong number of initializers.", SCM_EOL);
+
+ ret = scm_words (SCM_UNPACK (vtable) | scm_tc3_struct, n_init + 1);
+
+ for (i = 0; i < n_init; i++, init = scm_cdr (init))
+ {
+ SCM_ASSERT (!SCM_VTABLE_FIELD_IS_UNBOXED (vtable, i),
+ vtable, 1, FUNC_NAME);
+ SCM_STRUCT_SLOT_SET (ret, i, scm_car (init));
+ }
+
+ return ret;
+}
+#undef FUNC_NAME
+
SCM_DEFINE (scm_make_struct_no_tail, "make-struct/no-tail", 1, 0, 1,
(SCM vtable, SCM init),
"Create a new structure.\n\n"