@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
35 lines • 2.3 kB
TypeScript
import type { ArithResult, ElementOps } from './types.ts';
/** `value` wrapped to a signed 64-bit integer, as bash's arithmetic wraps. */
export declare function wrapInt64(value: bigint): bigint;
/**
* `text` as a plain decimal (ASCII digits, no leading `0`, which would read
* as octal), wrapped to 64 bits; null when it is anything else and has to
* be evaluated.
*/
export declare function plainDecimal(text: string): bigint | null;
/**
* Evaluate a bash arithmetic expression.
*
* bash's grammar over 64-bit wrapping integers (BigInt), read and
* evaluated in one pass as bash does (`Reader`): comma sequences,
* assignment operators, the ternary, short-circuit `&&`/`||`, the bitwise,
* comparison, shift and arithmetic operators, right-grouping `**`, unary
* operators, `++`/`--`, and integer constants in any base from 2 to 64. A
* variable whose value is not a plain number is read as an expression of
* its own (`x="1+2"; $((x))` is 3). An error is worded as bash's line,
* naming the innermost expression it happened in (`x='1+'; $((x+1))`
* names `1+`). Element references (`a[i]`, `m[key]`) resolve and assign
* through `elements`; with null every subscript is a syntax error, which
* is what an evaluation with no session behind it can honestly say.
* `nounset` is `set -u` for the names the expression reads: one that no
* variable holds throws UnboundVariable instead of reading 0. `frozen`
* names the readonly variable a write to a name reaches, through a
* reference, or null: the evaluation stops there with ReadonlyVariableError. An
* ArithError or ReadonlyVariableError carries the writes made before it. `added`
* is a second expression read after `expr` in the same record and added to
* it: an integer `+=`, whose held value and added text bash evaluates in
* turn, the second seeing what the first assigned (`n='x=5'; n+=x` stores
* 10), each error naming its own side.
*/
export declare function evaluateArith(expr: string, env: Readonly<Record<string, string>>, elements?: ElementOps | null, readVar?: ((name: string) => string | null) | null, wroteVar?: ((name: string, value: string) => void) | null, nounset?: boolean, frozen?: ((name: string) => string | null) | null, added?: string | null): ArithResult;
//# sourceMappingURL=arith.d.ts.map