diff --git a/libc3/array.c b/libc3/array.c
index fe0df65..fb06852 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -327,7 +327,7 @@ s_array * array_init_copy (s_array *a, const s_array *src)
s_array * array_init_void (s_array *array)
{
s_array tmp = {0};
- tmp.type = sym_1("Void");
+ tmp.type = &g_sym_Void;
*array = tmp;
return array;
}
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 4a5aef2..852dc99 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -241,9 +241,9 @@ sw buf_inspect_call (s_buf *buf, const s_call *call)
sw r;
sw result = 0;
if (operator_find(&call->ident) &&
- operator_symbol(&call->ident) == sym_1("[]"))
+ operator_symbol(&call->ident) == &g_sym__brackets)
return buf_inspect_call_brackets(buf, call);
- if (call->ident.sym == sym_1("cast"))
+ if (call->ident.sym == &g_sym_cast)
return buf_inspect_cast(buf, call);
if (operator_find(&call->ident) &&
operator_arity(&call->ident) == 1)
@@ -415,7 +415,7 @@ sw buf_inspect_call_op_unary (s_buf *buf, const s_call *call)
s_ident tmp;
assert(buf);
assert(call);
- if (operator_symbol(&call->ident) == sym_1("()"))
+ if (operator_symbol(&call->ident) == &g_sym__paren)
return buf_inspect_call_paren(buf, call);
if (operator_ident(&call->ident, &tmp) != &tmp)
return -1;
@@ -1919,7 +1919,7 @@ sw buf_inspect_struct_type (s_buf *buf, const s_struct_type *st)
return r;
result += r;
offset_array_dimension = st->map.count;
- array_init(&offset_array, sym_1("Uw"), 1, &offset_array_dimension);
+ array_init(&offset_array, &g_sym_Uw, 1, &offset_array_dimension);
offset_array.data = st->offset;
if ((r = buf_inspect_array(buf, &offset_array)) < 0) {
array_clean(&offset_array);
@@ -1959,7 +1959,7 @@ sw buf_inspect_struct_type_size (const s_struct_type *st)
result += r;
result += strlen(", offset: ");
offset_array_dimension = st->map.count;
- array_init(&offset_array, sym_1("Uw"), 1, &offset_array_dimension);
+ array_init(&offset_array, &g_sym_Uw, 1, &offset_array_dimension);
offset_array.data = st->offset;
if ((r = buf_inspect_array_size(&offset_array)) < 0) {
array_clean(&offset_array);
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 5eb0907..d89fcd1 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -474,9 +474,9 @@ sw buf_parse_brackets (s_buf *buf, s_call *dest)
goto restore;
}
arg_addr->type = TAG_ARRAY;
- if (! list_to_array(addr, sym_1("Uw"), &arg_addr->data.array))
+ if (! list_to_array(addr, &g_sym_Uw, &arg_addr->data.array))
goto restore;
- ident_init(&tmp.ident, NULL, sym_1("[]"));
+ ident_init(&tmp.ident, NULL, &g_sym__brackets);
if (! operator_resolve(&tmp.ident, 2, &tmp.ident)) {
err_puts("buf_parse_brackets: could not resolve operator []");
goto restore;
@@ -854,7 +854,7 @@ sw buf_parse_cast (s_buf *buf, s_call *dest)
goto restore;
result += r;
call_init_op_unary(&tmp);
- ident_init(&tmp.ident, module, sym_1("cast"));
+ ident_init(&tmp.ident, module, &g_sym_cast);
if ((r = buf_parse_tag(buf, &tmp.arguments->tag)) <= 0)
goto clean;
result += r;
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 75b4468..2f51cb4 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -75,8 +75,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
a = args;
while (cfn_arg_types) {
assert(cfn_arg_types->tag.type == TAG_SYM);
- if (cfn_arg_types->tag.data.sym == sym_1("Result") ||
- cfn_arg_types->tag.data.sym == sym_1("&result")) {
+ if (cfn_arg_types->tag.data.sym == &g_sym_Result) {
cfn_tag_init(&tmp2, cfn->result_type);
if (cfn->cif.rtype == &ffi_type_pointer) {
if (! tag_to_ffi_pointer(&tmp2, cfn->result_type, arg_pointers + i))
@@ -257,7 +256,7 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
free(arg_ffi_type);
return NULL;
}
- if (a->tag.data.sym == sym_1("Result")) {
+ if (a->tag.data.sym == &g_sym_Result) {
cfn->arg_result = true;
arg_ffi_type[i] = &ffi_type_pointer;
result_ffi_type = &ffi_type_pointer;
diff --git a/libc3/data.c b/libc3/data.c
index 66b3f51..b715187 100644
--- a/libc3/data.c
+++ b/libc3/data.c
@@ -15,69 +15,69 @@
sw data_buf_inspect (const s_sym *type, s_buf *buf, const void *data)
{
const s_struct_type *st;
- if (type == sym_1("Array"))
+ if (type == &g_sym_Array)
return buf_inspect_array(buf, data);
- if (type == sym_1("Bool"))
+ if (type == &g_sym_Bool)
return buf_inspect_bool(buf, data);
- if (type == sym_1("Call"))
+ if (type == &g_sym_Call)
return buf_inspect_call(buf, data);
- if (type == sym_1("Cfn"))
+ if (type == &g_sym_Cfn)
return buf_inspect_cfn(buf, data);
- if (type == sym_1("Character"))
+ if (type == &g_sym_Character)
return buf_inspect_character(buf, data);
- if (type == sym_1("F32"))
+ if (type == &g_sym_F32)
return buf_inspect_f32(buf, data);
- if (type == sym_1("F64"))
+ if (type == &g_sym_F64)
return buf_inspect_f64(buf, data);
- if (type == sym_1("Fact"))
+ if (type == &g_sym_Fact)
return buf_inspect_fact(buf, data);
- if (type == sym_1("Fn"))
+ if (type == &g_sym_Fn)
return buf_inspect_fn(buf, data);
- if (type == sym_1("Ident"))
+ if (type == &g_sym_Ident)
return buf_inspect_ident(buf, data);
- if (type == sym_1("Integer"))
+ if (type == &g_sym_Integer)
return buf_inspect_integer(buf, data);
- if (type == sym_1("List"))
+ if (type == &g_sym_List)
return buf_inspect_list(buf, data);
- if (type == sym_1("Ptag"))
+ if (type == &g_sym_Ptag)
return buf_inspect_ptag(buf, data);
- if (type == sym_1("Ptr"))
+ if (type == &g_sym_Ptr)
return buf_inspect_ptr(buf, data);
- if (type == sym_1("PtrFree"))
+ if (type == &g_sym_PtrFree)
return buf_inspect_ptr_free(buf, data);
- if (type == sym_1("Quote"))
+ if (type == &g_sym_Quote)
return buf_inspect_quote(buf, data);
- if (type == sym_1("S8"))
+ if (type == &g_sym_S8)
return buf_inspect_s8(buf, data);
- if (type == sym_1("S16"))
+ if (type == &g_sym_S16)
return buf_inspect_s16(buf, data);
- if (type == sym_1("S32"))
+ if (type == &g_sym_S32)
return buf_inspect_s32(buf, data);
- if (type == sym_1("S64"))
+ if (type == &g_sym_S64)
return buf_inspect_s64(buf, data);
- if (type == sym_1("Str"))
+ if (type == &g_sym_Str)
return buf_inspect_str(buf, data);
- if (type == sym_1("Struct"))
+ if (type == &g_sym_Struct)
return buf_inspect_struct(buf, data);
- if (type == sym_1("Sw"))
+ if (type == &g_sym_Sw)
return buf_inspect_sw(buf, data);
- if (type == sym_1("Sym"))
+ if (type == &g_sym_Sym)
return buf_inspect_sym(buf, data);
- if (type == sym_1("Tuple"))
+ if (type == &g_sym_Tuple)
return buf_inspect_tuple(buf, data);
- if (type == sym_1("U8"))
+ if (type == &g_sym_U8)
return buf_inspect_u8(buf, data);
- if (type == sym_1("U16"))
+ if (type == &g_sym_U16)
return buf_inspect_u16(buf, data);
- if (type == sym_1("U32"))
+ if (type == &g_sym_U32)
return buf_inspect_u32(buf, data);
- if (type == sym_1("U64"))
+ if (type == &g_sym_U64)
return buf_inspect_u64(buf, data);
- if (type == sym_1("Uw"))
+ if (type == &g_sym_Uw)
return buf_inspect_uw(buf, data);
- if (type == sym_1("Var"))
+ if (type == &g_sym_Var)
return buf_inspect_var(buf, data);
- if (type == sym_1("Void"))
+ if (type == &g_sym_Void)
return buf_inspect_void(buf, data);
/*
if (sym_is_array_type(type)) {
@@ -99,69 +99,69 @@ sw data_buf_inspect (const s_sym *type, s_buf *buf, const void *data)
sw data_buf_inspect_size (const s_sym *type, const void *data)
{
const s_struct_type *st;
- if (type == sym_1("Array"))
+ if (type == &g_sym_Array)
return buf_inspect_array_size(data);
- if (type == sym_1("Bool"))
+ if (type == &g_sym_Bool)
return buf_inspect_bool_size(data);
- if (type == sym_1("Call"))
+ if (type == &g_sym_Call)
return buf_inspect_call_size(data);
- if (type == sym_1("Cfn"))
+ if (type == &g_sym_Cfn)
return buf_inspect_cfn_size(data);
- if (type == sym_1("Character"))
+ if (type == &g_sym_Character)
return buf_inspect_character_size(data);
- if (type == sym_1("F32"))
+ if (type == &g_sym_F32)
return buf_inspect_f32_size(data);
- if (type == sym_1("F64"))
+ if (type == &g_sym_F64)
return buf_inspect_f64_size(data);
- if (type == sym_1("Fact"))
+ if (type == &g_sym_Fact)
return buf_inspect_fact_size(data);
- if (type == sym_1("Fn"))
+ if (type == &g_sym_Fn)
return buf_inspect_fn_size(data);
- if (type == sym_1("Ident"))
+ if (type == &g_sym_Ident)
return buf_inspect_ident_size(data);
- if (type == sym_1("Integer"))
+ if (type == &g_sym_Integer)
return buf_inspect_integer_size(data);
- if (type == sym_1("List"))
+ if (type == &g_sym_List)
return buf_inspect_list_size(data);
- if (type == sym_1("Ptag"))
+ if (type == &g_sym_Ptag)
return buf_inspect_ptag_size(data);
- if (type == sym_1("Ptr"))
+ if (type == &g_sym_Ptr)
return buf_inspect_ptr_size(data);
- if (type == sym_1("PtrFree"))
+ if (type == &g_sym_PtrFree)
return buf_inspect_ptr_free_size(data);
- if (type == sym_1("Quote"))
+ if (type == &g_sym_Quote)
return buf_inspect_quote_size(data);
- if (type == sym_1("S8"))
+ if (type == &g_sym_S8)
return buf_inspect_s8_size(data);
- if (type == sym_1("S16"))
+ if (type == &g_sym_S16)
return buf_inspect_s16_size(data);
- if (type == sym_1("S32"))
+ if (type == &g_sym_S32)
return buf_inspect_s32_size(data);
- if (type == sym_1("S64"))
+ if (type == &g_sym_S64)
return buf_inspect_s64_size(data);
- if (type == sym_1("Str"))
+ if (type == &g_sym_Str)
return buf_inspect_str_size(data);
- if (type == sym_1("Struct"))
+ if (type == &g_sym_Struct)
return buf_inspect_struct_size(data);
- if (type == sym_1("Sw"))
+ if (type == &g_sym_Sw)
return buf_inspect_sw_size(data);
- if (type == sym_1("Sym"))
+ if (type == &g_sym_Sym)
return buf_inspect_sym_size(data);
- if (type == sym_1("Tuple"))
+ if (type == &g_sym_Tuple)
return buf_inspect_tuple_size(data);
- if (type == sym_1("U8"))
+ if (type == &g_sym_U8)
return buf_inspect_u8_size(data);
- if (type == sym_1("U16"))
+ if (type == &g_sym_U16)
return buf_inspect_u16_size(data);
- if (type == sym_1("U32"))
+ if (type == &g_sym_U32)
return buf_inspect_u32_size(data);
- if (type == sym_1("U64"))
+ if (type == &g_sym_U64)
return buf_inspect_u64_size(data);
- if (type == sym_1("Uw"))
+ if (type == &g_sym_Uw)
return buf_inspect_uw_size(data);
- if (type == sym_1("Var"))
+ if (type == &g_sym_Var)
return buf_inspect_var_size(data);
- if (type == sym_1("Void"))
+ if (type == &g_sym_Void)
return buf_inspect_void_size(data);
/*
if (sym_is_array_type(type)) {
@@ -184,115 +184,115 @@ bool data_clean (const s_sym *type, void *data)
{
const s_struct_type *st;
assert(type);
- if (type == sym_1("Array")) {
+ if (type == &g_sym_Array) {
array_clean(data);
return true;
}
- if (type == sym_1("Bool")) {
+ if (type == &g_sym_Bool) {
return true;
}
- if (type == sym_1("Call")) {
+ if (type == &g_sym_Call) {
call_clean(data);
return true;
}
- if (type == sym_1("Cfn")) {
+ if (type == &g_sym_Cfn) {
cfn_clean(data);
return true;
}
- if (type == sym_1("Character")) {
+ if (type == &g_sym_Character) {
return true;
}
- if (type == sym_1("F32")) {
+ if (type == &g_sym_F32) {
return true;
}
- if (type == sym_1("F64")) {
+ if (type == &g_sym_F64) {
return true;
}
- if (type == sym_1("Fact")) {
+ if (type == &g_sym_Fact) {
return true;
}
- if (type == sym_1("Fn")) {
+ if (type == &g_sym_Fn) {
fn_clean(data);
return true;
}
- if (type == sym_1("Ident")) {
+ if (type == &g_sym_Ident) {
return true;
}
- if (type == sym_1("Integer")) {
+ if (type == &g_sym_Integer) {
integer_clean(data);
return true;
}
- if (type == sym_1("List")) {
+ if (type == &g_sym_List) {
list_f_clean(data);
return true;
}
- if (type == sym_1("Map")) {
+ if (type == &g_sym_Map) {
map_clean(data);
return true;
}
- if (type == sym_1("Ptag")) {
+ if (type == &g_sym_Ptag) {
return true;
}
- if (type == sym_1("Ptr")) {
+ if (type == &g_sym_Ptr) {
return true;
}
- if (type == sym_1("PtrFree")) {
+ if (type == &g_sym_PtrFree) {
ptr_free_clean(data);
return true;
}
- if (type == sym_1("Quote")) {
+ if (type == &g_sym_Quote) {
quote_clean(data);
return true;
}
- if (type == sym_1("S8")) {
+ if (type == &g_sym_S8) {
return true;
}
- if (type == sym_1("S16")) {
+ if (type == &g_sym_S16) {
return true;
}
- if (type == sym_1("S32")) {
+ if (type == &g_sym_S32) {
return true;
}
- if (type == sym_1("S64")) {
+ if (type == &g_sym_S64) {
return true;
}
- if (type == sym_1("Str")) {
+ if (type == &g_sym_Str) {
str_clean(data);
return true;
}
- if (type == sym_1("Struct")) {
+ if (type == &g_sym_Struct) {
struct_clean(data);
return true;
}
- if (type == sym_1("Sw")) {
+ if (type == &g_sym_Sw) {
return true;
}
- if (type == sym_1("Sym")) {
+ if (type == &g_sym_Sym) {
return true;
}
- if (type == sym_1("Tuple")) {
+ if (type == &g_sym_Tuple) {
tuple_clean(data);
return true;
}
- if (type == sym_1("U8")) {
+ if (type == &g_sym_U8) {
return true;
}
- if (type == sym_1("U16")) {
+ if (type == &g_sym_U16) {
return true;
}
- if (type == sym_1("U32")) {
+ if (type == &g_sym_U32) {
return true;
}
- if (type == sym_1("U64")) {
+ if (type == &g_sym_U64) {
return true;
}
- if (type == sym_1("Uw")) {
+ if (type == &g_sym_Uw) {
return true;
}
- if (type == sym_1("Var")) {
+ if (type == &g_sym_Var) {
return true;
}
- if (type == sym_1("Void")) {
+ if (type == &g_sym_Void) {
return true;
}
/*
@@ -316,69 +316,69 @@ bool data_clean (const s_sym *type, void *data)
bool data_compare (const s_sym *type, const void *a, const void *b)
{
const s_struct_type *st;
- if (type == sym_1("Array"))
+ if (type == &g_sym_Array)
return compare_array(a, b);
- if (type == sym_1("Bool"))
+ if (type == &g_sym_Bool)
return compare_bool(*(bool *) a, *(bool *) b);
- if (type == sym_1("Call"))
+ if (type == &g_sym_Call)
return compare_call(a, b);
- if (type == sym_1("Cfn"))
+ if (type == &g_sym_Cfn)
return compare_cfn(a, b);
- if (type == sym_1("Character"))
+ if (type == &g_sym_Character)
return compare_character(*(character *) a, *(character *) b);
- if (type == sym_1("F32"))
+ if (type == &g_sym_F32)
return compare_f32(*(f64 *) a, *(f64 *) b);
- if (type == sym_1("F64"))
+ if (type == &g_sym_F64)
return compare_f64(*(f64 *) a, *(f64 *) b);
- if (type == sym_1("Fact"))
+ if (type == &g_sym_Fact)
return compare_fact(a, b);
- if (type == sym_1("Fn"))
+ if (type == &g_sym_Fn)
return compare_fn(a, b);
- if (type == sym_1("Ident"))
+ if (type == &g_sym_Ident)
return compare_ident(a, b);
- if (type == sym_1("Integer"))
+ if (type == &g_sym_Integer)
return compare_integer(a, b);
- if (type == sym_1("List"))
+ if (type == &g_sym_List)
return compare_list(a, b);
- if (type == sym_1("Ptag"))
+ if (type == &g_sym_Ptag)
return compare_ptag(a, b);
- if (type == sym_1("Ptr"))
+ if (type == &g_sym_Ptr)
return compare_ptr(a, b);
- if (type == sym_1("PtrFree"))
+ if (type == &g_sym_PtrFree)
return compare_ptr(a, b);
- if (type == sym_1("Quote"))
+ if (type == &g_sym_Quote)
return compare_quote(a, b);
- if (type == sym_1("S8"))
+ if (type == &g_sym_S8)
return compare_s8(*(s8 *) a, *(s8 *) b);
- if (type == sym_1("S16"))
+ if (type == &g_sym_S16)
return compare_s16(*(s16 *) a, *(s16 *) b);
- if (type == sym_1("S32"))
+ if (type == &g_sym_S32)
return compare_s32(*(s32 *) a, *(s32 *) b);
- if (type == sym_1("S64"))
+ if (type == &g_sym_S64)
return compare_s64(*(s64 *) a, *(s64 *) b);
- if (type == sym_1("Str"))
+ if (type == &g_sym_Str)
return compare_str(a, b);
- if (type == sym_1("Struct"))
+ if (type == &g_sym_Struct)
return compare_struct(a, b);
- if (type == sym_1("Sw"))
+ if (type == &g_sym_Sw)
return compare_sw(*(sw *) a, *(sw *) b);
- if (type == sym_1("Sym"))
+ if (type == &g_sym_Sym)
return compare_sym(a, b);
- if (type == sym_1("Tuple"))
+ if (type == &g_sym_Tuple)
return compare_tuple(a, b);
- if (type == sym_1("U8"))
+ if (type == &g_sym_U8)
return compare_u8(*(u8 *) a, *(u8 *) b);
- if (type == sym_1("U16"))
+ if (type == &g_sym_U16)
return compare_u16(*(u16 *) a, *(u16 *) b);
- if (type == sym_1("U32"))
+ if (type == &g_sym_U32)
return compare_u32(*(u32 *) a, *(u32 *) b);
- if (type == sym_1("U64"))
+ if (type == &g_sym_U64)
return compare_u64(*(u64 *) a, *(u64 *) b);
- if (type == sym_1("Uw"))
+ if (type == &g_sym_Uw)
return compare_uw(*(uw *) a, *(uw *) b);
- if (type == sym_1("Var"))
+ if (type == &g_sym_Var)
return compare_ptr(a, b);
- if (type == sym_1("Void"))
+ if (type == &g_sym_Void)
return 0;
/*
if (sym_is_array_type(type)) {
@@ -403,69 +403,69 @@ bool data_compare (const s_sym *type, const void *a, const void *b)
bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
{
const s_struct_type *st;
- if (type == sym_1("Array"))
+ if (type == &g_sym_Array)
return hash_update_array(hash, data);
- if (type == sym_1("Bool"))
+ if (type == &g_sym_Bool)
return hash_update_bool(hash, data);
- if (type == sym_1("Call"))
+ if (type == &g_sym_Call)
return hash_update_call(hash, data);
- if (type == sym_1("Cfn"))
+ if (type == &g_sym_Cfn)
return hash_update_cfn(hash, data);
- if (type == sym_1("Character"))
+ if (type == &g_sym_Character)
return hash_update_character(hash, data);
- if (type == sym_1("F32"))
+ if (type == &g_sym_F32)
return hash_update_f32(hash, data);
- if (type == sym_1("F64"))
+ if (type == &g_sym_F64)
return hash_update_f64(hash, data);
- if (type == sym_1("Fact"))
+ if (type == &g_sym_Fact)
return hash_update_fact(hash, data);
- if (type == sym_1("Fn"))
+ if (type == &g_sym_Fn)
return hash_update_fn(hash, data);
- if (type == sym_1("Ident"))
+ if (type == &g_sym_Ident)
return hash_update_ident(hash, data);
- if (type == sym_1("Integer"))
+ if (type == &g_sym_Integer)
return hash_update_integer(hash, data);
- if (type == sym_1("List"))
+ if (type == &g_sym_List)
return hash_update_list(hash, data);
- if (type == sym_1("Ptag"))
+ if (type == &g_sym_Ptag)
return hash_update_ptag(hash, data);
- if (type == sym_1("Ptr"))
+ if (type == &g_sym_Ptr)
return hash_update_ptr(hash, data);
- if (type == sym_1("PtrFree"))
+ if (type == &g_sym_PtrFree)
return hash_update_ptr_free(hash, data);
- if (type == sym_1("Quote"))
+ if (type == &g_sym_Quote)
return hash_update_quote(hash, data);
- if (type == sym_1("S8"))
+ if (type == &g_sym_S8)
return hash_update_s8(hash, data);
- if (type == sym_1("S16"))
+ if (type == &g_sym_S16)
return hash_update_s16(hash, data);
- if (type == sym_1("S32"))
+ if (type == &g_sym_S32)
return hash_update_s32(hash, data);
- if (type == sym_1("S64"))
+ if (type == &g_sym_S64)
return hash_update_s64(hash, data);
- if (type == sym_1("Str"))
+ if (type == &g_sym_Str)
return hash_update_str(hash, data);
- if (type == sym_1("Struct"))
+ if (type == &g_sym_Struct)
return hash_update_struct(hash, data);
- if (type == sym_1("Sw"))
+ if (type == &g_sym_Sw)
return hash_update_sw(hash, data);
- if (type == sym_1("Sym"))
+ if (type == &g_sym_Sym)
return hash_update_sym(hash, data);
- if (type == sym_1("Tuple"))
+ if (type == &g_sym_Tuple)
return hash_update_tuple(hash, data);
- if (type == sym_1("U8"))
+ if (type == &g_sym_U8)
return hash_update_u8(hash, data);
- if (type == sym_1("U16"))
+ if (type == &g_sym_U16)
return hash_update_u16(hash, data);
- if (type == sym_1("U32"))
+ if (type == &g_sym_U32)
return hash_update_u32(hash, data);
- if (type == sym_1("U64"))
+ if (type == &g_sym_U64)
return hash_update_u64(hash, data);
- if (type == sym_1("Uw"))
+ if (type == &g_sym_Uw)
return hash_update_uw(hash, data);
- if (type == sym_1("Var"))
+ if (type == &g_sym_Var)
return hash_update_var(hash, data);
- if (type == sym_1("Void"))
+ if (type == &g_sym_Void)
return hash_update_void(hash, data);
/*
if (sym_is_array_type(type)) {
@@ -487,69 +487,69 @@ bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
void * data_init_cast (const s_sym *type, void *data, const s_tag *tag)
{
const s_struct_type *st;
- if (type == sym_1("Array"))
+ if (type == &g_sym_Array)
return array_init_cast(data, tag);
- if (type == sym_1("Bool"))
+ if (type == &g_sym_Bool)
return bool_init_cast(data, tag);
- if (type == sym_1("Call"))
+ if (type == &g_sym_Call)
return call_init_cast(data, tag);
- if (type == sym_1("Cfn"))
+ if (type == &g_sym_Cfn)
return cfn_init_cast(data, tag);
- if (type == sym_1("Character"))
+ if (type == &g_sym_Character)
return character_init_cast(data, tag);
- if (type == sym_1("F32"))
+ if (type == &g_sym_F32)
return f32_init_cast(data, tag);
- if (type == sym_1("F64"))
+ if (type == &g_sym_F64)
return f64_init_cast(data, tag);
- if (type == sym_1("Fact"))
+ if (type == &g_sym_Fact)
return fact_init_cast(data, tag);
- if (type == sym_1("Fn"))
+ if (type == &g_sym_Fn)
return fn_init_cast(data, tag);
- if (type == sym_1("Ident"))
+ if (type == &g_sym_Ident)
return ident_init_cast(data, tag);
- if (type == sym_1("Integer"))
+ if (type == &g_sym_Integer)
return integer_init_cast(data, tag);
- if (type == sym_1("List"))
+ if (type == &g_sym_List)
return list_init_cast(data, tag);
- if (type == sym_1("Ptag"))
+ if (type == &g_sym_Ptag)
return ptag_init_cast(data, tag);
- if (type == sym_1("Ptr"))
+ if (type == &g_sym_Ptr)
return ptr_init_cast(data, tag);
- if (type == sym_1("PtrFree"))
+ if (type == &g_sym_PtrFree)
return ptr_free_init_cast(data, tag);
- if (type == sym_1("Quote"))
+ if (type == &g_sym_Quote)
return quote_init_cast(data, tag);
- if (type == sym_1("S8"))
+ if (type == &g_sym_S8)
return s8_init_cast(data, tag);
- if (type == sym_1("S16"))
+ if (type == &g_sym_S16)
return s16_init_cast(data, tag);
- if (type == sym_1("S32"))
+ if (type == &g_sym_S32)
return s32_init_cast(data, tag);
- if (type == sym_1("S64"))
+ if (type == &g_sym_S64)
return s64_init_cast(data, tag);
- if (type == sym_1("Str"))
+ if (type == &g_sym_Str)
return str_init_cast(data, tag);
- if (type == sym_1("Struct"))
+ if (type == &g_sym_Struct)
return struct_init_cast(data, tag);
- if (type == sym_1("Sw"))
+ if (type == &g_sym_Sw)
return sw_init_cast(data, tag);
- if (type == sym_1("Sym"))
+ if (type == &g_sym_Sym)
return sym_init_cast(data, tag);
- if (type == sym_1("Tuple"))
+ if (type == &g_sym_Tuple)
return tuple_init_cast(data, tag);
- if (type == sym_1("U8"))
+ if (type == &g_sym_U8)
return u8_init_cast(data, tag);
- if (type == sym_1("U16"))
+ if (type == &g_sym_U16)
return u16_init_cast(data, tag);
- if (type == sym_1("U32"))
+ if (type == &g_sym_U32)
return u32_init_cast(data, tag);
- if (type == sym_1("U64"))
+ if (type == &g_sym_U64)
return u64_init_cast(data, tag);
- if (type == sym_1("Uw"))
+ if (type == &g_sym_Uw)
return uw_init_cast(data, tag);
- if (type == sym_1("Var"))
+ if (type == &g_sym_Var)
return data;
- if (type == sym_1("Void"))
+ if (type == &g_sym_Void)
return data;
/*
if (sym_is_array_type(type)) {
@@ -571,69 +571,69 @@ void * data_init_cast (const s_sym *type, void *data, const s_tag *tag)
void * data_init_copy (const s_sym *type, void *data, const void *src)
{
const s_struct_type *st;
- if (type == sym_1("Array"))
+ if (type == &g_sym_Array)
return array_init_copy(data, src);
- if (type == sym_1("Bool"))
+ if (type == &g_sym_Bool)
return bool_init_copy(data, src);
- if (type == sym_1("Call"))
+ if (type == &g_sym_Call)
return call_init_copy(data, src);
- if (type == sym_1("Cfn"))
+ if (type == &g_sym_Cfn)
return cfn_init_copy(data, src);
- if (type == sym_1("Character"))
+ if (type == &g_sym_Character)
return character_init_copy(data, src);
- if (type == sym_1("F32"))
+ if (type == &g_sym_F32)
return f32_init_copy(data, src);
- if (type == sym_1("F64"))
+ if (type == &g_sym_F64)
return f64_init_copy(data, src);
- if (type == sym_1("Fact"))
+ if (type == &g_sym_Fact)
return fact_init_copy(data, src);
- if (type == sym_1("Fn"))
+ if (type == &g_sym_Fn)
return fn_init_copy(data, src);
- if (type == sym_1("Ident"))
+ if (type == &g_sym_Ident)
return ident_init_copy(data, src);
- if (type == sym_1("Integer"))
+ if (type == &g_sym_Integer)
return integer_init_copy(data, src);
- if (type == sym_1("List"))
+ if (type == &g_sym_List)
return list_init_copy(data, src);
- if (type == sym_1("Ptag"))
+ if (type == &g_sym_Ptag)
return ptag_init_copy(data, src);
- if (type == sym_1("Ptr"))
+ if (type == &g_sym_Ptr)
return ptr_init_copy(data, src);
- if (type == sym_1("PtrFree"))
+ if (type == &g_sym_PtrFree)
return ptr_free_init_copy(data, src);
- if (type == sym_1("Quote"))
+ if (type == &g_sym_Quote)
return quote_init_copy(data, src);
- if (type == sym_1("S8"))
+ if (type == &g_sym_S8)
return s8_init_copy(data, src);
- if (type == sym_1("S16"))
+ if (type == &g_sym_S16)
return s16_init_copy(data, src);
- if (type == sym_1("S32"))
+ if (type == &g_sym_S32)
return s32_init_copy(data, src);
- if (type == sym_1("S64"))
+ if (type == &g_sym_S64)
return s64_init_copy(data, src);
- if (type == sym_1("Str"))
+ if (type == &g_sym_Str)
return str_init_copy(data, src);
- if (type == sym_1("Struct"))
+ if (type == &g_sym_Struct)
return struct_init_copy(data, src);
- if (type == sym_1("Sw"))
+ if (type == &g_sym_Sw)
return sw_init_copy(data, src);
- if (type == sym_1("Sym"))
+ if (type == &g_sym_Sym)
return sym_init_copy(data, src);
- if (type == sym_1("Tuple"))
+ if (type == &g_sym_Tuple)
return tuple_init_copy(data, src);
- if (type == sym_1("U8"))
+ if (type == &g_sym_U8)
return u8_init_copy(data, src);
- if (type == sym_1("U16"))
+ if (type == &g_sym_U16)
return u16_init_copy(data, src);
- if (type == sym_1("U32"))
+ if (type == &g_sym_U32)
return u32_init_copy(data, src);
- if (type == sym_1("U64"))
+ if (type == &g_sym_U64)
return u64_init_copy(data, src);
- if (type == sym_1("Uw"))
+ if (type == &g_sym_Uw)
return uw_init_copy(data, src);
- if (type == sym_1("Var"))
+ if (type == &g_sym_Var)
return data;
- if (type == sym_1("Void"))
+ if (type == &g_sym_Void)
return data;
st = struct_type_find(type);
if (st) {
diff --git a/libc3/env.c b/libc3/env.c
index e00d950..ebb3b73 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -855,6 +855,7 @@ s_env * env_init (s_env *env, int argc, char **argv)
assert(env);
if (! env_init_args(env, argc, argv))
return NULL;
+ sym_init_g_sym();
env->error_handler = NULL;
env->frame = frame_new(NULL);
buf_init_alloc(&env->in, BUF_SIZE);
@@ -874,13 +875,13 @@ s_env * env_init (s_env *env, int argc, char **argv)
(NULL, "../../../../../", list_new_str_1
(NULL, "../../../../../../", NULL))))))));
str_init_1(&path, NULL, "lib/c3/0.1/");
- if (! file_search(&path, sym_1("x"), &env->module_path)) {
+ if (! file_search(&path, &g_sym_x, &env->module_path)) {
assert(! "env_init: module path not found");
warn("env_init: module_path not found");
return NULL;
}
- env->current_module = sym_1("C3");
- if (! module_load(sym_1("C3"), &env->facts)) {
+ env->current_module = &g_sym_C3;
+ if (! module_load(&g_sym_C3, &env->facts)) {
env_clean(env);
return NULL;
}
diff --git a/libc3/file.c b/libc3/file.c
index 4d37d85..e0217b6 100644
--- a/libc3/file.c
+++ b/libc3/file.c
@@ -35,19 +35,19 @@ bool * file_access (const s_str *path, const s_sym *mode,
bool *dest)
{
sw m;
- if (mode == sym_1("r"))
+ if (mode == &g_sym_r)
m = R_OK;
- else if (mode == sym_1("rw"))
+ else if (mode == &g_sym_rw)
m = R_OK | W_OK;
- else if (mode == sym_1("rwx"))
+ else if (mode == &g_sym_rwx)
m = R_OK | W_OK | X_OK;
- else if (mode == sym_1("rx"))
+ else if (mode == &g_sym_rx)
m = R_OK | X_OK;
- else if (mode == sym_1("w"))
+ else if (mode == &g_sym_w)
m = W_OK;
- else if (mode == sym_1("wx"))
+ else if (mode == &g_sym_wx)
m = W_OK | X_OK;
- else if (mode == sym_1("x"))
+ else if (mode == &g_sym_x)
m = X_OK;
else
m = F_OK;
diff --git a/libc3/sym.c b/libc3/sym.c
index 29e8d59..0e2acde 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -14,12 +14,62 @@
#include <string.h>
#include "c3.h"
+const s_sym g_sym__brackets = {{{NULL}, 2, {"[]"}}};
+const s_sym g_sym__paren = {{{NULL}, 2, {"()"}}};
+const s_sym g_sym_Array = {{{NULL}, 5, {"Array"}}};
+const s_sym g_sym_Bool = {{{NULL}, 4, {"Bool"}}};
+const s_sym g_sym_C3 = {{{NULL}, 2, {"C3"}}};
+const s_sym g_sym_Call = {{{NULL}, 4, {"Call"}}};
+const s_sym g_sym_Cfn = {{{NULL}, 3, {"Cfn"}}};
+const s_sym g_sym_Character = {{{NULL}, 9, {"Character"}}};
+const s_sym g_sym_Char__star = {{{NULL}, 5, {"Char*"}}};
+const s_sym g_sym_F32 = {{{NULL}, 3, {"F32"}}};
+const s_sym g_sym_F64 = {{{NULL}, 3, {"F64"}}};
+const s_sym g_sym_Fact = {{{NULL}, 4, {"Fact"}}};
+const s_sym g_sym_Fn = {{{NULL}, 2, {"Fn"}}};
+const s_sym g_sym_Ident = {{{NULL}, 5, {"Ident"}}};
+const s_sym g_sym_Integer = {{{NULL}, 7, {"Integer"}}};
+const s_sym g_sym_List = {{{NULL}, 4, {"List"}}};
+const s_sym g_sym_Map = {{{NULL}, 3, {"Map"}}};
+const s_sym g_sym_Ptag = {{{NULL}, 4, {"Ptag"}}};
+const s_sym g_sym_Ptr = {{{NULL}, 3, {"Ptr"}}};
+const s_sym g_sym_PtrFree = {{{NULL}, 7, {"PtrFree"}}};
+const s_sym g_sym_Quote = {{{NULL}, 5, {"Quote"}}};
+const s_sym g_sym_Result = {{{NULL}, 6, {"Result"}}};
+const s_sym g_sym_S8 = {{{NULL}, 2, {"S8"}}};
+const s_sym g_sym_S16 = {{{NULL}, 3, {"S16"}}};
+const s_sym g_sym_S32 = {{{NULL}, 3, {"S32"}}};
+const s_sym g_sym_S64 = {{{NULL}, 3, {"S64"}}};
+const s_sym g_sym_Str = {{{NULL}, 3, {"Str"}}};
+const s_sym g_sym_Struct = {{{NULL}, 6, {"Struct"}}};
+const s_sym g_sym_StructType = {{{NULL}, 10, {"StructType"}}};
+const s_sym g_sym_Sw = {{{NULL}, 2, {"Sw"}}};
+const s_sym g_sym_Sym = {{{NULL}, 3, {"Sym"}}};
+const s_sym g_sym_Tag = {{{NULL}, 3, {"Tag"}}};
+const s_sym g_sym_Tuple = {{{NULL}, 5, {"Tuple"}}};
+const s_sym g_sym_U8 = {{{NULL}, 2, {"U8"}}};
+const s_sym g_sym_U16 = {{{NULL}, 3, {"U16"}}};
+const s_sym g_sym_U32 = {{{NULL}, 3, {"U32"}}};
+const s_sym g_sym_U64 = {{{NULL}, 3, {"U64"}}};
+const s_sym g_sym_Uw = {{{NULL}, 2, {"Uw"}}};
+const s_sym g_sym_Var = {{{NULL}, 3, {"Var"}}};
+const s_sym g_sym_Void = {{{NULL}, 4, {"Void"}}};
+const s_sym g_sym_cast = {{{NULL}, 4, {"cast"}}};
+const s_sym g_sym_r = {{{NULL}, 1, {"r"}}};
+const s_sym g_sym_rw = {{{NULL}, 2, {"rw"}}};
+const s_sym g_sym_rwx = {{{NULL}, 3, {"rwx"}}};
+const s_sym g_sym_rx = {{{NULL}, 2, {"rx"}}};
+const s_sym g_sym_w = {{{NULL}, 1, {"w"}}};
+const s_sym g_sym_wx = {{{NULL}, 2, {"wx"}}};
+const s_sym g_sym_x = {{{NULL}, 1, {"x"}}};
+
+static s_sym_list * g_sym_list = NULL;
+
void sym_delete (s_sym *sym);
s_str * sym_inspect_reserved (const s_sym *sym, s_str *dest);
sw sym_inspect_reserved_size (const s_sym *sym);
-s_sym_list * sym_list_new (s_sym *sym, s_sym_list *next);
-
-static s_sym_list * g_sym_list = NULL;
+s_sym_list * sym_list_new (const s_sym *sym, s_sym *free_sym,
+ s_sym_list *next);
const s_sym * sym_1 (const char *p)
{
@@ -54,14 +104,15 @@ void sym_delete_all (void)
{
s_sym_list *sym_list;
sym_list = g_sym_list;
+ g_sym_list = NULL;
while (sym_list) {
s_sym_list *tmp;
tmp = sym_list;
sym_list = sym_list->next;
- sym_delete(tmp->sym);
+ if (tmp->free_sym)
+ sym_delete(tmp->free_sym);
free(tmp);
}
- g_sym_list = NULL;
}
const s_sym * sym_find (const s_str *str)
@@ -69,7 +120,7 @@ const s_sym * sym_find (const s_str *str)
s_sym_list *sym_list;
sym_list = g_sym_list;
while (sym_list) {
- s_sym *sym = sym_list->sym;
+ const s_sym *sym = sym_list->sym;
if (compare_str(str, &sym->str) == 0)
return sym;
sym_list = sym_list->next;
@@ -136,6 +187,59 @@ const s_sym ** sym_init_copy (const s_sym **sym,
return sym;
}
+void sym_init_g_sym (void)
+{
+ sym_intern(&g_sym__brackets, NULL);
+ sym_intern(&g_sym__paren, NULL);
+ sym_intern(&g_sym_Array, NULL);
+ sym_intern(&g_sym_Bool, NULL);
+ sym_intern(&g_sym_C3, NULL);
+ sym_intern(&g_sym_Call, NULL);
+ sym_intern(&g_sym_Cfn, NULL);
+ sym_intern(&g_sym_Character, NULL);
+ sym_intern(&g_sym_Char__star, NULL);
+ sym_intern(&g_sym_F32, NULL);
+ sym_intern(&g_sym_F64, NULL);
+ sym_intern(&g_sym_Fact, NULL);
+ sym_intern(&g_sym_Fn, NULL);
+ sym_intern(&g_sym_Ident, NULL);
+ sym_intern(&g_sym_Integer, NULL);
+ sym_intern(&g_sym_List, NULL);
+ sym_intern(&g_sym_Map, NULL);
+ sym_intern(&g_sym_Ptag, NULL);
+ sym_intern(&g_sym_Ptr, NULL);
+ sym_intern(&g_sym_PtrFree, NULL);
+ sym_intern(&g_sym_Quote, NULL);
+ sym_intern(&g_sym_Result, NULL);
+ sym_intern(&g_sym_S8, NULL);
+ sym_intern(&g_sym_S16, NULL);
+ sym_intern(&g_sym_S32, NULL);
+ sym_intern(&g_sym_S64, NULL);
+ sym_intern(&g_sym_Str, NULL);
+ sym_intern(&g_sym_Struct, NULL);
+ sym_intern(&g_sym_StructType, NULL);
+ sym_intern(&g_sym_Sw, NULL);
+ sym_intern(&g_sym_Sym, NULL);
+ sym_intern(&g_sym_Tag, NULL);
+ sym_intern(&g_sym_Tuple, NULL);
+ sym_intern(&g_sym_U8, NULL);
+ sym_intern(&g_sym_U16, NULL);
+ sym_intern(&g_sym_U32, NULL);
+ sym_intern(&g_sym_U64, NULL);
+ sym_intern(&g_sym_Uw, NULL);
+ sym_intern(&g_sym_Var, NULL);
+ sym_intern(&g_sym_Void, NULL);
+ sym_intern(&g_sym_cast, NULL);
+ sym_intern(&g_sym_r, NULL);
+ sym_intern(&g_sym_rw, NULL);
+ sym_intern(&g_sym_rwx, NULL);
+ sym_intern(&g_sym_rx, NULL);
+ sym_intern(&g_sym_w, NULL);
+ sym_intern(&g_sym_wx, NULL);
+ sym_intern(&g_sym_x, NULL);
+
+}
+
const s_sym ** sym_init_str (const s_sym **sym, const s_str *src)
{
const s_sym *tmp;
@@ -163,6 +267,19 @@ s_str * sym_inspect (const s_sym *sym, s_str *dest)
return buf_to_str(&tmp, dest);
}
+bool sym_intern (const s_sym *sym, s_sym *free_sym)
+{
+ s_sym_list *tmp;
+ assert(sym);
+ if (sym_find(&sym->str))
+ return false;
+ tmp = sym_list_new(sym, free_sym, g_sym_list);
+ if (! tmp)
+ return false;
+ g_sym_list = tmp;
+ return true;
+}
+
bool sym_is_module (const s_sym *sym)
{
character c;
@@ -171,7 +288,8 @@ bool sym_is_module (const s_sym *sym)
return character_is_uppercase(c);
}
-s_sym_list * sym_list_new (s_sym *sym, s_sym_list *next)
+s_sym_list * sym_list_new (const s_sym *sym, s_sym *free_sym,
+ s_sym_list *next)
{
s_sym_list *sym_list;
sym_list = malloc(sizeof(s_sym_list));
@@ -181,6 +299,7 @@ s_sym_list * sym_list_new (s_sym *sym, s_sym_list *next)
return NULL;
}
sym_list->sym = sym;
+ sym_list->free_sym = free_sym;
sym_list->next = next;
return sym_list;
}
@@ -199,7 +318,7 @@ const s_sym * sym_new (const s_str *src)
free(sym);
return NULL;
}
- tmp = sym_list_new(sym, g_sym_list);
+ tmp = sym_list_new(sym, sym, g_sym_list);
if (! tmp) {
str_clean(&sym->str);
free(sym);
@@ -209,295 +328,11 @@ const s_sym * sym_new (const s_str *src)
return sym;
}
-/*
-bool sym_to_buf_inspect (const s_sym *type, f_buf_inspect *dest)
-{
- if (type == sym_1("Array")) {
- *dest = (f_buf_inspect) buf_inspect_array;
- return true;
- }
- if (type == sym_1("Bool")) {
- *dest = (f_buf_inspect) buf_inspect_bool;
- return true;
- }
- if (type == sym_1("Call")) {
- *dest = (f_buf_inspect) buf_inspect_call;
- return true;
- }
- if (type == sym_1("Cfn")) {
- *dest = (f_buf_inspect) buf_inspect_cfn;
- return true;
- }
- if (type == sym_1("Character")) {
- *dest = (f_buf_inspect) buf_inspect_character;
- return true;
- }
- if (type == sym_1("F32")) {
- *dest = (f_buf_inspect) buf_inspect_f32;
- return true;
- }
- if (type == sym_1("F64")) {
- *dest = (f_buf_inspect) buf_inspect_f64;
- return true;
- }
- if (type == sym_1("Fact")) {
- *dest = (f_buf_inspect) buf_inspect_fact;
- return true;
- }
- if (type == sym_1("Fn")) {
- *dest = (f_buf_inspect) buf_inspect_fn;
- return true;
- }
- if (type == sym_1("Ident")) {
- *dest = (f_buf_inspect) buf_inspect_ident;
- return true;
- }
- if (type == sym_1("Integer")) {
- *dest = (f_buf_inspect) buf_inspect_integer;
- return true;
- }
- if (type == sym_1("List")) {
- *dest = (f_buf_inspect) buf_inspect_list;
- return true;
- }
- if (type == sym_1("Ptag")) {
- *dest = (f_buf_inspect) buf_inspect_ptag;
- return true;
- }
- if (type == sym_1("Ptr")) {
- *dest = (f_buf_inspect) buf_inspect_ptr;
- return true;
- }
- if (type == sym_1("PtrFree")) {
- *dest = (f_buf_inspect) buf_inspect_ptr_free;
- return true;
- }
- if (type == sym_1("Quote")) {
- *dest = (f_buf_inspect) buf_inspect_quote;
- return true;
- }
- if (type == sym_1("S8")) {
- *dest = (f_buf_inspect) buf_inspect_s8;
- return true;
- }
- if (type == sym_1("S16")) {
- *dest = (f_buf_inspect) buf_inspect_s16;
- return true;
- }
- if (type == sym_1("S32")) {
- *dest = (f_buf_inspect) buf_inspect_s32;
- return true;
- }
- if (type == sym_1("S64")) {
- *dest = (f_buf_inspect) buf_inspect_s64;
- return true;
- }
- if (type == sym_1("Str")) {
- *dest = (f_buf_inspect) buf_inspect_str;
- return true;
- }
- if (type == sym_1("Struct")) {
- *dest = (f_buf_inspect) buf_inspect_struct;
- return true;
- }
- if (type == sym_1("Sw")) {
- *dest = (f_buf_inspect) buf_inspect_sw;
- return true;
- }
- if (type == sym_1("Sym")) {
- *dest = (f_buf_inspect) buf_inspect_sym;
- return true;
- }
- if (type == sym_1("Tuple")) {
- *dest = (f_buf_inspect) buf_inspect_tuple;
- return true;
- }
- if (type == sym_1("U8")) {
- *dest = (f_buf_inspect) buf_inspect_u8;
- return true;
- }
- if (type == sym_1("U16")) {
- *dest = (f_buf_inspect) buf_inspect_u16;
- return true;
- }
- if (type == sym_1("U32")) {
- *dest = (f_buf_inspect) buf_inspect_u32;
- return true;
- }
- if (type == sym_1("U64")) {
- *dest = (f_buf_inspect) buf_inspect_u64;
- return true;
- }
- if (type == sym_1("Uw")) {
- *dest = (f_buf_inspect) buf_inspect_uw;
- return true;
- }
- if (type == sym_1("Var")) {
- *dest = (f_buf_inspect) buf_inspect_var;
- return true;
- }
- if (type == sym_1("Void")) {
- *dest = (f_buf_inspect) buf_inspect_var;
- return true;
- }
- if (struct_type_exists(type)) {
- *dest = (f_buf_inspect) buf_inspect_struct;
- return true;
- }
- err_write_1("sym_to_buf_inspect: unknown type: ");
- err_write_1(type->str.ptr.pchar);
- err_write_1("\n");
- assert(! "sym_to_buf_inspect: unknown type");
- return false;
-}
-
-bool sym_to_buf_inspect_size (const s_sym *type, f_buf_inspect_size *dest)
-{
- if (type == sym_1("Array")) {
- *dest = (f_buf_inspect_size) buf_inspect_array_size;
- return true;
- }
- if (type == sym_1("Bool")) {
- *dest = (f_buf_inspect_size) buf_inspect_bool_size;
- return true;
- }
- if (type == sym_1("Call")) {
- *dest = (f_buf_inspect_size) buf_inspect_call_size;
- return true;
- }
- if (type == sym_1("Cfn")) {
- *dest = (f_buf_inspect_size) buf_inspect_cfn_size;
- return true;
- }
- if (type == sym_1("Character")) {
- *dest = (f_buf_inspect_size) buf_inspect_character_size;
- return true;
- }
- if (type == sym_1("F32")) {
- *dest = (f_buf_inspect_size) buf_inspect_f32_size;
- return true;
- }
- if (type == sym_1("F64")) {
- *dest = (f_buf_inspect_size) buf_inspect_f64_size;
- return true;
- }
- if (type == sym_1("Fact")) {
- *dest = (f_buf_inspect_size) buf_inspect_fact_size;
- return true;
- }
- if (type == sym_1("Fn")) {
- *dest = (f_buf_inspect_size) buf_inspect_fn_size;
- return true;
- }
- if (type == sym_1("Ident")) {
- *dest = (f_buf_inspect_size) buf_inspect_ident_size;
- return true;
- }
- if (type == sym_1("Integer")) {
- *dest = (f_buf_inspect_size) buf_inspect_integer_size;
- return true;
- }
- if (type == sym_1("List")) {
- *dest = (f_buf_inspect_size) buf_inspect_list_size;
- return true;
- }
- if (type == sym_1("Ptag")) {
- *dest = (f_buf_inspect_size) buf_inspect_ptag_size;
- return true;
- }
- if (type == sym_1("Ptr")) {
- *dest = (f_buf_inspect_size) buf_inspect_ptr_size;
- return true;
- }
- if (type == sym_1("PtrFree")) {
- *dest = (f_buf_inspect_size) buf_inspect_ptr_free_size;
- return true;
- }
- if (type == sym_1("Quote")) {
- *dest = (f_buf_inspect_size) buf_inspect_quote_size;
- return true;
- }
- if (type == sym_1("S8")) {
- *dest = (f_buf_inspect_size) buf_inspect_s8_size;
- return true;
- }
- if (type == sym_1("S16")) {
- *dest = (f_buf_inspect_size) buf_inspect_s16_size;
- return true;
- }
- if (type == sym_1("S32")) {
- *dest = (f_buf_inspect_size) buf_inspect_s32_size;
- return true;
- }
- if (type == sym_1("S64")) {
- *dest = (f_buf_inspect_size) buf_inspect_s64_size;
- return true;
- }
- if (type == sym_1("Str")) {
- *dest = (f_buf_inspect_size) buf_inspect_str_size;
- return true;
- }
- if (type == sym_1("Struct")) {
- *dest = (f_buf_inspect_size) buf_inspect_struct_size;
- return true;
- }
- if (type == sym_1("Sw")) {
- *dest = (f_buf_inspect_size) buf_inspect_sw_size;
- return true;
- }
- if (type == sym_1("Sym")) {
- *dest = (f_buf_inspect_size) buf_inspect_sym_size;
- return true;
- }
- if (type == sym_1("Tuple")) {
- *dest = (f_buf_inspect_size) buf_inspect_tuple_size;
- return true;
- }
- if (type == sym_1("U8")) {
- *dest = (f_buf_inspect_size) buf_inspect_u8_size;
- return true;
- }
- if (type == sym_1("U16")) {
- *dest = (f_buf_inspect_size) buf_inspect_u16_size;
- return true;
- }
- if (type == sym_1("U32")) {
- *dest = (f_buf_inspect_size) buf_inspect_u32_size;
- return true;
- }
- if (type == sym_1("U64")) {
- *dest = (f_buf_inspect_size) buf_inspect_u64_size;
- return true;
- }
- if (type == sym_1("Uw")) {
- *dest = (f_buf_inspect_size) buf_inspect_uw_size;
- return true;
- }
- if (type == sym_1("Var")) {
- *dest = (f_buf_inspect_size) buf_inspect_var_size;
- return true;
- }
- if (type == sym_1("Void")) {
- *dest = (f_buf_inspect_size) buf_inspect_void_size;
- return true;
- }
- if (struct_type_exists(type)) {
- *dest = (f_buf_inspect_size) buf_inspect_struct_size;
- return true;
- }
- err_write_1("sym_to_buf_inspect_size: unknown type: ");
- err_inspect_sym(&type);
- err_write_1("\n");
- assert(! "sym_to_buf_inspect_size: unknown type");
- return false;
-}
-*/
-
bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
ffi_type **dest)
{
assert(sym);
- if (sym == sym_1("Result")) {
+ if (sym == &g_sym_Result) {
if (! result_type) {
err_puts("sym_to_ffi_type: invalid result type: Result");
return false;
@@ -505,107 +340,107 @@ bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
*dest = result_type;
return true;
}
- if (sym == sym_1("Array")) {
+ if (sym == &g_sym_Array) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Bool")) {
+ if (sym == &g_sym_Bool) {
*dest = &ffi_type_uint8;
return true;
}
- if (sym == sym_1("Character")) {
+ if (sym == &g_sym_Character) {
*dest = &ffi_type_uint32;
return true;
}
- if (sym == sym_1("F32")) {
+ if (sym == &g_sym_F32) {
*dest = &ffi_type_float;
return true;
}
- if (sym == sym_1("F64")) {
+ if (sym == &g_sym_F64) {
*dest = &ffi_type_double;
return true;
}
- if (sym == sym_1("Fn")) {
+ if (sym == &g_sym_Fn) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Integer")) {
+ if (sym == &g_sym_Integer) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("List")) {
+ if (sym == &g_sym_List) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Map")) {
+ if (sym == &g_sym_Map) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Ptr")) {
+ if (sym == &g_sym_Ptr) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("PtrFree")) {
+ if (sym == &g_sym_PtrFree) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("S8")) {
+ if (sym == &g_sym_S8) {
*dest = &ffi_type_sint8;
return true;
}
- if (sym == sym_1("S16")) {
+ if (sym == &g_sym_S16) {
*dest = &ffi_type_sint16;
return true;
}
- if (sym == sym_1("S32")) {
+ if (sym == &g_sym_S32) {
*dest = &ffi_type_sint32;
return true;
}
- if (sym == sym_1("S64")) {
+ if (sym == &g_sym_S64) {
*dest = &ffi_type_sint64;
return true;
}
- if (sym == sym_1("Str")) {
+ if (sym == &g_sym_Str) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Struct")) {
+ if (sym == &g_sym_Struct) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Sym")) {
+ if (sym == &g_sym_Sym) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("Sw")) {
+ if (sym == &g_sym_Sw) {
*dest = &ffi_type_slong;
return true;
}
- if (sym == sym_1("Tag")) {
+ if (sym == &g_sym_Tag) {
*dest = &ffi_type_pointer;
return true;
}
- if (sym == sym_1("U8")) {
+ if (sym == &g_sym_U8) {
*dest = &ffi_type_uint8;
return true;
}
- if (sym == sym_1("U16")) {
+ if (sym == &g_sym_U16) {
*dest = &ffi_type_uint16;
return true;
}
- if (sym == sym_1("U32")) {
+ if (sym == &g_sym_U32) {
*dest = &ffi_type_uint32;
return true;
}
- if (sym == sym_1("U64")) {
+ if (sym == &g_sym_U64) {
*dest = &ffi_type_uint64;
return true;
}
- if (sym == sym_1("Uw")) {
+ if (sym == &g_sym_Uw) {
*dest = &ffi_type_ulong;
return true;
}
- if (sym == sym_1("Void")) {
+ if (sym == &g_sym_Void) {
*dest = &ffi_type_void;
return true;
}
@@ -623,131 +458,131 @@ bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
/*
bool sym_to_init_cast (const s_sym *type, f_init_cast *dest)
{
- if (type == sym_1("Array")) {
+ if (type == &g_sym_Array) {
*dest = (f_init_cast) array_init_cast;
return true;
}
- if (type == sym_1("Bool")) {
+ if (type == &g_sym_Bool) {
*dest = (f_init_cast) bool_init_cast;
return true;
}
- if (type == sym_1("Call")) {
+ if (type == &g_sym_Call) {
*dest = (f_init_cast) call_init_cast;
return true;
}
- if (type == sym_1("Cfn")) {
+ if (type == &g_sym_Cfn) {
*dest = (f_init_cast) cfn_init_cast;
return true;
}
- if (type == sym_1("Character")) {
+ if (type == &g_sym_Character) {
*dest = (f_init_cast) character_init_cast;
return true;
}
- if (type == sym_1("F32")) {
+ if (type == &g_sym_F32) {
*dest = (f_init_cast) f32_init_cast;
return true;
}
- if (type == sym_1("F64")) {
+ if (type == &g_sym_F64) {
*dest = (f_init_cast) f64_init_cast;
return true;
}
- if (type == sym_1("Fact")) {
+ if (type == &g_sym_Fact) {
*dest = (f_init_cast) fact_init_cast;
return true;
}
- if (type == sym_1("Fn")) {
+ if (type == &g_sym_Fn) {
*dest = (f_init_cast) fn_init_cast;
return true;
}
- if (type == sym_1("Ident")) {
+ if (type == &g_sym_Ident) {
*dest = (f_init_cast) ident_init_cast;
return true;
}
- if (type == sym_1("Integer")) {
+ if (type == &g_sym_Integer) {
*dest = (f_init_cast) integer_init_cast;
return true;
}
- if (type == sym_1("List")) {
+ if (type == &g_sym_List) {
*dest = (f_init_cast) list_init_cast;
return true;
}
- if (type == sym_1("Ptag")) {
+ if (type == &g_sym_Ptag) {
*dest = (f_init_cast) ptag_init_cast;
return true;
}
- if (type == sym_1("Ptr")) {
+ if (type == &g_sym_Ptr) {
*dest = (f_init_cast) ptr_init_cast;
return true;
}
- if (type == sym_1("PtrFree")) {
+ if (type == &g_sym_PtrFree) {
*dest = (f_init_cast) ptr_free_init_cast;
return true;
}
- if (type == sym_1("Quote")) {
+ if (type == &g_sym_Quote) {
*dest = (f_init_cast) quote_init_cast;
return true;
}
- if (type == sym_1("S8")) {
+ if (type == &g_sym_S8) {
*dest = (f_init_cast) s8_init_cast;
return true;
}
- if (type == sym_1("S16")) {
+ if (type == &g_sym_S16) {
*dest = (f_init_cast) s16_init_cast;
return true;
}
- if (type == sym_1("S32")) {
+ if (type == &g_sym_S32) {
*dest = (f_init_cast) s32_init_cast;
return true;
}
- if (type == sym_1("S64")) {
+ if (type == &g_sym_S64) {
*dest = (f_init_cast) s64_init_cast;
return true;
}
- if (type == sym_1("Str")) {
+ if (type == &g_sym_Str) {
*dest = (f_init_cast) str_init_cast;
return true;
}
- if (type == sym_1("Struct")) {
+ if (type == &g_sym_Struct) {
*dest = (f_init_cast) struct_init_cast;
return true;
}
- if (type == sym_1("Sw")) {
+ if (type == &g_sym_Sw) {
*dest = (f_init_cast) sw_init_cast;
return true;
}
- if (type == sym_1("Sym")) {
+ if (type == &g_sym_Sym) {
*dest = (f_init_cast) sym_init_cast;
return true;
}
- if (type == sym_1("Tuple")) {
+ if (type == &g_sym_Tuple) {
*dest = (f_init_cast) tuple_init_cast;
return true;
}
- if (type == sym_1("U8")) {
+ if (type == &g_sym_U8) {
*dest = (f_init_cast) u8_init_cast;
return true;
}
- if (type == sym_1("U16")) {
+ if (type == &g_sym_U16) {
*dest = (f_init_cast) u16_init_cast;
return true;
}
- if (type == sym_1("U32")) {
+ if (type == &g_sym_U32) {
*dest = (f_init_cast) u32_init_cast;
return true;
}
- if (type == sym_1("U64")) {
+ if (type == &g_sym_U64) {
*dest = (f_init_cast) u64_init_cast;
return true;
}
- if (type == sym_1("Uw")) {
+ if (type == &g_sym_Uw) {
*dest = (f_init_cast) uw_init_cast;
return true;
}
- if (type == sym_1("Var")) {
+ if (type == &g_sym_Var) {
*dest = NULL;
return true;
}
- if (type == sym_1("Void")) {
+ if (type == &g_sym_Void) {
*dest = NULL;
return true;
}
@@ -764,131 +599,131 @@ bool sym_to_init_cast (const s_sym *type, f_init_cast *dest)
bool sym_to_init_copy (const s_sym *type, f_init_copy *dest)
{
- if (type == sym_1("Array")) {
+ if (type == &g_sym_Array) {
*dest = (f_init_copy) array_init_copy;
return true;
}
- if (type == sym_1("Bool")) {
+ if (type == &g_sym_Bool) {
*dest = (f_init_copy) bool_init_copy;
return true;
}
- if (type == sym_1("Call")) {
+ if (type == &g_sym_Call) {
*dest = (f_init_copy) call_init_copy;
return true;
}
- if (type == sym_1("Cfn")) {
+ if (type == &g_sym_Cfn) {
*dest = (f_init_copy) cfn_init_copy;
return true;
}
- if (type == sym_1("Character")) {
+ if (type == &g_sym_Character) {
*dest = (f_init_copy) character_init_copy;
return true;
}
- if (type == sym_1("F32")) {
+ if (type == &g_sym_F32) {
*dest = (f_init_copy) f32_init_copy;
return true;
}
- if (type == sym_1("F64")) {
+ if (type == &g_sym_F64) {
*dest = (f_init_copy) f64_init_copy;
return true;
}
- if (type == sym_1("Fact")) {
+ if (type == &g_sym_Fact) {
*dest = (f_init_copy) fact_init_copy;
return true;
}
- if (type == sym_1("Fn")) {
+ if (type == &g_sym_Fn) {
*dest = (f_init_copy) fn_init_copy;
return true;
}
- if (type == sym_1("Ident")) {
+ if (type == &g_sym_Ident) {
*dest = (f_init_copy) ident_init_copy;
return true;
}
- if (type == sym_1("Integer")) {
+ if (type == &g_sym_Integer) {
*dest = (f_init_copy) integer_init_copy;
return true;
}
- if (type == sym_1("List")) {
+ if (type == &g_sym_List) {
*dest = (f_init_copy) list_init_copy;
return true;
}
- if (type == sym_1("Ptag")) {
+ if (type == &g_sym_Ptag) {
*dest = (f_init_copy) ptag_init_copy;
return true;
}
- if (type == sym_1("Ptr")) {
+ if (type == &g_sym_Ptr) {
*dest = (f_init_copy) ptr_init_copy;
return true;
}
- if (type == sym_1("PtrFree")) {
+ if (type == &g_sym_PtrFree) {
*dest = (f_init_copy) ptr_free_init_copy;
return true;
}
- if (type == sym_1("Quote")) {
+ if (type == &g_sym_Quote) {
*dest = (f_init_copy) quote_init_copy;
return true;
}
- if (type == sym_1("S8")) {
+ if (type == &g_sym_S8) {
*dest = (f_init_copy) s8_init_copy;
return true;
}
- if (type == sym_1("S16")) {
+ if (type == &g_sym_S16) {
*dest = (f_init_copy) s16_init_copy;
return true;
}
- if (type == sym_1("S32")) {
+ if (type == &g_sym_S32) {
*dest = (f_init_copy) s32_init_copy;
return true;
}
- if (type == sym_1("S64")) {
+ if (type == &g_sym_S64) {
*dest = (f_init_copy) s64_init_copy;
return true;
}
- if (type == sym_1("Str")) {
+ if (type == &g_sym_Str) {
*dest = (f_init_copy) str_init_copy;
return true;
}
- if (type == sym_1("Struct")) {
+ if (type == &g_sym_Struct) {
*dest = (f_init_copy) struct_init_copy;
return true;
}
- if (type == sym_1("Sw")) {
+ if (type == &g_sym_Sw) {
*dest = (f_init_copy) sw_init_copy;
return true;
}
- if (type == sym_1("Sym")) {
+ if (type == &g_sym_Sym) {
*dest = (f_init_copy) sym_init_copy;
return true;
}
- if (type == sym_1("Tuple")) {
+ if (type == &g_sym_Tuple) {
*dest = (f_init_copy) tuple_init_copy;
return true;
}
- if (type == sym_1("U8")) {
+ if (type == &g_sym_U8) {
*dest = (f_init_copy) u8_init_copy;
return true;
}
- if (type == sym_1("U16")) {
+ if (type == &g_sym_U16) {
*dest = (f_init_copy) u16_init_copy;
return true;
}
- if (type == sym_1("U32")) {
+ if (type == &g_sym_U32) {
*dest = (f_init_copy) u32_init_copy;
return true;
}
- if (type == sym_1("U64")) {
+ if (type == &g_sym_U64) {
*dest = (f_init_copy) u64_init_copy;
return true;
}
- if (type == sym_1("Uw")) {
+ if (type == &g_sym_Uw) {
*dest = (f_init_copy) uw_init_copy;
return true;
}
- if (type == sym_1("Var")) {
+ if (type == &g_sym_Var) {
*dest = NULL;
return true;
}
- if (type == sym_1("Void")) {
+ if (type == &g_sym_Void) {
*dest = NULL;
return true;
}
@@ -906,131 +741,131 @@ bool sym_to_init_copy (const s_sym *type, f_init_copy *dest)
bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
{
- if (sym == sym_1("Array")) {
+ if (sym == &g_sym_Array) {
*dest = TAG_ARRAY;
return true;
}
- if (sym == sym_1("Bool")) {
+ if (sym == &g_sym_Bool) {
*dest = TAG_BOOL;
return true;
}
- if (sym == sym_1("Call")) {
+ if (sym == &g_sym_Call) {
*dest = TAG_CALL;
return true;
}
- if (sym == sym_1("Cfn")) {
+ if (sym == &g_sym_Cfn) {
*dest = TAG_CFN;
return true;
}
- if (sym == sym_1("Character")) {
+ if (sym == &g_sym_Character) {
*dest = TAG_CHARACTER;
return true;
}
- if (sym == sym_1("F32")) {
+ if (sym == &g_sym_F32) {
*dest = TAG_F32;
return true;
}
- if (sym == sym_1("F64")) {
+ if (sym == &g_sym_F64) {
*dest = TAG_F64;
return true;
}
- if (sym == sym_1("Fn")) {
+ if (sym == &g_sym_Fn) {
*dest = TAG_FN;
return true;
}
- if (sym == sym_1("Ident")) {
+ if (sym == &g_sym_Ident) {
*dest = TAG_IDENT;
return true;
}
- if (sym == sym_1("Integer")) {
+ if (sym == &g_sym_Integer) {
*dest = TAG_INTEGER;
return true;
}
- if (sym == sym_1("List")) {
+ if (sym == &g_sym_List) {
*dest = TAG_LIST;
return true;
}
- if (sym == sym_1("Ptag")) {
+ if (sym == &g_sym_Ptag) {
*dest = TAG_PTAG;
return true;
}
- if (sym == sym_1("Ptr")) {
+ if (sym == &g_sym_Ptr) {
*dest = TAG_PTR;
return true;
}
- if (sym == sym_1("PtrFree")) {
+ if (sym == &g_sym_PtrFree) {
*dest = TAG_PTR_FREE;
return true;
}
- if (sym == sym_1("Quote")) {
+ if (sym == &g_sym_Quote) {
*dest = TAG_QUOTE;
return true;
}
- if (sym == sym_1("S8")) {
+ if (sym == &g_sym_S8) {
*dest = TAG_S8;
return true;
}
- if (sym == sym_1("S16")) {
+ if (sym == &g_sym_S16) {
*dest = TAG_S16;
return true;
}
- if (sym == sym_1("S32")) {
+ if (sym == &g_sym_S32) {
*dest = TAG_S32;
return true;
}
- if (sym == sym_1("S64")) {
+ if (sym == &g_sym_S64) {
*dest = TAG_S64;
return true;
}
- if (sym == sym_1("Str")) {
+ if (sym == &g_sym_Str) {
*dest = TAG_STR;
return true;
}
- if (sym == sym_1("Struct")) {
+ if (sym == &g_sym_Struct) {
*dest = TAG_STRUCT;
return true;
}
- if (sym == sym_1("Sw")) {
+ if (sym == &g_sym_Sw) {
*dest = TAG_SW;
return true;
}
- if (sym == sym_1("Sym")) {
+ if (sym == &g_sym_Sym) {
*dest = TAG_SYM;
return true;
}
- if (sym == sym_1("Tag")) {
+ if (sym == &g_sym_Tag) {
*dest = TAG_VOID;
return true;
}
- if (sym == sym_1("Tuple")) {
+ if (sym == &g_sym_Tuple) {
*dest = TAG_TUPLE;
return true;
}
- if (sym == sym_1("U8")) {
+ if (sym == &g_sym_U8) {
*dest = TAG_U8;
return true;
}
- if (sym == sym_1("U16")) {
+ if (sym == &g_sym_U16) {
*dest = TAG_U16;
return true;
}
- if (sym == sym_1("U32")) {
+ if (sym == &g_sym_U32) {
*dest = TAG_U32;
return true;
}
- if (sym == sym_1("U64")) {
+ if (sym == &g_sym_U64) {
*dest = TAG_U64;
return true;
}
- if (sym == sym_1("Uw")) {
+ if (sym == &g_sym_Uw) {
*dest = TAG_UW;
return true;
}
- if (sym == sym_1("Var")) {
+ if (sym == &g_sym_Var) {
*dest = TAG_VAR;
return true;
}
- if (sym == sym_1("Void")) {
+ if (sym == &g_sym_Void) {
*dest = TAG_VOID;
return true;
}
@@ -1048,131 +883,131 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
bool sym_type_size (const s_sym *type, uw *dest)
{
const s_struct_type *st;
- if (type == sym_1("Array")) {
+ if (type == &g_sym_Array) {
*dest = sizeof(s_array);
return true;
}
- if (type == sym_1("Bool")) {
+ if (type == &g_sym_Bool) {
*dest = sizeof(bool);
return true;
}
- if (type == sym_1("Call")) {
+ if (type == &g_sym_Call) {
*dest = sizeof(s_call);
return true;
}
- if (type == sym_1("Cfn")) {
+ if (type == &g_sym_Cfn) {
*dest = sizeof(s_cfn);
return true;
}
- if (type == sym_1("Character")) {
+ if (type == &g_sym_Character) {
*dest = sizeof(character);
return true;
}
- if (type == sym_1("F32")) {
+ if (type == &g_sym_F32) {
*dest = sizeof(f32);
return true;
}
- if (type == sym_1("F64")) {
+ if (type == &g_sym_F64) {
*dest = sizeof(f64);
return true;
}
- if (type == sym_1("Fact")) {
+ if (type == &g_sym_Fact) {
*dest = sizeof(s_fact);
return true;
}
- if (type == sym_1("Fn")) {
+ if (type == &g_sym_Fn) {
*dest = sizeof(s_fn);
return true;
}
- if (type == sym_1("Ident")) {
+ if (type == &g_sym_Ident) {
*dest = sizeof(s_ident);
return true;
}
- if (type == sym_1("Integer")) {
+ if (type == &g_sym_Integer) {
*dest = sizeof(s_integer);
return true;
}
- if (type == sym_1("List")) {
+ if (type == &g_sym_List) {
*dest = sizeof(s_list *);
return true;
}
- if (type == sym_1("Ptag")) {
+ if (type == &g_sym_Ptag) {
*dest = sizeof(p_tag);
return true;
}
- if (type == sym_1("Ptr")) {
+ if (type == &g_sym_Ptr) {
*dest = sizeof(void *);
return true;
}
- if (type == sym_1("PtrFree")) {
+ if (type == &g_sym_PtrFree) {
*dest = sizeof(void *);
return true;
}
- if (type == sym_1("Quote")) {
+ if (type == &g_sym_Quote) {
*dest = sizeof(s_quote);
return true;
}
- if (type == sym_1("S8")) {
+ if (type == &g_sym_S8) {
*dest = sizeof(s8);
return true;
}
- if (type == sym_1("S16")) {
+ if (type == &g_sym_S16) {
*dest = sizeof(s16);
return true;
}
- if (type == sym_1("S32")) {
+ if (type == &g_sym_S32) {
*dest = sizeof(s32);
return true;
}
- if (type == sym_1("S64")) {
+ if (type == &g_sym_S64) {
*dest = sizeof(s64);
return true;
}
- if (type == sym_1("Str")) {
+ if (type == &g_sym_Str) {
*dest = sizeof(s_str);
return true;
}
- if (type == sym_1("Struct")) {
+ if (type == &g_sym_Struct) {
*dest = sizeof(s_struct);
return true;
}
- if (type == sym_1("Sw")) {
+ if (type == &g_sym_Sw) {
*dest = sizeof(sw);
return true;
}
- if (type == sym_1("Sym")) {
+ if (type == &g_sym_Sym) {
*dest = sizeof(s_sym *);
return true;
}
- if (type == sym_1("Tuple")) {
+ if (type == &g_sym_Tuple) {
*dest = sizeof(s_tuple);
return true;
}
- if (type == sym_1("U8")) {
+ if (type == &g_sym_U8) {
*dest = sizeof(u8);
return true;
}
- if (type == sym_1("U16")) {
+ if (type == &g_sym_U16) {
*dest = sizeof(u16);
return true;
}
- if (type == sym_1("U32")) {
+ if (type == &g_sym_U32) {
*dest = sizeof(u32);
return true;
}
- if (type == sym_1("U64")) {
+ if (type == &g_sym_U64) {
*dest = sizeof(u64);
return true;
}
- if (type == sym_1("Uw")) {
+ if (type == &g_sym_Uw) {
*dest = sizeof(uw);
return true;
}
- if (type == sym_1("Var")) {
+ if (type == &g_sym_Var) {
*dest = 0;
return true;
}
- if (type == sym_1("Void")) {
+ if (type == &g_sym_Void) {
*dest = 0;
return true;
}
diff --git a/libc3/sym.h b/libc3/sym.h
index 83d1929..6168a41 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -26,13 +26,63 @@
#define SYM_MAX 1024
+extern const s_sym g_sym__brackets;
+extern const s_sym g_sym__paren;
+extern const s_sym g_sym_Array;
+extern const s_sym g_sym_Bool;
+extern const s_sym g_sym_C3;
+extern const s_sym g_sym_Call;
+extern const s_sym g_sym_Cfn;
+extern const s_sym g_sym_Character;
+extern const s_sym g_sym_Char__star;
+extern const s_sym g_sym_F32;
+extern const s_sym g_sym_F64;
+extern const s_sym g_sym_Fact;
+extern const s_sym g_sym_Fn;
+extern const s_sym g_sym_Ident;
+extern const s_sym g_sym_Integer;
+extern const s_sym g_sym_List;
+extern const s_sym g_sym_Map;
+extern const s_sym g_sym_Ptag;
+extern const s_sym g_sym_Ptr;
+extern const s_sym g_sym_PtrFree;
+extern const s_sym g_sym_Quote;
+extern const s_sym g_sym_Result;
+extern const s_sym g_sym_S8;
+extern const s_sym g_sym_S16;
+extern const s_sym g_sym_S32;
+extern const s_sym g_sym_S64;
+extern const s_sym g_sym_Str;
+extern const s_sym g_sym_Struct;
+extern const s_sym g_sym_StructType;
+extern const s_sym g_sym_Sw;
+extern const s_sym g_sym_Sym;
+extern const s_sym g_sym_Tag;
+extern const s_sym g_sym_Tuple;
+extern const s_sym g_sym_U8;
+extern const s_sym g_sym_U16;
+extern const s_sym g_sym_U32;
+extern const s_sym g_sym_U64;
+extern const s_sym g_sym_Uw;
+extern const s_sym g_sym_Var;
+extern const s_sym g_sym_Void;
+extern const s_sym g_sym_cast;
+extern const s_sym g_sym_r;
+extern const s_sym g_sym_rw;
+extern const s_sym g_sym_rwx;
+extern const s_sym g_sym_rx;
+extern const s_sym g_sym_w;
+extern const s_sym g_sym_wx;
+extern const s_sym g_sym_x;
+
const s_sym * sym_1 (const char *p);
const s_sym ** sym_init_1 (const s_sym **sym, const char *p);
const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *tag);
const s_sym ** sym_init_copy (const s_sym **sym,
const s_sym * const *src);
+void sym_init_g_sym (void);
const s_sym ** sym_init_str (const s_sym **sym, const s_str *src);
-
+bool sym_intern (const s_sym *sym, s_sym *free_sym);
/* Heap-allocation functions, call sym_delete_all at exit. */
void sym_delete_all (void);
diff --git a/libc3/tag.c b/libc3/tag.c
index 6c4c9d1..f45ea78 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -37,6 +37,7 @@
#include "str.h"
#include "struct.h"
#include "struct_type.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "time.h"
@@ -706,192 +707,192 @@ bool tag_to_const_pointer (const s_tag *tag, const s_sym *type,
bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest)
{
- if (type == sym_1("Tag")) {
+ if (type == &g_sym_Tag) {
*dest = tag;
return true;
}
switch (tag->type) {
case TAG_VOID:
- if (type == sym_1("Void")) {
+ if (type == &g_sym_Void) {
*dest = NULL;
return true;
}
goto invalid_cast;
case TAG_ARRAY:
- if (type == sym_1("Array")) {
+ if (type == &g_sym_Array) {
*dest = tag->data.array.data;
return true;
}
goto invalid_cast;
case TAG_BOOL:
- if (type == sym_1("Bool")) {
+ if (type == &g_sym_Bool) {
*dest = &tag->data.bool;
return true;
}
goto invalid_cast;
case TAG_CALL:
- if (type == sym_1("Call")) {
+ if (type == &g_sym_Call) {
*dest = &tag->data.call;
return true;
}
goto invalid_cast;
case TAG_CFN:
- if (type == sym_1("Cfn")) {
+ if (type == &g_sym_Cfn) {
*dest = &tag->data.cfn;
return true;
}
goto invalid_cast;
case TAG_CHARACTER:
- if (type == sym_1("Character")) {
+ if (type == &g_sym_Character) {
*dest = &tag->data.character;
return true;
}
goto invalid_cast;
case TAG_F32:
- if (type == sym_1("F32")) {
+ if (type == &g_sym_F32) {
*dest = &tag->data.f32;
return true;
}
goto invalid_cast;
case TAG_F64:
- if (type == sym_1("F64")) {
+ if (type == &g_sym_F64) {
*dest = &tag->data.f64;
return true;
}
goto invalid_cast;
case TAG_FACT:
- if (type == sym_1("Fact")) {
+ if (type == &g_sym_Fact) {
*dest = &tag->data.fact;
return true;
}
goto invalid_cast;
case TAG_FN:
- if (type == sym_1("Fn")) {
+ if (type == &g_sym_Fn) {
*dest = &tag->data.fn;
return true;
}
goto invalid_cast;
case TAG_IDENT:
- if (type == sym_1("Ident")) {
+ if (type == &g_sym_Ident) {
*dest = &tag->data.ident;
return true;
}
goto invalid_cast;
case TAG_INTEGER:
- if (type == sym_1("Integer")) {
+ if (type == &g_sym_Integer) {
*dest = &tag->data.integer;
return true;
}
goto invalid_cast;
case TAG_SW:
- if (type == sym_1("Sw")) {
+ if (type == &g_sym_Sw) {
*dest = &tag->data.sw;
return true;
}
goto invalid_cast;
case TAG_S64:
- if (type == sym_1("S64")) {
+ if (type == &g_sym_S64) {
*dest = &tag->data.s64;
return true;
}
goto invalid_cast;
case TAG_S32:
- if (type == sym_1("S32")) {
+ if (type == &g_sym_S32) {
*dest = &tag->data.s32;
return true;
}
goto invalid_cast;
case TAG_S16:
- if (type == sym_1("S16")) {
+ if (type == &g_sym_S16) {
*dest = &tag->data.s16;
return true;
}
goto invalid_cast;
case TAG_S8:
- if (type == sym_1("S8")) {
+ if (type == &g_sym_S8) {
*dest = &tag->data.s8;
return true;
}
goto invalid_cast;
case TAG_U8:
- if (type == sym_1("U8")) {
+ if (type == &g_sym_U8) {
*dest = &tag->data.u8;
return true;
}
goto invalid_cast;
case TAG_U16:
- if (type == sym_1("U16")) {
+ if (type == &g_sym_U16) {
*dest = &tag->data.u16;
return true;
}
goto invalid_cast;
case TAG_U32:
- if (type == sym_1("U32")) {
+ if (type == &g_sym_U32) {
*dest = &tag->data.u32;
return true;
}
goto invalid_cast;
case TAG_U64:
- if (type == sym_1("U64")) {
+ if (type == &g_sym_U64) {
*dest = &tag->data.u64;
return true;
}
goto invalid_cast;
case TAG_UW:
- if (type == sym_1("Uw")) {
+ if (type == &g_sym_Uw) {
*dest = &tag->data.uw;
return true;
}
goto invalid_cast;
case TAG_LIST:
- if (type == sym_1("List")) {
+ if (type == &g_sym_List) {
*dest = &tag->data.list;
return true;
}
goto invalid_cast;
case TAG_MAP:
- if (type == sym_1("Map")) {
+ if (type == &g_sym_Map) {
*dest = &tag->data.map;
return true;
}
goto invalid_cast;
case TAG_PTAG:
- if (type == sym_1("Ptag")) {
+ if (type == &g_sym_Ptag) {
*dest = (void *) tag->data.ptag;
return true;
}
goto invalid_cast;
case TAG_PTR:
- if (type == sym_1("Ptr")) {
+ if (type == &g_sym_Ptr) {
*dest = &tag->data.ptr.p;
return true;
}
goto invalid_cast;
case TAG_PTR_FREE:
- if (type == sym_1("Ptr") ||
- type == sym_1("PtrFree")) {
+ if (type == &g_sym_Ptr ||
+ type == &g_sym_PtrFree) {
*dest = &tag->data.ptr_free.p;
return true;
}
goto invalid_cast;
case TAG_QUOTE:
- if (type == sym_1("Quote")) {
+ if (type == &g_sym_Quote) {
*dest = &tag->data.quote;
return true;
}
goto invalid_cast;
case TAG_STR:
- if (type == sym_1("Str")) {
+ if (type == &g_sym_Str) {
*dest = &tag->data.str;
return true;
}
- if (type == sym_1("Char*")) {
+ if (type == &g_sym_Char__star) {
*dest = (void *) tag->data.str.ptr.pchar;
return true;
}
goto invalid_cast;
case TAG_STRUCT:
- if (type == sym_1("Struct")) {
+ if (type == &g_sym_Struct) {
*dest = &tag->data.struct_;
return true;
}
@@ -901,27 +902,27 @@ bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest)
}
goto invalid_cast;
case TAG_STRUCT_TYPE:
- if (type == sym_1("StructType")) {
+ if (type == &g_sym_StructType) {
*dest = &tag->data.struct_type;
return true;
}
goto invalid_cast;
case TAG_SYM:
- if (type == sym_1("Sym")) {
+ if (type == &g_sym_Sym) {
*dest = (void *) &tag->data.sym;
return true;
}
- if (type == sym_1("Str")) {
+ if (type == &g_sym_Str) {
*dest = (void *) &tag->data.sym->str;
return true;
}
- if (type == sym_1("Char*")) {
+ if (type == &g_sym_Char__star) {
*dest = (void *) tag->data.sym->str.ptr.pchar;
return true;
}
goto invalid_cast;
case TAG_TUPLE:
- if (type == sym_1("Tuple")) {
+ if (type == &g_sym_Tuple) {
*dest = &tag->data.tuple;
return true;
}
@@ -997,41 +998,41 @@ const s_sym ** tag_type (const s_tag *tag, const s_sym **dest)
assert(tag);
assert(dest);
switch (tag->type) {
- case TAG_VOID: *dest = sym_1("Void"); return dest;
- case TAG_ARRAY: *dest = sym_1("Array"); return dest;
- case TAG_BOOL: *dest = sym_1("Bool"); return dest;
- case TAG_CALL: *dest = sym_1("Call"); return dest;
- case TAG_CFN: *dest = sym_1("Cfn"); return dest;
- case TAG_CHARACTER: *dest = sym_1("Character"); return dest;
- case TAG_F32: *dest = sym_1("F32"); return dest;
- case TAG_F64: *dest = sym_1("F64"); return dest;
- case TAG_FACT: *dest = sym_1("Fact"); return dest;
- case TAG_FN: *dest = sym_1("Fn"); return dest;
- case TAG_IDENT: *dest = sym_1("Ident"); return dest;
- case TAG_INTEGER: *dest = sym_1("Integer"); return dest;
- case TAG_SW: *dest = sym_1("Sw"); return dest;
- case TAG_S64: *dest = sym_1("S64"); return dest;
- case TAG_S32: *dest = sym_1("S32"); return dest;
- case TAG_S16: *dest = sym_1("S16"); return dest;
- case TAG_S8: *dest = sym_1("S8"); return dest;
- case TAG_U8: *dest = sym_1("U8"); return dest;
- case TAG_U16: *dest = sym_1("U16"); return dest;
- case TAG_U32: *dest = sym_1("U32"); return dest;
- case TAG_U64: *dest = sym_1("U64"); return dest;
- case TAG_UW: *dest = sym_1("Uw"); return dest;
- case TAG_LIST: *dest = sym_1("List"); return dest;
- case TAG_MAP: *dest = sym_1("Map"); return dest;
- case TAG_PTAG: *dest = sym_1("Ptag"); return dest;
- case TAG_PTR: *dest = sym_1("Ptr"); return dest;
- case TAG_PTR_FREE: *dest = sym_1("PtrFree"); return dest;
- case TAG_QUOTE: *dest = sym_1("Quote"); return dest;
- case TAG_STR: *dest = sym_1("Str"); return dest;
+ case TAG_VOID: *dest = &g_sym_Void; return dest;
+ case TAG_ARRAY: *dest = &g_sym_Array; return dest;
+ case TAG_BOOL: *dest = &g_sym_Bool; return dest;
+ case TAG_CALL: *dest = &g_sym_Call; return dest;
+ case TAG_CFN: *dest = &g_sym_Cfn; return dest;
+ case TAG_CHARACTER: *dest = &g_sym_Character; return dest;
+ case TAG_F32: *dest = &g_sym_F32; return dest;
+ case TAG_F64: *dest = &g_sym_F64; return dest;
+ case TAG_FACT: *dest = &g_sym_Fact; return dest;
+ case TAG_FN: *dest = &g_sym_Fn; return dest;
+ case TAG_IDENT: *dest = &g_sym_Ident; return dest;
+ case TAG_INTEGER: *dest = &g_sym_Integer; return dest;
+ case TAG_SW: *dest = &g_sym_Sw; return dest;
+ case TAG_S64: *dest = &g_sym_S64; return dest;
+ case TAG_S32: *dest = &g_sym_S32; return dest;
+ case TAG_S16: *dest = &g_sym_S16; return dest;
+ case TAG_S8: *dest = &g_sym_S8; return dest;
+ case TAG_U8: *dest = &g_sym_U8; return dest;
+ case TAG_U16: *dest = &g_sym_U16; return dest;
+ case TAG_U32: *dest = &g_sym_U32; return dest;
+ case TAG_U64: *dest = &g_sym_U64; return dest;
+ case TAG_UW: *dest = &g_sym_Uw; return dest;
+ case TAG_LIST: *dest = &g_sym_List; return dest;
+ case TAG_MAP: *dest = &g_sym_Map; return dest;
+ case TAG_PTAG: *dest = &g_sym_Ptag; return dest;
+ case TAG_PTR: *dest = &g_sym_Ptr; return dest;
+ case TAG_PTR_FREE: *dest = &g_sym_PtrFree; return dest;
+ case TAG_QUOTE: *dest = &g_sym_Quote; return dest;
+ case TAG_STR: *dest = &g_sym_Str; return dest;
case TAG_STRUCT: *dest = tag->data.struct_.type->module;
return dest;
- case TAG_STRUCT_TYPE: *dest = sym_1("StructType"); return dest;
- case TAG_SYM: *dest = sym_1("Sym"); return dest;
- case TAG_TUPLE: *dest = sym_1("Tuple"); return dest;
- case TAG_VAR: *dest = sym_1("Var"); return dest;
+ case TAG_STRUCT_TYPE: *dest = &g_sym_StructType; return dest;
+ case TAG_SYM: *dest = &g_sym_Sym; return dest;
+ case TAG_TUPLE: *dest = &g_sym_Tuple; return dest;
+ case TAG_VAR: *dest = &g_sym_Var; return dest;
}
warnx("tag_type: unknown tag type: %d", tag->type);
assert(! "tag_type: unknown tag type");
diff --git a/libc3/types.h b/libc3/types.h
index ee95d1e..6c61ebb 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -261,7 +261,8 @@ struct struct_ {
};
struct sym_list {
- s_sym *sym;
+ const s_sym *sym;
+ s_sym *free_sym;
s_sym_list *next;
};