# HG changeset patch # User Steve Losh # Date 1458994916 0 # Node ID 859a6c1314d399b4ed9b6157e52c7a3e036b234a # Parent 68ed4af714526719e3213074c243e8964400ce57 Add a few comments and a pair of utility functions for the WAM heap diff -r 68ed4af71452 -r 859a6c1314d3 src/wam/instructions.lisp --- a/src/wam/instructions.lisp Sat Mar 26 12:02:43 2016 +0000 +++ b/src/wam/instructions.lisp Sat Mar 26 12:21:56 2016 +0000 @@ -26,3 +26,4 @@ (wam-heap-push! wam (wam-register wam register)) (values)) + diff -r 68ed4af71452 -r 859a6c1314d3 src/wam/wam.lisp --- a/src/wam/wam.lisp Sat Mar 26 12:02:43 2016 +0000 +++ b/src/wam/wam.lisp Sat Mar 26 12:21:56 2016 +0000 @@ -1,5 +1,6 @@ (in-package #:bones.wam) +;;;; WAM (defclass wam () ((heap :initform (make-array 16 @@ -30,6 +31,12 @@ (make-instance 'wam)) +;;;; Heap +;;; The WAM heap is a fixed-length array of cells and a heap pointer. +;;; +;;; TODO: Consider using an adjustable array. There must still be a max size +;;; because you can only index so many addresses with N bits. + (defun* wam-heap-push! ((wam wam) (cell heap-cell)) (:returns heap-cell) "Push the cell onto the WAM heap and increment the heap pointer. @@ -42,6 +49,19 @@ (incf heap-pointer) cell)) + +(defun* wam-heap-cell ((wam wam) (address heap-index)) + (:returns heap-cell) + "Return the heap cell at the given address." + (aref (wam-heap wam) address)) + +(defun (setf wam-heap-cell) (new-value wam address) + (setf (aref (wam-heap wam) address) new-value)) + + +;;;; Registers +;;; WAM registers are implemented as an array of a fixed number of registers. + (defun* wam-register ((wam wam) (register register-index)) (:returns heap-cell) "Return the WAM register with the given index." @@ -51,6 +71,13 @@ (setf (aref (wam-registers wam) register) new-value)) +;;;; Functors +;;; Functors are symbols stored in an adjustable array. Cells refer to +;;; a functor using the functor's address in this array. +;;; +;;; TODO: Limit the number of functors based on the number of addressable +;;; functors in the functor cell index bits. + (defun* wam-ensure-functor-index ((wam wam) (functor symbol)) (:returns functor-index) "Return the index of the functor in the WAM's functor table.