richardhundt / shine

A Shiny Lua Dialect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

implementing the TDUP instructions

franko opened this issue · comments

Hi Richard,

this is not really an issue but I would like to implement the bytecode generator for table literals using the TDUP instruction like LuaJIT is doing.

Do you have any idea where should I begin to look ? For the moment I don't have any idea at all of where to begin.

On 2/16/14 11:51 PM, Francesco wrote:

Hi Richard,

this is not really an issue but I would like to implement the bytecode
generator for table literals using the TDUP instruction like LuaJIT is
doing.

Do you have any idea where should I begin to look ? For the moment I
don't have any idea at all of where to begin.

Hi Francesco,

I'll answer your previous message when I've got time... there was a lot
going into that commit and I can't remember it all. For TDUP though, I
did experiment a little and from what I can tell, LuaJIT separates all
non-constant members out of the table and if there's anything left, it
stores that and reconstructs it with a TDUP and then fills in the
dynamic stuff.

That part is easy to see:

$ luajit -bl -e "local t = { foo = 42 }"
-- BYTECODE -- "local t = { foo = 42 }":0-1
0001    TDUP     0   0
0002    RET0     0   1

$ luajit -bl -e "local t = { foo = 42, print = print }"
-- BYTECODE -- "local t = { foo = 42, print = print }":0-1
0001    TDUP     0   0
0002    GGET     1   1      ; "print"
0003    TSETS    1   0   1  ; "print"
0004    RET0     0   1

How it's written is in lj_bcwrite.c in functions bcwrite_ktab and
bcwrite_ktabk, but I haven't studied those in detail.

Hope that helps

-R

Hi Richard,

thank you for your help, I've implemented the TDUP stuff in luajit-lang-toolkit in this branch:

https://github.com/franko/luajit-lang-toolkit/tree/tdup-emit

Otherwise I've also integrated some of the changes you've made to the bytecode generator for the uclo instructions before you remove the module in favor of tvmjit.

I was very surprised of this move after all the great work you have made in the bytecode generator. I guess it is because you want to focus on the language itself, Nyanga, instead of working a lot on the bytecode generator.

By the way, I'm quite happy of what I have right now in the luajit-language toolkit. I've created an automated & powerful test suite and I'm ironing out the remaining bugs.

On 3/7/14 11:14 PM, Francesco wrote:

Hi Richard,

thank you for your help, I've implemented the TDUP stuff in
luajit-lang-toolkit in this branch:

https://github.com/franko/luajit-lang-toolkit/tree/tdup-emit

Good work!

Otherwise I've also integrated some of the changes you've made to the
bytecode generator for the uclo instructions before you remove the
module in favor of tvmjit.

I was very surprised of this move after all the great work you have
made in the bytecode generator. I guess it is because you want to
focus on the language itself, Nyanga, instead of working a lot on the
bytecode generator.

Yeah, it was a difficult decision. I put a lot of time into that
bytecode generator, but it still had some edge cases which produced code
I wasn't happy with. TvmJIT produces exactly the same code as LuaJIT
because it is LuaJIT, just with a different lexer and parser. Also
compilation is faster, it has some cool features (support for unicode
escapes, do blocks as expressions, etc.) and it will stay in sync with
luajit 2.1 when it is released. It is also code I don't need to
maintain, which is nice, because as you said, I'm focusing more on the
language itself these days.

Having complete control over the bytecode gives you more flexibility
though, so maybe I change my mind again at some point and put your
version in ;-)

By the way, I'm quite happy of what I have right now in the
luajit-language toolkit. I've created an automated & powerful test
suite and I'm ironing out the remaining bugs.


Reply to this email directly or view it on GitHub
#34 (comment).

Ok, that reassure me.
If later you want to come back and use again the bytecode generator I will be glad to propose my version.
In the meantime I'm going to work to improve it as a separate project as I told you before.
Good luck with Nyanga