Skip to content

Commit

Permalink
fix file organization
Browse files Browse the repository at this point in the history
  • Loading branch information
james.j.tolton@toltontechnology.ai committed Aug 23, 2024
1 parent ca83e3c commit 4768c01
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 322 deletions.
21 changes: 11 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ ego-tree = "0.6.2"

serde_json = "1.0.122"
serde = "1.0.204"
wasm-bindgen = "0.2.93"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossterm = { version = "0.28.1", optional = true }
Expand Down
30 changes: 9 additions & 21 deletions docs/shared_library/libscryer_prolog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern "C" {

/**
* Consults a Scryer Prolog module from a string, optionally with a given module name.
* Will panic if provided invalid Scryer Prolog code.
*
* # Safety
*
Expand All @@ -40,10 +41,6 @@ extern "C" {
* Scryer Prolog module name.
* * `input` - A pointer to a null-terminated UTF-8 string representing Scryer Prolog code.
*
* # Returns
*
* - [`true`] if the module was successfully loaded.
* - [`false`] if an error occurred while loading the module.
*/
void scryer_consult_module_string(struct Machine *machine,
const char *module_name,
Expand Down Expand Up @@ -100,22 +97,18 @@ void scryer_query_state_free(struct QueryState *query_state);

/**
* Greedily evaluate a prolog query, returning all results in a JSON-formatted string.
* Errors are printed to stderr and a null pointer is returned.
*
* # Safety
*
* * `machine` must be a valid [`Machine`] pointer created with [`machine_new`]
* that has not yet been freed.
* * `query_state` must be a valid [`QueryState`] created with
* [`run_query_iter`] that has not yet been freed.
* * There must be no existing [`QueryState`] for this [`Machine`] started by
* [`run_query_iter`] that has not yet been freed with
* [`query_state_free`] or the [`Machine`] state will enter an undefined
* configuration with unpredictable results.
* * it is the responsibility of the caller to deallocate the pointer returned by
* this function with [`scyer_free_c_string`] in order to avoid memory leaks.
* * once the first boolean result has been returned, the query has been exhausted,
* and the caller should call [`query_state_free`] on the
* [`QueryState`] before calling any other [`Machine`] functions from this shared library.
*
*
* # Returns
Expand All @@ -128,50 +121,45 @@ void scryer_query_state_free(struct QueryState *query_state);
* // current limitation is that only concrete (equality) bindings are returned,
* // residual goals not yet supported.
* {
* "status": "ok", // Can also be "error" or "panic"
* "status": "ok",
* "result": [{ ... }],
* }
*
* // if result is a boolean goal
*
* {
* "status": "ok", // Can also be "error" or "panic"
* "status": "ok",
* "result": boolean
* }
*
* // if panic
* {
* "status": "error" | "panic",
* "error": error message | "panic"
* }
*/
char *scryer_run_query(struct Machine *machine, const char *input);

/**
* Returns a new query generator for the given virtual machine.
* Returns a new query generator for the given virtual machine. Null pointer returned
* if string is not valid UTF-8.
*
* # Safety
*
* Caller must satisfy the following preconditions for this function:
*
* * Valid [`Machine`] pointer created with [`machine_new`] that has not yet been freed.
* * the input fulfill the safety requirements of [`CStr::From_ptr`].
* * the input fulfill the safety requirements of [`CStr::from_ptr`].
* * There must be no other [`QueryState`] for this [`Machine`] started by
* [`run_query_iter`] that has not yet been freed with
* [`query_state_free`] or the [`Machine`] state will enter an undefined
* configuration with unpredictable results.
*
* Other concerns:
* * after invoking this function, calling any other function besides [`run_query_next`]
* before invoking [`query_state_free`] on the [`Machine`] pointer and [`QueryState`] pointer
* before invoking [`query_state_free`] on the [`QueryState`] pointer
* will leave the [`Machine`] in an undefined state
*
*/
struct QueryState *scryer_run_query_iter(struct Machine *machine, const char *input);

/**
* Returns a NULL POINTER if no addition iterations, else returns a
* JSON encoded UTF-8 string with one iteration of results from a Scryer Prolog query.
* UTF-8 encoded JSON string with one iteration of results from a Scryer Prolog query.
*
* See documentation for known limitations (e.g., concrete goals only).
*
Expand Down
4 changes: 4 additions & 0 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(not(target_arch = "wasm32"))]
pub mod shared_library;
#[cfg(target_arch = "wasm32")]
pub mod wasm;
Loading

0 comments on commit 4768c01

Please sign in to comment.