Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 57 additions & 248 deletions src/Engine/ProtoAssociative/CodeGen.cs

Large diffs are not rendered by default.

44 changes: 11 additions & 33 deletions src/Engine/ProtoAssociative/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@ public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBl
{
ProtoCore.CodeGen oldCodegen = core.assocCodegen;

if (ProtoCore.DSASM.InterpreterMode.Normal == core.Options.RunMode)
if ((core.IsParsingPreloadedAssembly || core.IsParsingCodeBlockNode) && parentBlock == null)
{
if ((core.IsParsingPreloadedAssembly || core.IsParsingCodeBlockNode) && parentBlock == null)
if (core.CodeBlockList.Count == 0)
{
if (core.CodeBlockList.Count == 0)
{
core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock);
}
else
{
// We reuse the existing toplevel CodeBlockList's for the procedureTable's
// by calling this overloaded constructor - pratapa
core.assocCodegen = new ProtoAssociative.CodeGen(core);
}
core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock);
}
else
core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock);
{
// We reuse the existing toplevel CodeBlockList's for the procedureTable's
// by calling this overloaded constructor - pratapa
core.assocCodegen = new ProtoAssociative.CodeGen(core);
}
}
else
core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock);

if (null != core.AssocNode)
{
Expand Down Expand Up @@ -76,31 +73,12 @@ public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBl
}

core.assocCodegen.context = callContext;

//Temporarily change the code block for code gen to the current block, in the case it is an imperative block
//CodeGen for ProtoImperative is modified to passing in the core object.
ProtoCore.DSASM.CodeBlock oldCodeBlock = core.assocCodegen.codeBlock;
if (core.Options.RunMode == ProtoCore.DSASM.InterpreterMode.Expression)
{
int tempBlockId = callContext.CurrentBlockId;
ProtoCore.DSASM.CodeBlock tempCodeBlock = ProtoCore.Utils.CoreUtils.GetCodeBlock(core.CodeBlockList, tempBlockId);
while (null != tempCodeBlock && tempCodeBlock.blockType != ProtoCore.DSASM.CodeBlockType.Language)
{
tempCodeBlock = tempCodeBlock.parent;
}
core.assocCodegen.codeBlock = tempCodeBlock;
}
core.assocCodegen.codeBlock.EventSink = sink;

if (core.BuildStatus.ErrorCount == 0) //if there is syntax error, no build needed
{
blockId = core.assocCodegen.Emit((codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode);
}
if (core.Options.RunMode == ProtoCore.DSASM.InterpreterMode.Expression)
{
blockId = core.assocCodegen.codeBlock.codeBlockId;
//Restore the code block.
core.assocCodegen.codeBlock = oldCodeBlock;
}
}

// @keyu: we have to restore asscoCodegen here. It may be
Expand Down
146 changes: 1 addition & 145 deletions src/Engine/ProtoCore/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public abstract class CodeGen
protected ProtoCore.DSASM.ProcedureNode localProcedure;
protected ProtoCore.AST.Node localFunctionDefNode;
protected ProtoCore.AST.Node localCodeBlockNode;
protected bool emitDebugInfo = true;

protected List<ProtoCore.DSASM.ProcedureNode> functionCallStack;
protected bool IsAssociativeArrayIndexing { get; set; }
Expand Down Expand Up @@ -197,14 +196,6 @@ protected void AllocateVar(ProtoCore.DSASM.SymbolNode symbol)

protected void SetStackIndex(ProtoCore.DSASM.SymbolNode symbol)
{
if (core.Options.RunMode == ProtoCore.DSASM.InterpreterMode.Expression)
{
//Set the index of the symbol relative to the watching stack
symbol.index = core.watchBaseOffset;
core.watchBaseOffset += 1;
return;
}

int langblockOffset = 0;
bool isGlobal = null == localProcedure;

Expand Down Expand Up @@ -330,27 +321,6 @@ protected string GetConstructBlockName(string construct)
return blockScope.ToString() + "_" + construct + "_" + desc;
}

