mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The compiler emits its runtime helpers by name and the VM defines them by name, so the two are one contract. It was renamed on one side only: all three engines -- the Python VM, the TypeScript VM, and the JS emitter -- already said `__printScriptValue`, while every committed snapshot still said `__printHogValue`. The snapshots had not been regenerated since. That was not only cosmetic. `catch.script` and `catch2.script` call `HogError(...)`, an STL name that became `ScriptError`, so both had been failing; and `stl.stdout` recorded `__hogInterval__` for a marker the engines stopped writing two renames ago. So: drop the language's name from the helpers, since inside its own runtime every value is a Script value and the infix distinguishes nothing. Both sides move here, together, and the snapshots are regenerated from the compiler rather than edited to agree. Two names could not simply lose the infix, and the collision is the interesting part: __toScriptDate/DateTime -> __newDate/__newDateTime, not __toDate, which already exists and is a different function -- the STL builtin that PARSES a foreign input, where these build a value from its parts. They join `__newError`, which was already named that way. ScriptError stays. Its remaining word is `Error`, also taken, and also a different function: `Error(message)` fixes the type, `ScriptError( type, message)` takes it. Leaving the families orthogonal: `__new*` builds, `__to*` converts, `__is*` tests, `__x__` marks, `__print*` renders. Verified with the two engines this ABI spans, python-VM output against compiled-JS output per test: 31 pass / 4 fail, against 29 / 6 on the commit before this one. The two it fixes are catch and catch2. The four that remain fail identically on both trees and are untouched by this. `insightsqlx.js` is deliberately NOT regenerated and still spells the old names: its source does not compile on either tree (`BytecodeCompiler has no method visit_insights_qlxtag`), and editing a snapshot by hand to agree with a rename is the exact failure this commit exists to undo. Co-authored-by: Hanzo Dev <[email protected]>
97 lines
2.3 KiB
Python
97 lines
2.3 KiB
Python
from dataclasses import dataclass
|
|
from typing import Any, Optional
|
|
|
|
|
|
@dataclass
|
|
class CallFrame:
|
|
ip: int
|
|
chunk: str
|
|
stack_start: int
|
|
arg_len: int
|
|
closure: dict
|
|
|
|
|
|
@dataclass
|
|
class ThrowFrame:
|
|
call_stack_len: int
|
|
stack_len: int
|
|
catch_ip: int
|
|
|
|
|
|
def is_script_date(obj: Any) -> bool:
|
|
return isinstance(obj, dict) and "__date__" in obj and "year" in obj and "month" in obj and "day" in obj
|
|
|
|
|
|
def is_script_datetime(obj: Any) -> bool:
|
|
return isinstance(obj, dict) and "__dateTime__" in obj and "dt" in obj and "zone" in obj
|
|
|
|
|
|
def is_script_error(obj: Any) -> bool:
|
|
return isinstance(obj, dict) and "__error__" in obj and "type" in obj and "message" in obj
|
|
|
|
|
|
def new_script_error(type: str, message: Any, payload: Any = None) -> dict:
|
|
return {
|
|
"__error__": True,
|
|
"type": type or "Error",
|
|
"message": message or "An error occurred",
|
|
"payload": payload,
|
|
}
|
|
|
|
|
|
def is_script_callable(obj: Any) -> bool:
|
|
return (
|
|
isinstance(obj, dict)
|
|
and "__callable__" in obj
|
|
and "argCount" in obj
|
|
and "ip" in obj
|
|
# and "chunk" in obj # TODO: enable after this has been live for some hours
|
|
and "upvalueCount" in obj
|
|
)
|
|
|
|
|
|
def is_script_closure(obj: Any) -> bool:
|
|
return isinstance(obj, dict) and "__closure__" in obj and "callable" in obj and "upvalues" in obj
|
|
|
|
|
|
def new_script_closure(callable: dict, upvalues: Optional[list] = None) -> dict:
|
|
return {
|
|
"__closure__": True,
|
|
"callable": callable,
|
|
"upvalues": upvalues or [],
|
|
}
|
|
|
|
|
|
def new_script_callable(type: str, arg_count: int, upvalue_count: int, ip: int, name: str, chunk: str) -> dict:
|
|
return {
|
|
"__callable__": type,
|
|
"name": name,
|
|
"chunk": chunk,
|
|
"argCount": arg_count,
|
|
"upvalueCount": upvalue_count,
|
|
"ip": ip,
|
|
}
|
|
|
|
|
|
def is_script_upvalue(obj: Any) -> bool:
|
|
return (
|
|
isinstance(obj, dict)
|
|
and "__upValue__" in obj
|
|
and "location" in obj
|
|
and "closed" in obj
|
|
and "value" in obj
|
|
and "id" in obj
|
|
)
|
|
|
|
|
|
def is_script_interval(obj: Any) -> bool:
|
|
return isinstance(obj, dict) and obj.get("__interval__") is True
|
|
|
|
|
|
def to_script_interval(value: int, unit: str):
|
|
return {
|
|
"__interval__": True,
|
|
"value": value,
|
|
"unit": unit,
|
|
}
|