From 2b8985608d33abaae7b201a008e292cbbe2167ef Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 27 Jul 2023 14:26:33 -0700 Subject: add automated refcounting pass --- python/dietc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'python/dietc.py') diff --git a/python/dietc.py b/python/dietc.py index 1101062..58d7e42 100644 --- a/python/dietc.py +++ b/python/dietc.py @@ -43,7 +43,7 @@ class Function: def code_start(self): return next(i for i, l in enumerate(self.body) - if not l.line.startswith("\tType_")) + if not l[0].startswith("Type_")) def insert(self, i, string): self.body.insert(i, Instruction(string)) @@ -71,6 +71,11 @@ class Instruction: if self[0] == "*": return program.object_types[self[1]].base return program.object_types[self[0]] + def replace_token(self, old, new): + self = Instruction(self.line) + self.tokens = [t if t != old else new for t in self.tokens] + self.line = ' '.join(self.tokens) + return self class Program: def __init__(self, string): -- cgit v1.2.3