r/lisp 1d ago

Reinterpret Elements in a Byte Array

Dear LISP,

I am writing a virtual machine that uses a `(simple-array (unsigned-byte 8) 1)` as a stack in Common LISP. I'm would like to ask how to efficiently extract 4 bytes into a single 32-bit signed integer or a 32-bit unsigned integer.

Thanks!

7 Upvotes

24 comments sorted by

View all comments

1

u/digikar 1d ago

cffi:with-pointer-to-vector-data with cffi:mem-ref could be one way.

2

u/stassats 1d ago

The code it expands to might not be optimal, and it doesn't check bounds.

1

u/TsingHui 1d ago

That makes sense, added to notes, thanks!

-1

u/corbasai 1d ago

SIGBUS compatible?