Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C API for Villain #56

Merged
merged 4 commits into from
Feb 24, 2021
Merged

C API for Villain #56

merged 4 commits into from
Feb 24, 2021

Conversation

8tx7K38ej1aBTKWK
Copy link
Contributor

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.

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

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

  1. use untagged value for len
  2. use UTF32 for buf. Each character should also be untagged.

Tagging should only be done when string-ref or string-length are called.

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;
}

@8tx7K38ej1aBTKWK
Copy link
Contributor Author

8tx7K38ej1aBTKWK commented Feb 24, 2021

I have resolved all the merging conflicts and added API for ports

oops :)

@dvanhorn dvanhorn merged commit 902704c into main Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants