@sschepis/resolang
Version:
ResoLang - Core quantum resonance computation library for browser and Node.js
175 lines • 5.04 kB
TypeScript
import { ExecutionResult, PrimeValue, Transfer, ResonanceAccount, ValidationResult } from './types.js';
import { isPrime, generatePrimes, factorizeToArray as factorize } from './prime-math.js';
import { computeResonance } from './math.js';
import { GasMeter } from './gas.js';
export { GasMeter, GasExhaustedError, GAS_COSTS, type GasOperation } from './gas.js';
export { validate } from './validator.js';
declare class ResoLangInterpreter {
private tokens;
private current;
private context;
private economy;
private gasMeter;
private scopeStack;
private stats;
constructor(gasLimit?: number);
/**
* Initialize the scope stack with a global scope
*/
private initializeScopeStack;
/**
* Get the current (innermost) scope
*/
private currentScope;
/**
* Push a new scope onto the stack (for function calls, blocks, etc.)
*/
private pushScope;
/**
* Pop the current scope from the stack
*/
private popScope;
/**
* Resolve a variable by walking up the scope chain
* Returns the value if found, null if not found
*/
private resolveVariable;
/**
* Check if a variable exists in any scope
*/
private hasVariable;
/**
* Set a variable value
* @param name - Variable name
* @param value - Value to set
* @param forceLocal - If true, always create in current scope (for VAR declarations)
* If false, update existing variable or create in current scope
*/
private setVariable;
/**
* Get the scope where a variable is defined (for debugging/introspection)
*/
private getVariableScope;
/**
* Set gas limit for execution
*/
setGasLimit(limit: number): void;
/**
* Get gas meter for inspection
*/
getGasMeter(): GasMeter;
private createContext;
private createEconomyContext;
/**
* Set execution context for contract calls
*/
setEconomyContext(caller: string, contract?: string): void;
/**
* Register an account for use in execution
*/
registerAccount(account: ResonanceAccount): void;
/**
* Get all transfers from last execution
*/
getTransfers(): Transfer[];
/**
* Get pending stakes from last execution
*/
getPendingStakes(): Map<string, PrimeValue>;
/**
* Get pending rewards from last execution
*/
getPendingRewards(): Map<string, PrimeValue>;
execute(source: string, options?: {
gasLimit?: number;
}): ExecutionResult;
private parseAndExecute;
private executeStatement;
private executeProgram;
private executeConfig;
private executeVariableDeclaration;
private userFunctions;
private executeFunction;
private callUserFunction;
private executeExecuteBlock;
private executeBlock;
private executeIf;
private executeFor;
private executeWhile;
private executeLog;
private executeStoreResult;
private executeDistribute;
/**
* PAY(from, to, amount)
* Transfer value from one account to another
*/
private executePay;
/**
* STAKE(staker, contract, amount)
* Lock value in a contract
*/
private executeStake;
/**
* REWARD(recipient, amount)
* Distribute rewards to an account
*/
private executeReward;
/**
* Resolve account identifier (CALLER, SELF, string, or variable)
*/
private resolveAccountIdentifier;
/**
* Convert expression to PrimeValue
*/
private toPrimeValue;
/**
* Execute a value transfer
*/
private executeTransfer;
/**
* Execute a stake operation
*/
private executeStakeOperation;
/**
* Execute a reward operation
*/
private executeRewardOperation;
private executeAssignmentOrCall;
private parseExpression;
private parseComparison;
private parseAddition;
private parseMultiplication;
private parseUnary;
private parsePrimary;
private parseArray;
private parseObject;
private parseIdentifier;
private parseQuaternion;
private executeGetPrimes;
private executeComputeResonance;
private executeFactorize;
private executeIsPrime;
private executeComputeEntropy;
private executeMeasureCoherence;
private executeComputeEnergy;
private executeCreateSuperposition;
private executeVectorAdd;
private executeScale;
private executeDistance;
private executeNormalizeTanh;
private executeGetEigenvector;
private executeCopy;
private isQuaternion;
private skipBlock;
private isTruthy;
private stringify;
private isAtEnd;
private peek;
private advance;
private check;
private consume;
}
export declare function execute(source: string): ExecutionResult;
export { ResoLangInterpreter, generatePrimes, isPrime, factorize, computeResonance };
export type { ExecutionResult, ValidationResult };
//# sourceMappingURL=interpreter.d.ts.map