Merge pull request #2523 from bakaq/visibility
Be conservative with visibility
This commit is contained in:
@@ -5,7 +5,7 @@ mod setup;
|
||||
mod iai {
|
||||
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
|
||||
|
||||
use scryer_prolog::machine::parsed_results::QueryResolution;
|
||||
use scryer_prolog::QueryResolution;
|
||||
|
||||
use super::setup;
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use std::{collections::BTreeMap, fs, path::Path};
|
||||
|
||||
use maplit::btreemap;
|
||||
use scryer_prolog::machine::{
|
||||
parsed_results::{QueryResolution, Value},
|
||||
Machine,
|
||||
};
|
||||
use scryer_prolog::{Machine, QueryResolution, Value};
|
||||
|
||||
pub fn prolog_benches() -> BTreeMap<&'static str, PrologBenchmark> {
|
||||
[
|
||||
@@ -88,7 +85,7 @@ mod test {
|
||||
#[test]
|
||||
fn validate_benchmarks() {
|
||||
use super::prolog_benches;
|
||||
use scryer_prolog::machine::parsed_results::{QueryMatch, QueryResolution};
|
||||
use scryer_prolog::{QueryMatch, QueryResolution};
|
||||
use std::{fmt::Write, fs};
|
||||
|
||||
struct BenchResult {
|
||||
|
||||
@@ -137,7 +137,7 @@ enum InlinedClauseType {
|
||||
#[allow(dead_code)]
|
||||
#[derive(ToDeriveInput, EnumDiscriminants)]
|
||||
#[strum_discriminants(derive(EnumProperty, EnumString))]
|
||||
enum REPLCodePtr {
|
||||
enum ReplCodePtr {
|
||||
#[strum_discriminants(strum(props(Arity = "4", Name = "$add_discontiguous_predicate")))]
|
||||
AddDiscontiguousPredicate,
|
||||
#[strum_discriminants(strum(props(Arity = "4", Name = "$add_dynamic_predicate")))]
|
||||
@@ -534,7 +534,7 @@ enum SystemClauseType {
|
||||
#[strum_discriminants(strum(props(Arity = "2", Name = "$shell")))]
|
||||
Shell,
|
||||
#[strum_discriminants(strum(props(Arity = "1", Name = "$pid")))]
|
||||
PID,
|
||||
Pid,
|
||||
#[strum_discriminants(strum(props(Arity = "4", Name = "$chars_base64")))]
|
||||
CharsBase64,
|
||||
#[strum_discriminants(strum(props(Arity = "1", Name = "$devour_whitespace")))]
|
||||
@@ -608,7 +608,7 @@ enum SystemClauseType {
|
||||
InferenceLimitExceeded,
|
||||
#[strum_discriminants(strum(props(Arity = "1", Name = "$argv")))]
|
||||
Argv,
|
||||
REPL(REPLCodePtr),
|
||||
Repl(ReplCodePtr),
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -811,7 +811,7 @@ fn derive_input(ty: &Type) -> Option<DeriveInput> {
|
||||
let system_clause_type: Type = parse_quote! { SystemClauseType };
|
||||
let compare_term_type: Type = parse_quote! { CompareTerm };
|
||||
let compare_number_type: Type = parse_quote! { CompareNumber };
|
||||
let repl_code_ptr_type: Type = parse_quote! { REPLCodePtr };
|
||||
let repl_code_ptr_type: Type = parse_quote! { ReplCodePtr };
|
||||
|
||||
if ty == &clause_type {
|
||||
Some(ClauseType::to_derive_input())
|
||||
@@ -826,7 +826,7 @@ fn derive_input(ty: &Type) -> Option<DeriveInput> {
|
||||
} else if ty == &compare_term_type {
|
||||
Some(CompareTerm::to_derive_input())
|
||||
} else if ty == &repl_code_ptr_type {
|
||||
Some(REPLCodePtr::to_derive_input())
|
||||
Some(ReplCodePtr::to_derive_input())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -983,6 +983,7 @@ fn generate_instruction_preface() -> TokenStream {
|
||||
}
|
||||
|
||||
/// `IndexingInstruction` cf. page 110 of wambook.
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum IndexingInstruction {
|
||||
// The first index is the optimal argument being indexed.
|
||||
@@ -1867,7 +1868,7 @@ fn generate_instruction_preface() -> TokenStream {
|
||||
&Instruction::CallSetEnv |
|
||||
&Instruction::CallUnsetEnv |
|
||||
&Instruction::CallShell |
|
||||
&Instruction::CallPID |
|
||||
&Instruction::CallPid |
|
||||
&Instruction::CallCharsBase64 |
|
||||
&Instruction::CallDevourWhitespace |
|
||||
&Instruction::CallIsSTOEnabled |
|
||||
@@ -2104,7 +2105,7 @@ fn generate_instruction_preface() -> TokenStream {
|
||||
&Instruction::ExecuteSetEnv |
|
||||
&Instruction::ExecuteUnsetEnv |
|
||||
&Instruction::ExecuteShell |
|
||||
&Instruction::ExecutePID |
|
||||
&Instruction::ExecutePid |
|
||||
&Instruction::ExecuteCharsBase64 |
|
||||
&Instruction::ExecuteDevourWhitespace |
|
||||
&Instruction::ExecuteIsSTOEnabled |
|
||||
@@ -2357,7 +2358,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
let builtin_type_variants = attributeless_enum::<BuiltInClauseType>();
|
||||
let inlined_type_variants = attributeless_enum::<InlinedClauseType>();
|
||||
let system_clause_type_variants = attributeless_enum::<SystemClauseType>();
|
||||
let repl_code_ptr_variants = attributeless_enum::<REPLCodePtr>();
|
||||
let repl_code_ptr_variants = attributeless_enum::<ReplCodePtr>();
|
||||
let compare_number_variants = attributeless_enum::<CompareNumber>();
|
||||
let compare_term_variants = attributeless_enum::<CompareTerm>();
|
||||
|
||||
@@ -2708,14 +2709,14 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
|
||||
clause_type_from_name_and_arity_arms.push(if !variant_fields.is_empty() {
|
||||
quote! {
|
||||
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::REPL(
|
||||
REPLCodePtr::#ident(#(#variant_fields),*)
|
||||
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::Repl(
|
||||
ReplCodePtr::#ident(#(#variant_fields),*)
|
||||
))
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::REPL(
|
||||
REPLCodePtr::#ident
|
||||
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::Repl(
|
||||
ReplCodePtr::#ident
|
||||
))
|
||||
}
|
||||
});
|
||||
@@ -2723,13 +2724,13 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
clause_type_name_arms.push(if !variant_fields.is_empty() {
|
||||
quote! {
|
||||
ClauseType::System(
|
||||
SystemClauseType::REPL(REPLCodePtr::#ident(..))
|
||||
SystemClauseType::Repl(ReplCodePtr::#ident(..))
|
||||
) => atom!(#name)
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
ClauseType::System(
|
||||
SystemClauseType::REPL(REPLCodePtr::#ident)
|
||||
SystemClauseType::Repl(ReplCodePtr::#ident)
|
||||
) => atom!(#name)
|
||||
}
|
||||
});
|
||||
@@ -2743,14 +2744,14 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
|
||||
clause_type_to_instr_arms.push(if !variant_fields.is_empty() {
|
||||
quote! {
|
||||
ClauseType::System(SystemClauseType::REPL(
|
||||
REPLCodePtr::#ident(#(#placeholder_ids),*)
|
||||
ClauseType::System(SystemClauseType::Repl(
|
||||
ReplCodePtr::#ident(#(#placeholder_ids),*)
|
||||
)) => Instruction::#instr_ident(#(*#placeholder_ids),*)
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
ClauseType::System(SystemClauseType::REPL(
|
||||
REPLCodePtr::#ident
|
||||
ClauseType::System(SystemClauseType::Repl(
|
||||
ReplCodePtr::#ident
|
||||
)) => Instruction::#instr_ident
|
||||
}
|
||||
});
|
||||
@@ -3109,6 +3110,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
quote! {
|
||||
#preface_tokens
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum CompareTerm {
|
||||
#(
|
||||
@@ -3116,6 +3118,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
)*
|
||||
}
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum CompareNumber {
|
||||
#(
|
||||
@@ -3161,7 +3164,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum REPLCodePtr {
|
||||
pub enum ReplCodePtr {
|
||||
#(
|
||||
#repl_code_ptr_variants,
|
||||
)*
|
||||
@@ -3228,7 +3231,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_default(self) -> Instruction {
|
||||
pub fn into_default(self) -> Instruction {
|
||||
match self {
|
||||
#(
|
||||
#to_default_arms,
|
||||
@@ -3237,7 +3240,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_execute(self) -> Instruction {
|
||||
pub fn into_execute(self) -> Instruction {
|
||||
match self {
|
||||
#(
|
||||
#to_execute_arms,
|
||||
@@ -3252,6 +3255,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_ctrl_instr(&self) -> bool {
|
||||
matches!(self,
|
||||
Instruction::Allocate(_) |
|
||||
@@ -3262,6 +3266,7 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_query_instr(&self) -> bool {
|
||||
matches!(self,
|
||||
&Instruction::GetVariable(..) |
|
||||
@@ -3281,14 +3286,14 @@ pub fn generate_instructions_rs() -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! _instr {
|
||||
#(
|
||||
#instr_macro_arms
|
||||
);*
|
||||
}
|
||||
|
||||
pub use _instr as instr; // https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997
|
||||
// https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997
|
||||
pub(crate) use _instr as instr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3416,8 +3421,8 @@ impl InstructionData {
|
||||
);
|
||||
|
||||
(name, arity, CountableInference::NotCounted)
|
||||
} else if id == "REPLCodePtr" {
|
||||
let (name, arity) = add_discriminant_data::<REPLCodePtrDiscriminants>(
|
||||
} else if id == "ReplCodePtr" {
|
||||
let (name, arity) = add_discriminant_data::<ReplCodePtrDiscriminants>(
|
||||
&variant,
|
||||
prefix,
|
||||
&mut self.repl_code_ptr_variants,
|
||||
|
||||
@@ -156,15 +156,12 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
|
||||
let static_strs: &Vec<_> = &visitor.static_strs.into_iter().collect();
|
||||
|
||||
quote! {
|
||||
use phf;
|
||||
|
||||
static STRINGS: [&str; #static_strs_len] = [
|
||||
#(
|
||||
#static_strs,
|
||||
)*
|
||||
];
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! atom {
|
||||
#((#static_strs) => { Atom { index: #indices_iter } };)*
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ use std::ptr::addr_of_mut;
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! arena_alloc {
|
||||
($e:expr, $arena:expr) => {{
|
||||
let result = $e;
|
||||
@@ -37,7 +36,6 @@ macro_rules! arena_alloc {
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! float_alloc {
|
||||
($e:expr, $arena:expr) => {{
|
||||
let result = $e;
|
||||
@@ -896,6 +894,8 @@ const_assert!(mem::size_of::<OrderedFloat<f64>>() == 8);
|
||||
mod tests {
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::arena::*;
|
||||
use crate::atom_table::*;
|
||||
use crate::machine::mock_wam::*;
|
||||
use crate::machine::partial_string::*;
|
||||
|
||||
|
||||
@@ -124,13 +124,6 @@ impl Hash for Atom {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_char {
|
||||
($s:expr) => {
|
||||
!$s.is_empty() && $s.chars().nth(1).is_none()
|
||||
};
|
||||
}
|
||||
|
||||
pub enum AtomString<'a> {
|
||||
Static(&'a str),
|
||||
Dynamic(AtomTableRef<str>),
|
||||
|
||||
@@ -1,27 +1,3 @@
|
||||
fn main() -> std::process::ExitCode {
|
||||
use scryer_prolog::atom_table::Atom;
|
||||
use scryer_prolog::*;
|
||||
|
||||
#[cfg(feature = "repl")]
|
||||
ctrlc::set_handler(move || {
|
||||
scryer_prolog::machine::INTERRUPT.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
runtime.block_on(async move {
|
||||
let mut wam = machine::Machine::new(Default::default());
|
||||
wam.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 0))
|
||||
})
|
||||
scryer_prolog::run_binary()
|
||||
}
|
||||
|
||||
@@ -8,11 +8,9 @@ use crate::instructions::*;
|
||||
use crate::iterators::*;
|
||||
use crate::parser::ast::*;
|
||||
use crate::targets::*;
|
||||
use crate::temp_v;
|
||||
use crate::types::*;
|
||||
use crate::variable_records::*;
|
||||
|
||||
use crate::instr;
|
||||
use crate::machine::disjuncts::*;
|
||||
use crate::machine::machine_errors::*;
|
||||
|
||||
@@ -559,14 +557,14 @@ impl<'b> CodeGenerator<'b> {
|
||||
match call_policy {
|
||||
CallPolicy::Default => {
|
||||
if self.marker.in_tail_position {
|
||||
code.push_back(call_instr.to_execute().to_default());
|
||||
code.push_back(call_instr.into_execute().into_default());
|
||||
} else {
|
||||
code.push_back(call_instr.to_default())
|
||||
code.push_back(call_instr.into_default())
|
||||
}
|
||||
}
|
||||
CallPolicy::Counted => {
|
||||
if self.marker.in_tail_position {
|
||||
code.push_back(call_instr.to_execute());
|
||||
code.push_back(call_instr.into_execute());
|
||||
} else {
|
||||
code.push_back(call_instr)
|
||||
}
|
||||
|
||||
11
src/forms.rs
11
src/forms.rs
@@ -159,17 +159,6 @@ impl ChunkedTermVec {
|
||||
.push_back(ChunkedTerms::Branch(Vec::with_capacity(capacity)));
|
||||
}
|
||||
|
||||
pub fn push_branch_arm(&mut self, branch: VecDeque<ChunkedTerms>) {
|
||||
match self.chunk_vec.back_mut().unwrap() {
|
||||
ChunkedTerms::Branch(branches) => {
|
||||
branches.push(branch);
|
||||
}
|
||||
ChunkedTerms::Chunk(_) => {
|
||||
self.chunk_vec.push_back(ChunkedTerms::Branch(vec![branch]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn add_chunk(&mut self) {
|
||||
self.chunk_vec
|
||||
|
||||
@@ -4,11 +4,6 @@ use crate::parser::ast::*;
|
||||
use crate::parser::dashu::base::RemEuclid;
|
||||
use crate::parser::dashu::integer::Sign;
|
||||
use crate::parser::dashu::{ibig, Integer, Rational};
|
||||
use crate::{
|
||||
alpha_numeric_char, capital_letter_char, cut_char, decimal_digit_char, graphic_token_char,
|
||||
semicolon_char, sign_char, single_quote_char, small_letter_char, solo_char,
|
||||
variable_indicator_char,
|
||||
};
|
||||
|
||||
use crate::forms::*;
|
||||
use crate::heap_iter::*;
|
||||
@@ -332,8 +327,6 @@ pub trait HCValueOutputter {
|
||||
fn new() -> Self;
|
||||
fn push_char(&mut self, c: char);
|
||||
fn append(&mut self, s: &str);
|
||||
fn begin_new_var(&mut self);
|
||||
fn insert(&mut self, index: usize, c: char);
|
||||
fn result(self) -> Self::Output;
|
||||
fn ends_with(&self, s: &str) -> bool;
|
||||
fn len(&self) -> usize;
|
||||
@@ -367,16 +360,6 @@ impl HCValueOutputter for PrinterOutputter {
|
||||
self.contents.push(c);
|
||||
}
|
||||
|
||||
fn begin_new_var(&mut self) {
|
||||
if !self.contents.is_empty() {
|
||||
self.contents += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
fn insert(&mut self, idx: usize, c: char) {
|
||||
self.contents.insert(idx, c);
|
||||
}
|
||||
|
||||
fn result(self) -> Self::Output {
|
||||
self.contents
|
||||
}
|
||||
@@ -501,7 +484,6 @@ pub struct HCPrinter<'a, Outputter> {
|
||||
pub numbervars: bool,
|
||||
pub quoted: bool,
|
||||
pub ignore_ops: bool,
|
||||
pub print_strings_as_strs: bool,
|
||||
pub max_depth: usize,
|
||||
pub double_quotes: bool,
|
||||
}
|
||||
@@ -566,7 +548,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
quoted: false,
|
||||
ignore_ops: false,
|
||||
var_names: IndexMap::new(),
|
||||
print_strings_as_strs: false,
|
||||
max_depth: 0,
|
||||
double_quotes: false,
|
||||
}
|
||||
|
||||
56
src/lib.rs
56
src/lib.rs
@@ -7,44 +7,48 @@ extern crate static_assertions;
|
||||
extern crate maplit;
|
||||
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
pub(crate) mod macros;
|
||||
#[macro_use]
|
||||
pub mod atom_table;
|
||||
pub(crate) mod atom_table;
|
||||
#[macro_use]
|
||||
pub mod arena;
|
||||
pub(crate) mod arena;
|
||||
#[macro_use]
|
||||
pub mod parser;
|
||||
pub(crate) mod parser;
|
||||
mod allocator;
|
||||
mod arithmetic;
|
||||
pub mod codegen;
|
||||
pub(crate) mod codegen;
|
||||
mod debray_allocator;
|
||||
#[cfg(feature = "ffi")]
|
||||
mod ffi;
|
||||
mod forms;
|
||||
mod heap_iter;
|
||||
pub mod heap_print;
|
||||
pub(crate) mod heap_print;
|
||||
#[cfg(feature = "http")]
|
||||
mod http;
|
||||
mod indexing;
|
||||
mod variable_records;
|
||||
#[macro_use]
|
||||
pub mod instructions {
|
||||
pub(crate) mod instructions {
|
||||
include!(concat!(env!("OUT_DIR"), "/instructions.rs"));
|
||||
}
|
||||
mod iterators;
|
||||
pub mod machine;
|
||||
pub(crate) mod machine;
|
||||
mod raw_block;
|
||||
pub mod read;
|
||||
pub(crate) mod read;
|
||||
#[cfg(feature = "repl")]
|
||||
mod repl_helper;
|
||||
mod targets;
|
||||
pub mod types;
|
||||
|
||||
use instructions::instr;
|
||||
pub(crate) mod types;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// Re-exports
|
||||
pub use machine::config::*;
|
||||
pub use machine::lib_machine::*;
|
||||
pub use machine::parsed_results::*;
|
||||
pub use machine::Machine;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[wasm_bindgen]
|
||||
pub fn eval_code(s: &str) -> String {
|
||||
@@ -56,3 +60,31 @@ pub fn eval_code(s: &str) -> String {
|
||||
let bytes = wam.test_load_string(s);
|
||||
String::from_utf8_lossy(&bytes).to_string()
|
||||
}
|
||||
|
||||
pub fn run_binary() -> std::process::ExitCode {
|
||||
use crate::atom_table::Atom;
|
||||
use crate::machine::{Machine, INTERRUPT};
|
||||
|
||||
#[cfg(feature = "repl")]
|
||||
ctrlc::set_handler(move || {
|
||||
INTERRUPT.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
runtime.block_on(async move {
|
||||
let mut wam = Machine::new(Default::default());
|
||||
wam.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 0))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ use crate::parser::ast::*;
|
||||
use crate::parser::dashu::{Integer, Rational};
|
||||
use crate::types::*;
|
||||
|
||||
use crate::fixnum;
|
||||
|
||||
use ordered_float::{Float, OrderedFloat};
|
||||
|
||||
use std::cmp;
|
||||
@@ -24,7 +22,6 @@ use std::convert::TryFrom;
|
||||
use std::f64;
|
||||
use std::mem;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! try_numeric_result {
|
||||
($e: expr, $stub_gen: expr) => {
|
||||
match $e {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::heap_iter::*;
|
||||
use crate::machine::*;
|
||||
use crate::parser::ast::*;
|
||||
use crate::temp_v;
|
||||
use crate::types::*;
|
||||
|
||||
use indexmap::IndexSet;
|
||||
|
||||
@@ -1194,11 +1194,8 @@ fn print_overwrite_warning(
|
||||
key: PredicateKey,
|
||||
is_dynamic: bool,
|
||||
) {
|
||||
if let CompilationTarget::Module(module_name) = compilation_target {
|
||||
match module_name {
|
||||
atom!("builtins") | atom!("loader") => return,
|
||||
_ => {}
|
||||
}
|
||||
if let CompilationTarget::Module(atom!("builtins") | atom!("loader")) = compilation_target {
|
||||
return;
|
||||
}
|
||||
|
||||
match code_ptr.tag() {
|
||||
|
||||
@@ -95,11 +95,6 @@ pub struct ChunkInfo {
|
||||
vars: Vec<VarInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BranchArm {
|
||||
pub arm_terms: Vec<QueryTerm>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BranchInfo {
|
||||
branch_num: BranchNumber,
|
||||
|
||||
@@ -7,8 +7,6 @@ use crate::machine::machine_state::*;
|
||||
use crate::machine::*;
|
||||
use crate::types::*;
|
||||
|
||||
use crate::try_numeric_result;
|
||||
|
||||
use fxhash::FxBuildHasher;
|
||||
|
||||
macro_rules! step_or_fail {
|
||||
@@ -4613,11 +4611,11 @@ impl Machine {
|
||||
self.shell();
|
||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||
}
|
||||
&Instruction::CallPID => {
|
||||
&Instruction::CallPid => {
|
||||
self.pid();
|
||||
step_or_fail!(self, self.machine_st.p += 1);
|
||||
}
|
||||
&Instruction::ExecutePID => {
|
||||
&Instruction::ExecutePid => {
|
||||
self.pid();
|
||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::atom_table::*;
|
||||
use crate::machine::heap::*;
|
||||
use crate::types::*;
|
||||
|
||||
@@ -211,7 +211,6 @@ impl PredicateQueue {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! predicate_queue {
|
||||
[$($v:expr),*] => (
|
||||
PredicateQueue {
|
||||
|
||||
@@ -572,15 +572,6 @@ impl MachineState {
|
||||
stub,
|
||||
)
|
||||
}
|
||||
SessionError::QueryCannotBeDefinedAsFact => {
|
||||
let error_atom = atom!("query_cannot_be_defined_as_fact");
|
||||
|
||||
self.permission_error(
|
||||
Permission::Create,
|
||||
atom!("static_procedure"),
|
||||
functor!(error_atom),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,9 +701,7 @@ impl MachineError {
|
||||
pub enum CompilationError {
|
||||
Arithmetic(ArithmeticError),
|
||||
ParserError(ParserError),
|
||||
CannotParseCyclicTerm,
|
||||
ExceededMaxArity,
|
||||
ExpectedRel,
|
||||
InadmissibleFact,
|
||||
InadmissibleQueryTerm,
|
||||
InvalidDirective(DirectiveError),
|
||||
@@ -722,7 +711,6 @@ pub enum CompilationError {
|
||||
InvalidRuleHead,
|
||||
InvalidUseModuleDecl,
|
||||
InvalidModuleResolution(Atom),
|
||||
UnreadableTerm,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -765,15 +753,9 @@ impl CompilationError {
|
||||
CompilationError::Arithmetic(..) => {
|
||||
functor!(atom!("arithmetic_error"))
|
||||
}
|
||||
CompilationError::CannotParseCyclicTerm => {
|
||||
functor!(atom!("cannot_parse_cyclic_term"))
|
||||
}
|
||||
CompilationError::ExceededMaxArity => {
|
||||
functor!(atom!("exceeded_max_arity"))
|
||||
}
|
||||
CompilationError::ExpectedRel => {
|
||||
functor!(atom!("expected_relation"))
|
||||
}
|
||||
CompilationError::InadmissibleFact => {
|
||||
// TODO: type_error(callable, _).
|
||||
functor!(atom!("inadmissible_fact"))
|
||||
@@ -806,9 +788,6 @@ impl CompilationError {
|
||||
CompilationError::ParserError(ref err) => {
|
||||
functor!(err.as_atom())
|
||||
}
|
||||
CompilationError::UnreadableTerm => {
|
||||
functor!(atom!("unreadable_term"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1063,7 +1042,6 @@ pub enum SessionError {
|
||||
NamelessEntry,
|
||||
OpIsInfixAndPostFix(Atom),
|
||||
PredicateNotMultifileOrDiscontiguous(CompilationTarget, PredicateKey),
|
||||
QueryCannotBeDefinedAsFact,
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for SessionError {
|
||||
|
||||
@@ -256,31 +256,16 @@ impl MachineState {
|
||||
unifier.unify_internal();
|
||||
}
|
||||
|
||||
pub fn unify_structure(&mut self, s1: usize, value: HeapCellValue) {
|
||||
let mut unifier = DefaultUnifier::from(self);
|
||||
unifier.unify_structure(s1, value);
|
||||
}
|
||||
|
||||
pub fn unify_atom(&mut self, atom: Atom, value: HeapCellValue) {
|
||||
let mut unifier = DefaultUnifier::from(self);
|
||||
unifier.unify_atom(atom, value);
|
||||
}
|
||||
|
||||
pub fn unify_list(&mut self, l1: usize, value: HeapCellValue) {
|
||||
let mut unifier = DefaultUnifier::from(self);
|
||||
unifier.unify_list(l1, value);
|
||||
}
|
||||
|
||||
pub fn unify_complete_string(&mut self, atom: Atom, value: HeapCellValue) {
|
||||
let mut unifier = DefaultUnifier::from(self);
|
||||
unifier.unify_complete_string(atom, value);
|
||||
}
|
||||
|
||||
pub fn unify_partial_string(&mut self, value_1: HeapCellValue, value_2: HeapCellValue) {
|
||||
let mut unifier = DefaultUnifier::from(self);
|
||||
unifier.unify_partial_string(value_1, value_2);
|
||||
}
|
||||
|
||||
pub fn unify_char(&mut self, c: char, value: HeapCellValue) {
|
||||
let mut unifier = DefaultUnifier::from(self);
|
||||
unifier.unify_char(c, value);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
pub use crate::arena::*;
|
||||
pub use crate::atom_table::*;
|
||||
use crate::heap_print::*;
|
||||
pub use crate::machine::heap::*;
|
||||
pub use crate::machine::machine_state::*;
|
||||
pub use crate::machine::stack::*;
|
||||
pub use crate::machine::streams::*;
|
||||
pub use crate::machine::*;
|
||||
pub use crate::parser::ast::*;
|
||||
@@ -23,9 +20,10 @@ use std::ops::{Deref, DerefMut, Index, IndexMut};
|
||||
pub struct MockWAM {
|
||||
pub machine_st: MachineState,
|
||||
pub op_dir: OpDir,
|
||||
pub flags: MachineFlags,
|
||||
//pub flags: MachineFlags,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl MockWAM {
|
||||
pub fn new() -> Self {
|
||||
let op_dir = default_op_dir();
|
||||
@@ -33,7 +31,7 @@ impl MockWAM {
|
||||
Self {
|
||||
machine_st: MachineState::new(),
|
||||
op_dir,
|
||||
flags: MachineFlags::default(),
|
||||
//flags: MachineFlags::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod args;
|
||||
#[macro_use]
|
||||
pub mod arithmetic_ops;
|
||||
pub mod attributed_variables;
|
||||
pub mod code_walker;
|
||||
@@ -250,7 +251,7 @@ pub(crate) fn get_structure_index(value: HeapCellValue) -> Option<CodeIndex> {
|
||||
|
||||
impl Machine {
|
||||
#[inline]
|
||||
pub fn prelude_view_and_machine_st(&mut self) -> (MachinePreludeView, &mut MachineState) {
|
||||
fn prelude_view_and_machine_st(&mut self) -> (MachinePreludeView, &mut MachineState) {
|
||||
(
|
||||
MachinePreludeView {
|
||||
indices: &mut self.indices,
|
||||
@@ -270,15 +271,7 @@ impl Machine {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) {
|
||||
let err = self.machine_st.session_error(err);
|
||||
let stub = functor_stub(key.0, key.1);
|
||||
let err = self.machine_st.error_form(err, stub);
|
||||
|
||||
self.machine_st.throw_exception(err);
|
||||
}
|
||||
|
||||
pub fn run_module_predicate(
|
||||
pub(crate) fn run_module_predicate(
|
||||
&mut self,
|
||||
module_name: Atom,
|
||||
key: PredicateKey,
|
||||
@@ -297,7 +290,7 @@ impl Machine {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
pub fn load_file(&mut self, path: &str, stream: Stream) {
|
||||
fn load_file(&mut self, path: &str, stream: Stream) {
|
||||
self.machine_st.registers[1] = stream_as_cell!(stream);
|
||||
self.machine_st.registers[2] =
|
||||
atom_as_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, path));
|
||||
@@ -357,15 +350,6 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_user_input(&mut self, input: String) {
|
||||
self.user_input = Stream::from_owned_string(input, &mut self.machine_st.arena);
|
||||
}
|
||||
|
||||
pub fn get_user_output(&self) -> String {
|
||||
let output_bytes: Vec<_> = self.user_output.bytes().map(|b| b.unwrap()).collect();
|
||||
String::from_utf8(output_bytes).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn configure_modules(&mut self) {
|
||||
fn update_call_n_indices(
|
||||
loader: &Module,
|
||||
|
||||
@@ -24,7 +24,7 @@ pub enum QueryResolution {
|
||||
Matches(Vec<QueryMatch>),
|
||||
}
|
||||
|
||||
pub fn write_prolog_value_as_json<W: Write>(
|
||||
fn write_prolog_value_as_json<W: Write>(
|
||||
writer: &mut W,
|
||||
value: &Value,
|
||||
) -> Result<(), std::fmt::Error> {
|
||||
|
||||
@@ -103,11 +103,6 @@ impl<'a> HeapPStrIter<'a> {
|
||||
self.focus.is_string_terminator(self.heap)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn num_steps(&self) -> usize {
|
||||
self.brent_st.num_steps()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn chars(mut self) -> PStrCharsIter<'a> {
|
||||
let item = self.next();
|
||||
@@ -218,8 +213,7 @@ impl<'a> HeapPStrIter<'a> {
|
||||
self.brent_st.hare = orig_hare;
|
||||
}
|
||||
|
||||
#[allow(clippy::inherent_to_string)]
|
||||
pub fn to_string(&mut self) -> String {
|
||||
pub fn to_string_mut(&mut self) -> String {
|
||||
let mut buf = String::with_capacity(32);
|
||||
|
||||
for iteratee in self.by_ref() {
|
||||
|
||||
@@ -528,11 +528,6 @@ impl From<TypedArenaPtr<ReadlineStream>> for Stream {
|
||||
}
|
||||
|
||||
impl Stream {
|
||||
#[inline]
|
||||
pub fn from_readline_stream(stream: ReadlineStream, arena: &mut Arena) -> Stream {
|
||||
Stream::Readline(arena_alloc!(StreamLayout::new(stream), arena))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_owned_string(string: String, arena: &mut Arena) -> Stream {
|
||||
Stream::Byte(arena_alloc!(
|
||||
|
||||
@@ -1040,7 +1040,7 @@ impl MachineState {
|
||||
self.heap.push(value);
|
||||
|
||||
let mut iter = HeapPStrIter::new(&self.heap, h);
|
||||
let string = iter.to_string();
|
||||
let string = iter.to_string_mut();
|
||||
let at_terminator = iter.at_string_terminator();
|
||||
|
||||
self.heap.pop();
|
||||
|
||||
@@ -7,8 +7,6 @@ use crate::parser::ast::*;
|
||||
use crate::parser::parser::*;
|
||||
use crate::read::devour_whitespace;
|
||||
|
||||
use crate::predicate_queue;
|
||||
|
||||
use fxhash::FxBuildHasher;
|
||||
use indexmap::IndexSet;
|
||||
|
||||
|
||||
@@ -144,7 +144,6 @@ macro_rules! stack_loc_as_cell {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! heap_loc_as_cell {
|
||||
($h:expr) => {
|
||||
HeapCellValue::build_with(HeapCellValueTag::Var, $h as u64)
|
||||
|
||||
@@ -26,6 +26,7 @@ pub type Specifier = u32;
|
||||
|
||||
pub const MAX_ARITY: usize = 1023;
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum OpDeclSpec {
|
||||
XFX = 0x0001,
|
||||
@@ -139,7 +140,6 @@ pub const BTERM: u32 = 0x11000;
|
||||
|
||||
pub const NEGATIVE_SIGN: u32 = 0x0200;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fixnum {
|
||||
($wrapper:tt, $n:expr, $arena:expr) => {
|
||||
Fixnum::build_with_checked($n)
|
||||
@@ -180,21 +180,12 @@ macro_rules! is_negate {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_prefix {
|
||||
($x:expr) => {
|
||||
$x as u32 & ($crate::parser::ast::FX as u32 | $crate::parser::ast::FY as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_postfix {
|
||||
($x:expr) => {
|
||||
$x as u32 & ($crate::parser::ast::XF as u32 | $crate::parser::ast::YF as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_infix {
|
||||
($x:expr) => {
|
||||
($x as u32
|
||||
@@ -205,48 +196,41 @@ macro_rules! is_infix {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_xfx {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::XFX as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_xfy {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::XFY as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_yfx {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::YFX as u32) != 0
|
||||
};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! is_yf {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::YF as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_xf {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::XF as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_fx {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::FX as u32) != 0
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! is_fy {
|
||||
($x:expr) => {
|
||||
($x as u32 & $crate::parser::ast::FY as u32) != 0
|
||||
@@ -317,20 +301,12 @@ impl Default for VarReg {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! temp_v {
|
||||
($x:expr) => {
|
||||
$crate::parser::ast::RegType::Temp($x)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! perm_v {
|
||||
($x:expr) => {
|
||||
$crate::parser::ast::RegType::Perm($x)
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum GenContext {
|
||||
Head,
|
||||
@@ -420,10 +396,6 @@ impl DoubleQuotes {
|
||||
matches!(self, DoubleQuotes::Chars)
|
||||
}
|
||||
|
||||
pub fn is_atom(self) -> bool {
|
||||
matches!(self, DoubleQuotes::Atom)
|
||||
}
|
||||
|
||||
pub fn is_codes(self) -> bool {
|
||||
matches!(self, DoubleQuotes::Codes)
|
||||
}
|
||||
@@ -437,20 +409,6 @@ pub enum Unknown {
|
||||
Warn,
|
||||
}
|
||||
|
||||
impl Unknown {
|
||||
pub fn is_error(self) -> bool {
|
||||
matches!(self, Unknown::Error)
|
||||
}
|
||||
|
||||
pub fn is_fail(self) -> bool {
|
||||
matches!(self, Unknown::Fail)
|
||||
}
|
||||
|
||||
pub fn is_warn(self) -> bool {
|
||||
matches!(self, Unknown::Warn)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_op_dir() -> OpDir {
|
||||
let mut op_dir = OpDir::with_hasher(FxBuildHasher::default());
|
||||
|
||||
@@ -468,6 +426,7 @@ pub enum ArithmeticError {
|
||||
UninstantiatedVar,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum ParserError {
|
||||
BackQuotedString(usize, usize),
|
||||
@@ -702,7 +661,7 @@ impl fmt::Display for Literal {
|
||||
}
|
||||
|
||||
impl Literal {
|
||||
pub fn to_atom(&self, atom_tbl: &Arc<AtomTable>) -> Option<Atom> {
|
||||
pub fn as_atom(&self, atom_tbl: &Arc<AtomTable>) -> Option<Atom> {
|
||||
match self {
|
||||
Literal::Atom(atom) => Some(atom.defrock_brackets(atom_tbl)),
|
||||
_ => None,
|
||||
@@ -796,14 +755,6 @@ impl From<&str> for Var {
|
||||
}
|
||||
|
||||
impl Var {
|
||||
#[inline(always)]
|
||||
pub fn as_str(&self) -> Option<&str> {
|
||||
match self {
|
||||
Var::Named(value) => Some(value),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::inherent_to_string)]
|
||||
#[inline(always)]
|
||||
pub fn to_string(&self) -> String {
|
||||
@@ -828,13 +779,6 @@ pub enum Term {
|
||||
}
|
||||
|
||||
impl Term {
|
||||
pub fn into_literal(self) -> Option<Literal> {
|
||||
match self {
|
||||
Term::Literal(_, c) => Some(c),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn first_arg(&self) -> Option<&Term> {
|
||||
match self {
|
||||
Term::Clause(_, _, ref terms) => terms.first(),
|
||||
@@ -842,15 +786,6 @@ impl Term {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, new_name: Atom) {
|
||||
match self {
|
||||
Term::Literal(_, Literal::Atom(ref mut atom)) | Term::Clause(_, ref mut atom, ..) => {
|
||||
*atom = new_name;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<Atom> {
|
||||
match self {
|
||||
&Term::Literal(_, Literal::Atom(ref atom)) | &Term::Clause(_, ref atom, ..) => {
|
||||
@@ -868,15 +803,6 @@ impl Term {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn source_arity(terms: &[Term]) -> usize {
|
||||
if let Some(Term::Literal(_, Literal::CodeIndex(_))) = terms.last() {
|
||||
return terms.len() - 1;
|
||||
}
|
||||
|
||||
terms.len()
|
||||
}
|
||||
|
||||
pub(crate) fn unfold_by_str_once(term: &mut Term, s: Atom) -> Option<(Term, Term)> {
|
||||
if let Term::Clause(_, ref name, ref mut subterms) = term {
|
||||
if let Some(Term::Literal(_, Literal::CodeIndex(_))) = subterms.last() {
|
||||
|
||||
@@ -52,11 +52,6 @@ impl<R> CharReader<R> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner(&self) -> &R {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_mut(&mut self) -> &mut R {
|
||||
&mut self.inner
|
||||
@@ -100,10 +95,6 @@ impl<R> CharReader<R> {
|
||||
&self.buf[self.pos..]
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> R {
|
||||
self.inner
|
||||
}
|
||||
|
||||
pub fn reset_buffer(&mut self) {
|
||||
self.buf.clear();
|
||||
self.pos = 0;
|
||||
|
||||
@@ -1,237 +1,204 @@
|
||||
#[macro_export]
|
||||
macro_rules! char_class {
|
||||
($c: expr, [$head:expr]) => ($c == $head);
|
||||
($c: expr, [$head:expr $(, $cs:expr)+]) => ($c == $head || $crate::char_class!($c, [$($cs),*]));
|
||||
($c: expr, [$head:expr $(, $cs:expr)+]) => ($c == $head || char_class!($c, [$($cs),*]));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! alpha_char {
|
||||
($c: expr) => {
|
||||
(!$c.is_numeric()
|
||||
&& !$c.is_whitespace()
|
||||
&& !$c.is_control()
|
||||
&& !$crate::graphic_token_char!($c)
|
||||
&& !$crate::layout_char!($c)
|
||||
&& !$crate::meta_char!($c)
|
||||
&& !$crate::solo_char!($c))
|
||||
&& !graphic_token_char!($c)
|
||||
&& !layout_char!($c)
|
||||
&& !meta_char!($c)
|
||||
&& !solo_char!($c))
|
||||
|| $c == '_'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! alpha_numeric_char {
|
||||
($c: expr) => {
|
||||
$crate::alpha_char!($c) || $c.is_numeric()
|
||||
alpha_char!($c) || $c.is_numeric()
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! backslash_char {
|
||||
($c: expr) => {
|
||||
$c == '\\'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! back_quote_char {
|
||||
($c: expr) => {
|
||||
$c == '`'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! octet_char {
|
||||
($c: expr) => {
|
||||
('\u{0000}'..='\u{00FF}').contains(&$c)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! capital_letter_char {
|
||||
($c: expr) => {
|
||||
$c.is_uppercase()
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! comment_1_char {
|
||||
($c: expr) => {
|
||||
$c == '/'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! comment_2_char {
|
||||
($c: expr) => {
|
||||
$c == '*'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! cut_char {
|
||||
($c: expr) => {
|
||||
$c == '!'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! decimal_digit_char {
|
||||
($c: expr) => {
|
||||
$c.is_ascii_digit()
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! decimal_point_char {
|
||||
($c: expr) => {
|
||||
$c == '.'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! double_quote_char {
|
||||
($c: expr) => {
|
||||
$c == '"'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! end_line_comment_char {
|
||||
($c: expr) => {
|
||||
$c == '%'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! exponent_char {
|
||||
($c: expr) => {
|
||||
$c == 'e' || $c == 'E'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! graphic_char {
|
||||
($c: expr) => ($crate::char_class!($c, ['#', '$', '&', '*', '+', '-', '.', '/', ':',
|
||||
($c: expr) => (char_class!($c, ['#', '$', '&', '*', '+', '-', '.', '/', ':',
|
||||
'<', '=', '>', '?', '@', '^', '~']))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! graphic_token_char {
|
||||
($c: expr) => {
|
||||
$crate::graphic_char!($c) || $crate::backslash_char!($c)
|
||||
graphic_char!($c) || backslash_char!($c)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! hexadecimal_digit_char {
|
||||
($c: expr) => {
|
||||
$c.is_ascii_digit() || ('A'..='F').contains(&$c) || ('a'..='f').contains(&$c)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! layout_char {
|
||||
($c: expr) => {
|
||||
$crate::char_class!($c, [' ', '\r', '\n', '\t', '\u{0B}', '\u{0C}'])
|
||||
char_class!($c, [' ', '\r', '\n', '\t', '\u{0B}', '\u{0C}'])
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! meta_char {
|
||||
($c: expr) => {
|
||||
$crate::char_class!($c, ['\\', '\'', '"', '`'])
|
||||
char_class!($c, ['\\', '\'', '"', '`'])
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! new_line_char {
|
||||
($c: expr) => {
|
||||
$c == '\n'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! octal_digit_char {
|
||||
($c: expr) => {
|
||||
('0'..='7').contains(&$c)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! binary_digit_char {
|
||||
($c: expr) => {
|
||||
$c == '0' || $c == '1'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! prolog_char {
|
||||
($c: expr) => {
|
||||
$crate::graphic_char!($c)
|
||||
|| $crate::alpha_numeric_char!($c)
|
||||
|| $crate::solo_char!($c)
|
||||
|| $crate::layout_char!($c)
|
||||
|| $crate::meta_char!($c)
|
||||
graphic_char!($c)
|
||||
|| alpha_numeric_char!($c)
|
||||
|| solo_char!($c)
|
||||
|| layout_char!($c)
|
||||
|| meta_char!($c)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! semicolon_char {
|
||||
($c: expr) => {
|
||||
$c == ';'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! sign_char {
|
||||
($c: expr) => {
|
||||
$c == '-' || $c == '+'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! single_quote_char {
|
||||
($c: expr) => {
|
||||
$c == '\''
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! small_letter_char {
|
||||
($c: expr) => {
|
||||
$c.is_alphabetic() && !$c.is_uppercase()
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! solo_char {
|
||||
($c: expr) => {
|
||||
$crate::char_class!($c, ['!', '(', ')', ',', ';', '[', ']', '{', '}', '|', '%'])
|
||||
char_class!($c, ['!', '(', ')', ',', ';', '[', ']', '{', '}', '|', '%'])
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! space_char {
|
||||
($c: expr) => {
|
||||
$c == ' '
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! symbolic_control_char {
|
||||
($c: expr) => {
|
||||
$crate::char_class!($c, ['a', 'b', 'f', 'n', 'r', 't', 'v', '0'])
|
||||
char_class!($c, ['a', 'b', 'f', 'n', 'r', 't', 'v', '0'])
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! symbolic_hexadecimal_char {
|
||||
($c: expr) => {
|
||||
$c == 'x'
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! variable_indicator_char {
|
||||
($c: expr) => {
|
||||
$c == '_'
|
||||
|
||||
@@ -180,31 +180,6 @@ pub fn get_op_desc(name: Atom, op_dir: &CompositeOpDir) -> Option<CompositeOpDes
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_clause_spec(name: Atom, arity: usize, op_dir: &CompositeOpDir) -> Option<OpDesc> {
|
||||
match arity {
|
||||
1 => {
|
||||
/* This is a clause with an operator principal functor. Prefix operators
|
||||
are supposed over post.
|
||||
*/
|
||||
if let Some(cell) = op_dir.get(name, Fixity::Pre) {
|
||||
return Some(cell);
|
||||
}
|
||||
|
||||
if let Some(cell) = op_dir.get(name, Fixity::Post) {
|
||||
return Some(cell);
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
if let Some(cell) = op_dir.get(name, Fixity::In) {
|
||||
return Some(cell);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn affirm_xfx(priority: usize, d2: TokenDesc, d3: TokenDesc, d1: TokenDesc) -> bool {
|
||||
d2.priority <= priority
|
||||
&& is_term!(d3.spec)
|
||||
@@ -341,16 +316,6 @@ impl<'a, R: CharRead> Parser<'a, R> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn line_num(&self) -> usize {
|
||||
self.lexer.line_num
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn col_num(&self) -> usize {
|
||||
self.lexer.col_num
|
||||
}
|
||||
|
||||
fn get_term_name(&mut self, td: TokenDesc) -> Option<Atom> {
|
||||
match td.tt {
|
||||
TokenType::HeadTailSeparator => Some(atom!("|")),
|
||||
|
||||
@@ -26,7 +26,7 @@ impl Expectable for &[u8] {
|
||||
/// Tests whether the file can be successfully loaded
|
||||
/// and produces the expected output during it
|
||||
pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) {
|
||||
use scryer_prolog::machine::mock_wam::*;
|
||||
use scryer_prolog::Machine;
|
||||
|
||||
let mut wam = Machine::with_test_streams();
|
||||
expected.assert_eq(wam.test_load_file(file).as_slice());
|
||||
|
||||
Reference in New Issue
Block a user