Scryer-prolog: Question about prolog

Created on 2 May 2020  ยท  5Comments  ยท  Source: mthom/scryer-prolog

The tree of the project looks like this:

$ tree -L 3 -F
.                                                                              
โ”œโ”€โ”€ build.rs
โ”œโ”€โ”€ Cargo.lock
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ rustfmt.toml
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ main.rs
    โ”œโ”€โ”€ prolog/
    โ”‚ย ย  โ”œโ”€โ”€ allocator.rs
    โ”‚ย ย  โ”œโ”€โ”€ arithmetic.rs
    โ”‚ย ย  โ”œโ”€โ”€ clause_types.rs
    โ”‚ย ย  โ”œโ”€โ”€ codegen.rs
    โ”‚ย ย  โ”œโ”€โ”€ debray_allocator.rs
    โ”‚ย ย  โ”œโ”€โ”€ examples/
    โ”‚ย ย  โ”œโ”€โ”€ fixtures.rs
    โ”‚ย ย  โ”œโ”€โ”€ forms.rs
    โ”‚ย ย  โ”œโ”€โ”€ heap_iter.rs
    โ”‚ย ย  โ”œโ”€โ”€ heap_print.rs
    โ”‚ย ย  โ”œโ”€โ”€ indexing.rs
    โ”‚ย ย  โ”œโ”€โ”€ instructions.rs
    โ”‚ย ย  โ”œโ”€โ”€ iterators.rs
    โ”‚ย ย  โ”œโ”€โ”€ lib/
    โ”‚ย ย  โ”œโ”€โ”€ machine/
    โ”‚ย ย  โ”œโ”€โ”€ macros.rs
    โ”‚ย ย  โ”œโ”€โ”€ mod.rs
    โ”‚ย ย  โ”œโ”€โ”€ read.rs
    โ”‚ย ย  โ”œโ”€โ”€ targets.rs
    โ”‚ย ย  โ”œโ”€โ”€ toplevel.pl
    โ”‚ย ย  โ””โ”€โ”€ write.rs
    โ””โ”€โ”€ tests/
        โ”œโ”€โ”€ builtins.pl
        โ”œโ”€โ”€ call_with_inference_limit.pl
        โ”œโ”€โ”€ facts.pl
        โ”œโ”€โ”€ predicates.pl
        โ”œโ”€โ”€ rules.pl
        โ””โ”€โ”€ setup_call_cleanup.pl

6 directories, 31 files
$
  1. Why is there a module prolog?

  2. Why is the library src/prolog/lib in src? Couldn't it be outside of src?

  3. Why is the tests directory src/prolog/tests in src without any Rust code? Couldn't it be outside of src?

  4. Why is the example directory src/prolog/examples in src? Couldn't it be outside of src?

  5. Could src be like this?

โ”œโ”€โ”€ allocator.rs
โ”œโ”€โ”€ arithmetic.rs
โ”œโ”€โ”€ clause_types.rs
โ”œโ”€โ”€ codegen.rs
โ”œโ”€โ”€ debray_allocator.rs
โ”œโ”€โ”€ fixtures.rs
โ”œโ”€โ”€ forms.rs
โ”œโ”€โ”€ heap_iter.rs
โ”œโ”€โ”€ heap_print.rs
โ”œโ”€โ”€ indexing.rs
โ”œโ”€โ”€ instructions.rs
โ”œโ”€โ”€ iterators.rs
โ”œโ”€โ”€ machine/
โ”‚ย ย  โ”œโ”€โ”€ arithmetic_ops.rs
โ”‚ย ย  โ”œโ”€โ”€ attributed_variables.pl
โ”‚ย ย  โ”œโ”€โ”€ attributed_variables.rs
โ”‚ย ย  โ”œโ”€โ”€ code_repo.rs
โ”‚ย ย  โ”œโ”€โ”€ code_walker.rs
โ”‚ย ย  โ”œโ”€โ”€ compile.rs
โ”‚ย ย  โ”œโ”€โ”€ copier.rs
โ”‚ย ย  โ”œโ”€โ”€ dynamic_database.rs
โ”‚ย ย  โ”œโ”€โ”€ heap.rs
โ”‚ย ย  โ”œโ”€โ”€ machine_errors.rs
โ”‚ย ย  โ”œโ”€โ”€ machine_indices.rs
โ”‚ย ย  โ”œโ”€โ”€ machine_state_impl.rs
โ”‚ย ย  โ”œโ”€โ”€ machine_state.rs
โ”‚ย ย  โ”œโ”€โ”€ mod.rs
โ”‚ย ย  โ”œโ”€โ”€ modules.rs
โ”‚ย ย  โ”œโ”€โ”€ partial_string.rs
โ”‚ย ย  โ”œโ”€โ”€ project_attributes.pl
โ”‚ย ย  โ”œโ”€โ”€ raw_block.rs
โ”‚ย ย  โ”œโ”€โ”€ stack.rs
โ”‚ย ย  โ”œโ”€โ”€ streams.rs
โ”‚ย ย  โ”œโ”€โ”€ system_calls.rs
โ”‚ย ย  โ”œโ”€โ”€ term_expansion.rs
โ”‚ย ย  โ””โ”€โ”€ toplevel.rs
โ”œโ”€โ”€ macros.rs
โ”œโ”€โ”€ main.rs
โ”œโ”€โ”€ read.rs
โ”œโ”€โ”€ targets.rs
โ”œโ”€โ”€ toplevel.pl
โ””โ”€โ”€ write.rs

