Skip to content

Commit

Permalink
simplify even more
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 10, 2025
1 parent 91bc597 commit 329e6cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
7 changes: 4 additions & 3 deletions compiler/build_cf_graph.jou
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def add_unary_op(
target: LocalVariable*,
) -> None:
ins = CfInstruction{location = location, kind = op, destvar = target}
ins.set_1_operand(arg)
ins.add_operand(arg)
add_instruction(st, ins)


Expand All @@ -128,7 +128,8 @@ def add_binary_op(
target: LocalVariable*,
) -> None:
ins = CfInstruction{location = location, kind = op, destvar = target}
ins.set_2_operands(lhs, rhs)
ins.add_operand(lhs)
ins.add_operand(rhs)
add_instruction(st, ins)


Expand Down Expand Up @@ -325,7 +326,7 @@ def build_class_field_pointer(
kind = CfInstructionKind::PtrClassField,
destvar = result,
}
ins.set_1_operand(instance)
ins.add_operand(instance)

assert sizeof(ins.fieldname) == sizeof(f->name)
strcpy(ins.fieldname, f->name)
Expand Down
14 changes: 3 additions & 11 deletions compiler/cf_graph.jou
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,10 @@ class CfInstruction:
free_signature(&self->signature)
free(self->operands)

def set_1_operand(self, operand: LocalVariable*) -> None:
self->noperands = 1
self->operands = malloc(sizeof(self->operands[0]))
def add_operand(self, operand: LocalVariable*) -> None:
self->operands = realloc(self->operands, sizeof(self->operands[0]) * (self->noperands + 1))
assert self->operands != NULL
self->operands[0] = operand

def set_2_operands(self, operand1: LocalVariable*, operand2: LocalVariable*) -> None:
self->noperands = 2
self->operands = malloc(2 * sizeof(self->operands[0]))
assert self->operands != NULL
self->operands[0] = operand1
self->operands[1] = operand2
self->operands[self->noperands++] = operand


class CfBlock:
Expand Down

0 comments on commit 329e6cf

Please sign in to comment.