-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add brief READMEs and some documentation
Decided to finally publish the repository, so some guidance about usage was needed. Most importantly, the warning not to use this in production!
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2022- bensku | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# code4jvm | ||
code4jvm is a high-level JVM bytecode generation library for writing | ||
compiler backends. It allows generating Java-like code without worrying | ||
about low-level features, while still supporting JVM features that cannot | ||
be expressed in Java. | ||
|
||
The core code4jvm library consists of: | ||
* Automatic stack management and local variable slot tracking | ||
* Stack map frame generation (with control flow tracing) | ||
* An extensible expression system that allows generation of custom bytecode | ||
* Simple control flow (basic blocks, jumps) | ||
* Java-like type conversions (complex casts, boxing) | ||
* Exception handling (including try-finally block support) | ||
|
||
On top of this, some higher-level features are included: | ||
* Structured control flow (conditional blocks, loops) | ||
* Method calls, including use of constructors | ||
* Arithmetic and bitwise operations | ||
* String concatenation | ||
* Enum classes | ||
|
||
Under the hood, JVM bytecode is generated using the low-level | ||
[ASM](https://asm.ow2.io/) library. | ||
|
||
## Usage | ||
As of now, the only use case worth of mentioning is | ||
[lua4jvm](lua4jvm/README.md), a work-in-progress Lua 5.4 implementation for JVM. | ||
|
||
## Status | ||
This library is work-in-progress. It is being worked on in author's spare time, | ||
and there are no guarantees about when bug fixes or new features will be | ||
available. Additionally, code4jvm is not yet published on Maven central. | ||
Naturally, there are also zero guarantees about API stability. | ||
|
||
As you might notice, the documentation is also quite sparse. There are | ||
Javadocs, but beyond them you'd have to learn by example. | ||
|
||
In short: don't use this in production. If you just want to hack around, | ||
feel free to open issues (or even pull requests!). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# lua4jvm | ||
lua4jvm is a work-in-progress JIT compiler for Lua 5.4 built on top | ||
of JVM. Originally, it started as an university course project, but most of | ||
*that* code has been rewritten at least once. | ||
|
||
In its current form, you shouldn't use lua4jvm. While usually reliable, it | ||
lacks the Lua standard library implementation; instead, the development has | ||
focused on core VM features. Rest of the work is arguably easier; the author | ||
has just been busy for a while. | ||
|
||
## Architecture | ||
The lua4jvm lacks formal documentation. However, below is a brief description | ||
of its architecture. | ||
|
||
### Frontend | ||
Lua is parsed with a custom Antlr 4 grammar. From there, it is translated to | ||
an internal IR format that the backend consumes. There is nothing too special | ||
about this; initially, the project included a custom parser, but quite soon I | ||
realized that I wanted to focus on the backend. | ||
|
||
### Backend | ||
Lua is a dynamically typed language with extensive runtime metaprogramming | ||
facilities (metatables). Both of these characteristics make compiling it | ||
into performant code rather difficult. This is especially true when the | ||
compilation target has been primarily built for statically-typed languages; | ||
on JVM, optimizations such as NaN tagging cannot be done. | ||
|
||
To tackle this issue, lua4jvm generally compiles code only immediately before | ||
it would be executed. Function calls generate their targets on first call | ||
based on the real types at call sites; and should the types change, the target | ||
will just get compiled again. The same system is also used for Lua's many | ||
operators, since they can be overridden by metatables. The generated | ||
specializations are cached between all call sites. | ||
|
||
This approach also allows usage of 'static' analysis at runtime. Since the | ||
function compiler effectively knows types of its arguments and upvalues, it | ||
can for example use primitive types for numerical code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters