# HG changeset patch # User Richard Westhaver # Date 1723601123 14400 # Node ID 7046f3bdb66899a6c94efc47723e4c38404a4bfb # Parent 1d6e3bbdaebbd6774f546ac4ce12faa6e9b67ecb skel-vm diff -r 1d6e3bbdaebb -r 7046f3bdb668 lisp/lib/cli/tools/tmux.lisp --- a/lisp/lib/cli/tools/tmux.lisp Mon Aug 12 22:24:31 2024 -0400 +++ b/lisp/lib/cli/tools/tmux.lisp Tue Aug 13 22:05:23 2024 -0400 @@ -137,6 +137,8 @@ (defun format-tmux-string (dst fmt &rest args) (apply #'format dst fmt (mapcar (lambda (a) (format nil "#{~A}" a)) args))) +(defvar *tmux-var-table* (make-hash-table)) + (defmacro tmux-format (dst fmt &rest args) "Format a tmux string, replacing symbols in ARGS that match a member of *TMUX-VARIABLES* with their corresponding lower-case name." diff -r 1d6e3bbdaebb -r 7046f3bdb668 lisp/lib/skel/core/pkg.lisp --- a/lisp/lib/skel/core/pkg.lisp Mon Aug 12 22:24:31 2024 -0400 +++ b/lisp/lib/skel/core/pkg.lisp Tue Aug 13 22:05:23 2024 -0400 @@ -120,7 +120,23 @@ :stack-op-type :*skel-op-types* :skel-op-type - :new-skel-arena)) + :new-skel-arena + :with-skel-vm + :with-skel-scope + :skel-op + :make-skel-op + :skel-op-p + :copy-skel-op + :skel-op-scope + :skel-op-body + :*skel-stack-size* + :*skel-arena* + :*skel-scope* + :init-skel-op-scope + :*skel-arena-size* + :init-skel-scope + :init-skel-value-scope + :init-skel-function-scope)) (defpackage :skel/core/print (:use :cl :std :skel/core/err :skel/core/obj :skel/core/types :skel/core/proto :skel/core/vars) diff -r 1d6e3bbdaebb -r 7046f3bdb668 lisp/lib/skel/core/vm.lisp --- a/lisp/lib/skel/core/vm.lisp Mon Aug 12 22:24:31 2024 -0400 +++ b/lisp/lib/skel/core/vm.lisp Tue Aug 13 22:05:23 2024 -0400 @@ -6,26 +6,64 @@ ;;; Code: (in-package :skel/core/vm) -(defvar *skel-op-types* - (list :nop :eval :set :get :end :jump :pop :spawn :wait :print :let)) +(eval-always + (defvar *skel-op-types* + (vector :nil :eval :set :get :end :jump :pop :spawn :wait :print :let)) + (defvar *skel-arena-size* (ash 1 16)) + (defun new-skel-arena () (sb-vm:new-arena *skel-arena-size*)) + (defun init-skel-scope (&optional (map (sb-lockless:make-so-map/fixnum))) + (sb-lockless:so-insert map 0) + (sb-lockless:so-insert map 1) + (sb-lockless:so-insert map 2) + map)) -(deftype skel-op-type () `(member ,@*skel-op-types*)) +(defun init-skel-value-scope (scope &rest values) + (sb-lockless:so-insert + scope 1 + (apply #'vector values))) + +(defun init-skel-function-scope (scope &rest functions) + (sb-lockless:so-insert + scope 2 + (apply #'vector functions))) + +(defvar *skel-arena* (new-skel-arena)) + +(defvar *skel-stack-size* 128) + +(deftype skel-op-type () `(member ,@(coerce *skel-op-types* 'list))) (defstruct skel-op - (type :nop :type skel-op-type) - body) - + (type 0 :type unsigned-byte :read-only t) + (scope 0 :type (unsigned-byte 64) :read-only t) + (thunk #'identity :type function :read-only t)) + (defstruct skel-vm - (ip (make-stack-slot) :type stack-slot) - (stack (make-array 0) :type (array stack-slot))) + (ip 0 :type (integer 0 #.*skel-stack-size*)) ;; to be atomic type needs to be (unsigned-byte 64) + (stack (make-array *skel-stack-size* :element-type 'skel-op) + :type (vector skel-op))) + +(defvar *skel-scope* + (let ((scope (init-skel-scope))) + (init-skel-function-scope scope #'funcall) + (init-skel-value-scope scope nil t) + scope)) -(defvar *skel-arena-size* (ash 1 16)) -(defvar *skel-arenas* nil) - -(defun new-skel-arena () (sb-vm:new-arena *skel-arena-size*)) +(defmacro with-skel-scope ((&optional (scope *skel-scope*)) &body body) + `(let ((*skel-scope* ,scope)) + ,@body)) -(sb-ext:defglobal *skel-arena* (make-skel-arena)) - -;; (defmacro with-skel-arena (arena &body body)) -;; (defmacro with-skel-stack ((stack &key arena) &body body)) -;; (defmacro with-skel-vm ((vm &optional arena) &body body)) +(defmacro with-skel-vm ((vm-sym &optional (vm (make-skel-vm)) + (scope *skel-scope*) + (arena *skel-arena*)) + &body body) + `(sb-vm:with-arena (,arena) + (let ((*skel-scope* ,scope) + (*skel-arena* ,arena) + (,vm-sym ,vm)) + (prog1 + ,@body + (log:info! (format nil "skel-vm alloc-info: ~A/~A~% userdata: ~A" + (sb-vm:arena-bytes-used ,arena) + (sb-vm:arena-length ,arena) + (sb-vm:arena-userdata ,arena)))))))