Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Richer types #63

Draft
wants to merge 17 commits into
base: tealish-types
Choose a base branch
from
Prev Previous commit
Next Next commit
rename struct to scratch in ObjectType
barnjamin committed Jan 31, 2023
commit bfe257cdf8f87cf6099610ccfd416ac78a295a23
4 changes: 2 additions & 2 deletions tealish/expression_nodes.py
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ def process(self) -> None:
raise CompileError(e.args[0], node=self)
# is it a struct or box?
if type(self.type) == tuple:
if self.type[0] == ObjectType.struct:
if self.type[0] == ObjectType.scratch:
self.type = AVMType.bytes
elif self.type[0] == ObjectType.box:
raise CompileError("Invalid use of a Box reference", node=self)
@@ -479,7 +479,7 @@ def process(self) -> None:
self.type = struct_field.data_type

def write_teal(self, writer: "TealWriter") -> None:
if self.object_type == ObjectType.struct:
if self.object_type == ObjectType.scratch:
writer.write(self, f"load {self.slot} // {self.name}")
if self.type == AVMType.int:
writer.write(self, f"pushint {self.offset}")
4 changes: 2 additions & 2 deletions tealish/nodes.py
Original file line number Diff line number Diff line change
@@ -1608,7 +1608,7 @@ class StructDeclaration(LineStatement):

def process(self) -> None:
self.name.slot = self.declare_var(
self.name.value, (ObjectType.struct, self.struct_name)
self.name.value, (ObjectType.scratch, self.struct_name)
)
if self.expression:
self.expression.process()
@@ -1667,7 +1667,7 @@ def process(self) -> None:
)

def write_teal(self, writer: "TealWriter") -> None:
if self.object_type == ObjectType.struct:
if self.object_type == ObjectType.scratch:
writer.write(self, f"// {self.line} [slot {self.name.slot}]")
writer.write(self, f"load {self.name.slot} // {self.name.value}")
writer.write(self, self.expression)
2 changes: 1 addition & 1 deletion tealish/tealish_builtins.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ class ObjectType(str, Enum):
`box` - the field is in a box, use box_extract to get the bytes
"""

struct = "struct"
scratch = "scratch"
box = "box"