Re: Adding assembler code to Lua programs

  • From: Konstantin Olkhovskiy <lupus@xxxxxxxxxx>
  • To: luajit <luajit@xxxxxxxxxxxxx>
  • Date: Tue, 4 Mar 2014 23:29:51 +0400

Hey,

I was curious about DynASM for some time, and now you gave me an occasion
to play with it. I've created a tiny example project [1] that illustrates
it's usage as
a standalone tool. Hopefully I've done it right, since I was unable to find
documentation, describing how to use it this way and hacked it together
based
on comments and the source code of LuaJIT itself.

2014-03-01 14:28 GMT+04:00 Mike Pall <mike-1403@xxxxxxxxxx>:

> Right now, DynASM only translates/generates C code. And the (tiny)
> machine-specific encoding engines are in C, too. It's certainly
> doable to port those to Lua, but so far nobody had a need.


In order to overcome this limitation, you can require dynasm.lua, make it
produce
a string with C code, add required bits and pieces and use TinyCC [2] to
compile
the resulting code on the fly. TinyCC does not do any sophisticated
optimizations,
but it does compile really fast and is tiny, which fits this task.

I have not tried this approach, but it might work and not be too ugly :) It
could be
even wrapped into some inline dynassembly library.

[1] https://github.com/Lupus/dynasm-example
[2] http://bellard.org/tcc/

-- 
Regards,
Konstantin

Other related posts: