Add lib.c and hvm_lib.h for embedding HVM as a library#51
Open
lancejpollard wants to merge 1 commit intoHigherOrderCO:mainfrom
Open
Add lib.c and hvm_lib.h for embedding HVM as a library#51lancejpollard wants to merge 1 commit intoHigherOrderCO:mainfrom
lancejpollard wants to merge 1 commit intoHigherOrderCO:mainfrom
Conversation
Adds a library entry point (lib.c) and public header (hvm_lib.h) so HVM
can be built as a static or shared library for embedding. lib.c includes
hvm.c and wraps selected static inline functions as real exported symbols
with an hvm_ namespace prefix.
Exported API:
- Lifecycle: hvm_init, hvm_free, hvm_prepare, hvm_prepare_text
- Evaluation: hvm_wnf, hvm_normalize
- Term constructors: hvm_term_new_{num,ctr,sup,dup,app,lam,lam_at,var,ref}
- Term accessors: hvm_term_{tag,ext,val}
- Heap: hvm_heap_{read,set,alloc}
- Symbol table: hvm_table_find
- Primitives: hvm_prim_register
Build:
clang -O2 -c lib.c -o hvm.o && ar rcs libhvm.a hvm.o
7fde163 to
3ef07bb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
clang/lib.candclang/hvm_lib.hso HVM can be compiled as a static or shared library for embedding in other applications.Since
hvm.cuses#define fn static inline, all functions are private.lib.cincludeshvm.cand provides non-static wrapper functions that create real linker symbols, following the same single-TU pattern asmain.c.All exported symbols use an
hvm_prefix to avoid name collisions when linked into a host application.Benefits
lib.c, it can be linked into any C, Rust, Swift, or Kotlin project as a library.#include "hvm.c"pattern thatmain.calready uses. No refactoring of the core. The thin wrappers inline away at-O2, so there is no performance cost.hvm_prefix prevents collisions when linked into larger applications that may have their owninit,free, etc.lib.ccompiles for macOS, Linux, iOS (static), Android (shared), and WASM (via emcc). One source file for all platforms.hvm_lib.hgives consumers a versioned header to code against, decoupled from internal function names that may change upstream.Usage
Exported API
hvm_init,hvm_free,hvm_prepare,hvm_prepare_texthvm_wnf,hvm_normalizehvm_term_new_{num,ctr,sup,dup,app,lam,lam_at,var,ref}hvm_term_{tag,ext,val}hvm_heap_{read,set,alloc}hvm_table_findhvm_prim_register