# HG changeset patch # User Steve Losh # Date 1460814636 0 # Node ID 15db57524dd356812e81214f1ec660a4e91e0f00 # Parent b8bc9b1756361ef5ecdefe4a558b199af61f7661 Fix the interpreter and add a simple UI diff -r b8bc9b175636 -r 15db57524dd3 bones.asd --- a/bones.asd Sat Apr 16 13:07:16 2016 +0000 +++ b/bones.asd Sat Apr 16 13:50:36 2016 +0000 @@ -29,6 +29,7 @@ (:file "wam") (:file "compiler") (:file "interpreter") - (:file "dump"))) + (:file "dump") + (:file "ui"))) (:file "bones"))))) diff -r b8bc9b175636 -r 15db57524dd3 src/wam/interpreter.lisp --- a/src/wam/interpreter.lisp Sat Apr 16 13:07:16 2016 +0000 +++ b/src/wam/interpreter.lisp Sat Apr 16 13:50:36 2016 +0000 @@ -368,13 +368,24 @@ (when step (break "About to execute instruction at ~4,'0X" program-counter)) (eswitch (opcode) - (+opcode-get-structure+ (instruction-call wam %get-structure code program-counter 2)) + ;; Query + (+opcode-put-structure+ (instruction-call wam %put-structure code program-counter 2)) + (+opcode-set-variable+ (instruction-call wam %set-variable code program-counter 1)) + (+opcode-set-value+ (instruction-call wam %set-value code program-counter 1)) + (+opcode-put-variable+ (instruction-call wam %put-variable code program-counter 2)) + (+opcode-put-value+ (instruction-call wam %put-value code program-counter 2)) + ;; Program + (+opcode-get-structure+ (instruction-call wam %get-structure code program-counter 2)) (+opcode-unify-variable+ (instruction-call wam %unify-variable code program-counter 1)) - (+opcode-unify-value+ (instruction-call wam %unify-value code program-counter 1)) - (+opcode-get-variable+ (instruction-call wam %get-variable code program-counter 2)) - (+opcode-get-value+ (instruction-call wam %get-value code program-counter 2)) - ;; need to skip the PC increment for PROC/CALL + (+opcode-unify-value+ (instruction-call wam %unify-value code program-counter 1)) + (+opcode-get-variable+ (instruction-call wam %get-variable code program-counter 2)) + (+opcode-get-value+ (instruction-call wam %get-value code program-counter 2)) + ;; Control + (+opcode-allocate+ (instruction-call wam %allocate code program-counter 1)) + ;; need to skip the PC increment for PROC/CALL/DEAL ;; TODO: this is ugly + (+opcode-deallocate+ (instruction-call wam %deallocate code program-counter 0) + (return-from op)) (+opcode-proceed+ (instruction-call wam %proceed code program-counter 0) (return-from op)) (+opcode-call+ (instruction-call wam %call code program-counter 1) @@ -392,6 +403,7 @@ When `step` is true, break into the debugger before calling the procedure. " + ;; TODO: dedupe this interpreter code (let ((code (compile-query wam term))) (wam-reset! wam) (loop diff -r b8bc9b175636 -r 15db57524dd3 src/wam/ui.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wam/ui.lisp Sat Apr 16 13:50:36 2016 +0000 @@ -0,0 +1,21 @@ +(in-package #:bones.wam) + + +(defparameter *database* nil) + +(defmacro with-database (&body body) + `(let ((*database* (make-wam))) + ,@body)) + +(defun add-rule (rule) + (compile-program *database* rule)) + +(defmacro rule (&body body) + `(add-rule ',body)) + +(defun perform-query (query) + (run-query *database* query)) + +(defmacro query (&body body) + `(perform-query ',body)) +