src/wam/compiler/8-ui.lisp @ a095d20eeebc

Split up the damn compiler.lisp file
author Steve Losh <steve@stevelosh.com>
date Fri, 15 Jul 2016 19:37:17 +0000
parents (none)
children c4dd0b6c3a91
(in-package #:bones.wam)

;;;; ,-.  .                 ,-_/     .
;;;;   |  |   ,-. ,-. ,-.   '  | ,-. |- ,-. ,-. ," ,-. ,-. ,-.
;;;;   |  | . `-. |-' |     .^ | | | |  |-' |   |- ,-| |   |-'
;;;;   `--^-' `-' `-' '     `--' ' ' `' `-' '   |  `-^ `-' `-'
;;;;                                            '

;;; The final phase wraps everything else up into a sane UI.

(defun* compile-query ((wam wam) (query list))
  "Compile `query` into the query section of the WAM's code store.

  `query` should be a list of goal terms.

  Returns the permanent variables.

  "
  (multiple-value-bind (instructions permanent-variables)
      (precompile-query wam query)
    (optimize-instructions wam instructions)
    (render-query wam instructions)
    permanent-variables))

(defun* compile-rules ((wam wam) (rules list))
  "Compile `rules` into the WAM's code store.

  Each rule in `rules` should be a clause consisting of a head term and zero or
  more body terms.  A rule with no body is called a fact.

  "
  (multiple-value-bind (instructions functor arity)
      (precompile-rules wam rules)
    (optimize-instructions wam instructions)
    (render-rules wam functor arity instructions)))