diff --git a/.ikc3_history b/.ikc3_history
index d3dab1d..7e54e8b 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,30 +1,3 @@
-List.reverse([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
-(List) {1, 2}
-?
-cow 1
-(Tag) cow 1
-a = cow 1
-a
-a + 1
-cow 1
-type(cow 1)
-cow 1 + cow 1
-cow(1) + cow(1)
-quote [a: 1, b: 2]
-quote [{:a, 1}, {:b, 2}]
-%C3.Operator{}
-%GL.Vertex{}
-123.456
-abc.def
-%{a: 1}
-%{a: 1}.a
-x = %C3.Operator{}
-x.sym
-quote x.sym
-x = %C3.Operator{}
-x.sym
-x = %{
-x = %C3.Operator{sym: :-}
x = %C3.Operator{sym: 1}
x = %C3.Operator{sym: (Sym) "1"}
x = %C3.Operator{sym: :1}
@@ -97,3 +70,30 @@ server_client = Socket.Buf.accept(server)
req = HTTP.Request.buf_parse(server_client.buf_rw.r)
%HTTP.Response{}
Struct.offset(%HTTP.Response{}, :message)
+Sym.type_size(Str)
+Struct.offset(%HTTP.Response{}, :message)
+res = %HTTP.Response{}
+res.message
+Sym.type_size(Str)
+Sym.type_size(HTTP.Response)
+Struct.offset(%HTTP.Response{}, :message)
+Sym.type_size(Str)
+Struct.offset(%HTTP.Response{}, :code)
+Struct.offset(%HTTP.Response{}, :message)
+Struct.offset(%HTTP.Response{}, :response)
+Struct.offset(%HTTP.Response{}, :protocol)
+Struct.offset(%HTTP.Response{}, :code)
+Struct.offset(%HTTP.Response{}, :message)
+Struct.offset(%HTTP.Response{}, :headers)
+Struct.offset(%HTTP.Response{}, :body)
+Struct.offset(%HTTP.Response{}, :message)
+Struct.offset(%HTTP.Response{}, :protocol)
+Struct.offset(%HTTP.Response{}, :code)
+Struct.offset(%HTTP.Response{}, :message)
+Struct.offset(%HTTP.Response{}, :headers)
+Struct.offset(%HTTP.Response{}, :body)
+Struct.offset(%HTTP.Request{}, :method)
+Struct.offset(%HTTP.Request{}, :url)
+Struct.offset(%HTTP.Request{}, :protocol)
+Struct.offset(%HTTP.Request{}, :headers)
+Struct.offset(%HTTP.Response{}, :message)
diff --git a/lib/kc3/0.1/struct.kc3 b/lib/kc3/0.1/struct.kc3
new file mode 100644
index 0000000..0836b72
--- /dev/null
+++ b/lib/kc3/0.1/struct.kc3
@@ -0,0 +1,5 @@
+defmodule Struct do
+
+ def offset = cfn Uw "struct_offset" (Struct, Sym, Result)
+
+end
diff --git a/lib/kc3/0.1/sym.facts b/lib/kc3/0.1/sym.facts
index 6fd21c4..a375c07 100644
--- a/lib/kc3/0.1/sym.facts
+++ b/lib/kc3/0.1/sym.facts
@@ -3,3 +3,5 @@
replace {Sym, :is_a, :module}
replace {Sym, :symbol, Sym.cast}
replace {Sym.cast, :symbol_value, cfn Sym "sym_init_cast" (Result, Sym, Tag)}
+add {Sym, :symbol, Sym.type_size}
+replace {Sym.type_size, :symbol_value, cfn Uw "sym_type_size" (Sym, Result)}
diff --git a/libkc3/array.c b/libkc3/array.c
index a604a56..d445165 100644
--- a/libkc3/array.c
+++ b/libkc3/array.c
@@ -44,7 +44,7 @@ void array_clean (s_array *a)
if (a->data &&
sym_must_clean(a->element_type, &must_clean) &&
must_clean &&
- sym_type_size(a->element_type, &size) &&
+ sym_type_size(&a->element_type, &size) &&
size) {
data = a->data;
i = 0;
@@ -189,7 +189,7 @@ s_array * array_init (s_array *a, const s_sym *array_type, uw dimension,
i++;
}
i--;
- if (! sym_type_size(tmp.element_type, &item_size)) {
+ if (! sym_type_size(&tmp.element_type, &item_size)) {
free(tmp.dimensions);
return NULL;
}
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 7653114..1960d95 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -288,7 +288,7 @@ sw buf_parse_array_dimensions (s_buf *buf, s_array *dest)
assert(buf);
assert(dest);
tmp = *dest;
- if (! sym_type_size(tmp.element_type, &size))
+ if (! sym_type_size(&tmp.element_type, &size))
return -1;
if (! size) {
err_puts("buf_parse_array_dimensions: zero item size");
diff --git a/libkc3/hash.c b/libkc3/hash.c
index 6a3e403..b43842a 100644
--- a/libkc3/hash.c
+++ b/libkc3/hash.c
@@ -95,7 +95,7 @@ bool hash_update_array (t_hash *hash, const s_array *a)
i++;
}
if (a->data &&
- sym_type_size(a->element_type, &size) &&
+ sym_type_size(&a->element_type, &size) &&
size) {
data = a->data;
i = 0;
diff --git a/libkc3/list.c b/libkc3/list.c
index ea25edb..1a3b6ae 100644
--- a/libkc3/list.c
+++ b/libkc3/list.c
@@ -302,7 +302,7 @@ s_array * list_to_array (const s_list *list, const s_sym *array_type,
len = list_length(list);
tmp.array_type = array_type;
tmp.element_type = sym_array_type(array_type);
- if (! sym_type_size(tmp.element_type, &size))
+ if (! sym_type_size(&tmp.element_type, &size))
return NULL;
if (! size) {
err_puts("list_to_array: zero item size");
diff --git a/libkc3/ptr.c b/libkc3/ptr.c
index 1028bab..bc7508a 100644
--- a/libkc3/ptr.c
+++ b/libkc3/ptr.c
@@ -44,7 +44,7 @@ u_ptr_w * ptr_init_cast (u_ptr_w *p,
case TAG_F64: p->p = (void *) ((uw) tag->data.f64); return p;
case TAG_INTEGER:
p->p = (void *) integer_to_uw(&tag->data.integer); return p;
- case TAG_PTR: p->p = tag->data.ptr.p; return p;
+ case TAG_PTR: *p = tag->data.ptr; return p;
case TAG_PTR_FREE: p->p = tag->data.ptr_free.p; return p;
case TAG_S8: p->p = (void *) ((uw) tag->data.s8); return p;
case TAG_S16: p->p = (void *) ((uw) tag->data.s16); return p;
@@ -74,11 +74,9 @@ u_ptr_w * ptr_init_cast (u_ptr_w *p,
u_ptr_w * ptr_init_copy (u_ptr_w *ptr, const u_ptr_w *src)
{
- u_ptr_w tmp = {0};
assert(ptr);
assert(src);
- tmp.p = src->p;
- *ptr = tmp;
+ *ptr = *src;
return ptr;
}
diff --git a/libkc3/struct_type.c b/libkc3/struct_type.c
index 146e438..1dfec05 100644
--- a/libkc3/struct_type.c
+++ b/libkc3/struct_type.c
@@ -231,13 +231,9 @@ s_struct_type * struct_type_new (const s_sym *module,
uw struct_type_padding (uw offset, uw size)
{
unsigned int align = 1;
- if (size == 2)
- align = 2;
- else if (size == 4)
- align = 4;
- else if (size == 8)
- align = 8;
- else if (size == 16)
+ if (size >= 16)
align = 16;
+ else if (size >= 8)
+ align = 8;
return (offset + align - 1) / align * align;
}
diff --git a/libkc3/sym.c b/libkc3/sym.c
index 7514633..0411c30 100644
--- a/libkc3/sym.c
+++ b/libkc3/sym.c
@@ -1014,175 +1014,175 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
return false;
}
-bool sym_type_size (const s_sym *type, uw *dest)
+uw * sym_type_size (const s_sym * const *type, uw *dest)
{
const s_struct_type *st;
- if (type == &g_sym_Array ||
- sym_is_array_type(type)) {
+ if (*type == &g_sym_Array ||
+ sym_is_array_type(*type)) {
*dest = sizeof(s_array);
- return true;
+ return dest;
}
- if (type == &g_sym_Block) {
+ if (*type == &g_sym_Block) {
*dest = sizeof(s_block);
- return true;
+ return dest;
}
- if (type == &g_sym_Bool) {
+ if (*type == &g_sym_Bool) {
*dest = sizeof(bool);
- return true;
+ return dest;
}
- if (type == &g_sym_Call) {
+ if (*type == &g_sym_Call) {
*dest = sizeof(s_call);
- return true;
+ return dest;
}
- if (type == &g_sym_Cfn) {
+ if (*type == &g_sym_Cfn) {
*dest = sizeof(s_cfn);
- return true;
+ return dest;
}
- if (type == &g_sym_Character) {
+ if (*type == &g_sym_Character) {
*dest = sizeof(character);
- return true;
+ return dest;
}
- if (type == &g_sym_Complex) {
+ if (*type == &g_sym_Complex) {
*dest = sizeof(s_complex);
- return true;
+ return dest;
}
- if (type == &g_sym_Cow) {
+ if (*type == &g_sym_Cow) {
*dest = sizeof(s_cow);
- return true;
+ return dest;
}
- if (type == &g_sym_F32) {
+ if (*type == &g_sym_F32) {
*dest = sizeof(f32);
- return true;
+ return dest;
}
- if (type == &g_sym_F64) {
+ if (*type == &g_sym_F64) {
*dest = sizeof(f64);
- return true;
+ return dest;
}
- if (type == &g_sym_F128) {
+ if (*type == &g_sym_F128) {
*dest = sizeof(f128);
- return true;
+ return dest;
}
- if (type == &g_sym_Fact) {
+ if (*type == &g_sym_Fact) {
*dest = sizeof(s_fact);
- return true;
+ return dest;
}
- if (type == &g_sym_Fn) {
+ if (*type == &g_sym_Fn) {
*dest = sizeof(s_fn);
- return true;
+ return dest;
}
- if (type == &g_sym_Ident) {
+ if (*type == &g_sym_Ident) {
*dest = sizeof(s_ident);
- return true;
+ return dest;
}
- if (type == &g_sym_Integer) {
+ if (*type == &g_sym_Integer) {
*dest = sizeof(s_integer);
- return true;
+ return dest;
}
- if (type == &g_sym_List) {
+ if (*type == &g_sym_List) {
*dest = sizeof(s_list *);
- return true;
+ return dest;
}
- if (type == &g_sym_Ptag) {
+ if (*type == &g_sym_Ptag) {
*dest = sizeof(p_tag);
- return true;
+ return dest;
}
- if (type == &g_sym_Ptr) {
+ if (*type == &g_sym_Ptr) {
*dest = sizeof(void *);
- return true;
+ return dest;
}
- if (type == &g_sym_PtrFree) {
+ if (*type == &g_sym_PtrFree) {
*dest = sizeof(void *);
- return true;
+ return dest;
}
- if (type == &g_sym_Quote) {
+ if (*type == &g_sym_Quote) {
*dest = sizeof(s_quote);
- return true;
+ return dest;
}
- if (type == &g_sym_Ratio) {
+ if (*type == &g_sym_Ratio) {
*dest = sizeof(s_ratio);
- return true;
+ return dest;
}
- if (type == &g_sym_S8) {
+ if (*type == &g_sym_S8) {
*dest = sizeof(s8);
- return true;
+ return dest;
}
- if (type == &g_sym_S16) {
+ if (*type == &g_sym_S16) {
*dest = sizeof(s16);
- return true;
+ return dest;
}
- if (type == &g_sym_S32) {
+ if (*type == &g_sym_S32) {
*dest = sizeof(s32);
- return true;
+ return dest;
}
- if (type == &g_sym_S64) {
+ if (*type == &g_sym_S64) {
*dest = sizeof(s64);
- return true;
+ return dest;
}
- if (type == &g_sym_Str) {
+ if (*type == &g_sym_Str) {
*dest = sizeof(s_str);
- return true;
+ return dest;
}
- if (type == &g_sym_Struct) {
+ if (*type == &g_sym_Struct) {
*dest = sizeof(s_struct);
- return true;
+ return dest;
}
- if (type == &g_sym_StructType) {
+ if (*type == &g_sym_StructType) {
*dest = sizeof(s_struct_type);
- return true;
+ return dest;
}
- if (type == &g_sym_Sw) {
+ if (*type == &g_sym_Sw) {
*dest = sizeof(sw);
- return true;
+ return dest;
}
- if (type == &g_sym_Sym) {
+ if (*type == &g_sym_Sym) {
*dest = sizeof(p_sym);
- return true;
+ return dest;
}
- if (type == &g_sym_Tag) {
+ if (*type == &g_sym_Tag) {
*dest = sizeof(s_tag);
- return true;
+ return dest;
}
- if (type == &g_sym_Tuple) {
+ if (*type == &g_sym_Tuple) {
*dest = sizeof(s_tuple);
- return true;
+ return dest;
}
- if (type == &g_sym_U8) {
+ if (*type == &g_sym_U8) {
*dest = sizeof(u8);
- return true;
+ return dest;
}
- if (type == &g_sym_U16) {
+ if (*type == &g_sym_U16) {
*dest = sizeof(u16);
- return true;
+ return dest;
}
- if (type == &g_sym_U32) {
+ if (*type == &g_sym_U32) {
*dest = sizeof(u32);
- return true;
+ return dest;
}
- if (type == &g_sym_U64) {
+ if (*type == &g_sym_U64) {
*dest = sizeof(u64);
- return true;
+ return dest;
}
- if (type == &g_sym_Uw) {
+ if (*type == &g_sym_Uw) {
*dest = sizeof(uw);
- return true;
+ return dest;
}
- if (type == &g_sym_Var) {
+ if (*type == &g_sym_Var) {
*dest = sizeof(s_tag);
- return true;
+ return dest;
}
- if (type == &g_sym_Void) {
+ if (*type == &g_sym_Void) {
*dest = 0;
- return true;
+ return dest;
}
- if (! struct_type_find(type, &st))
- return false;
+ if (! struct_type_find(*type, &st))
+ return NULL;
if (st) {
*dest = st->size;
- return true;
+ return dest;
}
err_write_1("sym_type_size: unknown type: ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_write_1("\n");
assert(! "sym_type_size: unknown type");
- return false;
+ return NULL;
}
diff --git a/libkc3/sym.h b/libkc3/sym.h
index d2be769..8615b72 100644
--- a/libkc3/sym.h
+++ b/libkc3/sym.h
@@ -143,6 +143,6 @@ bool sym_search_modules (const s_sym *sym, const s_sym **dest);
bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
ffi_type **dest);
bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest);
-bool sym_type_size (const s_sym *type, uw *size);
+uw * sym_type_size (const s_sym * const *type, uw *size);
#endif /* LIBKC3_SYM_H */
diff --git a/libkc3/tag.c b/libkc3/tag.c
index e69203d..49ac9c2 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -819,11 +819,11 @@ uw * tag_size (const s_tag *tag, uw *dest)
uw tmp = 0;
assert(tag);
if (tag->type == TAG_VAR) {
- if (! sym_type_size(tag->data.var.type, &tmp))
+ if (! sym_type_size(&tag->data.var.type, &tmp))
return NULL;
}
else if (! tag_type(tag, &type) ||
- ! sym_type_size(type, &tmp))
+ ! sym_type_size(&type, &tmp))
return NULL;
*dest = tmp;
return dest;