Skip to content

Commit

Permalink
frequent commits (trying to minmax)
Browse files Browse the repository at this point in the history
  • Loading branch information
cetio committed May 9, 2024
1 parent 7c37e26 commit fc8d585
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
39 changes: 33 additions & 6 deletions source/fnc/propagation.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ public:
final:
Glob glob;

Symbol interpret(Function func)
Symbol interpret(Function func, Symbol[] parameters)
{
Variable[] state;
foreach (var; func.locals)
state ~= var.qdup;
// TODO: Restore all parameters?
Symbol[] state = func.locals;
// ?? ungggg
foreach (i, var; func.locals)
{
if ((var.attr & SymAttr.STATIC) == 0 && (var.attr & SymAttr.REF) == 0 && var.isVariable)
state[i] = cast(Symbol)var.freeze();
}

if (parameters.length > 0)
func.locals[parameters.length..$] = cast(Variable[])parameters;

foreach (instr; func.instructions)
{
Expand All @@ -28,12 +36,31 @@ final:
else if (instr.operands[0].isAlias)
(cast(Alias)instr.operands[0]).data = instr.operands[1];
break;
case CALL:
if (instr.operands[0].name == "rt.cast")
(cast(Variable)instr.operands[1]).data = (cast(Variable)instr.operands[2]).data.dup;
else
{
Symbol[] params = (cast(Function)instr.operands[0]).parameters;
foreach (i, operand; instr.operands[1..$])
{
if ((operand.attr & SymAttr.REF) == 0 && (operand.attr & SymAttr.CONST) != 0 && operand.isVariable)
params[i] = cast(Symbol)operand.freeze();
}
interpret(cast(Function)instr.operands[0], params);
}
break;
default:
assert(0, "Unsupported CTFE instruction!");
}
}

scope (exit) func.locals = state;
return func.parameters[0];
scope (exit)
{
func.locals = state;
func.parameters[parameters.length..$] = state;
}
// Maybe?
return func.locals[0].freeze();
}
}
19 changes: 15 additions & 4 deletions source/fnc/symbols.d
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ final:

bool isExpression() => (attr & SymAttr.EXPRESSION) != 0;
bool isLiteral() => (attr & SymAttr.LITERAL) != 0;

Symbol freeze()
{
if (isVariable)
{
Variable temp = cast(Variable)this;
temp.data = temp.data.dup;
return cast(Symbol)temp;
}
return this;
}
}

public class Type : Symbol
Expand Down Expand Up @@ -213,10 +224,10 @@ public class Function : Symbol
{
public:
final:
// The first parameter is always the return.
Variable[] parameters;
// This will include the return and parameters as the first locals.
Variable[] locals;
// Will begin with all alias parameters and then subsequently ret-args.
Symbol[] parameters;
// Will begin with ret-args and then subsequently all locals.
Symbol[] locals;
Instruction[] instructions;
size_t alignment;

Expand Down

0 comments on commit fc8d585

Please sign in to comment.