Expand description
javars — Java as a fusevm frontend.
Pipeline: lexer → parser builds a Java AST → compiler lowers it to a
fusevm::Chunk → fusevm executes it on the shared three-tier Cranelift JIT,
calling back into host (the strict numeric hook) for Java’s String +
overload. There is no bespoke VM or JVM here — execution and codegen live in
fusevm, the same engine behind zshrs, stryke, awkrs, elisp, and ruby.
Re-exports§
pub use embed::run_program;
Modules§
- ast
- The Java AST javars parses and lowers to fusevm bytecode.
- banner
- The
java --versionbanner string. - cli
- Command-line parsing for the
javabinary. - compiler
- Lower the Java AST to a
fusevm::Chunk. - dap
- Debug Adapter Protocol over stdio (
java --dap). - embed
- Embedding entry point: run a Java program from Rust with a given stdin and get its stdout back as a string.
- fdlibm
java.lang.FdLibm: the JDK’s own Java port of fdlibm, which everyStrictMathfunction answers from, and whichMathdelegates to wherever HotSpot has no intrinsic for the function.- flow
- Definite assignment (JLS chapter 16), checked the way
javacchecks it. - host
- The javars host: builtin registration, Java value formatting, and the strict numeric hook.
- hotspot_
trig Math.sinandMath.cosas HotSpot answers them on aarch64: a port of thedsin/dcosstubsMacroAssembler::generate_dsin_dcosemits (src/hotspot/cpu/aarch64/macroAssembler_aarch64_trig.cpp, openjdk 27), which the interpreter, C1 and C2 all call for those two methods.- jbig
java.math.BigInteger: the arithmetic ofnum-bigintbehind the JDK’s contract — truncatingdivide/remainder, always-non-negativemod, two’s-complement bitwise semantics on negatives, the exact exception messages,hashCodeover the big-endian 32-bit magnitude words, and the low-bits narrowing ofintValue/longValue.- jbigdec
java.math.BigDecimal,RoundingModeandMathContext: an unscaledBigIntplus a decimal scale, following the JDK’s contract — the preferred scales ofdivide/sqrt, the canonicaltoString, scale-sensitiveequals, the string grammar and its exception messages.- jbitset
java.util.BitSet, ported fromjava.base/java/util/BitSet.java(openjdk 27): a growable vector of 64-bit words with the JDK’s capacity rule (size()is the allocated word count times 64, doubling on growth), its index checks and their messages, itshashCode, and its{1, 3}rendering.- jdk_
generic_ statics - Generated by
scripts/GenJdkGenericStatics.javafrom OpenJDK 64-Bit Server VM 21.0.13.0.2 — do not edit. - jdk_
supertypes - Generated by
scripts/GenJdkSupertypes.javafrom OpenJDK 64-Bit Server VM 21.0.13.0.2 — do not edit. - jio
- Console and text input and output:
System.in,java.util.Scanner,java.io.BufferedReader/InputStreamReader/StringReader,java.util.StringTokenizer, and on the output sideSystem.out/err, thejava.iowriters (PrintWriter,BufferedWriter,OutputStreamWriter,StringWriter) and print streams (PrintStream,BufferedOutputStream). The output half is at the end of the file. - jrandom
java.util.Random: the JDK’s 48-bit linear congruential generator.- jstr
- Java’s
Stringmodel on fusevm’s UTF-8Value::Str. - lexer
- A hand-written Java lexer.
- lsp
- Language Server Protocol over stdio (
java --lsp). - parser
- A recursive-descent arser with precedence-climbing for expressions.
- prelude
- The implicit
java.lang/java.util.functionprelude. - reference
- The javars language-reference corpus.
- regex
java.util.regexonfancy-regex.- regex_
names - Generated by
scripts/GenRegexNames.javafrom OpenJDK 64-Bit Server VM 21.0.13.0.2 — do not edit. - regex_
syntax java.util.regex.Pattern’s syntax check, ported from its recursive-descent parser (Pattern.expr/sequence/atom/closure/group0/clazz/range/escapeand the escape helpers in OpenJDK 21’sPattern.java).- rust_
ffi - Java wiring for inline Rust FFI (
rust { ... }blocks). - tiers
- Which fusevm execution tier a program’s bytecode actually reaches.
- unicode_
tables - Unicode property tables for
java.lang.Character, generated fromopenjdk 21.0.13.0.2byscripts/GenUnicodeTables.java, which dumps the JDK’s own answers for every code point (Character.getType,getNumericValue,isIdeographic, the emoji properties,UnicodeBlock.of) as sorted, non-overlapping(first, last, value)runs. Regenerate rather than edit. - uninames
Character.getName, from the namesscripts/GenUnicodeTables.javadumps out of the JDK intosrc/data/uninames.bin(its header describes the format). A code point with no name of its own there is named as the JDK names it: its block, then its code point in upper-case hex.
Functions§
- compile
- Parse and lower Java
srcto a runnable fusevm chunk. - disassemble
- Compile
srcand return a human-readable disassembly of the fusevm chunk (forjava --disasm). - parse
- Parse Java
srcto an AST. Inlinerust { ... }FFI blocks are desugared to__rust_compile(...)statements first (seerust_ffi), so every parse path — run,--dump-ast,--disasm,--dap— sees the same rewritten source. No-op when the source has norustblock. - run_
file - Read and run a
.javafile. - run_str
- Compile and run a Java source string with no program arguments (
argsis a zero-lengthString[]); return the last VM value. - run_
str_ args - Compile and run a Java source string, binding
argvtomain’sString[]parameter.