News for hackers. Stuff that matters.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by Rochus on Saturday November 09, 2019 @03:11PM (#21494004)
Thanks for the suggestion. I think mostly people who want to use LuaJIT as a backend for another language, not primarily Lua programmers, might be interested in my work. Here is an article describing the project: https://medium.com/@rochus.keller/implementing-call-by-refer...
Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Saturday November 09, 2019 @03:48PM (#21494251)
> LuaJIT as a backend for another language, not primarily Lua programmers

Not exactly backend but that kinda fits my use case. I have a C embedded application that I need scripting on. Nothing unsecure from the user, from my own backend, but it requires a foreign function interface, and its a super constrained device.

Lua, JavaScript, forth, etc. None I’ve been able to find anything I like under 50 kB flash or are even slightly “friendly”.

Found one in JavaScript was close, but it’s an interpreted language which means every letter of code is a byte I need to transfer then have parsed.

I’ll look into this. Esp if it’s still possible to send just bytecode in.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by rafa1981 on Saturday November 09, 2019 @04:39PM (#21494560)
I don't know if luajit runs in your device, but vanilla luajit supports generating and loading bytecode.

https://luajit.org/running.html

Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Saturday November 09, 2019 @05:49PM (#21495031)
I think primarily it’s the ffi I would be missing. This would get me a turing complete language but set up as an executable it’s wrong for me.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by rafa1981 on Monday November 11, 2019 @07:23AM (#21504227)
Notice that if I remember correctly, you can generate bytecode on the PC (by using the luajit command) and have the resulting bytecode loaded through the C API on your device as if it were a regular script.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by Rochus on Sunday November 10, 2019 @05:49AM (#21497456)
I don't think this work fits your needs. Have a look at something like https://en.wikipedia.org/wiki/NodeMCU or http://www.eluaproject.net/ or https://github.com/whitecatboard/Lua-RTOS-ESP32 instead.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Sunday November 10, 2019 @04:42PM (#21500356)
The problem with eLua and others is that they either try and replace C or they focus on the headers/registers/peripherals of the micro. Design it to be the environment you do all your work in. Get there, stay there. It’s why eLua appears to have terrible micro support because they only have the bandwidth for specific chips. Other options like MicroPython have a VM you are never supposed to leave.

I think you’re right that Lua is the way to go. But I have yet to see someone package it nicely for gcc and to be included and built from an MCU IDE (Keil, Segger Emebbeded, IAR, etc). I’ll keep looking.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by connicpu on Saturday November 09, 2019 @06:03PM (#21495097)
The basic lua VM (not luajit) is only like 11kb compiled. You can't directly do FFI from lua, but you can set up the FFI functions from the C API
Re:Show HN: LuaJIT assembler/assembly language for direct by... by SlowRobotAhead on Saturday November 09, 2019 @09:18PM (#21495992)
Any examples of code or know where someone has done this?
Re:Show HN: LuaJIT assembler/assembly language for direct by... by matheusmoreira on Saturday November 09, 2019 @11:13PM (#21496361)
Lua was made for this! Here's a simple example:

https://gist.github.com/Vesnica/3672425

It loads and runs a Lua source code file which calls the exported C function. Lua compiles the source code into byte code before running it but that can also be done ahead of time with the Lua compiler:

https://www.lua.org/manual/5.3/luac.html

It can also be done manually with the dump and load functions:

https://www.lua.org/manual/5.3/manual.html#lua_dump

https://www.lua.org/manual/5.3/manual.html#lua_load

Re:Show HN: LuaJIT assembler/assembly language for direct by... by bryanrasmussen on Saturday November 09, 2019 @04:11PM (#21494378)
Normally JavaScript is a JIT compiled language because of the need to do stuff like hoisting etc.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by Stratoscope on Saturday November 09, 2019 @05:50PM (#21495040)
Just a nit on the JIT... JavaScript is almost always compiled, regardless of whether there is a JIT or not.

A typical JavaScript system first compiles the JS source code into bytecode. Then it starts executing (interpreting) the bytecode.

If there is a JIT, that is a second compiler. It monitors the execution of the bytecode to find hot spots where it compiles the bytecode into machine language.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by bryanrasmussen on Sunday November 10, 2019 @03:21AM (#21497072)
yeah but I was just nitpicking on the "interpreted" statement above. What comes around goes around I guess.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by rurban on Saturday November 09, 2019 @04:08PM (#21494364)
You are missing https://libraries.io/github/fperrad/tvmjit which adds a nice macro and OO layer (in lisp syntax) on top of LuaJIT. A much nicer way to use this superior VM.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by minxomat on Saturday November 09, 2019 @04:19PM (#21494428)
404 on all GitHub links
Re:Show HN: LuaJIT assembler/assembly language for direct by... by rurban on Sunday November 10, 2019 @09:49AM (#21498114)
Yeah, he left github. Maybe you'll get it through shine, which uses tvm. https://github.com/richardhundt/shine

Or I'll upload a fork.

Re:Show HN: LuaJIT assembler/assembly language for direct by... by rurban on Monday November 11, 2019 @03:05AM (#21502980)
Here you are: https://github.com/perl11/tvmjit From an older richardhundt/shine source, in its deps.

Found it also at https://github.com/richardhundt/tvmjit

Re:Show HN: LuaJIT assembler/assembly language for direct by... by Rochus on Thursday November 14, 2019 @07:40AM (#21534922)
Thanks, interesting. But so far I don't see such a big advantage over LuaJIT or the Lua language that would justify creating a new, incompatible fork. It's just another variant, not necessarily a better one. Or have I missed something which is so much better than the original?
Re:Show HN: LuaJIT assembler/assembly language for direct by... by luadigest on Saturday November 09, 2019 @03:37PM (#21494188)
Perfect, I will include it in the next issue.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by microcolonel on Saturday November 09, 2019 @08:30PM (#21495792)
Is RaptorJIT abandoned? It seems like they got a couple optimizations, deleted most of the dynasm backends, then gave up.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by lukego on Sunday November 10, 2019 @12:56AM (#21496642)
RaptorJIT is working well for Snabb but it's not clear what other projects can benefit from it. We're using Lua to compete with C while most other projects seem to be using it to compete with Go/Python/node. So for the moment I'm not actively courting new users because I don't find many kindred spirits in the wider LuaJIT community.

EDIT: To clarify, the big advantage of RaptorJIT is that it takes dramatically less time and effort to profile and optimize programs to become competitive with C. If you're spending a lot of time scratching your head over long 'jit.dump' reports then RaptorJIT will save you lots of time. That's a big win for Snabb hackers but we seem to spend much more time on JIT-optimization than other LuaJIT users.

(Anecdotally it seems like most other LuaJIT users eventually give up on understanding the JIT entirely because they don't see it as being worth the effort. This doesn't really bode well for LuaJIT world domination.)

Re:Show HN: LuaJIT assembler/assembly language for direct by... by microcolonel on Sunday November 10, 2019 @12:25PM (#21498981)
I really like the streams and resources you put up, Luke. Thanks for clarifying. Studio is so cool, I've been looking at maybe hacking it to work with my spreadsheet compiler, using Lua (or maybe LJ bytecode) as IR, and source maps.

Your live streams are a massive resource.

They are so dazzling to others that they'll sit through an explanation of phi nodes, while I assure you they would not otherwise. If you ever want a change of pace, we'd probably be interested in bringing you on board in 2020. Cheers, and I hope the fellas are doing well. :- )

Re:Show HN: LuaJIT assembler/assembly language for direct by... by Rochus on Sunday November 10, 2019 @08:24AM (#21497860)
I had also a look at RaptorJIT. But as far as I understood it only runs on x86-64, not on x86. Or do I have a misunderstanding?
Re:Show HN: LuaJIT assembler/assembly language for direct by... by lukego on Sunday November 10, 2019 @08:25AM (#21497862)
That's correct.
Re:Show HN: LuaJIT assembler/assembly language for direct by... by Rochus on Sunday November 10, 2019 @08:29AM (#21497877)
Does your fork base on LJ 2.0 or 2.1 beta?