Skip to content

Commit 7886f32

Browse files
committed
wip
1 parent b91ec44 commit 7886f32

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

scrapscript.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,20 @@ def improve_closure(closure: Closure) -> Closure:
11811181
return Closure(env, closure.func)
11821182

11831183

1184+
def lift_simple(x: object) -> Object:
1185+
if isinstance(x, int):
1186+
return Int(x)
1187+
if isinstance(x, str):
1188+
return String(x)
1189+
raise NotImplementedError(type(x))
1190+
1191+
1192+
def as_record(obj: dict[str, object]) -> Record:
1193+
conv: Callable[[object], Object] = lambda x: as_record(x) if isinstance(x, dict) else lift_simple(x)
1194+
return Record({key: conv(value) for key, value in obj.items()})
1195+
1196+
1197+
# pylint: disable=redefined-builtin
11841198
def eval_exp(env: Env, exp: Object) -> Object:
11851199
logger.debug(exp)
11861200
if isinstance(exp, (Int, Float, String, Bytes, Hole, Closure, NativeFunction, Symbol)):
@@ -4381,6 +4395,7 @@ def listlength(obj: Object) -> Object:
43814395
"$$jsondecode": NativeFunction("$$jsondecode", jsondecode),
43824396
"$$serialize": NativeFunction("$$serialize", lambda obj: Bytes(serialize(obj))),
43834397
"$$listlength": NativeFunction("$$listlength", listlength),
4398+
"$$asrecord": NativeFunction("$$asrecord", lambda exp: as_record(exp.serialize())),
43844399
}
43854400

43864401

0 commit comments

Comments
 (0)