Skip to content

Commit

Permalink
wtf was i thinking II
Browse files Browse the repository at this point in the history
  • Loading branch information
cetio committed May 9, 2024
1 parent abddd99 commit 7c37e26
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions source/fnc/propagation.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module fnc.propagation;

import fnc.symbols;
import fnc.emission;
import std.typecons;
import tern.object : qdup;

public struct Engine
{
Expand All @@ -12,25 +14,26 @@ final:

Symbol interpret(Function func)
{
Function temp = func.ddup;
Variable[] state;
foreach (var; func.locals)
state ~= var.qdup;

foreach (instr; func.instructions)
{
with (OpCode) switch (instr.opcode)
{
case MOV:
Symbol lhs = glob.symbols[instr.operands[0]];
Symbol rhs = glob.symbols[instr.operands[1]];

if (lhs.isVariable)
(cast(Variable)lhs).data = (cast(Variable)rhs).data.dup;
else if (lhs.isAlias)
(cast(Alias)lhs).data = rhs;
if (instr.operands[0].isVariable)
(cast(Variable)instr.operands[0]).data = (cast(Variable)instr.operands[1]).data.dup;
else if (instr.operands[0].isAlias)
(cast(Alias)instr.operands[0]).data = instr.operands[1];
break;
default:
assert(0, "Unsupported CTFE instruction!");
}
}
scope (exit) func = temp;

scope (exit) func.locals = state;
return func.parameters[0];
}
}

0 comments on commit 7c37e26

Please sign in to comment.