Skip to content

Commit

Permalink
fix file structure, fix cbindgen.toml, cargofmt, fix docs
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 f7c0cda commit 464a6b5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ usize_is_size_t = true


[export]
include = ["src/lib/machine/lib.rs"]
exclude = ["BTERM", "DELIMITER", "LTERM", "MAX_ARITY", "NEGATIVE_SIGN", "TERM"] # Exclude the definitions from the generated file
# prefix = "CAPI_"
include = []
exclude = ["BTERM", "DELIMITER", "LTERM", "NEGATIVE_SIGN", "TERM"] # Exclude the definitions from the generated file
prefix = "SCRYER_"
item_types = []
renaming_overrides_prefixing = false

Expand Down
20 changes: 11 additions & 9 deletions docs/shared_library/libscryer_prolog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@



typedef struct Machine Machine;
#define SCRYER_MAX_ARITY 1023

typedef struct QueryState QueryState;
typedef struct SCRYER_Machine SCRYER_Machine;

typedef struct SCRYER_QueryState SCRYER_QueryState;

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -42,7 +44,7 @@ extern "C" {
* * `input` - A pointer to a null-terminated UTF-8 string representing Scryer Prolog code.
*
*/
void scryer_consult_module_string(struct Machine *machine,
void scryer_consult_module_string(struct SCRYER_Machine *machine,
const char *module_name,
const char *input);

Expand All @@ -68,7 +70,7 @@ void scryer_free_c_string(char *ptr);
* not be deallocated until the program terminates.
*
*/
void scryer_machine_free(struct Machine *ptr);
void scryer_machine_free(struct SCRYER_Machine *ptr);

/**
* Create a new instance of the Scryer Machine.
Expand All @@ -79,7 +81,7 @@ void scryer_machine_free(struct Machine *ptr);
* resources. Failure to do so may lead to memory leaks.
*
*/
struct Machine *scryer_machine_new(void);
struct SCRYER_Machine *scryer_machine_new(void);

/**
* Cleans up the [`QueryState`] in the associated Scryer [`Machine`].
Expand All @@ -93,7 +95,7 @@ struct Machine *scryer_machine_new(void);
* [`query_state_free`] or the [`Machine`] state will enter an undefined
* configuration with unpredictable results.
*/
void scryer_query_state_free(struct QueryState *query_state);
void scryer_query_state_free(struct SCRYER_QueryState *query_state);

/**
* Greedily evaluate a prolog query, returning all results in a JSON-formatted string.
Expand Down Expand Up @@ -132,7 +134,7 @@ void scryer_query_state_free(struct QueryState *query_state);
* "result": boolean
* }
*/
char *scryer_run_query(struct Machine *machine, const char *input);
char *scryer_run_query(struct SCRYER_Machine *machine, const char *input);

/**
* Returns a new query generator for the given virtual machine. Null pointer returned
Expand All @@ -155,7 +157,7 @@ char *scryer_run_query(struct Machine *machine, const char *input);
* will leave the [`Machine`] in an undefined state
*
*/
struct QueryState *scryer_run_query_iter(struct Machine *machine, const char *input);
struct SCRYER_QueryState *scryer_run_query_iter(struct SCRYER_Machine *machine, const char *input);

/**
* Returns a NULL POINTER if no addition iterations, else returns a
Expand All @@ -172,7 +174,7 @@ struct QueryState *scryer_run_query_iter(struct Machine *machine, const char *in
* [`query_state_free`] or the [`Machine`] state will enter an undefined
* configuration with unpredictable results.
*/
char *scryer_run_query_next(struct QueryState *query_state);
char *scryer_run_query_next(struct SCRYER_QueryState *query_state);

#ifdef __cplusplus
} // extern "C"
Expand Down
5 changes: 4 additions & 1 deletion docs/shared_library/scryer_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PanicResult(TypedDict):
# replace 'release' with 'debug' if you are developing the bindings
# compile the code with `cargo build --lib` for 'debug'
# compile the code with `cargo build --release` for speed in production.
shared_library_path = os.path.join(install_location, 'target', 'release', shared_library_name)
shared_library_path = os.path.join(install_location, 'target', 'debug', shared_library_name)

########################
## LOW LEVEL BINDINGS ##
Expand Down Expand Up @@ -354,6 +354,7 @@ def eval(self, query: str):

if __name__ == '__main__':


with ScryerMachine(":- use_module(library(dif)). "
":- use_module(library(lists)).") as wam:
with wam.lazy_eval_context('member(X, [a,"a",f(a),"f(a)",Y,"Y", true, "true", false, "false"]).') as query:
Expand All @@ -366,6 +367,7 @@ def eval(self, query: str):
# # {'X': 'f(a)'}
# # {'Y': 'X'}
# # {'X': 'Y'}
# # {'X': '_150', 'Y': '_180'}

with ScryerMachine("""
:- use_module(library(dcgs)).
Expand Down Expand Up @@ -421,3 +423,4 @@ def eval(self, query: str):
# 2 0 {'Fact': 0} {'As': 'aa'}
# 2 1 {'Fact': 1} {'As': 'aa'}
# 2 2 {'Fact': 2} {'As': 'aa'}

2 changes: 1 addition & 1 deletion src/ffi/shared_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub unsafe extern "C" fn run_query_iter(
let query_state = machine.run_query_iter(string);
Box::into_raw(Box::new(query_state))
}
Err(err) => std::ptr::null_mut(),
Err(_) => std::ptr::null_mut(),
}
}

Expand Down
1 change: 0 additions & 1 deletion src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod mock_wam;
pub mod parsed_results;
pub mod partial_string;
pub mod preprocessor;
pub mod shared_library;
pub mod stack;
pub mod streams;
pub mod system_calls;
Expand Down
9 changes: 6 additions & 3 deletions src/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use num_order::NumOrd;

use crate::arena::*;
use crate::atom_table::*;
#[cfg(feature = "ffi")]
use crate::machine::ffi::*;
use crate::forms::*;
use crate::heap_iter::*;
use crate::heap_print::*;
Expand All @@ -19,6 +17,8 @@ use crate::instructions::*;
use crate::machine;
use crate::machine::code_walker::*;
use crate::machine::copier::*;
#[cfg(feature = "ffi")]
use crate::machine::ffi::*;
use crate::machine::heap::*;
use crate::machine::machine_errors::*;
use crate::machine::machine_indices::*;
Expand Down Expand Up @@ -4745,7 +4745,10 @@ impl Machine {
let return_value = self.deref_register(3);
if let Some(function_name) = self.machine_st.value_to_str_like(function_name) {
let stub_gen = || functor_stub(atom!("foreign_call"), 3);
fn map_arg(machine_st: &mut MachineState, source: HeapCellValue) -> crate::machine::ffi::Value {
fn map_arg(
machine_st: &mut MachineState,
source: HeapCellValue,
) -> crate::machine::ffi::Value {
match Number::try_from(source) {
Ok(Number::Fixnum(n)) => Value::Int(n.get_num()),
Ok(Number::Float(n)) => Value::Float(n.into_inner()),
Expand Down

0 comments on commit 464a6b5

Please sign in to comment.