package.lisp @ ce87039ad178

Make L2 work properly

This changes a lot of things.

First, we split apart all the register-using opcodes into local and stack
variants, and tear out the register designator stuff.  This is ugly, but will be
way faster because the check doesn't need to happen at runtime any more.  It's
made slightly less ugly with a real nasty macro.

We also change how the head and first body term in clauses interact.  It turns
out the head needs to respect the arity of the first body clause (if it's
larger), and the two clauses need to share local variable register assignments.
Apparently when HAK says "compiled as one unit" in the book he means this.
Would have been nice if he could have explained that, or at least showed an
example that makes use of it so I have a chance of noticing it.

Still to do before we move on to L3:

* Add a few comments to document the stuff added in this commit.
* Rework the query code store to fall at the beginning of the `CODE` section so
  we can just have one program counter and interpreter function to rule them
  all.
* Consider figuring out the answer extraction process (we basically need to
  modify the query compiler to treat all variables as permanent, and keep that
  mapping so we can extract them from the stack at the very end).
author Steve Losh <steve@stevelosh.com>
date Sun, 17 Apr 2016 21:36:15 +0000
parents b8bc9b175636
children f3ed7ce70f3b
(defpackage #:bones
  (:use #:cl)
  (:export #:hello))

(defpackage #:bones.utils
  (:use #:cl
        #:defstar
        #:bones.quickutils)
  (:export
    #:repeat
    #:topological-sort
    #:push-if-new))

(defpackage #:bones.wam
  (:use #:cl
        #:defstar
        #:optima
        #:cl-arrows
        #:bones.quickutils
        #:bones.utils)
  (:import-from #:optima #:match)
  (:shadowing-import-from #:cl-arrows #:->))

(defpackage #:bones.paip
  (:use #:cl #:defstar #:bones.quickutils)
  (:documentation "Test?")
  (:export

   ;; Unification, constants
   #:unify
   #:fail #:no-bindings
   #:*check-occurs*

   ;; Destructive unification
   #:unify!
   #:unbound
   #:bound-p

   ;; Database management
   #:clear-db
   #:clear-predicate
   #:fact
   #:rule
   #:add-fact
   #:rule-fact

   ;; Lisp data structures as results
   #:return-one
   #:return-all

   ;; Interactive queries
   #:query
   #:query-one
   #:query-all
   ))