Skip to content

Commit

Permalink
Compile cross VM at high debug for source info
Browse files Browse the repository at this point in the history
This probably slows things down a little bit, but it has an
important advantage: assuming the host Lisp is decent, it can keep
enough information that the bytecode module and current IP can be
extracted from a host frame. And with that you can get source info
and whatever else. I wrote a proof of concept of this in SBCL, but
you need to use undocumented/fragile internals, so I won't be
including it in Maclina at least for the moment.
  • Loading branch information
Bike committed Jul 16, 2024
1 parent ac20e25 commit 54a421b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions vm-cross.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@
(defun bytecode-call (template closure-env args)
(declare (optimize speed)
(type list args))
(let* ((entry-pc (m:bytecode-function-entry-pc template))
(frame-size (m:bytecode-function-locals-frame-size template))
(module (m:bytecode-function-module template))
(bytecode (m:bytecode-module-bytecode module))
(literals (m:bytecode-module-literals module)))
(let ((entry-pc (m:bytecode-function-entry-pc template))
(frame-size (m:bytecode-function-locals-frame-size template))
(module (m:bytecode-function-module template)))
(declare (type (unsigned-byte 16) frame-size))
;; Set up the stack, then call VM.
(let* ((vm *vm*)
Expand All @@ -140,7 +138,7 @@
(setf (vm-stack-top vm) (+ (vm-frame-pointer vm) frame-size))
;; set up the stack, then call vm
(unwind-protect
(vm bytecode closure-env literals frame-size)
(vm module closure-env frame-size)
(setf (vm-dynenv-stack vm) old-de-stack))
;; tear down the frame.
(setf (vm-stack-top vm) (- (vm-frame-pointer vm) (length args)))
Expand Down Expand Up @@ -264,18 +262,20 @@
;; We take the max for partial frames.
(subseq stack frame-end (max sp frame-end)))))

(defun vm (bytecode closure constants frame-size)
(declare (type (simple-array (unsigned-byte 8) (*)) bytecode)
(type (simple-array t (*)) closure constants)
(defun vm (module closure frame-size)
(declare (type (simple-array t (*)) closure)
(type (unsigned-byte 16) frame-size)
(optimize speed))
(let* ((vm *vm*)
(optimize debug))
(let* ((bytecode (m:bytecode-module-bytecode module))
(constants (m:bytecode-module-literals module))
(vm *vm*)
(stack (vm-stack vm))
(ip (vm-pc vm))
(sp (vm-stack-top vm))
(bp (vm-frame-pointer vm))
(timeout *timeout*))
(declare (type (simple-array t (*)) stack)
(declare (type (simple-array (unsigned-byte 8) (*)) bytecode)
(type (simple-array t (*)) constants stack)
(type (and unsigned-byte fixnum) ip sp bp))
(labels ((stack (index)
;;(declare (optimize (safety 0))) ; avoid bounds check
Expand Down

0 comments on commit 54a421b

Please sign in to comment.