REPL¶
The Onion REPL is implemented by onion.tools.Repl and is the primary interactive shell for the language.
Starting the REPL¶
Use any of the following entry points:
Core Features¶
- Multi-line input with continuation prompts
- Session-scoped
module,import,val,var,def, and class declarations - Persistent
resNbindings for evaluated expressions - History and syntax highlighting through JLine 3
- Session compile caching for repeated inspections of the same source snapshot
Commands¶
:help Show help
:quit / :exit / :q Exit the REPL
:clear Clear the terminal
:history Show input history
:imports Show current module/imports
:type <expr> Show the inferred type of an expression
:ast <expr> Dump the parsed AST for an expression
:typed <expr> Dump the typed AST summary for an expression
:bytecode <expr> Dump generated JVM bytecode for an expression
:load <file> Load a file into the current session
:time [on|off] Toggle compile/eval timing
:classpath Show the active classpath
:reset Reset the session
:paste Enter paste mode
Examples¶
Results and resN¶
Multi-line Definitions¶
onion> def factorial(n: Int): Int {
| if n <= 1 {
| return 1;
| } else {
| return n * factorial(n - 1);
| }
| }
Inspecting Types and Bytecode¶
onion> :type Math::max(1, 2)
Math::max(1, 2): Int
onion> :bytecode 1 + 2
== <generated class> ==
...
Loading Files¶
Notes¶
onion replandonion-replstart the same implementation.:timeis useful when comparing REPL compile/eval latency while working on compiler performance.:bytecoderenders class output with ASM tracing, so helper/closure classes may appear alongside the primary generated class.