From: Mark Thom Date: Sat, 29 Feb 2020 04:42:22 +0000 (-0700) Subject: allow set_prolog_flag in declarations X-Git-Tag: v0.8.119~67 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=aa5f186a9627923b3b27b94e704dc6a260f5702b;p=scryer-prolog.git allow set_prolog_flag in declarations --- diff --git a/Cargo.lock b/Cargo.lock index fd3edc80..394f4511 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -316,7 +316,7 @@ dependencies = [ [[package]] name = "prolog_parser" -version = "0.8.41" +version = "0.8.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lexical 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -453,7 +453,7 @@ dependencies = [ "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-rug-adapter 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "prolog_parser 0.8.41 (registry+https://github.com/rust-lang/crates.io-index)", + "prolog_parser 0.8.42 (registry+https://github.com/rust-lang/crates.io-index)", "ref_thread_local 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rug 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustyline 5.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -614,7 +614,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "443c53b3c3531dfcbfa499d8893944db78474ad7a1d87fa2d94d1a2231693ac6" "checksum ordered-float 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7eb5259643245d3f292c7a146b2df53bba24d7eab159410e648eb73dc164669d" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum prolog_parser 0.8.41 (registry+https://github.com/rust-lang/crates.io-index)" = "92be83a8004ae2c476b4257722e86f7df25fba80027e3c9e2e0d57ff2edc0023" +"checksum prolog_parser 0.8.42 (registry+https://github.com/rust-lang/crates.io-index)" = "6e1dc25ecbd80bc9a1636b3c863ae95355b340cf2959f94fe8faeff13c4ad078" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" diff --git a/Cargo.toml b/Cargo.toml index f41007ec..85b7c9dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ libc = "0.2.62" nix = "0.15.0" num-rug-adapter = { optional = true, version = "0.1.1" } ordered-float = "0.5.0" -prolog_parser = { version = "0.8.41", default-features = false } +prolog_parser = { version = "0.8.42", default-features = false } ref_thread_local = "0.0.0" rug = { version = "1.4.0", optional = true } rustyline = "5.0.3" diff --git a/src/prolog/forms.rs b/src/prolog/forms.rs index 9897d9ce..9c402bd2 100644 --- a/src/prolog/forms.rs +++ b/src/prolog/forms.rs @@ -394,6 +394,7 @@ pub enum Declaration { MultiFile(MultiFileIndicator), NonCountedBacktracking(ClauseName, usize), // name, arity Op(OpDecl), + SetPrologFlag(DoubleQuotes), UseModule(ModuleSource), UseQualifiedModule(ModuleSource, Vec), } diff --git a/src/prolog/machine/compile.rs b/src/prolog/machine/compile.rs index ffa6d517..f13cb9bb 100644 --- a/src/prolog/machine/compile.rs +++ b/src/prolog/machine/compile.rs @@ -968,6 +968,10 @@ impl ListingCompiler { Declaration::Op(op_decl) => { self.submit_op(wam, indices, &op_decl) } + Declaration::SetPrologFlag(dbl_quotes) => { + wam.machine_st.flags.double_quotes = dbl_quotes; + Ok(()) + } Declaration::UseModule(ModuleSource::Library(name)) => { let name = if !wam.indices.modules.contains_key(&name) { load_library(wam, name, true)? diff --git a/src/prolog/machine/toplevel.rs b/src/prolog/machine/toplevel.rs index 3078beca..9b685b76 100644 --- a/src/prolog/machine/toplevel.rs +++ b/src/prolog/machine/toplevel.rs @@ -339,6 +339,32 @@ fn setup_use_module_decl(mut terms: Vec>) -> Result>) -> Result { + let dbl_quotes = *terms.pop().unwrap(); + + match terms[0].as_ref() { + Term::Constant(_, Constant::Atom(ref name, _)) + if name.as_str() == "double_quotes" => { + match dbl_quotes { + Term::Constant(_, Constant::Atom(name, _)) => { + match name.as_str() { + "atom" => Ok(DoubleQuotes::Atom), + "chars" => Ok(DoubleQuotes::Chars), + "codes" => Ok(DoubleQuotes::Codes), + _ => Err(ParserError::InvalidDoubleQuotesDecl), + } + } + _ => { + Err(ParserError::InvalidDoubleQuotesDecl) + } + } + }, + _ => { + Err(ParserError::InvalidDoubleQuotesDecl) + } + } +} + type UseModuleExport = (ModuleSource, Vec); fn setup_qualified_import( @@ -620,6 +646,9 @@ fn setup_declaration<'a, 'b, 'c, R: Read>( let (name, arity) = setup_predicate_indicator(&mut *terms.pop().unwrap())?; Ok(Declaration::NonCountedBacktracking(name, arity)) } + ("set_prolog_flag", 2) => { + Ok(Declaration::SetPrologFlag(setup_double_quotes(terms)?)) + } ("multifile", 1) => { let mut term = *terms.pop().unwrap();