Skip to content

Commit 49b30e9

Browse files
authored
Merge branch 'mthom:master' into patch-5
2 parents e40125f + a69303d commit 49b30e9

File tree

10 files changed

+204
-255
lines changed

10 files changed

+204
-255
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ hostname = ["dep:hostname"]
2424
tls = ["dep:native-tls"]
2525
http = ["dep:warp", "dep:reqwest"]
2626
crypto-full = []
27-
"rust-version-1.80" = []
2827

2928
[build-dependencies]
3029
indexmap = "2.3.0"

src/lib/clpz.pl

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5088,19 +5088,45 @@
50885088
; nonvar(Z), nonvar(X) ->
50895089
( Z > 0 ->
50905090
( X < 0 -> true
5091-
; X >= Z
5091+
; X >= Z,
5092+
% due to X = Z+Y*_ and Y > Z
5093+
( X-Z > 0 ->
5094+
X-Z > Z
5095+
; true
5096+
)
50925097
)
50935098
; Z < 0 ->
50945099
( X > 0 -> true
5095-
; X =< Z
5100+
; X =< Z,
5101+
% due to X = Z+Y*_ and Y < Z
5102+
( X-Z < 0 ->
5103+
X-Z < Z
5104+
; true
5105+
)
50965106
)
50975107
; Z =:= 0 % Multiple solutions so do nothing special.
50985108
),
50995109
( { fd_get(Y, _, _, n(YU), _),
51005110
YU < X, X =< 0 } -> kill(MState), Z =:= X
51015111
; { fd_get(Y, _, n(YL), _, _),
51025112
YL > X, X >= 0 } -> kill(MState), Z =:= X
5103-
; ( Z > 0 ->
5113+
; ( Z > 0, X < 0 ->
5114+
{ fd_get(Y, YD, YPs),
5115+
YMin is Z+1,
5116+
YMax is Z-X,
5117+
domain_remove_smaller_than(YD, YMin, YD1),
5118+
domain_remove_greater_than(YD1, YMax, YD2) },
5119+
fd_put(Y, YD2, YPs)
5120+
% queue_goal((Y #> Z, Y #=< Z-X))
5121+
; Z < 0, X > 0 ->
5122+
{ fd_get(Y, YD, YPs),
5123+
YMax is Z-1,
5124+
YMin is Z-X,
5125+
domain_remove_greater_than(YD, YMax, YD1),
5126+
domain_remove_smaller_than(YD1, YMin, YD2) },
5127+
fd_put(Y, YD2, YPs)
5128+
% queue_goal((Y #< Z, Y #>= Z-X))
5129+
; Z > 0 ->
51045130
{ fd_get(Y, YD, YPs),
51055131
YMin is Z + 1,
51065132
domain_remove_smaller_than(YD, YMin, YD1) },
@@ -5112,7 +5138,16 @@
51125138
domain_remove_greater_than(YD, YMax, YD1) },
51135139
fd_put(Y, YD1, YPs)
51145140
% queue_goal(Y #< Z)
5115-
; true
5141+
; Z =:= 0,
5142+
( X =:= 0 ->
5143+
kill(MState) % trivial
5144+
; % only 4 solutions {-abs(X),-1,1,abs(X)}
5145+
{ YL is -abs(X), YU is abs(X),
5146+
fd_get(Y, YD0, YPs),
5147+
domain_remove_smaller_than(YD0, YL, YD1),
5148+
domain_remove_greater_than(YD1, YU, YD) },
5149+
fd_put(Y, YD, YPs)
5150+
)
51165151
)
51175152
)
51185153
; run_propagator(pmodz(X,Y,Z), MState),

src/lib/dcgs.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
[op(1105, xfy, '|'),
1313
phrase/2,
1414
phrase/3,
15-
phrase/4,
16-
phrase/5,
15+
phrase//2,
16+
phrase//3,
1717
seq//1,
1818
seqq//1,
1919
... //0,
@@ -29,9 +29,9 @@
2929

3030
:- meta_predicate phrase(2, ?, ?).
3131

32-
:- meta_predicate phrase(2, ?, ?, ?).
32+
:- meta_predicate(phrase(3, ?, ?, ?)).
3333

34-
:- meta_predicate phrase(2, ?, ?, ?, ?).
34+
:- meta_predicate(phrase(4, ?, ?, ?, ?)).
3535

3636
:- meta_predicate(','(2, 2, ?, ?)).
3737

src/lib/ops_and_meta_predicates.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
:- op(200, xfy, ^).
2727
:- op(500, yfx, /\).
2828
:- op(500, yfx, \/).
29-
:- op(500, yfx, xor).
3029
:- op(400, yfx, div).
3130
:- op(400, yfx, //).
3231
:- op(400, yfx, rdiv).

src/machine/mod.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,32 +118,6 @@ fn current_dir() -> PathBuf {
118118
}
119119
}
120120

121-
#[cfg(not(feature = "rust-version-1.80"))]
122-
mod libraries {
123-
use indexmap::IndexMap;
124-
use std::sync::OnceLock;
125-
126-
fn libraries() -> &'static IndexMap<&'static str, &'static str> {
127-
static LIBRARIES: OnceLock<IndexMap<&'static str, &'static str>> = OnceLock::new();
128-
LIBRARIES.get_or_init(|| {
129-
let mut m = IndexMap::new();
130-
131-
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
132-
133-
m
134-
})
135-
}
136-
137-
pub(crate) fn contains(name: &str) -> bool {
138-
libraries().contains_key(name)
139-
}
140-
141-
pub(crate) fn get(name: &str) -> Option<&'static str> {
142-
libraries().get(name).copied()
143-
}
144-
}
145-
146-
#[cfg(feature = "rust-version-1.80")]
147121
mod libraries {
148122
use indexmap::IndexMap;
149123
use std::sync::LazyLock;

src/machine/system_calls.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -911,27 +911,16 @@ impl MachineState {
911911
use crate::parser::lexer::*;
912912

913913
let nx = self.store(self.deref(self.registers[2]));
914-
let add_dot = !string.ends_with('.');
915-
let cursor = std::io::Cursor::new(string);
916-
917-
let iter = std::io::Read::chain(cursor, {
918-
let mut dot_buf: [u8; '.'.len_utf8()] = [0u8];
919-
920-
if add_dot {
921-
'.'.encode_utf8(&mut dot_buf);
922-
}
923-
924-
std::io::Cursor::new(dot_buf)
925-
});
914+
let iter = std::io::Cursor::new(string);
926915

927916
let mut lexer = Lexer::new(CharReader::new(iter), self);
928917
let mut tokens = vec![];
929918

930-
match lexer.next_token() {
919+
match lexer.next_number_token() {
931920
Ok(token @ Token::Literal(Literal::Atom(atom!("-")) | Literal::Char('-'))) => {
932921
tokens.push(token);
933922

934-
if let Ok(token) = lexer.next_token() {
923+
if let Ok(token) = lexer.next_number_token() {
935924
tokens.push(token);
936925
}
937926
}
@@ -979,9 +968,6 @@ impl MachineState {
979968

980969
break;
981970
}
982-
Ok('.') => {
983-
lexer.skip_char('.');
984-
}
985971
Ok(c) => {
986972
let (line_num, col_num) = (lexer.line_num, lexer.col_num);
987973

src/parser/ast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ pub enum ParserError {
432432
BackQuotedString(usize, usize),
433433
IO(IOError),
434434
IncompleteReduction(usize, usize),
435+
InfiniteFloat(usize, usize),
435436
InvalidSingleQuotedCharacter(char),
436437
LexicalError(lexical::Error),
437438
MissingQuote(usize, usize),
@@ -447,6 +448,7 @@ impl ParserError {
447448
match self {
448449
&ParserError::BackQuotedString(line_num, col_num)
449450
| &ParserError::IncompleteReduction(line_num, col_num)
451+
| &ParserError::InfiniteFloat(line_num, col_num)
450452
| &ParserError::MissingQuote(line_num, col_num)
451453
| &ParserError::NonPrologChar(line_num, col_num)
452454
| &ParserError::ParseBigInt(line_num, col_num)
@@ -463,6 +465,9 @@ impl ParserError {
463465
ParserError::InvalidSingleQuotedCharacter(..) => {
464466
atom!("invalid_single_quoted_character")
465467
}
468+
ParserError::InfiniteFloat(..) => {
469+
atom!("infinite_float")
470+
}
466471
ParserError::IO(e) if e.kind() == ErrorKind::UnexpectedEof => {
467472
atom!("unexpected_end_of_file")
468473
}

0 commit comments

Comments
 (0)