Recover practices and data on the current Ziran runtime
This commit is contained in:
1 parent
bd6d5a2c41
commit
ca99ca92ef
95 files changed
+3907
-1562
No files matched your search
@@ -6,6 +6,7 @@ import re
|
||||
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
schema = {}
|
||||
record_names = {}
|
||||
for file in [
|
||||
*sorted((root / "src/apps").glob("*_types.zi")),
|
||||
root / "apps/diary/diary_types.zi",
|
||||
@@ -19,6 +20,7 @@ for file in [
|
||||
):
|
||||
fields = re.findall(r"^\s*(\w+)\s*:\s*([^\n;]+)", body, re.M)
|
||||
schema[name] = [(n, re.sub(r"\s+", "", t.split("//")[0])) for n, t in fields]
|
||||
record_names[name] = f"{file.stem}.{name}"
|
||||
constants = {"CountSize": 4, "MaxRounds": 12}
|
||||
roots = [
|
||||
"LumiMessage",
|
||||
@@ -109,7 +111,7 @@ for t in needed:
|
||||
f"Encode{t} :: (data: {t}, codec: *{t}Codec) -> HostValue {{",
|
||||
" value: HostValue",
|
||||
" value.kind = cast(s32)HostRecord",
|
||||
f' value.type_name = "{t}".data',
|
||||
f' value.type_name = "{record_names[t]}".data',
|
||||
" value.fields = *codec.fields[0]",
|
||||
f" value.field_count = {len(schema[t])}",
|
||||
]
|
||||
@@ -226,9 +228,7 @@ for t in needed:
|
||||
for t in needed:
|
||||
lines += [
|
||||
f"Valid{t} :: (value: HostValue) -> bool {{",
|
||||
f' if value.kind != cast(s32)HostRecord || TextFromCString(value.type_name) != "{t}" ||',
|
||||
" value.field_count > cast(usize)HOST_FIELD_LIMIT ||",
|
||||
" (value.field_count > cast(usize)0 && value.fields == null) {",
|
||||
f' if !HostRecordValid(*value, "{record_names[t]}") {{',
|
||||
" return false",
|
||||
" }",
|
||||
]
|
||||
|
||||
@@ -121,6 +121,8 @@ def zx28_assets_section(data):
|
||||
|
||||
Ziran's ASSEMBLY/zx-executable-format.md: a 64-byte header, then 32-byte
|
||||
directory records in increasing kind order; the file length is exact."""
|
||||
if len(data) < 64:
|
||||
raise ValueError('truncated ZX 28 container')
|
||||
header_size, record_size = struct.unpack_from('<II', data, 8)
|
||||
count = struct.unpack_from('<I', data, 32)[0]
|
||||
length, directory = struct.unpack_from('<QQ', data, 40)
|
||||
|
||||
Reference in new issue
Block a user