-
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.
Merge pull request #3 from PRL-PRG/sexp-rds-compiler-init
Implement enough of `SEXP`, `RDSReader`, and `Compiler` to pass tests
- Loading branch information
Showing
85 changed files
with
4,774 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
{ | ||
"lspconfig": { | ||
"jdtls": { | ||
"java.configuration.runtimes": [ | ||
{ | ||
"name": "JavaSE-21", | ||
"path": "/home/krikava/.asdf/installs/java/openjdk-21", | ||
"default": true | ||
} | ||
] | ||
} | ||
} | ||
} |
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
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,32 @@ | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.prlprg.rds.RDSReader; | ||
import org.prlprg.sexp.SEXP; | ||
import org.prlprg.util.IO; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) throws Exception { | ||
new Main().doMain(args); | ||
} | ||
|
||
private void doMain(String[] args) throws Exception { | ||
compile(args[0]); | ||
} | ||
|
||
private void compile(String file) throws IOException { | ||
try (var input = new FileInputStream(file)) { | ||
compile(input); | ||
} | ||
} | ||
|
||
private void compile(InputStream input) throws IOException { | ||
compile(RDSReader.readStream(IO.maybeDecompress(input))); | ||
} | ||
|
||
private void compile(SEXP sexp) { | ||
System.out.println(sexp); | ||
} | ||
} |
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,8 @@ | ||
package org.prlprg; | ||
|
||
public final class RPlatform { | ||
public static final int INT_MAX = ~(1 << 31); | ||
|
||
private RPlatform() { | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,77 @@ | ||
package org.prlprg.bc; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.primitives.ImmutableIntArray; | ||
import org.prlprg.sexp.SEXP; | ||
|
||
// TODO: Remove stub with Sexp from branch `filip` | ||
class Sexp {} | ||
import java.util.*; | ||
|
||
/** A complete R bytecode, consisting of a version, array of instructions and associated data, and constants. */ | ||
public record Bc(BcCode code, ImmutableList<Sexp> constants) { | ||
public record Bc(BcCode code, ConstPool consts) { | ||
/** | ||
* The only version of R bytecodes we support, which is also the latest version. | ||
* The bytecode's version is denoted by the first integer in its code. | ||
*/ | ||
static int R_BC_VERSION = 13; | ||
public static final int R_BC_VERSION = 12; | ||
|
||
/** Create from the raw GNU-R representation, bytecodes not including the initial version number. */ | ||
public static Bc fromRaw(ImmutableIntArray bytecodes, List<SEXP> consts) throws BcFromRawException { | ||
var poolAndMakeIdx = ConstPool.fromRaw(consts); | ||
var pool = poolAndMakeIdx.a(); | ||
var makePoolIdx = poolAndMakeIdx.b(); | ||
try { | ||
return new Bc(BcCode.fromRaw(bytecodes, makePoolIdx), pool); | ||
} catch (BcFromRawException e) { | ||
throw new BcFromRawException("malformed bytecode\nConstants: " + pool, e); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return code() + "\n" + consts; | ||
} | ||
|
||
/** Equivalent to `CodeBuffer` in other projects */ | ||
public static class Builder { | ||
private final BcCode.Builder code = new BcCode.Builder(); | ||
private final ConstPool.Builder consts = new ConstPool.Builder(); | ||
|
||
/** | ||
* Append a constant and return its index. | ||
*/ | ||
public <S extends SEXP> ConstPool.TypedIdx<S> addConst(S c) { | ||
return consts.add(c); | ||
} | ||
|
||
/** | ||
* Append an instruction. | ||
*/ | ||
public void addInstr(BcInstr instr) { | ||
code.add(instr); | ||
} | ||
|
||
/** | ||
* Append a collection of constants and return its index. | ||
*/ | ||
public <S extends SEXP> ImmutableList<ConstPool.TypedIdx<S>> addAllConsts(Collection<? extends S> c) { | ||
return consts.addAll(c); | ||
} | ||
|
||
/** | ||
* Append instructions. | ||
*/ | ||
public void addAllInstrs(Collection<? extends BcInstr> c) { | ||
code.addAll(c); | ||
} | ||
|
||
/** | ||
* Finish building the bytecode. | ||
* | ||
* @return The bytecode. | ||
*/ | ||
public Bc build() { | ||
return new Bc(code.build(), consts.build()); | ||
} | ||
} | ||
|
||
} |
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
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
package org.prlprg.bc; | ||
|
||
public class BcFromRawException extends RuntimeException { | ||
public BcFromRawException(String message) { | ||
super(message); | ||
} | ||
|
||
public BcFromRawException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Oops, something went wrong.