inlineasm.py 909 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/python3
  2. from pyteal import *
  3. class CustomOp():
  4. def __init__(self, opcode):
  5. self.opcode = opcode
  6. self.mode = Mode.Signature | Mode.Application
  7. self.min_version = 2
  8. def __str__(self) -> str:
  9. return self.opcode
  10. class InlineAssembly(LeafExpr):
  11. def __init__(self, opcode: str, *args: "Expr", type: TealType = TealType.none) -> None:
  12. super().__init__()
  13. opcode_with_args = opcode.split(" ")
  14. self.op = CustomOp(opcode_with_args[0])
  15. self.type = type
  16. self.opcode_args = opcode_with_args[1:]
  17. self.args = args
  18. def __teal__(self, options: "CompileOptions"):
  19. op = TealOp(self, self.op, *self.opcode_args)
  20. return TealBlock.FromOp(options, op, *self.args[::1])
  21. def __str__(self):
  22. return "(InlineAssembly: {})".format(self.opcode)
  23. def type_of(self):
  24. return self.type