Skip to content

Commit

Permalink
Improve handling of immediate args, especially re stdlib functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fergalwalsh committed Feb 20, 2024
1 parent c538e41 commit 7d96142
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tealish/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def lookup_const(self, name: str) -> Tuple["TealishType", ConstValue]:
def lookup_avm_constant(self, name: str) -> Tuple["TealishType", Any]:
return lang_spec.lookup_avm_constant(name)

def lookup_op_field(self, op_name: str, field_name: str) -> "TealishType":
return lang_spec.lookup_op_field(op_name, field_name)

# TODO: these attributes are only available on Node and other children types
# we should either define them here or something else?
@property
Expand Down
6 changes: 5 additions & 1 deletion tealish/expression_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def process(self) -> None:
# builtin TEAL constants
type, value = self.lookup_avm_constant(self.name)
except KeyError:
raise CompileError(f'Unknown builtin enum "{self.name}"', node=self)
try:
# op field
type = self.lookup_op_field(self.parent.name, self.name)
except KeyError:
raise CompileError(f'Unknown builtin enum "{self.name}"', node=self)
if not isinstance(type, (IntType, BytesType, BigIntType, AddrType)):
raise CompileError(f"Unexpected const type {type}", node=self)

Expand Down
5 changes: 5 additions & 0 deletions tealish/langspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ def lookup_op(self, name: str) -> Op:
raise KeyError(f'Op "{name}" does not exist!')
return self.ops[name]

def lookup_op_field(self, op_name: str, field_name: str) -> Op:
op = self.lookup_op(op_name)
type = op.arg_enum_dict[field_name]
return type

def lookup_avm_constant(self, name: str) -> Tuple[TealishType, Any]:
if name not in constants:
raise KeyError(f'Constant "{name}" does not exist!')
Expand Down

0 comments on commit 7d96142

Please sign in to comment.