Skip to main content

Crate yomi_core

Crate yomi_core 

Source
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):

  1. Register stop commands in a Registry and bind the sugar. Register packages (Package) with Registry::package (or Registry::package_set and packages! to register a set in any order): effect and query commands, state slices, and host-declared variables.
  2. Turn the source into a Program with compile() (diagnostics are Diagnostic). To receive warnings as well, use compile_with_warnings. For multiple modules (files that refer to each other with import), the host collects the sources and calls compile_modules (with warnings: compile_modules_with_warnings).
  3. Create a VM with Vm::new and repeat Vm::run and Vm::resume.
  4. At a stop point, make a save with Vm::save and restore it with Vm::load. persistent vars and passed stop points are persistent data in a separate byte string (Vm::save_persistent, Vm::load_persistent).
  5. For rollback, store Vm::snapshots in a SnapshotLog at each stop point and go back with Vm::restore.
  6. Host structs and enums get #[derive(YomiType)] and are registered with Registry::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.
  7. For localization, pass a TextTable (a table that replaces texts, keyed by stable IDs) with Vm::set_texts. To switch languages while stopped, use Vm::refresh_current; to render the history in the current language, use Vm::render and Vm::history_text. Check a table with TextTable::check, and require IDs with CompileOptions::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.
CodeInfo
The public specification of one code.
CommandDecl
The declaration of a command (of any kind; for tools and declaration files; Registry::commands).
CommandError
A failure returned by a command function. When Err is returned, the VM returns it from run as a runtime error (the VM adds the position).
CommandId
The ID of a command (in registration order).
CompileOptions
Compile options. Built from Default with methods.
ContextualKeyword
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).
DeclError
The error when a declaration file could not be read. Has no message text.
Diagnostic
One diagnostic.
EnumValue
The contents of an enum value.
ErrorCodeInfo
One error code of a command (decided by the package; crate::CommandError::with_code).
ErrorPath
A path that ended with a runtime error.
ExploreConfig
Settings of explore.
ExploreReport
The result of explore.
ExploreStep
One answer on a path.
FnValue
The contents of a function value.
FrameInfo
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 "案内人" in identity 案内人 = "案内人").
Insertion
One addition.
InterruptHandle
The token to interrupt a run from another thread (spec/host/01-execution.md, 1.9a).
Keyword
One reserved word.
LineEvent
A line is about to run (spec/host/09-debug.md, 9.2).
ListData
The contents of a list. Holds the elements in an Arc, so cloning only shares them (the same approach as MapData).
LoadError
A load failure. Has no message text.
LoadReport
The report of a load.
LocalType
The type of a local variable (bound by let, for or match) 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::entries that goes through the pairs in insertion order (skipping holes left by removals).
MigrateError
A failure of a slice’s migrate. The load fails with LoadErrorKind::PackageSlice.
MissingId
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)).
PackageDecl
Information about a registered package (for declaration files and tools).
PackageItem
A type-erased package entry passed to bulk registration (Registry::package_set). Made with packages!.
PackageReg
A typed registration entry passed to Package::register.
PauseHandle
Asks a Debugger to pause at the next line, from any thread.
PendingStop
The stop point a save is stopped at, read without restoring the VM (pending_stop).
PersistentReport
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 random in 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.
SnapshotLog
A ring of snapshots (with a maximum count; when full, the oldest are dropped).
Span
A range in the source (within one line).
StopDecl
The declaration of a stop command.
StopRecord
A record of a stop point (one history entry; Vm::history).
StrValue
A str value. The contents are shared (cloning only copies the Arc; strings are never modified).
StructValue
The contents of a struct value.
StuckPath
A path that stopped at a stop point that could not be answered.
Submitted
The result of submit accepting input.
Symbol
One declared name.
TestPath
A path that reached the end.
TextError
An error in a translation that could not be put into the table, or in a line of the table file.
TextIssue
One result of checking a text table against the scripts.
TextTable
A per-language table that replaces bodies.
TypeDecl
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).
VariantDecl
The declaration of an enum variant.
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 a HashMap, because the iteration order of map in scripts is defined as insertion order). When converted to a script value with IntoValue, if a key repeats, the later value updates it (the position stays the first one).

Enums§

ApplyError
A failure of apply.
ApplyInvalid
The reason a check of apply failed.
CodeGroup
A group of codes (corresponds to the prefix of the FTL keys used to look up messages).
CommandErrorKind
The kind of command failure.
CommandKind
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).
ContextualPosition
Positions where a contextual word has meaning.
DebugYield
Why Vm::run_debug returned.
DeclErrorKind
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.
DiagCode
A diagnostic code. as_str is the stable English name.
ExtractError
Why the schema could not be taken out of a save.
FormatError
Why a source could not be formatted.
HookAction
What the hook decides at a line event.
Input
The input passed to resume.
InputKind
The kind of input.
KeywordKind
The category of a reserved word.
Kind
The kind of a variable (section 2.7 of spec/host/02-registry.md).
LoadErrorKind
The kind of load failure.
LoadPolicy
How a load treats variables whose saved type no longer matches the scripts (spec/host/04-save.md, 4.6).
RegistryError
A registry error.
ReloadError
Why Vm::reload failed.
ReplYield
The result of run.
ResolvedBy
How the position was found.
Severity
Severity.
StepMode
How the Debugger goes on after a pause.
StopKind
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.
SymbolKind
The kind of a symbol.
TextErrorKind
The kind of text table error.
TextIssueKind
The kind of result of checking a text table against the scripts (TextTable::check).
Ty
A type of the script language.
TypeKind
The contents of a type declaration.
UnitKind
Whether a line belongs to a label or to a fn (including lambdas and the functions the compiler makes).
Value
A value.
VmErrorKind
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, struct fields and enum arguments). 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§

DebugHook
Decides at each line event whether to pause.
EffectFn
The function of an effect command (Fn(&mut Ctx<P>, args...) -> R; 0 to 6 arguments).
FromArgs
Conversion from a list of evaluated arguments to a tuple.
FromValue
Conversion from script values to Rust values (command arguments).
IntoReturn
The return value of a command function (T or Result<T, CommandError>).
IntoValue
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).
YomiArgs
A list of parameter types (a tuple of 0 to 6).
YomiDecl
A Rust type that can be put into a registry as a struct or enum usable from scripts (implemented by #[derive(YomiType)]).
YomiType
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). insertions must 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_warnings with options.
compile_modules_with_warnings
A version of compile_modules that 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 with core.).
decode_slice
Turns the bytes of a slice (postcard) back into a type. Used by migrate to read bytes of an older version (the core provides this so that packages need not depend on postcard).
encode_slice
Turns a value into the bytes of a slice (postcard) (used in tests of migrate and 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 module in 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 (\n or \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::Unverified is returned.
frozen_schema
The content of schema/vN.yomi for the current scripts (N is Program::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 (None if not a reserved word).
migrate_template
The migrate block that yomi migrate-init makes from the latest frozen schema (frozen, the content of schema/v<version>.yomi) and the current scripts: every line inside is a comment (candidates for rename and convert). None if 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_limit was 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 version in Cargo.toml).

Type Aliases§

Str
The string type (str in scripts).

Derive Macros§

YomiType
Makes it a struct / enum usable from scripts. Requires #[yomi(namespace = "namespace")] (name = "TypeName" changes the type name in scripts).