picrin/record.c

113 lines
2.2 KiB
C
Raw Normal View History

2014-08-25 00:38:09 -04:00
/**
* See Copyright Notice in picrin.h
*/
#include "picrin.h"
#include "picrin/record.h"
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
#include "picrin/dict.h"
2014-08-25 00:38:09 -04:00
struct pic_record *
2014-09-12 06:49:58 -04:00
pic_make_record(pic_state *pic, pic_value rectype)
2014-08-25 00:38:09 -04:00
{
struct pic_record *rec;
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
struct pic_dict *data;
data = pic_make_dict(pic);
2014-08-25 00:38:09 -04:00
rec = (struct pic_record *)pic_obj_alloc(pic, sizeof(struct pic_record), PIC_TT_RECORD);
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
rec->data = data;
2014-08-25 00:38:09 -04:00
pic_record_set(pic, rec, pic_intern_cstr(pic, "@@type"), rectype);
return rec;
}
pic_value
pic_record_type(pic_state *pic, struct pic_record *rec)
{
return pic_record_ref(pic, rec, pic_intern_cstr(pic, "@@type"));
}
pic_value
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
pic_record_ref(pic_state *pic, struct pic_record *rec, pic_sym *slot)
2014-08-25 00:38:09 -04:00
{
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
if (! pic_dict_has(pic, rec->data, slot)) {
pic_errorf(pic, "slot named ~s is not found for record: ~s", pic_obj_value(slot), rec);
2014-08-25 00:38:09 -04:00
}
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
return pic_dict_ref(pic, rec->data, slot);
2014-08-25 00:38:09 -04:00
}
void
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
pic_record_set(pic_state *pic, struct pic_record *rec, pic_sym *slot, pic_value val)
2014-08-25 00:38:09 -04:00
{
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
pic_dict_set(pic, rec->data, slot, val);
2014-08-25 00:38:09 -04:00
}
static pic_value
pic_record_make_record(pic_state *pic)
{
struct pic_record * rec;
pic_value rectype;
pic_get_args(pic, "o", &rectype);
2014-09-12 06:49:58 -04:00
rec = pic_make_record(pic, rectype);
2014-08-25 00:38:09 -04:00
return pic_obj_value(rec);
}
static pic_value
pic_record_record_p(pic_state *pic)
{
pic_value rec;
pic_get_args(pic, "o", &rec);
return pic_bool_value(pic_record_p(rec));
}
static pic_value
pic_record_record_type(pic_state *pic)
{
struct pic_record *rec;
pic_get_args(pic, "r", &rec);
return pic_record_type(pic, rec);
}
static pic_value
pic_record_record_ref(pic_state *pic)
{
struct pic_record *rec;
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
pic_sym *slot;
2014-08-25 00:38:09 -04:00
pic_get_args(pic, "rm", &rec, &slot);
return pic_record_ref(pic, rec, slot);
}
static pic_value
pic_record_record_set(pic_state *pic)
{
struct pic_record *rec;
Squashed 'extlib/benz/' changes from 414f790..057b5f2 057b5f2 Merge pull request #245 from picrin-scheme/heap-symbol c91f6cd [bugfix] build failure in debug mode b1849c4 pic_sym is not a pointer e353b07 s/pic_sym/pic_sym_ptr/g a11fb91 [bugfix] irep->name is missed to mark 1820a25 [bugfix] wrong type specified for cxt->syms b8d2b8e better error messages against invalid use of auxiliary syntax d9ade33 mark only interned symbols and some specisl uninterned symbols da2217b move symbol constants to pic_state 78b035b [bugfix] pic_intern must count up reference of the return value bbdc663 rename internal object ba01821 s/SYMBOL_P/SYMBOLP/g, s/PAIR_P/PAIRP/g 1af32d1 improve error message dd09fbf don't malloc in pic_interned_p 7f51070 turn on GC 7460e81 add gc on/off flag f3742db move symbol-related macros to symbol.h ded6759 remove pic_sym_value ec97d07 remove pic_symbol_value 28bd059 heap symbol seems working (with GC stopped) e0d6fe9 change pic_intern interface 6750693 remove pic_ungensym 4ea7d3c add irep->syms ede7a99 use dictionary for senv->map b3cb50c use dictionaries for temporary import table fc698b5 use dictionary for rec->data 1b814d4 use dictionary for lib->exports 7ae1af4 use dictionaries for pic->globals and pic->macros 74f9979 remove 'struct pic_macro'. define-syntax spec is changed. 86136c5 some procedures are moved to contrib/ da99761 gather all includes of standard headers into picrin.h 7df8d77 add dictionary-map and dictionary-for-each b625ff8 revert 48f0ec90. dicitonary is now symbol-to-object structure f7657d7 [prepare] dictionary is to be changed to have only symbols for its keys git-subtree-dir: extlib/benz git-subtree-split: 057b5f29110ab3f75513573d291ea18acb782357
2015-01-20 03:44:06 -05:00
pic_sym *slot;
2014-08-25 00:38:09 -04:00
pic_value val;
pic_get_args(pic, "rmo", &rec, &slot, &val);
pic_record_set(pic, rec, slot, val);
return pic_none_value();
}
void
pic_init_record(pic_state *pic)
{
2014-08-31 22:37:52 -04:00
pic_defun(pic, "make-record", pic_record_make_record);
pic_defun(pic, "record?", pic_record_record_p);
pic_defun(pic, "record-type", pic_record_record_type);
pic_defun(pic, "record-ref", pic_record_record_ref);
pic_defun(pic, "record-set!", pic_record_record_set);
2014-08-25 00:38:09 -04:00
}