MCPcopy Create free account
hub / github.com/NICUP14/MiniLang / Operand

Class Operand

src/Def.py:340–379  ·  view source on GitHub ↗

Represents an operand of the AST node (operation). Operands are used internally in the code generator (Gen.py) to standardize snippet creation (`gen_*` functions return a list of snippets).

Source from the content-addressed store, hash-verified

338
339
340class Operand:
341 """
342 Represents an operand of the AST node (operation).
343 Operands are used internally in the code generator (Gen.py)
344 to standardize snippet creation (`gen_*` functions return a list of snippets).
345 """
346
347 def __init__(self, value: str, var_type: VariableType, reg: Register = Register.id_max, loaded: bool = False, imm: bool = False, ref: bool = False) -> None:
348 self.value = value
349 self.var_type = var_type
350 self.reg = reg
351 self.loaded = loaded
352 self.imm = imm
353 self.ref = ref
354
355 def is_ref(self) -> bool:
356 return self.ref
357
358 def is_imm(self) -> bool:
359 return self.imm
360
361 def is_loaded(self) -> bool:
362 return self.loaded
363
364 def load(self):
365 self.loaded = True
366 return self
367
368 def unload(self):
369 self.loaded = False
370 return self
371
372 def reg_str(self):
373 return reg_table_at(self.reg, self.var_type.kind())
374
375 def __str__(self) -> str:
376 attrs = []
377 for key, value in vars(self).items():
378 attrs.append(f"{key}={value}")
379 return f"{self.__class__.__name__}({', '.join(attrs)})"
380
381
382class GenBase:

Callers 4

gen_reg_swapFunction · 0.90
gen_fun_callFunction · 0.90
gen_fun_preambleFunction · 0.90
gen_treeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected