Skip to content

Commit

Permalink
Merge branch 'master' into library-use-case
Browse files Browse the repository at this point in the history
  • Loading branch information
lucksus committed Nov 2, 2023
2 parents 69a0725 + dfd9e43 commit ee1bd9e
Show file tree
Hide file tree
Showing 21 changed files with 788 additions and 550 deletions.
47 changes: 19 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ jobs:
fail-fast: false
matrix:
include:
- { os: windows-latest, rust-version: stable, target: 'x86_64-pc-windows-msvc'}
- { os: macos-11, rust-version: stable, target: 'x86_64-apple-darwin' }
- { os: ubuntu-22.04, rust-version: stable, target: 'x86_64-unknown-linux-gnu' }
- { os: ubuntu-20.04, rust-version: stable, target: 'x86_64-unknown-linux-gnu', extra: true }
- { os: ubuntu-20.04, rust-version: stable, target: 'i686-unknown-linux-gnu' }
- { os: ubuntu-20.04, rust-version: "1.70", target: 'x86_64-unknown-linux-gnu'}
- { os: ubuntu-20.04, rust-version: beta, target: 'x86_64-unknown-linux-gnu'}
- { os: ubuntu-20.04, rust-version: nightly, target: 'x86_64-unknown-linux-gnu'}
# operating systems
- { os: windows-latest, rust-version: stable, publish: true, target: 'x86_64-pc-windows-msvc'}
- { os: macos-11, rust-version: stable, publish: true, target: 'x86_64-apple-darwin' }
- { os: ubuntu-20.04, rust-version: stable, publish: true, target: 'x86_64-unknown-linux-gnu' }
# architectures
- { os: ubuntu-22.04, rust-version: stable, publish: true, target: 'x86_64-unknown-linux-gnu', extra: true }
- { os: ubuntu-22.04, rust-version: stable, publish: true, target: 'i686-unknown-linux-gnu' }
- { os: ubuntu-22.04, rust-version: nightly, publish: true, target: 'wasm32-unknown-unknown', args: '--no-default-features' }
# rust versions
- { os: ubuntu-22.04, rust-version: "1.70", target: 'x86_64-unknown-linux-gnu'}
- { os: ubuntu-22.04, rust-version: beta, target: 'x86_64-unknown-linux-gnu'}
- { os: ubuntu-22.04, rust-version: nightly, target: 'x86_64-unknown-linux-gnu'}
defaults:
run:
shell: bash
Expand Down Expand Up @@ -53,16 +57,13 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ matrix.os }}_${{ matrix.target }}_rustc-${{ steps.toolchain.outputs.cachekey }}_cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install wasm-pack
if: matrix.extra
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Build and test.
- name: Build library
run: cargo rustc --target ${{ matrix.target }} --verbose --lib -- -D warnings
run: cargo rustc --lib --target ${{ matrix.target }} ${{ matrix.args }} --verbose
- name: Test
if: "!matrix.extra"
run: cargo test --target ${{ matrix.target }} --all --verbose
run: cargo test --target ${{ matrix.target }} ${{ matrix.args }} --all --verbose || echo "::warning ::Tests failed"

