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

I have a C S-expression library floating around #1

Closed
marcoxa opened this issue May 4, 2021 · 7 comments
Closed

I have a C S-expression library floating around #1

marcoxa opened this issue May 4, 2021 · 7 comments

Comments

@marcoxa
Copy link

marcoxa commented May 4, 2021

I have to check the licensing, but otherwise I guess it could be included.

@lassik
Copy link
Collaborator

lassik commented May 4, 2021

Nice. If it's permissively licensed, it would be a useful starting point.

@lassik
Copy link
Collaborator

lassik commented May 4, 2021

The code in this repo so far is ISC-licensed but that's debatable. MIT license is the Lisp custom.

@marcoxa
Copy link
Author

marcoxa commented May 4, 2021

Hi

I dug it out. The License is BSD-like. It has to be like that, because the original code is from... Berkeley :)

I will create a separate repo that coulld be linked here after cleaning it up.

@marcoxa
Copy link
Author

marcoxa commented May 4, 2021

The repository is at marcoxa/crscl

It suffered from a lot of bit rot and it needs to be reworked. Mostly make it compile (and renaming the API C functions, getting rid of the C++ namespace which may become redundant).

Keep me posted...

Marco

@lassik
Copy link
Collaborator

lassik commented May 4, 2021

Thank you for the quick turnaround!

typedef struct lispval shows that your library supports the following types:

  • symbol
  • cons cell
  • string
  • fixnum
  • double

Those are the types that we're planning for POSE as well, which is great.

All of the above types use the obvious C representation, apart from symbols which are more involved:

/* symbol */
struct
{
  char *vpname;             /* print name */
  struct lispval *vshlink;  /* hash link */
  struct lispval *vplist;   /* property list (an alist) */
  short vsindex;            /* used by hasher */
} s;

I assume that's to keep a symbol table which lets you test symbols via eq using their numerical values. You also support an alist; POSE has no way to encode those.

There's a simple mark-sweep GC in the .c file. POSE won't be able to encode shared structure (i.e. circular lists and cyclic graphs) so it may be that malloc/free would be enough for POSE.

Fixnums are stored as int; nowadays that should probably be either int64_t or intmax_t. A complete implementation would support bignums, but C has no standard bignum library. GNU libgmp is probably the closest thing to a standard, but it's not universal.

You also support the following non-standard data types, which I assume come from the application where the lib was used:

  • IR node
  • Other (custom void* pointer)

The POSE C reader should probably be delivered as two modules:

  • Tokenizer (required for all users)
  • Parser (optional add-on for users who want it)

That way users can run a code generator to produce custom deserializers that can read the S-expression piecemeal, matching with expected tokens, and don't require the parser's help i building a representation complete in-memory copy of the S-expression on the heap.

The COPYING file has four copies of the BSD license with different Copyright line(s) in each. That would make quite a lot of license boilerplate for a small library. Would all of those license notices still be needed for a pared-down POSE version of the library, or could we manage with only one copy of the BSD license text?

@marcoxa
Copy link
Author

marcoxa commented May 5, 2021 via email

@lassik lassik mentioned this issue May 12, 2021
lassik added a commit that referenced this issue May 12, 2021
This is a self-contained S-expression library with its own a
symbol table and a very simple GC.

From Marco Antoniotti (https://github.com/marcoxa/crscl)
commit 421eb511fd7c471023b318bdaf1d2b8201716cba
lassik added a commit that referenced this issue May 12, 2021
As advised by Marco in issue #1.
@lassik
Copy link
Collaborator

lassik commented May 12, 2021

Now imported into the c directory. Thank you!

@lassik lassik closed this as completed May 12, 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

No branches or pull requests

2 participants