PriyoScriptPriyoScript

CLI and REPL

Use PriyoScript from terminal effectively, and know when to choose CLI vs REPL.

Theory

CLI (Command Line Interface) and REPL (Read-Eval-Print Loop) serve different development modes in PriyoScript. CLI is file-oriented and deterministic, making it ideal for repeatable execution, project workflows, and CI automation. REPL is interactive and stateful, making it ideal for experimentation, quick checks, and iterative learning. PriyoScript supports both flows with common diagnostics tooling (-errors, -explain) and runtime tracing (-trace) so users can move from exploration to production without changing language semantics.

Quick choice rule

Use CLI for real scripts and repeatable runs. Use REPL for rapid experiments and learning loops.

Core command summary

CLI essentials

CommandModePurpose
monalisa <file.priyo>CLIRun a PriyoScript file
monalisa -replREPLStart interactive shell
monalisa -trace <file>CLIRun with opcode-level trace

Help and diagnostics

CommandModePurpose
monalisa -hCLIHelp and command list (alias)
monalisa -helpCLIHelp and command list
monalisa -vCLIVersion (alias)
monalisa -versionCLIVersion
monalisa -sCLISyntax quick help (alias)
monalisa -syntaxCLISyntax quick help
monalisa -eCLIError code list (alias)
monalisa -errorsCLIList error codes
monalisa -x <CODE>CLIExplain error code (alias)
monalisa -explain <CODE>CLIExplain specific error code

Trace helpers and filters

CommandModePurpose
monalisa -thCLITrace help (alias)
monalisa -trace-helpCLIShow trace filtering options
monalisa -trace-format jsonCLIJSON trace lines for tooling
monalisa -trace-op ADD,SUBCLITrace only specific opcodes
monalisa -trace-op-exclude HALTCLIExclude opcodes from trace
monalisa -trace-file modulesCLITrace only matching file path
monalisa -trace-label labelCLITrace only matching breakpoint labels
monalisa -trace-type trace,breakCLITrace event types (trace, break, all)
monalisa -trace-frame <name>CLITrace only matching frame name
monalisa -trace-stack-min 2CLITrace only when stack depth >= N
monalisa -trace-stack-max 6CLITrace only when stack depth < N

REPL command summary

CommandPurpose
.helpShow REPL command list
.clearClear current multiline buffer
.editorEnter editor mode (edit> prompt)
.runExecute editor buffer (editor mode only)
.cancelDiscard editor buffer (editor mode only)
.resetReset runtime state and module cache
.load <file>Execute file in current REPL context
.reload [file]Reload last loaded file or explicit file
.historyShow executed snippets history
.save <file>Save snippet history to file
.envInspect current bindings with kind/type/value preview
.type <expr>Evaluate expression and print inferred type + value
.exitExit REPL

Program Examples

Example 1: Show Help

monalisa -h

Output (short):

PriyoScript CLI help...

Explanation: verifies installation and available command options.

Example 2: Run a File

monalisa hello.priyo

Output:

Hello, PriyoScript!

Explanation: standard production execution path for .priyo scripts.

Example 3: Start REPL

monalisa -repl

Output (short):

Hey, this is PriyoScript REPL...
priyo>

Explanation: opens interactive shell with persistent in-session state.

Example 4: REPL Session

priyo> priyoKeep x = 12
priyo> priyoTell(x * 2)
24

Output:

24

Explanation: second line uses variable from previous line because REPL keeps environment alive.

Example 5: Error Discovery Commands

monalisa -errors
monalisa -explain PSYN-002

Output (short):

List of error codes...
Explanation for PSYN-002...

Explanation: helps users map runtime/syntax failures to exact docs and fixes.

Example 6: Trace Mode

monalisa -trace examples/basics/for-loop.priyo

Output (short):

[TRACE #1] examples/basics/for-loop.priyo <main> ip=0 op=...
[TRACE #2] examples/basics/for-loop.priyo <main> ip=1 op=...
...

Explanation: shows VM instruction-by-instruction flow for deep debugging.

Filter examples:

monalisa -trace -trace-op CALL_METHOD,RETURN examples/basics/for-loop.priyo
monalisa -trace -trace-format json -trace-frame "<main>" examples/basics/for-loop.priyo

Example 7: Breakpoint-Style Hook

monalisa {
  priyoKeep total = 10
  prakritiThink("after-total")
  priyoTell(total)
}

Output (short):

[BREAK #1] label="after-total"
10

Explanation: prakritiThink(...) marks checkpoints inside trace output.

Example 8: Useful REPL commands

priyo> .help
priyo> .load examples/basics/main.priyo
priyo> .editor
edit> priyoKeep n = 10
edit> priyoTell(n * 5)
edit> .run
priyo> .reload
priyo> .env
priyo> .type 10 + 32
priyo> .history
priyo> .reset
priyo> .exit

Output (short):

REPL commands list...
Loaded: examples/basics/main.priyo
Editor mode enabled...
50
Reloaded: examples/basics/main.priyo
Bindings:
type: number
value: 42
REPL history:
Runtime state reset.

Explanation: supports structured iteration in interactive mode.

Example 9: REPL persistence file

PriyoScript REPL saves session history automatically to:

.priyo_repl_history.json

You can keep this file for continuity or remove it to start with clean persisted history.

Execution Flow

CLI flow:

  1. You pass file path.
  2. CLI loads full source.
  3. Parser/compiler/VM run once.
  4. Program exits with output or error.
  5. Each run starts with a clean runtime process.

REPL flow:

  1. You type one line/snippet.
  2. REPL evaluates it immediately.
  3. State stays in memory for next line.
  4. History is persisted to .priyo_repl_history.json on exit.
  5. You repeat until .exit.
  6. .reset clears runtime state and module cache for clean retry.
  7. Optional editor mode (.editor) lets you draft multi-line snippets before running .run.

Trace flow:

  1. You run with -trace (optional -trace-* filters).
  2. VM emits execution lines for each instruction.
  3. If prakritiThink(...) exists, VM prints a breakpoint marker.
  4. On runtime error, PriyoScript includes source-level stack context.
  5. Use trace output to isolate exact failing sequence.

Comparison With Other Languages

Node.js CLI/REPL:

  • node file.js
  • node (interactive REPL)

Python CLI/REPL:

  • python script.py
  • python (interactive shell)

Java:

  • Compile + run model (javac, java) and optional JShell for REPL-like experience.

C:

  • Compile then execute binary (gcc, ./a.out), no default built-in REPL.

PriyoScript:

  • monalisa file.priyo
  • monalisa -repl
  • monalisa -trace file.priyo

Difference summary:

  • PriyoScript behaves like modern interpreted workflows (Node/Python) with dedicated language diagnostics.
  • PriyoScript adds built-in error-code explanation flow (-errors and -explain) for beginner-friendly debugging.

Inspiration and Official References

Limitations

REPL is ideal for learning and prototyping, but long programs should be stored in .priyo files and executed via CLI.

Debug Tip

Start with normal run. If behavior is unclear, rerun with -trace and place prakritiThink("checkpoint") at important points.

Last updated on

On this page