protected ProtoCore.DSASM.DebugInfo GetDebugObject(int line, int col, int eline, int ecol, int nextStep_a, int nextStep_b = ProtoCore.DSASM.Constants.kInvalidIndex)
{
ProtoCore.DSASM.DebugInfo debug = null;

if (core.Options.EmitBreakpoints)
{
if ( (core.Options.IDEDebugMode || core.Options.WatchTestMode || core.Options.IsDeltaExecution)
&& ProtoCore.DSASM.Constants.kInvalidIndex != line
&& ProtoCore.DSASM.Constants.kInvalidIndex != col)
{
debug = new ProtoCore.DSASM.DebugInfo(line, col, eline, ecol, core.CurrentDSFileName);
debug.nextStep.Add(nextStep_a);

if (ProtoCore.DSASM.Constants.kInvalidIndex != nextStep_b)
debug.nextStep.Add(nextStep_b);
}
}

return debug;
}

abstract protected void EmitGetterSetterForIdentList(
ProtoCore.AST.Node node,
ref ProtoCore.Type inferedType,
Expand Down Expand Up @@ -969,11 +939,6 @@ protected bool VerifyAllocation(string name, int classScope, int functionScope,
symbol = null;
isAccessible = false;
CodeBlock currentCodeBlock = codeBlock;
if (core.Options.RunMode == DSASM.InterpreterMode.Expression)
{
int tempBlockId = context.CurrentBlockId;
currentCodeBlock = ProtoCore.Utils.CoreUtils.GetCodeBlock(core.CodeBlockList, tempBlockId);
}

if (classScope != Constants.kGlobalScope)
{
Expand Down Expand Up @@ -1006,17 +971,6 @@ protected bool VerifyAllocation(string name, int classScope, int functionScope,
return false;
}

if (core.Options.RunMode == ProtoCore.DSASM.InterpreterMode.Expression)
{
//Search local variables in the class member function first
if (functionScope != Constants.kGlobalScope)
{
symbol = core.GetFirstVisibleSymbol(name, classScope, functionScope, currentCodeBlock);
isAccessible = symbol != null;
return isAccessible;
}
}

ClassNode thisClass = core.ClassTable.ClassNodes[classScope];

bool hasThisSymbol;
Expand Down Expand Up @@ -1147,7 +1101,6 @@ protected void EmitCall(int fi,
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;
instr.debug = GetDebugObject(line, col, endLine, endCol, entrypoint);
AppendInstruction(instr);
}

Expand Down Expand Up @@ -1176,7 +1129,6 @@ protected void EmitDynamicCall(int functionIndex, int type,
instr.op2 = StackValue.BuildClassIndex(type);

++pc;
instr.debug = GetDebugObject(line, col, endline, endcol, entrypoint);
AppendInstruction(instr, line, col);
}

Expand All @@ -1190,7 +1142,6 @@ protected void EmitJmp(int L1, int line = ProtoCore.DSASM.Constants.kInvalidInde
instr.op1 = StackValue.BuildLabelIndex(L1);

++pc;
instr.debug = GetDebugObject(line, col, eline, ecol, L1);
AppendInstruction(instr, line, col);
}

Expand All @@ -1204,12 +1155,6 @@ protected void EmitCJmp(int label, int line = ProtoCore.DSASM.Constants.kInvalid
instr.op1 = StackValue.BuildLabelIndex(label);

++pc;
if (core.DebuggerProperties.breakOptions.HasFlag(DebugProperties.BreakpointOptions.EmitInlineConditionalBreakpoint))
{
instr.debug = null;
}
else
instr.debug = GetDebugObject(line, col, eline, ecol, label);

AppendInstruction(instr, line, col);
}
Expand Down Expand Up @@ -1281,7 +1226,6 @@ protected void EmitPop(StackValue op,
Validity.Assert(op.IsVariableIndex || op.IsMemberVariableIndex || op.IsRegister);

++pc;
instr.debug = GetDebugObject(line, col, eline, ecol, pc);
AppendInstruction(instr, line, col);
}

Expand Down Expand Up @@ -1324,19 +1268,6 @@ protected void EmitSetElement(SymbolNode symbol,
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;

bool outputBreakpoint = false;
DebugProperties.BreakpointOptions options = core.DebuggerProperties.breakOptions;
if (options.HasFlag(DebugProperties.BreakpointOptions.EmitPopForTempBreakpoint))
outputBreakpoint = true;

// Do not emit breakpoints for null or var type declarations
if (!core.DebuggerProperties.breakOptions.HasFlag(DebugProperties.BreakpointOptions.SuppressNullVarDeclarationBreakpoint))
{
// Don't need no pop for temp (unless caller demands it).
if (outputBreakpoint || !symbol.name.StartsWith("%"))
instr.debug = GetDebugObject(line, col, eline, ecol, pc);
}
AppendInstruction(instr, line, col);
}

Expand All @@ -1360,46 +1291,9 @@ protected void EmitPopForSymbol(SymbolNode symbol,
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;

bool outputBreakpoint = false;
DebugProperties.BreakpointOptions options = core.DebuggerProperties.breakOptions;
if (options.HasFlag(DebugProperties.BreakpointOptions.EmitPopForTempBreakpoint))
outputBreakpoint = true;

// Do not emit breakpoints for null or var type declarations
if (!core.DebuggerProperties.breakOptions.HasFlag(DebugProperties.BreakpointOptions.SuppressNullVarDeclarationBreakpoint))
{
// Don't need no pop for temp (unless caller demands it).
if (outputBreakpoint || !symbol.name.StartsWith("%"))
instr.debug = GetDebugObject(line, col, eline, ecol, pc);
}
AppendInstruction(instr, line, col);
}

protected void EmitPopForSymbolW(SymbolNode symbol,
int blockId,
int line = ProtoCore.DSASM.Constants.kInvalidIndex,
int col = ProtoCore.DSASM.Constants.kInvalidIndex,
int eline = ProtoCore.DSASM.Constants.kInvalidIndex,
int ecol = ProtoCore.DSASM.Constants.kInvalidIndex)
{
Validity.Assert(symbol != null);
if (symbol == null)
{
return;
}

Instruction instr = new Instruction();
instr.opCode = ProtoCore.DSASM.OpCode.POPW;
instr.op1 = BuildOperand(symbol);
instr.op2 = StackValue.BuildClassIndex(symbol.classScope);
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;

AppendInstruction(instr);
}

protected void EmitPushBlockID(int blockID)
{
EmitInstrConsole(ProtoCore.DSASM.kw.pushb, blockID.ToString());
Expand Down Expand Up @@ -1446,11 +1340,7 @@ protected void EmitPushUpdateInstruction(StackValue op,

private void AppendInstruction(Instruction instr, int line = Constants.kInvalidIndex, int col = Constants.kInvalidIndex)
{
if (DSASM.InterpreterMode.Expression == core.Options.RunMode)
{
core.ExprInterpreterExe.iStreamCanvas.instrList.Add(instr);
}
else if(!core.IsParsingCodeBlockNode && !core.IsParsingPreloadedAssembly)
if(!core.IsParsingCodeBlockNode && !core.IsParsingPreloadedAssembly)
{
codeBlock.instrStream.instrList.Add(instr);

Expand Down Expand Up @@ -1488,31 +1378,8 @@ protected void EmitPushForSymbol(SymbolNode symbol, int blockId, ProtoCore.AST.N
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;

DebugProperties.BreakpointOptions options = core.DebuggerProperties.breakOptions;
if (options.HasFlag(DebugProperties.BreakpointOptions.EmitIdentifierBreakpoint))
{
instr.debug = GetDebugObject(identNode.line, identNode.col,
identNode.endLine, identNode.endCol, pc);
}

AppendInstruction(instr, identNode.line, identNode.col);
}

protected void EmitPushForSymbolW(SymbolNode symbol, int blockId, int line = ProtoCore.DSASM.Constants.kInvalidIndex, int col = ProtoCore.DSASM.Constants.kInvalidIndex)
{
SetEntry();
Instruction instr = new Instruction();
instr.opCode = ProtoCore.DSASM.OpCode.PUSHW;
instr.op1 = BuildOperand(symbol);
instr.op2 = StackValue.BuildClassIndex(symbol.classScope);
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;
//instr.debug = GetDebugObject(line, col, pc);
AppendInstruction(instr);
}


protected void EmitPushm(StackValue op, int classIndex, int blockId, int line = ProtoCore.DSASM.Constants.kInvalidIndex, int col = ProtoCore.DSASM.Constants.kInvalidIndex,
int eline = ProtoCore.DSASM.Constants.kInvalidIndex, int ecol = ProtoCore.DSASM.Constants.kInvalidIndex)
Expand All @@ -1525,7 +1392,6 @@ protected void EmitPushm(StackValue op, int classIndex, int blockId, int line =
instr.op3 = StackValue.BuildBlockIndex(blockId);

++pc;
instr.debug = GetDebugObject(line, col, eline, ecol, pc);
AppendInstruction(instr, line, col);
}

Expand All @@ -1539,10 +1405,6 @@ protected void EmitSetMemElement(StackValue op, int blockId, int line = ProtoCor
instr.op2 = StackValue.BuildBlockIndex(blockId);

++pc;
if (emitDebugInfo)
{
instr.debug = GetDebugObject(line, col, endline, endcol, pc);
}
AppendInstruction(instr, line, col);
}

Expand All @@ -1556,10 +1418,6 @@ protected void EmitPopm(StackValue op, int blockId, int line = ProtoCore.DSASM.C
instr.op2 = StackValue.BuildBlockIndex(blockId);

++pc;
if (emitDebugInfo)
{
instr.debug = GetDebugObject(line, col, endline, endcol, pc);
}
AppendInstruction(instr, line, col);
}

Expand Down Expand Up @@ -1607,7 +1465,6 @@ protected void EmitBinary(
instr.opCode = opcode;

++pc;
instr.debug = GetDebugObject(line, col, eline, ecol, pc);
AppendInstruction(instr, line, col);
}

Expand All @@ -1619,7 +1476,6 @@ protected void EmitUnary(ProtoCore.DSASM.OpCode opcode, int line = ProtoCore.DSA
instr.opCode = opcode;

++pc;
instr.debug = GetDebugObject(line, col, eline, ecol, pc);
AppendInstruction(instr, line, col);
}

Expand Down
14 changes: 3 additions & 11 deletions src/Engine/ProtoCore/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class Context
/// <summary>
/// When compiling expression interpreter code, the codegen needs a copy of certain runtime values
/// </summary>
public int WatchClassScope { get; set; }
public DebugProperties DebugProps { get; private set; }
//public int WatchClassScope { get; set; }
//public DebugProperties DebugProps { get; private set; }

/// <summary>
/// This flag controls whether we want a full codeblock to apply SSA Transform.
Expand Down Expand Up @@ -56,14 +56,6 @@ public void SetData(string source, Dictionary<string, Object> context, Dictionar
applySSATransform = true;
}

public void SetExprInterpreterProperties(int currentBlockID, ProtoCore.Runtime.RuntimeMemory memState, int watchScope, DebugProperties debugProps)
{
CurrentBlockId = currentBlockID;
MemoryState = memState;
WatchClassScope = watchScope;
DebugProps = debugProps;
}

public Context(string source, Dictionary<string, Object> context = null, Dictionary<string, bool> flagList = null)
{
GlobalVarList = context;
Expand All @@ -78,4 +70,4 @@ public Context(string source, Dictionary<string, Object> context = null, Diction
}
}
}
}
}
Loading
Loading