I'm sorry for this long post/issue and for this many questions. But I don't understand the design/architecture choice.

Most helpful comment

Sorry for the delay in answering these questions.

Why is there a module prolog?

When I started Scryer -- back when it was called rusty-wam -- I planned on writing a series of blog posts explaining WAM implementation in Rust. There were originally the subdirectories l0, l1, ..., l3, culminating in Prolog. They reflected the progression of languages up to Prolog in the WAM book. I planned for the blog posts to follow the natural progression of the book. I abandoned that idea pretty quickly, but the prolog directory stuck around, because I was too lazy and indifferent to remove it.

Why is the library src/prolog/lib in src? Couldn't it be outside of src?

lib is part of the source code of Scryer, so.. why wouldn't it be in src?

Why is the tests directory src/prolog/tests in src without any Rust code? Couldn't it be outside of src?

It could be in or outside of src, sure. Outside would probably be more appropriate.

Why is the example directory src/prolog/examples in src? Couldn't it be outside of src?

Same answer as previous.

All 5 comments

These are eminently sensible questions! And regarding architecture, one interesting related question is also: Which of the Rust parts can be moved to Prolog, so that more of the engine is tested every time a Prolog program is compiled, and to make the compiler easier to understand and extend?

For comparison and inspiration, here is code_gen.pl from GNU Prolog:

https://sourceforge.net/p/gprolog/code/ci/457f7b447c2b9e90a09956ff15fd277d269b1d98/tree/src/Pl2Wam/code_gen.pl

@mthom , I looked at the git log, the module prolog has been there for a long time (since fcb3cc1287afa60844ceda083b1824a69a765cc2). As the parser which found its way out with since ff9d2662e62c466cd653e8cdb1da6a2979c4890e, some folders (examples, lib, ...) could also exit src (but remains in this crate).

By removing prolog, cross-module permissions issue will be minimized.

The last commit answered the main question, closing.

Sorry for the delay in answering these questions.

Why is there a module prolog?

When I started Scryer -- back when it was called rusty-wam -- I planned on writing a series of blog posts explaining WAM implementation in Rust. There were originally the subdirectories l0, l1, ..., l3, culminating in Prolog. They reflected the progression of languages up to Prolog in the WAM book. I planned for the blog posts to follow the natural progression of the book. I abandoned that idea pretty quickly, but the prolog directory stuck around, because I was too lazy and indifferent to remove it.

Why is the library src/prolog/lib in src? Couldn't it be outside of src?

lib is part of the source code of Scryer, so.. why wouldn't it be in src?

Why is the tests directory src/prolog/tests in src without any Rust code? Couldn't it be outside of src?

It could be in or outside of src, sure. Outside would probably be more appropriate.

Why is the example directory src/prolog/examples in src? Couldn't it be outside of src?

Same answer as previous.

lib is part of the source code of Scryer, so.. why wouldn't it be in src?

After the implementation of the Debug trait, I tried to print a Machine (everything) and the output was huge. So I'm interested in a subset of the ISO, the syntax of Prolog and a very small library (smaller than builtins.pl).
The implementation in toplevel.pl for handling the argument passed to Scryer-Prolog got me thinking what is really necessary/important, how everything is linked.

It doesn't seem like lib in src will interfere with src/lib.rs, staying seems good.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

triska picture triska  ยท  3Comments

dcnorris picture dcnorris  ยท  3Comments

triska picture triska  ยท  3Comments

XVilka picture XVilka  ยท  3Comments

UWN picture UWN  ยท  4Comments