summaryrefslogtreecommitdiffstats
path: root/lisplib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-05-06 06:47:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-05-06 06:47:30 -0700
commit209e731429a0fd890ec6d922c1efc6f02d81a032 (patch)
tree55302eeaaaf8ee7e0fdc7add129f2e6c68756f27 /lisplib.c
parentf7aaccf9231081e840987be9b1e5922592b147e6 (diff)
downloadtxr-209e731429a0fd890ec6d922c1efc6f02d81a032.tar.gz
txr-209e731429a0fd890ec6d922c1efc6f02d81a032.tar.bz2
txr-209e731429a0fd890ec6d922c1efc6f02d81a032.zip
New macro-based framework for assignment places.
The operators set, inc, dec, pop and others are now macros which generate code, rather than built-in special forms that use "C magic". Moreover, new such macros are easy to write, and several new ones are already available. Moreover, new kinds of assignable places are easy to create. * place.tl: New file. * lisplib.c, lisplib.h: New files. * Makefile (OBJS): New target, lisplib.o. (GEN_HDRS): New variable. (LISP_TO_C_STRING): New recipe macro, with rule. (clean): Remove generated headers named in $(GEN_HDRS). * eval.c (dec_s, push_s, pop_s, flip_s, del_s): Variables removed. (setq_s): New variable. (lookup_var, lokup_sym_lisp_1, lookup_var_l, lookup_fun, lookup_mac, lookup_symac, lookup_symac_lisp1): Trigger the delayed loading of libraries for undefined global symbols, and re-try the lookup. (op_modplace, dwim_loc, force_l): Static functions removed. (op_setq): New static function. (eval_init): Initialize setq_s; remove initializations of removed variables; remove registrations for op_modplace; add registration for sys:setq, sys:rplaca, sys:rplacd, sys:dwim-set and sys:dwim-del intrinsics. Call lisplib_init to initialize the dynamic library loading module. * lib.c (sys_rplaca, sys_rplacd): New functions, differing in return value from rplaca and rplacd. (ref, refset): Handle hash table. (dwim_set, dwim_del): New functions. * lib.h (sys_rplaca, sys_rplacd, dwim_set, dwim_del): Declared. * genvim.txr: Include place.tl in scan. * tests/010/seq.txr: The del operator test case no longer throws at run-time but at macro-expansion time, so the test case is simply removed. * tests/010/seq.expected: Updated output. * tests/011/macros-2.txr: Reset *gensym-counter* to zero, because the textual output of the test case includes gensyms, whose numberings fluctuate with the content of the new Lisp library material. * tests/011/macros-2.expected: Updated output.
Diffstat (limited to 'lisplib.c')
-rw-r--r--lisplib.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/lisplib.c b/lisplib.c
new file mode 100644
index 00000000..d6b7876a
--- /dev/null
+++ b/lisplib.c
@@ -0,0 +1,83 @@
+/* Copyright 2015
+ * Kaz Kylheku <kaz@kylheku.com>
+ * Vancouver, Canada
+ * All rights reserved.
+ *
+ * Redistribution of this software in source and binary forms, with or without
+ * modification, is permitted provided that the following two conditions are met.
+ *
+ * Use of this software in any manner constitutes agreement with the disclaimer
+ * which follows the two conditions.
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DAMAGES, HOWEVER CAUSED,
+ * AND UNDER ANY THEORY OF LIABILITY, ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+#include <dirent.h>
+#include <stdarg.h>
+#include "config.h"
+#include "lib.h"
+#include "eval.h"
+#include "parser.h"
+#include "stream.h"
+#include "hash.h"
+#include "gc.h"
+#include "place.h"
+#include "lisplib.h"
+
+static val dl_table;
+
+static void set_place_dlt_entries(val dlt, val fun)
+{
+ int i;
+ val dl_sym[] = {
+ lit("*place-clobber-expander*"), lit("*place-update-expander*"),
+ lit("*place-delete-expander*"),
+ lit("get-update-expander"), lit("get-clobber-expander"),
+ lit("get-delete-expander"),
+ lit("rlet"), lit("with-gensyms"),
+ lit("call-update-expander"), lit("call-clobber-expander"),
+ lit("call-delete-expander)"),
+ lit("with-update-expander"), lit("with-clobber-expander"),
+ lit("with-delete-expander"),
+ lit("set"), lit("zap"), lit("flip"), lit("inc"), lit("dec"),
+ lit("push"), lit("pop"), lit("swap"), lit("shift"), lit("rotate"),
+ lit("del"),
+ nil
+ };
+
+ for (i = 0; dl_sym[i]; i++)
+ sethash(dlt, intern(dl_sym[i], user_package), fun);
+}
+
+static val place_instantiate(val dlt)
+{
+ set_place_dlt_entries(dlt, nil);
+ return eval_intrinsic(lisp_parse(static_str(place_code), std_error, nil), nil);
+}
+
+void lisplib_init(void)
+{
+ prot1(&dl_table);
+ dl_table = make_hash(nil, nil, nil);
+ set_place_dlt_entries(dl_table, func_f0(dl_table, place_instantiate));
+}
+
+val lisplib_try_load(val sym)
+{
+ val fun = gethash(dl_table, sym);
+ return if3(fun, (funcall(fun), t), nil);
+}