Closed 8tx7K38ej1aBTKWK closed 3 years ago
This implements the C API part of #43. It simplifies the code base quite a lot so I'm sending a preliminary pull request.
The details of the API can be found in villain.h and wrap.c.
villain.h
wrap.c
I also changed the vector representation a little bit so it matches the C API
typedef struct vl_vec { uint64_t len; vl_val buf[]; } vl_vec;
In particular, len is no longer a tagged value so unwrapping the vector becomes a simple bit-untagging
len
vl_vec* vl_unwrap_vec(vl_val x) { return (vl_vec *)(x ^ vector_type_tag); }
The next step is to redo the string representation so it matches the definition in C
typedef struct vl_str { uint64_t len; vl_char buf[]; } vl_str;
We need to
buf
Tagging should only be done when string-ref or string-length are called.
string-ref
string-length
After the next step, unwrapping a string can be much simpler
vl_str* vl_unwrap_str(vl_val x) { return (vl_str *)(x ^ str_type_tag); } vl_val vl_wrap_str(vl_str *s) { return ((vl_val)s) | str_type_tag; }
I have resolved all the merging conflicts and added API for ports
oops :)
This implements the C API part of #43. It simplifies the code base quite a lot so I'm sending a preliminary pull request.
The details of the API can be found in
villain.h
andwrap.c
.I also changed the vector representation a little bit so it matches the C API
In particular,
len
is no longer a tagged value so unwrapping the vector becomes a simple bit-untaggingThe next step is to redo the string representation so it matches the definition in C
We need to
len
buf
. Each character should also be untagged.Tagging should only be done when
string-ref
orstring-length
are called.After the next step, unwrapping a string can be much simpler