From 4463445b017cd0099cbb0fa050d199a814505f72 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 30 Aug 2015 08:47:29 -0700 Subject: Introducing structs. * args.c (args_cat_zap): New function. * args.h: (args_cat_zap): Declared. * eval.c (struct_lit_s): New symbol variable. (eval_init): Initialize struct_lit_s. * eval.h (struct_lit_s): Declared. * gc.c (finalize): If a symbol has a struct slot hash attached to it, we must free it when the symbol is reclaimed. * lib.c (make_sym): Initialize symbol's slot_cache pointer to null. (copy): Copy structure objects. (init): Call struct_init to initialize struct module. * lib.h (SLOT_CACHE_SIZE): New preprocessor symbol (slot_cache_line_t, slot_cache_t): New typedefs. (struct sym): New member, slot_cache. * lisplib.c (struct_set_entries, struct_instantiate): New static functions. (liplib_init): Register new functions in dl_table. parser.y (HASH_S): New terminal symbol. (struct): New grammar rule. (n_expr): Derive struct. (yybadtoken): Map HASH_S to #S string. parser.l (grammar): Recognize #S and return HASH_S token. share/txr/stdlib/place.tl (slot): New defplace. share/txr/stdlib/struct.tl: New file. struct.c: New file. struct.h: New file. * Makefile (OBJS): Adding struct.o. --- lisplib.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lisplib.c') diff --git a/lisplib.c b/lisplib.c index 8a98a23e..0e70d7b4 100644 --- a/lisplib.c +++ b/lisplib.c @@ -166,6 +166,29 @@ static val path_test_instantiate(val set_fun) return nil; } +static val struct_set_entries(val dlt, val fun) +{ + val name[] = { + lit("defstruct"), lit("qref"), lit("new"), nil + }; + + set_dlt_entries(dlt, name, fun); + + if (fun) + sethash(dlt, struct_lit_s, fun); + else + remhash(dlt, struct_lit_s); + + return nil; +} + +static val struct_instantiate(val set_fun) +{ + funcall1(set_fun, nil); + load(format(nil, lit("~a/struct.tl"), stdlib_path, nao)); + return nil; +} + val dlt_register(val dlt, val (*instantiate)(val), val (*set_entries)(val, val)) @@ -183,6 +206,7 @@ void lisplib_init(void) dlt_register(dl_table, txr_case_instantiate, txr_case_set_entries); dlt_register(dl_table, with_resources_instantiate, with_resources_set_entries); dlt_register(dl_table, path_test_instantiate, path_test_set_entries); + dlt_register(dl_table, struct_instantiate, struct_set_entries); } val lisplib_try_load(val sym) -- cgit v1.2.3