-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idea: Write Lua parser and bytecode compiler in Lua #248
Comments
I kinda opened that issue so I could ship my LOVE code with a patched LuaJIT parser/compiler. it would only handle LuaJIT bytecode but I'm okay with that tbh. I don't think anyone builds their LOVE with RaptorJIT instead of LuaJIT. so I wouldn't get much (if any) benefit from such a pure-Lua RaptorJIT parser/compiler. |
@SoniEx2 This idea is still very interesting for RaptorJIT since we want to reduce the maintenance burden of the C code and evolve the language over time. I don't think it hurts to communicate between forks. If we implemented this on RaptorJIT you could probably port it pretty easily to your own LuaJIT fork and deploy on that. This is the way things work in the *BSD universe where each fork develops its own features and the best ones are picked up by the others over time. |
For what it's worth, I'm torn on this. "Embedding the binary blob" is not a trivial task here - I think it would involve linker scripts or being dumped into a C array for the preprocessor. Additionally, internal bytecode is not a stable format, so the front-ends would require updating as the bytecode format evolves. However, a rewrite to achieve this would majorly decouple the JIT from the front-end, and I think that's a goal worth pursuing in its own right; other languages could emit RJ bytecode to run on the RJ backend. So I suppose my opinion can be summarised as "I think this is a bad idea but an excellent concept". |
What? I'm just suggesting we write lua_load in pure Lua - but you need to bootstrap it so |
So, suppose somebody else comes along and thinks "this is a good runtime, let's write my language for the RaptorJIT VM". Then what?
So then you need APIs to load this bytecode into the VM. Granted, there is
Does arbitrary bytecode somehow become more trustworthy when embedded into the executable? |
it's no more arbitrary than the machine code around it. what's your C compiler written in? the lua_load bytecode would be internal to the VM. luajit already does this with a handful of builtin functions (they're interpreted and JITted like any lua function, there's little to no C around it) altho I don't fully understand how it works. |
And no more trustworthy, honestly.
C++, because C is a bad language to write C compilers in.
This is provably false. for i=0,100 do
local f = assert(load[[print("Hello, World!")]])
f()
end
The I haven't looked around, but I would imagine it translates to a call to |
try take a look here: https://github.com/LuaJIT/LuaJIT/blob/v2.1/src/host/genlibbc.lua |
I'd like to understand how the current bootstrap uses embedded bytecodes (if at all.) I was going to insist that we already do generate and embed bytecodes during bootstrap. There is a bootstrap module LJLIB_LUA(table_foreach) /*
function(t, f)
CHECK_tab(t)
CHECK_func(f)
for k, v in PAIRS(t) do
local r = f(k, v)
if r ~= nil then return r end
end
end
*/ ... but where do those bytecodes actually end up? I had expected to find them in |
@SoniEx2 That's one breadcrumb but |
the makefile generates an |
@SoniEx2 So is the Lua code embedded in C comments first bytecode compiled by I ask this question both sincerely (I don't know the answer and would prefer to thrash it out collaboratively rather than silently work it out myself) and also rhetorically (if it's really this complex what comment could we put into the code to make it clearer to the next saps who want to understand it?) |
I think so. I don't exactly think that should be in the code, tho. instead it should be in a separate file. |
I created an issue at #250 so that hopefully the next time somebody goes down this build-and-bootstrap rabbit hole they could capture that into a readme of some kind. |
hi all! :) edit: i didnt even see ur previous message, cuz i opened this page much earlier... i think the best for such descriptions would be best in a form like a recipe in order, like this generates that and that will be used by whatever for whatever purpose and so on... so one can gasp the whole pic from the perspective of a bird, see the "wires", and knows how things are assembled/working and where to go for a given purpose. otherwise i hate it when the source is hard to follow, but some hints/pointers to follow are enough for demistification in general. ((this latter applies to oop so badly, its a horror in general to track down the flow, even if basically it looks like a pretty library with every book on its well-defined place til its not about runtime, cuz its horribly fragmented.)) so the tldr: its all about showing the flow and giving the pointers whenever they are necessary to see the path. „Everything should be made as simple as possible, but not simpler.” - A. E. :) so the rest is about explanation. :D all the bests for all of u! :) |
Great tip from @CapsAdmin: There is already an implementation of the LuaJIT parser and bytecode compiler in Lua! Could we use this to retire some C code in RaptorJIT? https://github.com/franko/luajit-lang-toolkit |
Hey, I stumbled on this issue and it got me thinking, it could go in some interesting directions. I wrote a bit over at LuaJIT/LuaJIT#488. @lukego you mentioned you were really interested in the idea, and I'm not sure if GH creates pings when issues mention other issues - so, just making absolutely sure. :) I don't mind which thread the replies/discussion end up in. RJ and LJ have complimentary objectives. |
Sorry if I missed something, didn't read the full thread to be honest.. These projects might be of interest for redoing the bootstrapping part, might save you the trouble of reinventing a wheel or two: https://github.com/leegao/LuaInLua |
This issue is to "import" and idea that I really like from the LuaJIT repo: LuaJIT/LuaJIT#488
The Lua bytecode compiler is currently written in C but it does strike me that writing this in Lua instead would reduce overall complexity and make the language frontend easier to maintain and evolve. I don't see much of a bootstrapping problem since we could embed the precompiled bytecodes into the VM.
Cool idea @SoniEx2 :-)
The text was updated successfully, but these errors were encountered: