Add the dependency

In your project’s ziran.toml; pin ref to a commit for reproducible builds.

[dependencies.tcl]
git = "https://git.waozi.xyz/ziranlang/tcl.git"
ref = "master"

Overview

Use it in a Ziran project

ziran add https://git.waozi.xyz/ziranlang/tcl.git
#import "std/vec"
using Tcl :: #import "tcl/interpreter"

main :: () -> s32 {
    interpreter: Tcl.Interpreter;
    result := Tcl.Eval(*interpreter, "set width 6; expr {$width * 7}");
    print("%\n", TextView(result.value));
    return ifx result.code == .OK then 0 else 1;
}

A zero-initialized Interpreter is ready to use. Eval retains variables and procedure definitions. TakeOutput takes and clears the text accumulated by puts, including output written before an error. Results own their text. Each top-level evaluation has a 10,000-command budget that also charges loop iterations and permits up to 48 nested script levels.

Host extension points:

  • RegisterCommand adds a single host command, RegisterPrefix handles commands whose names are allocated at runtime, and RegisterLibrary provides command bundles activated by Tcl's load.
  • tcl/types holds text values and result types, tcl/packages adds versioned script packages, tcl/io adds channel backends. All exports are listed in ziran.toml.

Supported Tcl

  • Syntax: command separators, comments, nested braces, quoted and empty words, basic backslash escapes and line continuations, $name, ${name}, and $array(key) substitution (including inside parentheses), and nested [script] substitution.
  • Core commands: set, unset, incr, append, lappend, proc, return, if, while, for, foreach, break, continue, catch, error, eval. Procedures accept defaults and a trailing args; foreach takes a variable list and one value list; catch takes an optional result variable.
  • Frames and scope: array names, array size, global, upvar for one linked variable, uplevel, level, switch with exact patterns, - fallthrough and a final default, info args, body, commands, exists, procs. Frame selection accepts absolute levels (#0) and relative levels (-1, 1 for the caller). info commands and info procs accept the optional Limbo pattern argument without filtering. Prefix extensions supply command names dynamically and cannot be enumerated.
  • Lists: list, llength, lindex, lrange, join, concat, linsert, lreplace, exact lsearch, lsort with optional -decreasing, split. One-argument split preserves the string, following Limbo.
  • Strings: string compare, equal, length, index, range, first, last, tolower, toupper, trim, trimleft, trimright. Lengths and indexes count UTF-8 characters; case conversion and trim use ASCII rules. Indexes accept decimal integers, end, and end-N. A numeric last index in string range is exclusive, following Limbo; end and end-N are inclusive.
  • format: %%, %s, %d, %x, %f with width, left alignment, zero padding, and precision; literal text between fields is preserved. Following Limbo, %f defaults to one decimal place and %Nf sets precision; %W.Nf sets both. Fixed formatting rounds binary64 values to nearest with ties to even; precision and width are limited to 4096. Invalid real arguments return Tcl errors; nonfinite reals format as Inf, -Inf, NaN.
  • expr and calc accept signed 32-bit decimal, leading-zero octal, and 0x hexadecimal integers, decimal and scientific real literals, and the boolean words true/false, yes/no, on/off. Operators: parentheses, unary + - ! ~, binary + - * / %, comparisons == != < <= > >=, and << >> & ^ | && || ?:. Remainder, bitwise, and logical operators take integers; logical and conditional operands evaluate eagerly. A substitution inside braces must yield one numeric or boolean literal. Integer overflow and division by zero return errors; real arithmetic can return NaN or Infinity.
  • Real functions: abs, acos, asin, atan, atan2, ceil, cos, cosh, exp, floor, fmod, hypot, log, log10, pow, sin, sinh, sqrt, tan, tanh.
  • time script ?count? runs the script repeatedly in the calling frame and reports milliseconds per iteration; it shares the script command limit. Script errors are reported after the requested repetitions, and control flow such as return or exit propagates immediately. Supply a monotonic clock with SetClock; the callback receives a context ID and returns milliseconds or a negative value on failure.
  • dumpstack writes the scalar, array, and alias tables of the frames visible from the current frame to the output buffer, in variable insertion order, with no Limbo hash slot numbers.
  • load libname activates a bundle registered with RegisterLibrary (a slice of LibraryCommand descriptors plus one context ID). Loaded commands are visible to info commands and callable; loads are idempotent, and a command conflict rejects the whole bundle. calc, io, list, and string are available by default.
  • puts string and puts -nonewline string write to the output buffer.
  • exit stops the current evaluation, including from a procedure, source file, or catch body; Eval returns .Exit to the embedding application. As in Limbo, exit ignores its arguments.
  • source ?-encoding utf-8? fileName evaluates the loaded script in the current frame and shares the command and nesting budgets. Library callers supply the reader with SetSourceLoader; the callback receives its context ID, the path, and a pointer to a Result, sets the result's owned value to the script on success, or returns an error with code = .Error.

Unsupported: namespaces, {*} word expansion, numeric and Unicode backslash escapes, wide expression integers, expression string operands, and lazy expression operators. Several commands follow Inferno Tcl semantics as noted above. Compare a library's requirements against this command set before use.

Tcl script packages

Import tcl/packages and call Packages.Attach(*interpreter) to enable the package command; each interpreter has its own registry. Available subcommands: provide, require, present, ifneeded, names, versions, forget, vcompare, vsatisfies, prefer, unknown. require executes the chosen initialization script in the global frame with the caller's command budget and detects circular loads. Version checks include -exact, multiple requirements, ranges, and alpha and beta versions.

List directories that contain pkgIndex.tcl files in auto_path; Tcl reads them through the registered SetSourceLoader callback. An index sees its own directory in the local variable dir:

# /path/to/sample/pkgIndex.tcl
package ifneeded sample 1.0 [list source [file join $dir sample.tcl]]
lappend auto_path /path/to/sample
package require sample 1.0

Discovery checks the auto_path directories directly and runs scripts with the interpreter's supported commands. Tcl's standard library and Tcllib are separate dependencies; C extension loading and .tm discovery are unsupported. package unknown can supply a custom discovery command, and registrations also work entirely in memory. After initializing a Ziran extension, an embedder can call Packages.Provide(*interpreter, name, version) and check the returned Result; an ifneeded script can also call load name for a bundle supplied by RegisterLibrary.

Channels and files

  • open supports Limbo OREAD (the default), OWRITE, and ORDWR on existing files; r and r+ are aliases. w and w+ create or truncate a file, with optional octal or decimal permissions (default 0666). OWRITE preserves unwritten bytes. Append modes are unsupported.
  • close, eof, flush, gets, read, seek, tell, and channel puts ?-nonewline? fileId string are available. seek accepts SEEKSTART, SEEKRELA, and SEEKEND, as well as start, current, and end. Offsets and file sizes are signed 64-bit integers; failed seeks return Tcl errors.
  • Counted read returns up to the requested number of bytes. The Limbo line forms read one line; bare read appends a newline and read -nonewline returns the original line. gets strips the last character and accepts the legacy optional variable name without setting it. EOF becomes sticky after an empty read. Reads and lines are bounded to 1 MiB per command.
  • file join name ?name ...? joins POSIX paths without a file backend. file exists, file size, file isfile, and file isdirectory use the configured backend. Writes take effect immediately, so flush validates the channel and returns success without sending another write.

Install a channel backend with SetChannelBackend and tcl/io.Backend; callbacks receive the backend's context ID. File channels persist between Eval calls, and CloseChannels releases them, including after .Exit. Explicit stdout and implicit puts share TakeOutput.

Local tests

Run from the package root with ziran, zi2zx, and Python 3 on PATH:

python3 tests/run.py

Set ZIRAN and ZI2ZX to use specific toolchain binaries. For a checkout of Ziran at ../../ziran, use an ignored ziran.local.toml with this override:

[overrides]
ziran = "../../ziran"

The suite runs the same fixtures as a native executable and a portable .zx image. It checks parsing, control flow, error handling, numeric expressions, fixed-point formatting, registered commands, script package discovery, and injected I/O. The package discovery and channel fixtures use in-memory host callbacks.

Relocatable Tcl libraries

The default profile includes every manifest export and uses no feature defines. It ships as default.zx, with a default.json receipt recording the source commit, package and toolchain identities, dependency lock, exports, and SHA-256. Consumers import tcl/interpreter as usual, and Ziran uses the relocatable library when bundling the application, so the consumer can build without a Tcl source checkout.

For a production build, use a clean Tcl checkout without overrides and a cached build of the exact compiler revision recorded in ziran.lock. The compiler must support .zx objects with ziran pkg zx pack-ir and inspection with ziran pkg zx inspect-ir. The Gitea workflow builds the locked compiler before running these targets.

make check artifact artifact-smoke

The library and receipt land in build/artifacts/. The smoke runs ziran add against a local fixture registry and a fresh cache, then runs ziran lock, builds the consumer offline, and compares the output of tests/fixtures/core.tcl byte for byte. Development targets use the usual ignored ziran.local.toml overrides: pack-dev emits a local .zx library with a source fingerprint and receipt in build/artifacts-dev/, and a source-free consumer can load it from ZIRAN_DEV_ZX_DIR as <package-id>.zx.

make artifact-dev artifact-smoke ARTIFACT_FLAGS=--development

Once the library is published, ziran add and ziran lock discover its default profile and record the digest in the consumer's ziran.lock. Run ziran bundle --project --locked to build the application, adding --offline once the library is cached. The consumer can also specify the same package ID, profile, and digest explicitly in ziran.zx.lock. Native source development continues to use the standard package imports and overrides.

The Gitea master workflow publishes the verified default.zx and its default.zx.tsv descriptor through ziran pkg zx publish-ir to the tcl-zx-library Generic package, using the TCL_PACKAGE_USER and TCL_PACKAGE_TOKEN secrets for an account with package-write access. After publication the workflow repeats discovery and the offline test from a fresh cache against Gitea. Repeat that check with make artifact-smoke ARTIFACT_FLAGS=--registry.

License

MIT. See LICENSE and NOTICE for the original Inferno and TaijiOS attribution.

tcl/src/interpreter.zi

interpreter

Ported from Inferno's Tcl_Core, TclLib and Tcl_Stack. See ../NOTICE (MIT).

Import with #import "tcl/interpreter".

Parameter :: struct { name: Text; fallback: Text; optional: bool; }
Procedure :: struct { name: Text; parameters: Vec(Parameter); body: Text; variadic: bool; }

Command words exclude the command name. A handler fills an owned result.

CommandHandler :: #type (context: s64, args: []Text, result: *Result)

Command words exclude the command name. A handler fills an owned result. The client can use the context ID as a lookup key for its own widget state.

Extension :: struct { name: Text; context: s64; handler: CommandHandler; }
LibraryCommand :: struct { name: string; handler: CommandHandler; }
Library :: struct { name: Text; commands: Vec(Extension); loaded: bool; }
MonotonicClock :: #type (context: s64) -> s64

A prefix can supply dynamically named commands. A nonempty script is

PrefixHandler :: #type (context: s64, name: string, args: []Text, result: *Result, script: *Text)

A prefix can supply dynamically named commands. A nonempty script is evaluated in the current frame and its result becomes the command result.

CommandPrefix :: struct { name: Text; context: s64; handler: PrefixHandler; }
SourceLoader :: #type (context: s64, path: string, result: *Result)
PackageScript :: struct { version: Text; script: Text; }
Package :: struct { name: Text; provided: Text; scripts: Vec(PackageScript); }
PackageTable :: struct { entries: Vec(Package); loading: Vec(Text); unknown: Text; custom_unknown: bool; discovering: bool; prefer_latest: bool; }
PackageRunner :: #type (interpreter: *Interpreter, args: []Text, depth: s32, result: *Result)
Interpreter :: struct { globals: Frame; procedures: Vec(Procedure); extensions: Vec(Extension); libraries: Vec(Library); prefixes: Vec(CommandPrefix); source_loader: SourceLoader; source_context: s64; clock: MonotonicClock; clock_context: s64; output: Text; channels: Io.ChannelTable; steps: s64; packages: PackageTable; package_runner: PackageRunner; }
Eval :: (interpreter: *Interpreter, script: string) -> Result

A zero-initialized Interpreter is ready to use. Eval keeps globals and procedures between calls. Break/continue outside a loop are script errors.

TakeOutput :: (interpreter: *Interpreter) -> Text
SetSourceLoader :: (interpreter: *Interpreter, loader: SourceLoader, context: s64)
SetClock :: (interpreter: *Interpreter, clock: MonotonicClock, context: s64)

The callback returns monotonic milliseconds, or a negative value on failure.

SetChannelBackend :: (interpreter: *Interpreter, backend: Io.Backend) -> Result

Reconfiguration closes any channels previously opened by the interpreter.

CloseChannels :: (interpreter: *Interpreter) -> Result
RegisterCommand :: (interpreter: *Interpreter, name: string, handler: CommandHandler, context: s64) -> bool
FindLibrary :: (interpreter: *Interpreter, name: string) -> *Library
FindExtension :: (interpreter: *Interpreter, name: string) -> *Extension
BUILTIN_LIBRARIES :: "calc io list string"

A named bundle supplies commands when the script loads it. Copy each name so

RegisterLibrary :: (interpreter: *Interpreter, name: string, commands: []LibraryCommand, context: s64) -> bool

A named bundle supplies commands when the script loads it. Copy each name so callers can pass short-lived descriptors. Activation is local to an interpreter.

RegisterPrefix :: (interpreter: *Interpreter, prefix: string, handler: PrefixHandler, context: s64) -> bool
OutsideLoop :: (result: Result) -> Result
CopyResult :: (result: *Result) -> Result
CORE_COMMANDS :: "append array break calc catch continue dumpstack error eval exit expr for foreach format global if incr info lappend level load proc return set source string switch time unset uplevel upvar while"
IsBuiltin :: (name: string) -> bool
VariableSubstitution :: (interpreter: *Interpreter, frame: *Frame, cursor: *Cursor, depth: s32) -> Result
AtEnd :: (cursor: *Cursor, nested: bool) -> bool
SkipWordSpace :: (cursor: *Cursor)
ReadWord :: (interpreter: *Interpreter, frame: *Frame, cursor: *Cursor, depth: s32, nested: bool) -> Result
Substitute :: (interpreter: *Interpreter, frame: *Frame, cursor: *Cursor, depth: s32, out: *Vec(u8)) -> Result
SubstitutionValue :: (interpreter: *Interpreter, frame: *Frame, cursor: *Cursor, depth: s32) -> Result
EvalScript :: (interpreter: *Interpreter, frame: *Frame, script: string, depth: s32) -> Result
EvalCursor :: (interpreter: *Interpreter, frame: *Frame, cursor: *Cursor, depth: s32, nested: bool) -> Result
ExpressionValue :: (interpreter: *Interpreter, frame: *Frame, text: string, depth: s32) -> Result
FindProcedure :: (interpreter: *Interpreter, name: string) -> s64
DefineProcedure :: (interpreter: *Interpreter, args: []Text) -> Result
CallProcedure :: (interpreter: *Interpreter, caller: *Frame, index: s64, args: []Text, depth: s32) -> Result
RunIf :: (interpreter: *Interpreter, frame: *Frame, args: []Text, depth: s32) -> Result
RunLoop :: (interpreter: *Interpreter, frame: *Frame, test_source: string, body: string, next: string, depth: s32) -> Result
RunFor :: (interpreter: *Interpreter, frame: *Frame, args: []Text, depth: s32) -> Result
RunForeach :: (interpreter: *Interpreter, frame: *Frame, args: []Text, depth: s32) -> Result
Increment :: (frame: *Frame, args: []Text) -> Result
AppendVariable :: (frame: *Frame, args: []Text, as_list: bool) -> Result
JoinWords :: (args: []Text) -> Text
SelectSwitch :: (interpreter: *Interpreter, frame: *Frame, value: string, pairs: []Text, depth: s32) -> Result
RunSwitch :: (interpreter: *Interpreter, frame: *Frame, args: []Text, depth: s32) -> Result
RunInfo :: (interpreter: *Interpreter, frame: *Frame, args: []Text) -> Result
FrameLevel :: (frame: *Frame, word: string) -> (*Frame, bool)
RunFrameCommand :: (interpreter: *Interpreter, frame: *Frame, name: string, args: []Text, depth: s32) -> Result
RunSource :: (interpreter: *Interpreter, frame: *Frame, args: []Text, depth: s32) -> Result
RunLoad :: (interpreter: *Interpreter, args: []Text) -> Result
RunTime :: (interpreter: *Interpreter, frame: *Frame, args: []Text, depth: s32) -> Result
Dispatch :: (interpreter: *Interpreter, frame: *Frame, words: []Text, depth: s32) -> Result

Source ↗

tcl/src/calc.zi

calc

Numeric expression parser adapted from Inferno tcl_calc.b. See ../NOTICE (MIT).

Import with #import "tcl/calc".

Value :: struct { integer: s64; real: float64; floating: bool; }
Parser :: struct { cursor: Cursor; problem: string; }
Int :: (value: s64) -> Value
Real :: (value: float64) -> Value
Boolean :: (value: bool) -> Value
ToReal :: (value: Value) -> float64
Truth :: (value: Value) -> bool
SkipSpaces :: (cursor: *Cursor)
Fail :: (parser: *Parser, message: string) -> Value
Checked :: (parser: *Parser, value: s64) -> Value
RadixDigit :: (byte: u8) -> s64
IntegerLiteral :: (parser: *Parser, word: string, base: s64, negative: bool) -> Value
Number :: (parser: *Parser, negative: bool) -> Value
NamedValue :: (word: string) -> (Value, bool)
Function :: (parser: *Parser, name: string, arity: s32, depth: s32) -> Value
Operand :: (parser: *Parser, depth: s32) -> Value
Operator :: (cursor: *Cursor) -> (string, s32)
ApplyReal :: (parser: *Parser, op: string, a: float64, b: float64) -> Value
ApplyInteger :: (parser: *Parser, op: string, a: s64, b: s64) -> Value
Apply :: (parser: *Parser, op: string, left: Value, right: Value) -> Value
Binary :: (parser: *Parser, minimum: s32, depth: s32) -> Value
Conditional :: (parser: *Parser, depth: s32) -> Value
Evaluate :: (text: string) -> (Value, string)
ScalarOperand :: (text: string) -> bool

Substitution accepts one literal, preventing text values from becoming operators.

Format :: (value: Value) -> Result

Source ↗

tcl/src/decimal.zi

decimal

Fixed-point conversion for the Inferno Tcl format command. See ../NOTICE (MIT).

Import with #import "tcl/decimal".

DecimalDigits :: (value: float64, digits: []u8) -> (s64, s64)

The exact finite value is significand * 2^exponent. When the exponent is negative, represent it instead as significand * 5^-exponent / 10^-exponent. Base 10^9 limbs keep the longest binary64 expansion small.

Round :: (digits: []u8, count: s64, discard: s64) -> s64

Drop decimal places using round-to-nearest, ties-to-even. Digits are least significant first. Caller storage is zero-filled past count.

Fixed :: (input: string, precision: s64) -> (Text, bool, bool)

Return the sign separately so format can place zero padding after it.

Source ↗

tcl/src/io.zi

io

Tcl channel behavior adapted from Inferno tcl_io.b. See ../NOTICE (MIT).

Import with #import "tcl/io".

OpenCallback :: #type (context: s64, path: string, mode: s32) -> s32
CreateCallback :: #type (context: s64, path: string, mode: s32, permissions: s32) -> s32
ReadCallback :: #type (context: s64, handle: s32, buffer: []u8) -> s32
WriteCallback :: #type (context: s64, handle: s32, data: string) -> s32
CloseCallback :: #type (context: s64, handle: s32) -> s32
SeekCallback :: #type (context: s64, handle: s32, offset: s64, origin: s32) -> s64
StatCallback :: #type (context: s64, path: string, metadata: []u8) -> s32
ErrorCallback :: #type (context: s64) -> string
Backend :: struct { context: s64; open: OpenCallback; create: CreateCallback; read: ReadCallback; write: WriteCallback; close: CloseCallback; seek: SeekCallback; stat: StatCallback; error: ErrorCallback; stdin: bool; }
Channel :: struct { active: bool; handle: s32; mode: s32; eof: bool; pending: Vec(u8); next: s64; end: s64; }
ChannelTable :: struct { backend: Backend; files: Vec(Channel); input: Channel; stdout_closed: bool; }
COMMANDS :: "close eof file flush gets open puts read seek tell"
CHUNK :: 4096
MAX_READ :: 1048576
BackendError :: (table: *ChannelTable, operation: string) -> Result
ChannelError :: (name: string) -> Result
FindChannel :: (table: *ChannelTable, name: string) -> *Channel
OpenMode :: (name: string) -> (s32, bool)
Permissions :: (text: string) -> s32
OpenChannel :: (table: *ChannelTable, args: []Text) -> Result
CloseChannel :: (table: *ChannelTable, channel: *Channel) -> bool
CloseAll :: (table: *ChannelTable) -> Result
AppendPending :: (channel: *Channel, output: *Text, limit: s64, line: bool) -> (bool, bool)
ReadChannel :: (table: *ChannelTable, channel: *Channel, count: s64, line: bool) -> Result
WriteChannel :: (table: *ChannelTable, channel: *Channel, text: string, newline: bool) -> Result
RunPuts :: (table: *ChannelTable, output: *Text, args: []Text) -> Result
RunRead :: (table: *ChannelTable, command: string, args: []Text) -> Result
Origin :: (name: string) -> s32
RunSeek :: (table: *ChannelTable, channel: *Channel, args: []Text) -> Result
ParseFileOffset :: (text: string) -> (s64, bool)
AppendPath :: (path: *Text, part: string) -> bool
RunFile :: (table: *ChannelTable, args: []Text) -> Result
Run :: (table: *ChannelTable, output: *Text, name: string, args: []Text) -> Result

Source ↗

tcl/src/lists.zi

lists

Ported from the Inferno Limbo tcl_list.b and tcl_utils.b. See ../NOTICE (MIT).

Import with #import "tcl/lists".

List :: struct { words: Vec(Text); problem: string; }
ParseList :: (source: string) -> List
AppendElement :: (output: *Vec(u8), value: string, separate: bool)

Favor brace quoting for ordinary grouped items. Unbalanced braces and a trailing backslash require backslash quoting instead for a round trip.

Index :: (word: string, length: s64) -> (s64, bool)
LIST_COMMANDS :: "concat join lindex linsert list llength lrange lreplace lsearch lsort split"
IsListCommand :: (name: string) -> bool
AppendWords :: (output: *Text, words: []Text)
Split :: (args: []Text) -> Result
Sort :: (args: []Text) -> Result
RunList :: (name: string, args: []Text) -> Result

Source ↗

tcl/src/math.zi

math

Real-valued function vocabulary from Inferno tcl_calc.b. See ../NOTICE (MIT).

Import with #import "tcl/math".

Arity :: (name: string) -> s32
Absolute :: (value: float64) -> float64
Finite :: (value: float64) -> bool
RoundDirected :: (value: float64, upward: bool) -> float64
Hypot :: (first: float64, second: float64) -> float64
Remainder :: (first: float64, second: float64) -> float64
Call :: (name: string, first: float64, second: float64) -> float64

Source ↗

tcl/src/packages.zi

packages

Versioned Tcl script libraries for the headless Inferno Tcl port. See ../NOTICE (MIT).

Import with #import "tcl/packages".

Attach :: (interpreter: *Tcl.Interpreter)
Find :: (table: *Tcl.PackageTable, name: string) -> s64
Ensure :: (table: *Tcl.PackageTable, name: string) -> s64
Forget :: (table: *Tcl.PackageTable, name: string)
ValidVersion :: (version: string) -> bool

Alpha and beta markers occupy their own version component and sort below 0. Comparing decimal component text avoids truncating large version components.

NextComponent :: (version: string, at: *s64) -> string
CompareComponent :: (left: string, right: string) -> s64
Compare :: (left: string, right: string) -> s64
Prerelease :: (version: string) -> bool
CompareBound :: (version: string, bound: string) -> s64

Range endpoints use an implicit a0 on a stable version, so for example 1.2b1 is included at the lower bound 1.2 and excluded at the upper bound 1.2.

SplitRequirement :: (word: string) -> (string, string, bool)
BadVersion :: (version: string) -> Result
Validate :: (requirements: []Text, exact: bool) -> Result
Matches :: (version: string, requirements: []Text, exact: bool) -> bool
Provided :: (table: *Tcl.PackageTable, name: string) -> Result
Conflict :: (name: string, have: string, requirements: []Text, wanted: string) -> Result
Provide :: (interpreter: *Tcl.Interpreter, name: string, version: string) -> Result

An embedder calls Provide after it has attached its own implementation.

IfNeeded :: (table: *Tcl.PackageTable, name: string, version: string, args: []Text) -> Result
Choose :: (table: *Tcl.PackageTable, name: string, requirements: []Text, exact: bool) -> (s64, s64)
ScanIndexes :: (interpreter: *Tcl.Interpreter, depth: s32) -> Result
Discover :: (interpreter: *Tcl.Interpreter, name: string, requirements: []Text, exact: bool, depth: s32) -> Result
Require :: (interpreter: *Tcl.Interpreter, name: string, requirements: []Text, exact: bool, present: bool, depth: s32) -> Result
Run :: (interpreter: *Tcl.Interpreter, args: []Text, depth: s32) -> Result
Dispatch :: (interpreter: *Tcl.Interpreter, args: []Text, depth: s32, result: *Result)

Source ↗

tcl/src/strings.zi

strings

Ported string operations from Inferno tcl_string.b. See ../NOTICE (MIT).

Import with #import "tcl/strings".

RunString :: (args: []Text) -> Result
FormatNumber :: (cursor: *Cursor) -> s64
AppendField :: (output: *Text, value: string, width: s64, zeros: s64, negative: bool, left: bool, numeric: bool)
RunFormat :: (args: []Text) -> Result

Source ↗

tcl/src/types.zi

types

Ported from the Inferno Limbo Tcl interpreter. See ../NOTICE (MIT).

Import with #import "tcl/types".

Code :: enum { OK = 0; Error = 1; Return = 2; Break = 3; Continue = 4; Exit = 5; }
Result :: struct { code: Code; value: Text; }
Success :: (value: string) -> Result
Failure :: (message: string) -> Result
WrongArgs :: (usage: string) -> Result
QuotedError :: (prefix: string, word: string, suffix: string) -> Result
Integer :: (value: s64) -> Result
Space :: (byte: u8) -> bool
InlineSpace :: (byte: u8) -> bool
Digit :: (byte: u8) -> bool
NameByte :: (byte: u8) -> bool
NextCharacter :: (text: string, at: s64) -> s64
CharacterOffset :: (text: string, count: s64) -> s64
CharacterCount :: (text: string) -> s64
CompareText :: (left: string, right: string) -> s64
INT_MIN :: -2147483648

The legacy interpreter's int is signed 32-bit. Wider intermediates let us detect overflow before returning an expression result.

INT_MAX :: 2147483647
InRange :: (value: s64) -> bool
ParseInteger :: (text: string) -> (s64, bool)
Cursor :: struct { text: string; at: s64; }
Has :: (cursor: *Cursor) -> bool
Peek :: (cursor: *Cursor) -> u8
Take :: (cursor: *Cursor) -> u8
WordIn :: (words: string, target: string) -> bool
ContinuesLine :: (cursor: *Cursor) -> bool
SkipContinuation :: (cursor: *Cursor)
Unescape :: (cursor: *Cursor) -> u8
Braced :: (cursor: *Cursor) -> Result

Source ↗

tcl/src/variables.zi

variables

Tcl variables and stack links adapted from Inferno tcl_core.b and tcl_stack.b. See ../NOTICE.

Import with #import "tcl/variables".

Variable :: struct { name: Text; value: Text; }
VariableTable :: struct { entries: Vec(Variable); }
ArrayVariable :: struct { name: Text; elements: VariableTable; }
Alias :: struct { name: Text; target: Text; frame: *Frame; }
Frame :: struct { variables: VariableTable; arrays: Vec(ArrayVariable); aliases: Vec(Alias); parent: *Frame; level: s64; }
VariableRef :: struct { frame: *Frame; base: Text; key: Text; element: bool; valid: bool; }
Parts :: (frame: *Frame, name: string) -> VariableRef
ScalarName :: (name: string) -> bool
FindAlias :: (frame: *Frame, name: string) -> s64
ResolveVariable :: (frame: *Frame, name: string) -> VariableRef
FindVariable :: (variables: *VariableTable, name: string) -> s64
FindArray :: (frame: *Frame, name: string) -> s64
VariableExists :: (frame: *Frame, name: string) -> bool
ReadVariable :: (frame: *Frame, name: string) -> Result
StoreValue :: (values: *VariableTable, name: string, value: string) -> bool
StoreVariable :: (frame: *Frame, name: string, value: string) -> Result
RemoveValue :: (values: *VariableTable, name: string) -> bool
RemoveVariable :: (frame: *Frame, name: string) -> Result
RunArray :: (frame: *Frame, args: []Text) -> Result
LinkVariable :: (frame: *Frame, name: string, target: *Frame, target_name: string) -> Result
AppendDumpHeader :: (out: *Text, label: string, level: s64) -> bool
AppendDumpValues :: (out: *Text, table: *VariableTable, indent: string) -> bool
AppendStackDump :: (out: *Text, frame: *Frame) -> bool

Source ↗