From ca57d7ea5ff9eecef22d05ea9f3c5b7cf41f9a4e Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Wed, 12 Mar 2025 23:04:04 -0400 Subject: [PATCH] Add encoder and decoder proc --- auto_editor/lang/palet.py | 4 ++-- auto_editor/lang/stdenv.py | 12 ++++++++++++ docs/doc.pal | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/auto_editor/lang/palet.py b/auto_editor/lang/palet.py index 673539608..ac231fbe9 100644 --- a/auto_editor/lang/palet.py +++ b/auto_editor/lang/palet.py @@ -646,8 +646,8 @@ def pop(self) -> None: def my_eval(env: Env, node: object) -> Any: - def make_trace(sym: Sym) -> str: - return f" at {sym.val} ({sym.lineno}:{sym.column})" + def make_trace(sym: object) -> str: + return f" at {sym.val} ({sym.lineno}:{sym.column})" if type(sym) is Sym else "" if type(node) is Sym: val = env.get(node.val) diff --git a/auto_editor/lang/stdenv.py b/auto_editor/lang/stdenv.py index 581d76cdc..e6d737236 100644 --- a/auto_editor/lang/stdenv.py +++ b/auto_editor/lang/stdenv.py @@ -2,6 +2,8 @@ from typing import TYPE_CHECKING +import av + from auto_editor.analyze import mut_remove_large, mut_remove_small from auto_editor.lib.contracts import * from auto_editor.lib.data_structs import * @@ -749,6 +751,13 @@ def attr(env: Env, node: Node) -> Any: raise MyError("@r: attribute must be an identifier") base = my_eval(env, node[1]) + + if hasattr(base, "__pyx_vtable__"): + try: + return getattr(base, node[2].val) + except AttributeError as e: + raise MyError(e) + if type(base) is PaletClass: if type(name := node[2]) is not Sym: raise MyError("@r: class attribute must be an identifier") @@ -1171,6 +1180,9 @@ def change_file_ext(a, ext) -> str: "string->vector", lambda s: [Char(c) for c in s], (1, 1), is_str ), "range->vector": Proc("range->vector", list, (1, 1), is_range), + # av + "encoder": Proc("encoder", lambda x: av.Codec(x, "w"), (1, 1), is_str), + "decoder": Proc("decoder", lambda x: av.Codec(x), (1, 1), is_str), # reflexion "var-exists?": Proc("var-exists?", lambda sym: sym.val in env, (1, 1), is_symbol), "rename": Syntax(syn_rename), diff --git a/docs/doc.pal b/docs/doc.pal index b81c56d9c..d14cf3739 100644 --- a/docs/doc.pal +++ b/docs/doc.pal @@ -819,6 +819,14 @@ ) ) ] + "AV" #[ + (proc "encoder" '((value str?) any) + (text "Returns av.Codec("'value", mode=\"w\")") + ) + (proc "decoder" '((value str?) any) + (text "Returns av.Codec("'value", mode=\"r\")") + ) + ] "Reflection" #[ (syntax "quote" "body" (text