Giter Site home page Giter Site logo

luaj.luajc's Introduction

LuaJC Build Status

LuaJ, but faster

This is a fork of LuaJ's Lua to Java bytecode compiler. It has been converted to use the ASM framework and many bugs have been fixed.

Changes from the original

  • Core debug support (debug.traceback, debug.getinfo and all debug hooks - you cannot get or change locals/upvalues though)
  • string.dump support
  • getfenv and setfenv support
  • Delayed compilation: only compile after n calls.
  • Fixes several bugs with generation (see BranchUpvalue2, EdgeCases and NilCallReturn)

Performance

It is tricky to compare the default LuaClosure and LuaJC implementations as several optimisations are applied for debug hooks. These could also be applied to the default VM implementation and increase its performance too.

However there are still some performance increases. Testing on this aes implementation produces these results:

Task LuaJC LuaC Optimised LuaVM
Compilation 0.007993 0.004938 0.004938
Running 9.783356 16.707443 14.739549

Getting started

Firstly add this as a dependency:

repositories {
	maven {
		name = "squiddev"
		url = "https://dl.bintray.com/squiddev/maven"
	}
}

dependencies {
	compile 'org.squiddev:luaj.luajc:1.+'
}

Then install it as a compiler after setting up the globals.

import org.squiddev.luaj.luajc.LuaJC;

public LuaValue load(InputStream stream, String name) throws IOException {
	LuaValue globals = JsePlatform.debugGlobals();
	LuaC.install();
	return LoadState.load(stream, name, globals);
}

You can also pass an instance of the CompileOptions class when installing the compiler.

luaj.luajc's People

Contributors

squiddev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

luaj.luajc's Issues

Issue in kristwallet

In kristwallet, when you click around between the Transactions and Special TX tabs (try right clicking in the transactions panel a few times, too), eventually LuaJC will crash with a bytecode dump:

[ERROR] There was an error when compiling kristwallet.lua$35.
Please report this error message to http://github.com/SquidDev/luaj.luajc
proto '$35'

[lots of bytecode]

java.lang.RuntimeException: Method code too large!
    at org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2036)
    at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:827)
    at org.squiddev.luaj.luajc.compilation.JavaBuilder.completeClass(JavaBuilder.java:287)
    at org.squiddev.luaj.luajc.compilation.JavaGen.<init>(JavaGen.java:42)
    at org.squiddev.luaj.luajc.compilation.JavaLoader.include(JavaLoader.java:61)
    at org.squiddev.luaj.luajc.function.executors.ClosureExecutor.execute(ClosureExecutor.java:24)
        ...

Sometimes this makes the computer unusable, other times it'll act as if nothing happened.

Extensive API documentation

Please I need an extensive documentation/WIKI on how to use LuaJ. I can't seem to find any comprehensive tutorial or wiki online, thanks!

Unboxing types

A recent profile of the latest version shows (unsurprisingly) that the slowest part of the code is boxing/unboxing numbers.

I feel the best thing to do would be to generate a specialised bytecode which uses doubles instead. However this would require tracking the types of variables to see where it is worthwhile not boxing the types.

  • Incremental/delayed compilation
  • Specialise functions
  • Specialising function calls
  • Removing debug API calls when not needed
  • Inline calls to math.* and bit.* functions

LASM parser

It would be great to add a parser for LASM in order to test some bugs that can only occur in Lua bytecode.

Upvalue reassigned

From SquidDev-CC/Studio#14 and #1

We are getting generation errors with a very edge case piece of code:

local upvalue

local function closure()
    return upvalue
end

while true do
    if "const" ~= "const" then
        upvalue = "const"
    else
        for loop_num = "const", "const" do
            for loop_iter in func() do
                func(loop_num + loop_iter)
            end
        end
    end
end

The trouble is at the end of the for loop (line 12: for loop_iter in func()). As the upvalue is reassigned within a branch statement there seems to be an issue that the upvalue is created and stored as an upvalue straight away, and so the upvalue slot is empty.

It seems it wants to convert an upvalue despite one has already been converted.

Something is breaking in the logic here to do with loops.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.