Satyajit Sarangi bio photo

Satyajit Sarangi

I am a software engineer currently residing in Bay Area.

Email Twitter LinkedIn Github Stackoverflow

Luajit is for Lua !!!

I know… But out of curiosity and wanting to see more of it I decided to go ahead and try and see what I could get Luajit to run.

Luajit Architecture:

Luajit is written completely in C and has a huge helping hand from assembly too. But overall if you look at it, it has the same number of things a regular jitter does.

  • It lexes and parses lua code
  • Emit’s a bytecode from it.
  • From the bytecode it emits an SSA IR
  • It then optimizes the SSA IR.
  • It also has an interpreter which acts as a tracing jit.
  • Finally after identifying hotspots, it runs it on the full jit.
  • Garbage collection is also present and Mike had ideas on the next gen garbage collectors too.

Information:

Look on the Luajit Wiki. It has tons of information.

Code which is working:

Github Link

  • Simple functions
  • lists
  • While loops
  • If-else-elseif control flow

There is a hell lot of work left and am not even sure if everything can be / should be supported by this. If you would like to collaborate on this, drop me a line.

def foo():
    print("hello world")
    a = 3
    b = 2
    c = a * b
    return c

g = foo()
print(g)
def foo():
    a = 3
    b = 3
    if a > b:
        print("a > b")
    elif a == b:
        print("a == b")
    else:
        print("b > a")

foo()
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
print(days[0])
i = 3
i = i + 1
print(days[i])
print(days[4])
def foo():
    a = 1
    while a < 10:
        print(a)
        a = a + 1

foo()