Expand description
The core of the yomi language.
Has the parser, type checker, VM, saves and the package mechanism. Uses no unsafe (forbid(unsafe_code)).
How to run a script (spec/host/01-execution.md):
- Register stop commands in a
Registryand bind the sugar. Register packages (Package) withRegistry::package(orRegistry::package_setandpackages!to register a set in any order): effect and query commands, state slices, and host-declared variables. - Turn the source into a
Programwithcompile()(diagnostics areDiagnostic). To receive warnings as well, usecompile_with_warnings. For multiple modules (files that refer to each other withimport), the host collects the sources and callscompile_modules(with warnings:compile_modules_with_warnings). - Create a VM with
Vm::newand repeatVm::runandVm::resume. - At a stop point, make a save with
Vm::saveand restore it withVm::load.persistent vars and passed stop points are persistent data in a separate byte string (Vm::save_persistent,Vm::load_persistent). - For rollback, store
Vm::snapshots in aSnapshotLogat each stop point and go back withVm::restore. - Host
structs andenums get#[derive(YomiType)]and are registered withRegistry::ty. A registry can be written to a declaration file (Registry::export_decls,Registry::from_decls), so tools can check scripts without the host’s Rust code. - For localization, pass a
TextTable(a table that replaces texts, keyed by stable IDs) withVm::set_texts. To switch languages while stopped, useVm::refresh_current; to render the history in the current language, useVm::renderandVm::history_text. Check a table withTextTable::check, and require IDs withCompileOptions::require_text_ids(spec/host/05-texts.md).
Macros§
- packages
- Turns multiple packages into a list passed to
Registry::package_set.
Structs§
- Analysis
- The result of analysis.
- Applied
- The result of
apply. - Code
Info - The public specification of one code.
- Command
Decl - The declaration of a command (of any kind; for tools and declaration files;
Registry::commands). - Command
Error - A failure returned by a command function. When
Erris returned, the VM returns it fromrunas a runtime error (the VM adds the position). - Command
Id - The ID of a command (in registration order).
- Compile
Options - Compile options. Built from
Defaultwith methods. - Contextual
Keyword - A contextual word. Not a reserved word; it has meaning only in certain positions.
- Ctx
- The entry to state that command functions receive.
- CueRef
- One entry of the table of cues in the order written (
Vm::cue_order). - Debugger
- A ready-made hook: breakpoints, stepping, pause requests and a trace function (
spec/host/09-debug.md, 9.6). - Decl
Error - The error when a declaration file could not be read. Has no message text.
- Diagnostic
- One diagnostic.
- Enum
Value - The contents of an
enumvalue. - Error
Code Info - One error code of a command (decided by the package;
crate::CommandError::with_code). - Error
Path - A path that ended with a runtime error.
- Explore
Config - Settings of
explore. - Explore
Report - The result of
explore. - Explore
Step - One answer on a path.
- FnValue
- The contents of a function value.
- Frame
Info - One frame of the call stack (
Vm::call_stack). - IdRng
- The random generator for IDs (xorshift64*; can be fixed by a seed; not cryptographic).
- Identity
- The built-in type
Identity(the identity of quote lines;案内人and"案内人"inidentity 案内人 = "案内人"). - Insertion
- One addition.
- Interrupt
Handle - The token to interrupt a
runfrom another thread (spec/host/01-execution.md, 1.9a). - Keyword
- One reserved word.
- Line
Event - A line is about to run (
spec/host/09-debug.md, 9.2). - List
Data - The contents of a
list. Holds the elements in anArc, so cloning only shares them (the same approach asMapData). - Load
Error - A load failure. Has no message text.
- Load
Report - The report of a load.
- Local
Type - The type of a local variable (bound by
let,forormatch) as decided by the compiler. For editors and tools. - MapData
- The contents of a
map. Holds pairs of keys and values in insertion order, with an index for looking up keys (key → where the pair is stored). - MapEntries
- The iterator returned by
MapData::entriesthat goes through the pairs in insertion order (skipping holes left by removals). - Migrate
Error - A failure of a slice’s
migrate. The load fails withLoadErrorKind::PackageSlice. - Missing
Id - One line that can have an ID but has none.
- Name
- The name of a variable (module variables and host-declared variables include the module (namespace)).
- Package
Decl - Information about a registered package (for declaration files and tools).
- Package
Item - A type-erased package entry passed to bulk registration (
Registry::package_set). Made withpackages!. - Package
Reg - A typed registration entry passed to
Package::register. - Pause
Handle - Asks a
Debuggerto pause at the next line, from any thread. - Pending
Stop - The stop point a save is stopped at, read without restoring the VM (
pending_stop). - Persistent
Report - A report from reading persistent data. Compatibility of variables follows the same rules as save variables (only
persistent vars apply). - Program
- A compiled program (one or more modules).
- Reference
- A position where a name is used.
- Registry
- The command registry.
- Repl
- A REPL.
- Rng
- xoshiro256++. A random generator with serializable state, used by
randomin scripts and by package commands (Ctx::rng). - Snapshot
- A snapshot of the state at a stop point. Can only be restored into a VM of the same program.
- Snapshot
Log - A ring of snapshots (with a maximum count; when full, the oldest are dropped).
- Span
- A range in the source (within one line).
- Stop
Decl - The declaration of a stop command.
- Stop
Record - A record of a stop point (one history entry;
Vm::history). - StrValue
- A
strvalue. The contents are shared (cloning only copies theArc; strings are never modified). - Struct
Value - The contents of a
structvalue. - Stuck
Path - A path that stopped at a stop point that could not be answered.
- Submitted
- The result of
submitaccepting input. - Symbol
- One declared name.
- Test
Path - A path that reached the end.
- Text
Error - An error in a translation that could not be put into the table, or in a line of the table file.
- Text
Issue - One result of checking a text table against the scripts.
- Text
Table - A per-language table that replaces bodies.
- Type
Decl - The declaration of a type declared by users.
- VarDecl
- A variable declared by the host.
- VarHandle
- The continuation of registering a variable (to add
.read_only()). - Variable
- How a variable looks (for inspection).
- Variant
Decl - The declaration of an
enumvariant. - Vm
- The VM that runs scripts.
- VmConfig
- VM settings.
- VmError
- A runtime error.
- YomiMap
- The Rust type corresponding to
map<K, V>in scripts. Holds pairs of keys and values in insertion order (not aHashMap, because the iteration order ofmapin scripts is defined as insertion order). When converted to a script value withIntoValue, if a key repeats, the later value updates it (the position stays the first one).
Enums§
- Apply
Error - A failure of
apply. - Apply
Invalid - The reason a check of
applyfailed. - Code
Group - A group of codes (corresponds to the prefix of the FTL keys used to look up messages).
- Command
Error Kind - The kind of command failure.
- Command
Kind - The kind of a command (section 2.3 of
spec/host/02-registry.md). - Completeness
- The completion state of input, decided by syntax alone (section 7.5 of
spec/host/07-repl.md). - Contextual
Position - Positions where a contextual word has meaning.
- Debug
Yield - Why
Vm::run_debugreturned. - Decl
Error Kind - The reason a declaration file could not be read.
- Declared
- Something declared by input.
- Def
- Something declared in the REPL (
defs). - DiagArg
- The value of a diagnostic argument.
- Diag
Code - A diagnostic code.
as_stris the stable English name. - Extract
Error - Why the schema could not be taken out of a save.
- Format
Error - Why a source could not be formatted.
- Hook
Action - What the hook decides at a line event.
- Input
- The input passed to
resume. - Input
Kind - The kind of input.
- Keyword
Kind - The category of a reserved word.
- Kind
- The kind of a variable (section 2.7 of
spec/host/02-registry.md). - Load
Error Kind - The kind of load failure.
- Load
Policy - How a load treats variables whose saved type no longer matches the scripts (
spec/host/04-save.md, 4.6). - Registry
Error - A registry error.
- Reload
Error - Why
Vm::reloadfailed. - Repl
Yield - The result of
run. - Resolved
By - How the position was found.
- Severity
- Severity.
- Step
Mode - How the
Debuggergoes on after a pause. - Stop
Kind - The kind of stop point: a sugar (plain line, quote line, choice) or a command written with
@. Text tables (spec/host/05-texts.md) replace only the bodies of sugar. - Sugar
- The kind of sugar.
- Symbol
Kind - The kind of a symbol.
- Text
Error Kind - The kind of text table error.
- Text
Issue Kind - The kind of result of checking a text table against the scripts (
TextTable::check). - Ty
- A type of the script language.
- Type
Kind - The contents of a type declaration.
- Unit
Kind - Whether a line belongs to a label or to a
fn(including lambdas and the functions the compiler makes). - Value
- A value.
- VmError
Kind - The kind of runtime error.
- Yield
- The stop notification returned by
run.
Constants§
- AUTO_
ID_ LEN - The length of an automatic ID (without
#). - CONTEXTUAL_
KEYWORDS - The list of contextual words. In the same order as section 1.6 of the spec.
- DEFAULT_
HISTORY_ LIMIT - The default of
VmConfig::history_limit. - DEFAULT_
MAX_ STATES - The default of
ExploreConfig::max_states. - DEFAULT_
SEED - The default of
VmConfig::seed(fixed; the same seed gives the same random sequence). - KEYWORDS
- The list of reserved words. In the same order as section 1.6 of the spec.
- MAX_
DECLS_ BYTES - The maximum size of a declaration file to read (bytes).
- MAX_
JSON_ DEPTH - The maximum nesting depth of JSON.
- MAX_
TYPE_ DEPTH - The maximum nesting depth of types (the depth following
list,Option,structfields andenumarguments). Recursive types are not allowed, so the nesting depth of values does not exceed this either (a limit so that the recursion of drop, cloning and serialization does not overflow even a 1 MiB stack).
Traits§
- Debug
Hook - Decides at each line event whether to pause.
- Effect
Fn - The function of an effect command (
Fn(&mut Ctx<P>, args...) -> R; 0 to 6 arguments). - From
Args - Conversion from a list of evaluated arguments to a tuple.
- From
Value - Conversion from script values to Rust values (command arguments).
- Into
Return - The return value of a command function (
TorResult<T, CommandError>). - Into
Value - Conversion from Rust values to script values (command return values, initial values of host-declared variables).
- Package
- A package. A unit that groups commands and the state slices they use (per save, and shared by all saves).
- QueryFn
- The function of a query command (
Fn(&Ctx<P>, args...) -> R; 0 to 6 arguments). - Yomi
Args - A list of parameter types (a tuple of 0 to 6).
- Yomi
Decl - A Rust type that can be put into a registry as a
structorenumusable from scripts (implemented by#[derive(YomiType)]). - Yomi
Type - The script type corresponding to a Rust type.
Functions§
- all_
codes - The list of all codes (in group order; within a group, in definition order).
- analyze
- Analyzes modules (name and source).
- apply_
insertions - Applies the additions to a source (the original text is unchanged except where text is appended).
insertionsmust all be for the same module (in any order). - compile
- Compiles the source of one module. Diagnostics are returned in position order. If there is any error,
Err. - compile_
modules - Compiles multiple modules (
(module name, source)) into one program. - compile_
modules_ with_ options - A version of
compile_modules_with_warningswith options. - compile_
modules_ with_ warnings - A version of
compile_modulesthat also returns warnings. When it fails with errors, the diagnostics include the warnings too. - compile_
with_ warnings - Compiles the source of one module. On success, returns the program and the warnings (in position order).
- completeness
- Decides whether input is complete by syntax alone (independent of the environment; 7.5).
- core_
command_ error_ codes - The list of codes the core returns as command failures (
VmErrorKind::CommandFailed; codes start withcore.). - decode_
slice - Turns the bytes of a slice (
postcard) back into a type. Used bymigrateto read bytes of an older version (the core provides this so that packages need not depend onpostcard). - encode_
slice - Turns a value into the bytes of a slice (
postcard) (used in tests ofmigrateand so on). - explore
- Explores the branches of a script: tries the answers of every stop point and reports the paths to the end, the paths
that end with an error, and the stop points that could not be answered (
spec/host/08-test.md). - extract_
schema - Rebuilds the content of a frozen schema file from the schema embedded in a save and/or persistent data. The version in the header is the schema version of the save.
- find_
type - Finds a type declaration by name.
- format_
source - Formats the script
modulein the standard form.modules(name and source) are all the modules that are collected together; the names of their identities decide how lines are classified. The line ending (\nor\r\n) and a leading BOM of the source are kept. The result is checked by reading it again; if it does not mean the same as the source,FormatError::Unverifiedis returned. - frozen_
schema - The content of
schema/vN.yomifor the current scripts (NisProgram::schema_version). - infer_
local_ types - Finds the types of local variables. Even if compilation fails, returns those whose types were decided.
- is_
name_ char - Whether the token can be used as a name (for completion and extracting names).
- is_
reserved - Whether it is a reserved word.
- keyword
- The entry for the word (
Noneif not a reserved word). - migrate_
template - The
migrateblock thatyomi migrate-initmakes from the latest frozen schema (frozen, the content ofschema/v<version>.yomi) and the current scripts: every line inside is a comment (candidates forrenameandconvert).Noneif the variables did not change. If the frozen schema cannot be read, its diagnostics. - pending_
stop - Reads the command and arguments a save is stopped at, without the scripts, the registry or a VM (
spec/host/04-save.md, 4.9).Ok(None)if the save has no history (VmConfig::history_limitwas 0). - plan_
ids - Collects and compiles the scripts, and finds the IDs to give to lines without one and where to append them.
- plan_
ids_ program - Finds the positions to append from a compiled program (the second half of
plan). - version
- The version of the core (the
versioninCargo.toml).
Type Aliases§
- Str
- The string type (
strin scripts).
Derive Macros§
- Yomi
Type - Makes it a
struct/enumusable from scripts. Requires#[yomi(namespace = "namespace")](name = "TypeName"changes the type name in scripts).