Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

SBCL has an extremely sophisticated facility called a VOP (Virtual Operation) that allows you to write assembly with s-expressions and integrate the code into the compiler and runtime. The SBCL backend itself is composed of these VOPs.

Significantly, this means that you can write assembly macros with the full power and elegance of lisp. A trivial example is the move macro, which is used extensively in VOPs:

  (defmacro move (dst src)
    "Move SRC into DST unless they are location=."
    (once-only ((n-dst dst)
                (n-src src))
      `(unless (location= ,n-dst ,n-src)
         (inst mov ,n-dst ,n-src))))
Check out the SBCL source if you want to see some wild uses of VOPs and macros that expand into assembly code. In compiler/x86/arith.lisp there is a lisp/assembly implementation of the Mersenne Twister.

VOPs can optionally handle argument type checking and can be tuned to emit specialized code in various circumstances, such as when one of the arguments to the call is a compile-time constant.



What I want to see is Python or Ruby taking advantage of a runtime code generation library to start rewriting the VM or JIT'ing method calls.


Psyco.


Yep. I forgot about Psyco. Does it still work?


I am not sure which version of Python will break Psyco. It looks like it stopped being maintained in '06.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: