Skip to main content

Crate scalars

Crate scalars 

Source
Expand description

scalars — Scala as a fusevm frontend.

Pipeline: lexer → parser builds a Scala 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 Scala’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 banner::version_banner;
pub use embed::run_program;

Modules§

ast
The Scala AST scalars parses and lowers to fusevm bytecode.
banner
The scala --version banner string.
bigdec
scala.math.BigDecimal — java.math.BigDecimal under MathContext.DECIMAL128.
cli
Command-line parsing for the scala binary.
compiler
Lower the Scala AST to a fusevm::Chunk.
corpus
The language-reference corpus: the (name, chapter, doc, signature+example) table behind editor completion, editor hover (src/lsp.rs) and the generated docs/reference.html (src/bin/gen_docs.rs).
dap
Debug Adapter Protocol over stdio (scala --dap).
embed
Embedding entry point: run a Scala program from Rust with a given stdin and get its stdout back as a string.
fdlibm
java.lang.StrictMath: fdlibm 5.3, as the JDK transliterates it in java.lang.FdLibm (JDK 21).
host
The scalars host: builtin registration, Scala value formatting, and the strict numeric hook.
jlocale
java.util.Locale’s identity, text forms and English display names, ported from JDK 21: java.util.Locale, and sun.util.locale’s BaseLocale, LanguageTag, InternalLocaleBuilder, LocaleExtensions and UnicodeLocaleExtension.
jrandom
java.util.Random — the 48-bit linear congruential generator behind both java.util.Random and scala.util.Random (which delegates to it). A seeded generator reproduces the JVM’s sequence exactly; the derived draws (nextInt(bound), nextDouble, nextGaussian) are ports of the JDK algorithms, and between/nextLong(n)/shuffle are ports of scala.util.Random in the 2.13 library, which Scala 3 runs on.
lexer
A hand-written Scala lexer with newline inference.
locale_names
The English display names java.util.Locale answers through the JDK’s locale data — what getDisplayLanguage/getDisplayScript/ getDisplayCountry/getDisplayVariant and the Unicode extension names in getDisplayName produce in an English display locale.
lsp
Language Server Protocol over stdio (scala --lsp).
parser
A recursive-descent parser with precedence-climbing for expressions.
rbtree
scala.collection.immutable.RedBlackTree, ported from the Scala 3.10 library (scala/collection/immutable/RedBlackTree.scala) — the storage of an immutable TreeSet/TreeMap.
resolve
Lexical scoping: unique renaming of defs and shadowed bindings, plus lambda lifting.
rust_ffi
Scala wiring for inline Rust FFI (rust { ... } blocks).
tiers
Which fusevm execution tier a program’s bytecode actually reaches.
timsort
The two stable sorts a Scala program’s comparisons run through, ported so the comparator is asked exactly what the JVM asks it — in the same order, the same number of times. An Ordering.by(f) runs f once per operand of every comparison and a sortWith predicate is a user closure, so both the count and the sequence are observable.

Functions§

compile
Parse and lower Scala src to a runnable fusevm chunk.
compile_debug
Parse and lower Scala src with per-statement DBG_LINE markers (for scala --dap).
disassemble
Compile src and return a human-readable disassembly of the fusevm chunk (for scala --disasm).
eval_file_debug
Read and run a .scala file under the debug marker path (for scala --dap).
parse
Parse Scala src to an AST.
run_file
Read and run a .scala file.
run_str
Compile and run a Scala source string; return the last VM value.
run_str_with_args
Run a Scala source string with the program arguments a def main’s args parameter and a @main method’s parameters read from.