# Extra steps only run once to avoid duplication, when matrix.extra is true
- name: Test and report
Expand Down Expand Up @@ -95,26 +96,16 @@ jobs:
# artifact. These binaries could be useful for testing the pipeline but
# are only retained by github for 90 days.
- name: Build release binary
if: contains(matrix.rust-version,'stable')
if: matrix.publish
run: |
cargo rustc --target ${{ matrix.target }} --verbose --bin scryer-prolog --release -- -D warnings
cargo rustc --target ${{ matrix.target }} ${{ matrix.args }} --verbose --bin scryer-prolog --release
echo "$PWD/target/release" >> $GITHUB_PATH
- name: Build wasm
if: matrix.extra
run: |
wasm-pack build --target web -- --no-default-features
- name: Publish release binary artifact
if: contains(matrix.rust-version,'stable')
if: matrix.publish
uses: actions/upload-artifact@v3
with:
path: target/${{ matrix.target }}/release/scryer-prolog*
name: scryer-prolog_${{ matrix.os }}_${{ matrix.target }}
- name: Publish wasm artifact
if: matrix.extra
uses: actions/upload-artifact@v3
with:
path: pkg/*
name: scryer-prolog_unknown_wasm32

logtalk-test:
# if: false # uncomment to disable job
Expand Down Expand Up @@ -176,7 +167,7 @@ jobs:
zip scryer-prolog_ubuntu-20.04.zip ./scryer-prolog_ubuntu-20.04_x86_64-unknown-linux-gnu/scryer-prolog
zip scryer-prolog_ubuntu-22.04.zip ./scryer-prolog_ubuntu-22.04_x86_64-unknown-linux-gnu/scryer-prolog
zip scryer-prolog_windows-latest.zip ./scryer-prolog_windows-latest_x86_64-pc-windows-msvc/scryer-prolog.exe
zip -r scryer-prolog_unknown-wasm32.zip ./scryer-prolog_unknown_wasm32
zip scryer-prolog_wasm32.zip ./scryer-prolog_ubuntu-22.04_wasm32-unknown-unknown/scryer-prolog.wasm
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand All @@ -185,4 +176,4 @@ jobs:
scryer-prolog_ubuntu-20.04.zip
scryer-prolog_ubuntu-22.04.zip
scryer-prolog_windows-latest.zip
scryer-prolog_unknown-wasm32.zip
scryer-prolog_wasm32.zip
41 changes: 6 additions & 35 deletions build/instructions_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ enum InstructionTemplate {
// cut instruction
#[strum_discriminants(strum(props(Arity = "1", Name = "cut")))]
Cut(RegType),
#[strum_discriminants(strum(props(Arity = "1", Name = "cut_prev")))]
CutPrev(RegType),
#[strum_discriminants(strum(props(Arity = "1", Name = "get_level")))]
GetLevel(RegType),
#[strum_discriminants(strum(props(Arity = "1", Name = "get_prev_level")))]
Expand Down Expand Up @@ -764,20 +766,6 @@ enum InstructionTemplate {
Neg(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "plus")))]
Plus(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "acosh")))]
ACosh(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "asinh")))]
ASinh(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "atanh")))]
ATanh(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "cosh")))]
Cosh(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "sinh")))]
Sinh(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "tanh")))]
Tanh(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "log10")))]
Log10(ArithmeticTerm, usize),
#[strum_discriminants(strum(props(Arity = "1", Name = "bitwise_complement")))]
BitwiseComplement(ArithmeticTerm, usize),
// control instructions
Expand Down Expand Up @@ -1347,6 +1335,10 @@ fn generate_instruction_preface() -> TokenStream {
let rt_stub = reg_type_into_functor(r);
functor!(atom!("cut"), [str(h, 0)], [rt_stub])
}
&Instruction::CutPrev(r) => {
let rt_stub = reg_type_into_functor(r);
functor!(atom!("cut_prev"), [str(h, 0)], [rt_stub])
}
&Instruction::GetLevel(r) => {
let rt_stub = reg_type_into_functor(r);
functor!(atom!("get_level"), [str(h, 0)], [rt_stub])
Expand Down Expand Up @@ -1449,30 +1441,9 @@ fn generate_instruction_preface() -> TokenStream {
&Instruction::ATan(ref at, t) => {
arith_instr_unary_functor(h, atom!("atan"), arena, at, t)
}
&Instruction::ACosh(ref at, t) => {
arith_instr_unary_functor(h, atom!("acosh"), arena, at, t)
}
&Instruction::ASinh(ref at, t) => {
arith_instr_unary_functor(h, atom!("asinh"), arena, at, t)
}
&Instruction::ATanh(ref at, t) => {
arith_instr_unary_functor(h, atom!("atanh"), arena, at, t)
}
&Instruction::Cosh(ref at, t) => {
arith_instr_unary_functor(h, atom!("cosh"), arena, at, t)
}
&Instruction::Sinh(ref at, t) => {
arith_instr_unary_functor(h, atom!("sinh"), arena, at, t)
}
&Instruction::Tanh(ref at, t) => {
arith_instr_unary_functor(h, atom!("tanh"), arena, at, t)
}
&Instruction::Sqrt(ref at, t) => {
arith_instr_unary_functor(h, atom!("sqrt"), arena, at, t)
}
&Instruction::Log10(ref at, t) => {
arith_instr_unary_functor(h, atom!("log10"), arena, at, t)
}
&Instruction::Abs(ref at, t) => {
arith_instr_unary_functor(h, atom!("abs"), arena, at, t)
}
Expand Down
Empty file added log.txt
Empty file.
7 changes: 0 additions & 7 deletions src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,6 @@ impl<'a> ArithmeticEvaluator<'a> {
atom!("sin") => Ok(Instruction::Sin(a1, t)),
atom!("tan") => Ok(Instruction::Tan(a1, t)),
atom!("log") => Ok(Instruction::Log(a1, t)),
atom!("asinh") => Ok(Instruction::ASinh(a1, t)),
atom!("acosh") => Ok(Instruction::ACosh(a1, t)),
atom!("atanh") => Ok(Instruction::ATanh(a1, t)),
atom!("sinh") => Ok(Instruction::Sinh(a1, t)),
atom!("cosh") => Ok(Instruction::Cosh(a1, t)),
atom!("tanh") => Ok(Instruction::Tanh(a1, t)),
atom!("log10") => Ok(Instruction::Log10(a1, t)),
atom!("exp") => Ok(Instruction::Exp(a1, t)),
atom!("sqrt") => Ok(Instruction::Sqrt(a1, t)),
atom!("acos") => Ok(Instruction::ACos(a1, t)),
Expand Down
9 changes: 7 additions & 2 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,15 @@ impl<'b> CodeGenerator<'b> {
code.push_back(instr!("proceed"));
}
}
&QueryTerm::LocalCut(var_num) => {
&QueryTerm::LocalCut { var_num, cut_prev } => {
let code = branch_code_stack.code(code);
let r = self.marker.get_binding(var_num);
code.push_back(instr!("cut", r));

code.push_back(if cut_prev {
instr!("cut_prev", r)
} else {
instr!("cut", r)
});

if self.marker.in_tail_position {
if self.marker.var_data.allocates {
Expand Down
2 changes: 1 addition & 1 deletion src/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub enum QueryTerm {
// register, clause type, subterms, clause call policy.
Clause(Cell<RegType>, ClauseType, Vec<Term>, CallPolicy),
Fail,
LocalCut(usize), // var_num
LocalCut { var_num: usize, cut_prev: bool }, // var_num
GlobalCut(usize), // var_num
GetCutPoint { var_num: usize, prev_b: bool },
GetLevel(usize), // var_num
Expand Down
63 changes: 32 additions & 31 deletions src/heap_iter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(test)]
pub(crate) use crate::machine::gc::{IteratorUMP};
pub(crate) use crate::machine::gc::{CycleDetectorUMP, StacklessPreOrderHeapIter};
pub(crate) use crate::machine::gc::StacklessPreOrderHeapIter;

use crate::atom_table::*;
use crate::machine::cycle_detection::*;
use crate::machine::heap::*;
use crate::machine::stack::*;
use crate::types::*;
Expand Down Expand Up @@ -505,24 +505,16 @@ impl<'a, ElideLists: ListElisionPolicy> Iterator for StackfulPreOrderHeapIter<'a
}
}

#[cfg(test)]
#[inline(always)]
pub(crate) fn stackless_preorder_iter(
heap: &mut Vec<HeapCellValue>,
pub(crate) fn cycle_detecting_stackless_preorder_iter<'a>(
heap: &'a mut [HeapCellValue],
start: usize,
) -> StacklessPreOrderHeapIter<IteratorUMP> {
StacklessPreOrderHeapIter::<IteratorUMP>::new(heap, start)
) -> CycleDetectingIter<'a, true> {
// const generics argument of true so that cycle discovery stops
// the iterator.
CycleDetectingIter::new(heap, start)
}


pub(crate) fn cycle_detecting_stackless_preorder_iter(
heap: &mut Heap,
start: usize,
) -> StacklessPreOrderHeapIter<CycleDetectorUMP> {
StacklessPreOrderHeapIter::<CycleDetectorUMP>::new(heap, start)
}


#[inline(always)]
pub(crate) fn stackful_preorder_iter<'a, ElideLists: ListElisionPolicy>(
heap: &'a mut Vec<HeapCellValue>,
Expand Down Expand Up @@ -665,23 +657,30 @@ pub(crate) fn stackful_post_order_iter<'a, ElideLists: ListElisionPolicy>(
PostOrderIterator::new(StackfulPreOrderHeapIter::new(heap, stack, cell))
}

#[cfg(test)]
pub(crate) type RightistPostOrderHeapIter<'a> =
PostOrderIterator<StacklessPreOrderHeapIter<'a, IteratorUMP>>;

#[cfg(test)]
#[inline]
pub(crate) fn stackless_post_order_iter<'a>(
heap: &'a mut Heap,
start: usize,
) -> RightistPostOrderHeapIter<'a> {
PostOrderIterator::new(stackless_preorder_iter(heap, start))
}

#[cfg(test)]
mod tests {
use super::*;
use crate::machine::mock_wam::*;
use crate::machine::gc::{IteratorUMP};

pub(crate) type RightistPostOrderHeapIter<'a> =
PostOrderIterator<StacklessPreOrderHeapIter<'a, IteratorUMP>>;

#[inline(always)]
pub(crate) fn stackless_preorder_iter(
heap: &mut Vec<HeapCellValue>,
start: usize,
) -> StacklessPreOrderHeapIter<IteratorUMP> {
StacklessPreOrderHeapIter::<IteratorUMP>::new(heap, start)
}

#[inline]
pub(crate) fn stackless_post_order_iter<'a>(
heap: &'a mut Heap,
start: usize,
) -> RightistPostOrderHeapIter<'a> {
PostOrderIterator::new(stackless_preorder_iter(heap, start))
}

#[test]
fn heap_stackless_iter_tests() {
Expand Down Expand Up @@ -1267,6 +1266,10 @@ mod tests {
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(1)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(1)
);

assert_eq!(iter.next(), None);
}
Expand Down Expand Up @@ -2254,9 +2257,7 @@ mod tests {
list_loc_as_cell!(1)
);
assert_eq!(iter.next().unwrap(), cyclic_link);

assert_eq!(iter.next().unwrap(), cyclic_link);

assert_eq!(iter.next().unwrap(), cyclic_link);

assert_eq!(iter.next(), None);
Expand Down
13 changes: 13 additions & 0 deletions src/heap_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,19 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
var_opt => {
if is_cyclic && cell.is_compound(self.iter.heap) {
// self-referential variables are marked "cyclic".
read_heap_cell!(cell,
(HeapCellValueTag::Lis, vh) => {
if self.iter.heap[vh].get_forwarding_bit() {
self.iter.pop_stack();
}

if self.iter.heap[vh+1].get_forwarding_bit() {
self.iter.pop_stack();
}
}
_ => {}
);

match var_opt {
Some(var) => {
// If the term is bound to a named variable,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/charsio.pl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
% - `symbolic_control`
% - `symbolic_hexadecimal`
% - `upper`
% - `to_lower(Lower)`
% - `to_upper(Upper)`
% - `lower(Lower)`
% - `upper(Upper)`
% - `whitespace`
%
% An example:
Expand All @@ -124,8 +124,8 @@
% ; Type = octet
% ; Type = prolog
% ; Type = symbolic_control
% ; Type = to_lower("a")
% ; Type = to_upper("A")
% ; Type = lower("a")
% ; Type = upper("A")
% ; false.
% ```
%
Expand Down Expand Up @@ -168,8 +168,8 @@
ctype(solo).
ctype(symbolic_control).
ctype(symbolic_hexadecimal).
ctype(to_lower(_)).
ctype(to_upper(_)).
ctype(lower(_)).
ctype(upper(_)).
ctype(upper).
ctype(whitespace).

Expand Down
2 changes: 1 addition & 1 deletion src/lib/dif.pl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
term_variables(Goal0, Vars),
dif:vars_remove_goal(Vars, Goal0),
Goal0 = (L \== R),
dif(L, R)
dif:dif(L, R)
).

append_goals([], _).
Expand Down
Loading

0 comments on commit ee1bd9e

Please sign in to comment.