- REPL now runs every line on the SAME vm, so 'x = 50' then 'x'
persists across lines (was re-creating a vm per line)
- a lone expression echoes its value (new PRINTEXPR opcode), and a
call yielding no value (the empty object) is not echoed
- compiler: cat_compiler_compile_mode(src, err, repl) emits PRINTEXPR
for a lone expression in REPL mode
- _repr_ protocol: cat_value_repr honours a member (text value
used verbatim, or a callable invoked with the value as self); a
default by family otherwise. tostring is the display form (text
unquoted); the REPL echo is the repr form (text quoted)
- list/object default representations ([a, b], {k = v})
- tests: tests/repr.cat + REPL checks (92 total, all green)
26 lines
843 B
C
26 lines
843 B
C
/*
|
|
* cat/compiler.h -- source -> bytecode compiler.
|
|
*
|
|
* Naming rule: symbols here are cat_compiler_* / CAT_COMPILER_*.
|
|
*
|
|
* The compiler is a recursive-descent parser over the Lua-like syntax.
|
|
* It performs structural-typing checks only where cheap (nothing is
|
|
* nominal) and accepts optional `: type` hints, which are advisory.
|
|
*/
|
|
#ifndef CAT_COMPILER_H
|
|
#define CAT_COMPILER_H
|
|
|
|
#include "cat/bytecode.h"
|
|
#include "cat/error.h"
|
|
|
|
/* Compile `source` into a fresh top-level function. */
|
|
CAT_BYTECODE_Function *cat_compiler_compile(const char *source,
|
|
CAT_ERROR_Error *err);
|
|
|
|
/* Like cat_compiler_compile, but a lone expression statement is echoed
|
|
* (emits PRINTEXPR). Used by the REPL. */
|
|
CAT_BYTECODE_Function *cat_compiler_compile_mode(const char *source,
|
|
CAT_ERROR_Error *err, int repl);
|
|
|
|
#endif /* CAT_COMPILER_H */
|