From fc8d585f31377e033cc53878d9ff113d62a47f79 Mon Sep 17 00:00:00 2001 From: cetio Date: Thu, 9 May 2024 15:51:53 -0400 Subject: [PATCH] frequent commits (trying to minmax) --- source/fnc/propagation.d | 39 +++++++++++++++++++++++++++++++++------ source/fnc/symbols.d | 19 +++++++++++++++---- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/source/fnc/propagation.d b/source/fnc/propagation.d index b5ab306..475dd3e 100644 --- a/source/fnc/propagation.d +++ b/source/fnc/propagation.d @@ -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) { @@ -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(); } } \ No newline at end of file diff --git a/source/fnc/symbols.d b/source/fnc/symbols.d index b3fb3d2..b2d3c51 100644 --- a/source/fnc/symbols.d +++ b/source/fnc/symbols.d @@ -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 @@ -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;