本文整理汇总了C#中ProtoCore.AST.ImperativeAST.ImperativeNode类的典型用法代码示例。如果您正苦于以下问题:C# ImperativeNode类的具体用法?C# ImperativeNode怎么用?C# ImperativeNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImperativeNode类属于ProtoCore.AST.ImperativeAST命名空间,在下文中一共展示了ImperativeNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DfsExprValue
private int DfsExprValue(ImperativeNode node)
{
if (node is IdentifierNode)
{
int val = 0;
IdentifierNode t = node as IdentifierNode;
try
{
val = System.Convert.ToInt32(t.Value);
return val;
}
catch (OverflowException)
{
}
catch (FormatException)
{
}
}
else if (node is BinaryExpressionNode)
{
BinaryExpressionNode b = node as BinaryExpressionNode;
Debug.Assert(ProtoCore.DSASM.Operator.mul == b.Optr);
int left = DfsExprValue(b.LeftNode);
int right = DfsExprValue(b.RightNode);
return left * right;
}
return 1;
}
示例2: DfsEmitArrayIndex
// this method is used in conjuction with array indexing
private void DfsEmitArrayIndex(ImperativeNode node, int symbolindex, int index = 0)
{
// s = b + ((i * i.w) + (j * j.w) + (n * n.w))
if (node is ArrayNode)
{
ArrayNode array = node as ArrayNode;
ProtoCore.Type type = new ProtoCore.Type();
type.UID = (int)ProtoCore.PrimitiveType.kTypeVoid;
type.IsIndexable = false;
DfsTraverse(array.Expr, ref type);
// Max size of the current dimension
int w = codeBlock.symbolTable.symbolList[symbolindex].arraySizeList[index];
// TODO Jun: Performance improvement
// Avoid having to generate instructions for the current index if 'w' is 0
if (array.Type is ArrayNode)
{
DfsEmitArrayIndex(array.Type, symbolindex, index + 1);
}
}
else
{
Debug.Assert(false, "ast error – check ast construction");
}
}
示例3: BuildIdentList
public ImperativeNode BuildIdentList(ImperativeNode leftNode, ImperativeNode rightNode)
{
var identList = new IdentifierListNode();
identList.LeftNode = leftNode;
identList.RightNode = rightNode;
identList.Optr = ProtoCore.DSASM.Operator.dot;
return identList;
}
示例4: EmitPostFixNode
private void EmitPostFixNode(ImperativeNode node, ref ProtoCore.Type inferedType)
{
bool parseGlobal = null == localProcedure && ProtoCore.DSASM.ImperativeCompilePass.kAll == compilePass;
bool parseGlobalFunction = null != localProcedure && ProtoCore.DSASM.ImperativeCompilePass.kGlobalFuncBody == compilePass;
if (parseGlobal || parseGlobalFunction)
{
PostFixNode pfNode = node as PostFixNode;
//convert post fix operation to a binary operation
BinaryExpressionNode binRight = new BinaryExpressionNode();
BinaryExpressionNode bin = new BinaryExpressionNode();
binRight.LeftNode = pfNode.Identifier;
binRight.RightNode = new IntNode() { value = "1" };
binRight.Optr = (ProtoCore.DSASM.UnaryOperator.Increment == pfNode.Operator) ? ProtoCore.DSASM.Operator.add : ProtoCore.DSASM.Operator.sub;
bin.LeftNode = pfNode.Identifier;
bin.RightNode = binRight;
bin.Optr = ProtoCore.DSASM.Operator.assign;
EmitBinaryExpressionNode(bin, ref inferedType);
}
}
示例5: EmitWhileStmtNode
private void EmitWhileStmtNode(ImperativeNode node, ref ProtoCore.Type inferedType, bool isBooleanOp = false, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
{
if (IsParsingGlobal() || IsParsingGlobalFunctionBody())
{
/*
while(E) -> entry = pc
traverse E
emit(pop,cx)
L1 = pc + 1
L2 = null
bp = pc
emit(jmp, _cx, L1, L2)
* */
int bp = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
int L1 = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
int L2 = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
int entry = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
entry = pc;
WhileStmtNode whileNode = node as WhileStmtNode;
DfsTraverse(whileNode.Expr, ref inferedType);
ProtoCore.DSASM.StackValue opCX = new ProtoCore.DSASM.StackValue();
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regCX);
opCX.optype = ProtoCore.DSASM.AddressType.Register;
opCX.opdata = (int)ProtoCore.DSASM.Registers.CX;
EmitPop(opCX, Constants.kGlobalScope);
L1 = pc + 1;
L2 = ProtoCore.DSASM.Constants.kInvalidIndex;
bp = pc;
EmitCJmp(L1, L2, whileNode.Expr.line, whileNode.Expr.col, whileNode.Expr.endLine, whileNode.Expr.endCol);
EmitSetExpressionUID(compileStateTracker.ExpressionUID++);
/*
{
S -> traverse S
bptable.append(pc)
emit(jmp, entry)
}
-> backpatch(bp, pc)
*/
if (null != whileNode.Body)
{
// Create a new symboltable for this block
// Set the current table as the parent of the new table
// Set the new table as a new child of the current table
// Set the new table as the current table
// Create a new codeblock for this block
// Set the current codeblock as the parent of the new codeblock
// Set the new codeblock as a new child of the current codeblock
// Set the new codeblock as the current codeblock
ProtoCore.DSASM.CodeBlock localCodeBlock = new ProtoCore.DSASM.CodeBlock(
ProtoCore.DSASM.CodeBlockType.kConstruct,
Language.kInvalid,
compileStateTracker.CodeBlockIndex++,
new ProtoCore.DSASM.SymbolTable(GetConstructBlockName("while"), compileStateTracker.RuntimeTableIndex++),
null,
true);
localCodeBlock.instrStream = codeBlock.instrStream;
localCodeBlock.parent = codeBlock;
codeBlock.children.Add(localCodeBlock);
codeBlock = localCodeBlock;
compileStateTracker.CompleteCodeBlockList.Add(localCodeBlock);
backpatchMap.EntryTable[localCodeBlock.codeBlockId] = entry;
backpatchMap.BreakTable[localCodeBlock.codeBlockId] = new BackpatchTable();
EmitPushBlockID(localCodeBlock.codeBlockId);
foreach (ImperativeNode bodyNode in whileNode.Body)
{
inferedType = new ProtoCore.Type();
inferedType.UID = (int)PrimitiveType.kTypeVar;
if (bodyNode is LanguageBlockNode)
{
BinaryExpressionNode langBlockNode = new BinaryExpressionNode();
langBlockNode.LeftNode = nodeBuilder.BuildIdentfier(compileStateTracker.GenerateTempLangageVar());
langBlockNode.Optr = ProtoCore.DSASM.Operator.assign;
langBlockNode.RightNode = bodyNode;
DfsTraverse(langBlockNode, ref inferedType, isBooleanOp, graphNode);
}
else
{
DfsTraverse(bodyNode, ref inferedType, isBooleanOp, graphNode);
}
}
ProtoCore.AST.Node oldBlockNode = localCodeBlockNode;
localCodeBlockNode = node;
EmitInstrConsole(ProtoCore.DSASM.kw.retcn);
EmitRetcn(localCodeBlock.codeBlockId);
localCodeBlockNode = oldBlockNode;
// Restore - Set the local codeblock parent to be the current codeblock
//.........这里部分代码省略.........
示例6: EmitUnaryExpressionNode
private void EmitUnaryExpressionNode(ImperativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AST.ImperativeAST.BinaryExpressionNode parentNode)
{
if (IsParsingGlobal() || IsParsingGlobalFunctionBody())
{
UnaryExpressionNode u = node as UnaryExpressionNode;
bool isPrefixOperation = ProtoCore.DSASM.UnaryOperator.Increment == u.Operator || ProtoCore.DSASM.UnaryOperator.Decrement == u.Operator;
//(Ayush) In case of prefix, apply prefix operation first
if (isPrefixOperation)
{
if (u.Expression is IdentifierListNode || u.Expression is IdentifierNode)
{
BinaryExpressionNode binRight = new BinaryExpressionNode();
BinaryExpressionNode bin = new BinaryExpressionNode();
binRight.LeftNode = u.Expression;
binRight.RightNode = new IntNode { value = "1" };
binRight.Optr = (ProtoCore.DSASM.UnaryOperator.Increment == u.Operator) ? ProtoCore.DSASM.Operator.add : ProtoCore.DSASM.Operator.sub;
bin.LeftNode = u.Expression; bin.RightNode = binRight; bin.Optr = ProtoCore.DSASM.Operator.assign;
EmitBinaryExpressionNode(bin, ref inferedType);
}
else
throw new BuildHaltException("Invalid use of prefix operation (15BB9C10).");
}
DfsTraverse(u.Expression, ref inferedType, false, null, AssociativeSubCompilePass.kNone, parentNode);
if (!isPrefixOperation)
{
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regAX);
ProtoCore.DSASM.StackValue opAX = new ProtoCore.DSASM.StackValue();
opAX.optype = ProtoCore.DSASM.AddressType.Register;
opAX.opdata = (int)ProtoCore.DSASM.Registers.AX;
EmitPop(opAX, Constants.kGlobalScope);
string op = opKwData.unaryOpStringTable[u.Operator];
EmitInstrConsole(op, ProtoCore.DSASM.kw.regAX);
EmitUnary(opKwData.unaryOpCodeTable[u.Operator], opAX);
EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regAX);
ProtoCore.DSASM.StackValue opRes = new ProtoCore.DSASM.StackValue();
opRes.optype = ProtoCore.DSASM.AddressType.Register;
opRes.opdata = (int)ProtoCore.DSASM.Registers.AX;
EmitPush(opRes);
}
}
}
示例7: EmitLanguageBlockNode
private void EmitLanguageBlockNode(ImperativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AssociativeGraph.GraphNode propogateUpdateGraphNode = null)
{
//
// TODO Jun:
// Add support for language blocks, classes and functions in GRAPH post july release
// This Temporary guard will no longer be necessary
bool disableLanguageBlocks = compileStateTracker.IsParsingCodeBlockNode || compileStateTracker.IsParsingPreloadedAssembly;
if (disableLanguageBlocks)
{
compileStateTracker.BuildStatus.LogSemanticError("Defining language blocks are not yet supported");
}
if (IsParsingGlobal() || IsParsingGlobalFunctionBody())
{
LanguageBlockNode langblock = node as LanguageBlockNode;
//(Fuqiang, Ayush) : Throwing an assert stops NUnit. Negative tests expect to catch a
// CompilerException, so we throw that instead.
//Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language);
if (ProtoCore.Language.kInvalid == langblock.codeblock.language)
{
throw new ProtoCore.Exceptions.CompileErrorsOccured("Invalid language block");
}
ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
int entry = 0;
int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
if (ProtoCore.Language.kImperative == langblock.codeblock.language)
{
// TODO Jun: Move the associative and all common string into some table
buildStatus.LogSyntaxError("An imperative language block is declared within an imperative language block.", compileStateTracker.CurrentDSFileName, langblock.line, langblock.col);
}
if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && compileStateTracker.ProcNode == null)
{
compileStateTracker.ProcNode = codeBlock.procedureTable.procList[globalProcIndex];
}
compileStateTracker.Executives[langblock.codeblock.language].Compile(compileStateTracker, out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode);
if (propogateUpdateGraphNode != null)
{
propogateUpdateGraphNode.languageBlockId = blockId;
CodeBlock childBlock = compileStateTracker.CompleteCodeBlockList[blockId];
foreach (var subGraphNode in childBlock.instrStream.dependencyGraph.GraphList)
{
foreach (var depentNode in subGraphNode.dependentList)
{
if (depentNode.updateNodeRefList != null
&& depentNode.updateNodeRefList.Count > 0
&& depentNode.updateNodeRefList[0].nodeList != null
&& depentNode.updateNodeRefList[0].nodeList.Count > 0)
{
SymbolNode dependentSymbol = depentNode.updateNodeRefList[0].nodeList[0].symbol;
int symbolBlockId = dependentSymbol.codeBlockId;
if (symbolBlockId != Constants.kInvalidIndex)
{
CodeBlock symbolBlock = compileStateTracker.CompleteCodeBlockList[symbolBlockId];
if (!symbolBlock.IsMyAncestorBlock(codeBlock.codeBlockId))
{
propogateUpdateGraphNode.PushDependent(depentNode);
}
}
}
}
}
}
setBlkId(blockId);
inferedType = compileStateTracker.InferedType;
//Debug.Assert(codeBlock.children[codeBlock.children.Count - 1].blockType == ProtoCore.DSASM.CodeBlockType.kLanguage);
codeBlock.children[codeBlock.children.Count - 1].Attributes = PopulateAttributes(langblock.Attributes);
#if ENABLE_EXCEPTION_HANDLING
core.ExceptionHandlingManager.Register(blockId, globalProcIndex, globalClassIndex);
#endif
EmitInstrConsole("bounce " + blockId + ", " + entry.ToString());
EmitBounceIntrinsic(blockId, entry);
// The callee language block will have stored its result into the RX register.
EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regRX);
ProtoCore.DSASM.StackValue opRes = new ProtoCore.DSASM.StackValue();
opRes.optype = ProtoCore.DSASM.AddressType.Register;
opRes.opdata = (int)ProtoCore.DSASM.Registers.RX;
EmitPush(opRes);
}
}
示例8: EmitIfStmtNode
private void EmitIfStmtNode(ImperativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AST.ImperativeAST.BinaryExpressionNode parentNode = null, bool isForInlineCondition = false, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
{
if (IsParsingGlobal() || IsParsingGlobalFunctionBody())
{
/*
def backpatch(bp, pc)
instr = instrstream[bp]
if instr.opcode is jmp
instr.op1 = pc
elseif instr.opcode is cjmp
instr.op2 = pc
end
end
def backpatch(table, pc)
foreach node in table
backpatch(node.pc, pc)
end
end
*/
/*
if(E) -> traverse E
bpTable = new instance
L1 = pc + 1
L2 = null
bp = pc
emit(jmp, _cx, L1, L2)
{
S -> traverse S
L1 = null
bpTable.append(pc)
emit(jmp,labelEnd)
backpatch(bp,pc)
}
* */
int bp = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
int L1 = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
int L2 = (int)ProtoCore.DSASM.Constants.kInvalidIndex;
ProtoCore.DSASM.StackValue opCX = new ProtoCore.DSASM.StackValue();
// If-expr
IfStmtNode ifnode = node as IfStmtNode;
DfsTraverse(ifnode.IfExprNode, ref inferedType, false, graphNode, AssociativeSubCompilePass.kNone, parentNode);
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regCX);
opCX.optype = ProtoCore.DSASM.AddressType.Register;
opCX.opdata = (int)ProtoCore.DSASM.Registers.CX;
EmitPop(opCX, Constants.kGlobalScope);
L1 = pc + 1;
L2 = ProtoCore.DSASM.Constants.kInvalidIndex;
bp = pc;
EmitCJmp(L1, L2, ifnode.IfExprNode.line, ifnode.IfExprNode.col, ifnode.IfExprNode.endLine, ifnode.IfExprNode.endCol);
if (!isForInlineCondition)
{
EmitSetExpressionUID(compileStateTracker.ExpressionUID++);
}
// Create a new codeblock for this block
// Set the current codeblock as the parent of the new codeblock
// Set the new codeblock as a new child of the current codeblock
// Set the new codeblock as the current codeblock
ProtoCore.DSASM.CodeBlock localCodeBlock = new ProtoCore.DSASM.CodeBlock(
ProtoCore.DSASM.CodeBlockType.kConstruct,
Language.kInvalid,
compileStateTracker.CodeBlockIndex++,
new ProtoCore.DSASM.SymbolTable(GetConstructBlockName("if"), compileStateTracker.RuntimeTableIndex++),
null);
localCodeBlock.instrStream = codeBlock.instrStream;
localCodeBlock.parent = codeBlock;
codeBlock.children.Add(localCodeBlock);
codeBlock = localCodeBlock;
compileStateTracker.CompleteCodeBlockList.Add(localCodeBlock);
EmitPushBlockID(localCodeBlock.codeBlockId);
// If-body
foreach (ImperativeNode ifBody in ifnode.IfBody)
{
inferedType = new ProtoCore.Type();
inferedType.UID = (int)PrimitiveType.kTypeVar;
DfsTraverse(ifBody, ref inferedType, false, graphNode, AssociativeSubCompilePass.kNone, parentNode);
}
if (!isForInlineCondition)
{
ProtoCore.AST.Node oldBlockNode = localCodeBlockNode;
localCodeBlockNode = ifnode.IfBodyPosition;
EmitInstrConsole(ProtoCore.DSASM.kw.retcn);
EmitRetcn(localCodeBlock.codeBlockId);
localCodeBlockNode = oldBlockNode;
}
// Restore - Set the local codeblock parent to be the current codeblock
codeBlock = localCodeBlock.parent;
L1 = ProtoCore.DSASM.Constants.kInvalidIndex;
//.........这里部分代码省略.........
示例9: DfsEmitArrayIndex
// this method is used in conjuction with array indexing
private void DfsEmitArrayIndex(ImperativeNode node, int symbolindex, int index = 0)
{
// s = b + ((i * i.w) + (j * j.w) + (n * n.w))
if (node is ArrayNode)
{
ArrayNode array = node as ArrayNode;
ProtoCore.Type type = new ProtoCore.Type();
type.UID = (int)ProtoCore.PrimitiveType.kTypeVoid;
type.IsIndexable = false;
DfsTraverse(array.Expr, ref type);
// Max size of the current dimension
int w = codeBlock.symbolTable.symbolList[symbolindex].arraySizeList[index];
// TODO Jun: Performance improvement
// Avoid having to generate instructions for the current index if 'w' is 0
EmitInstrConsole(ProtoCore.DSASM.kw.push, w.ToString());
ProtoCore.DSASM.StackValue opWidth = new ProtoCore.DSASM.StackValue();
opWidth.optype = ProtoCore.DSASM.AddressType.Int;
opWidth.opdata = w;
EmitPush(opWidth);
string op = null;
ProtoCore.DSASM.StackValue opAX = new ProtoCore.DSASM.StackValue();
opAX.optype = ProtoCore.DSASM.AddressType.Register;
opAX.opdata = (int)ProtoCore.DSASM.Registers.AX;
ProtoCore.DSASM.StackValue opBX = new ProtoCore.DSASM.StackValue();
opBX.optype = ProtoCore.DSASM.AddressType.Register;
opBX.opdata = (int)ProtoCore.DSASM.Registers.BX;
ProtoCore.DSASM.StackValue opRes = new ProtoCore.DSASM.StackValue();
opRes.optype = ProtoCore.DSASM.AddressType.Register;
opRes.opdata = (int)ProtoCore.DSASM.Registers.AX;
// Multiplying the max array size by the number of elements
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regBX);
EmitPop(opBX, Constants.kGlobalScope);
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regAX);
EmitPop(opAX, Constants.kGlobalScope);
op = opKwData.opStringTable[ProtoCore.DSASM.Operator.mul];
EmitInstrConsole(op, ProtoCore.DSASM.kw.regAX, ProtoCore.DSASM.kw.regBX);
EmitBinary(opKwData.opCodeTable[ProtoCore.DSASM.Operator.mul], opAX, opBX);
EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regAX);
EmitPush(opRes);
if (array.Type is ArrayNode)
{
DfsEmitArrayIndex(array.Type, symbolindex, index + 1);
// Adding the previous arraysize to the current one
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regBX);
EmitPop(opBX, Constants.kGlobalScope);
EmitInstrConsole(ProtoCore.DSASM.kw.pop, ProtoCore.DSASM.kw.regAX);
EmitPop(opAX, Constants.kGlobalScope);
op = opKwData.opStringTable[ProtoCore.DSASM.Operator.add];
EmitInstrConsole(op, ProtoCore.DSASM.kw.regAX, ProtoCore.DSASM.kw.regBX);
EmitBinary(opKwData.opCodeTable[ProtoCore.DSASM.Operator.add], opAX, opBX);
EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regAX);
EmitPush(opRes);
}
}
else
{
Debug.Assert(false, "ast error – check ast construction");
}
}
示例10: DfsBuildIndex
// this method is used in conjuction with array var declarations
private void DfsBuildIndex(ImperativeNode node, List<int> indexlist)
{
if (node is ArrayNode)
{
ArrayNode array = node as ArrayNode;
int exprval = 0;
if (null != array.Expr) {
exprval = DfsExprValue(array.Expr);
}
indexlist.Add(exprval);
DfsBuildIndex(array.Type, indexlist);
}
}
示例11: AllocateArray
private void AllocateArray(ProtoCore.DSASM.SymbolNode symbol, ImperativeNode nodeArray)
{
symbol.isArray = true;
//===================================================
// TODO Jun:
// Determine which is optimal-
// 1. Storing the array flag in the symbol, or...
// 2. Storing the array flag as an instruction operand
//===================================================
// TODO Jun: allocate to the stack is the array has empty expressions
ArrayNode array = nodeArray as ArrayNode;
bool heapAlloc = null != array.Expr;
symbol.memregion = heapAlloc ? ProtoCore.DSASM.MemoryRegion.kMemHeap : ProtoCore.DSASM.MemoryRegion.kMemStack;
if (ProtoCore.DSASM.MemoryRegion.kMemStack == symbol.memregion)
{
symbol.arraySizeList = new List<int>();
List<int> indexlist = new List<int>();
// TODO Jun: Optimize this
DfsBuildIndex(nodeArray, indexlist);
foreach (int indexVal in indexlist)
{
if (0 != indexVal)
{
symbol.size *= indexVal;
}
}
// Rebuild the array that is needed to compute the size at each index
indexlist.RemoveAt(0);
indexlist.Add(symbol.datasize);
for (int n = 0; n < indexlist.Count; ++n)
{
symbol.arraySizeList.Add(1);
for (int i = n; i < indexlist.Count; ++i)
{
symbol.arraySizeList[n] *= indexlist[i];
}
}
}
else if (ProtoCore.DSASM.MemoryRegion.kMemHeap == symbol.memregion)
{
int indexCnt = DfsEmitArrayIndexHeap(nodeArray);
EmitInstrConsole(ProtoCore.DSASM.kw.push, indexCnt.ToString());
ProtoCore.DSASM.StackValue opSize = new ProtoCore.DSASM.StackValue();
opSize.optype = ProtoCore.DSASM.AddressType.Int;
opSize.opdata = indexCnt;
EmitPush(opSize);
SetHeapData(symbol);
}
else
{
Debug.Assert(false, "Invalid memory region");
}
SetStackIndex(symbol);
}
示例12: AllocateArg
private int AllocateArg(
string ident,
int funcIndex,
ProtoCore.Type datatype,
int size = 1,
int datasize = ProtoCore.DSASM.Constants.kPrimitiveSize,
ImperativeNode nodeArray = null,
ProtoCore.DSASM.MemoryRegion region = ProtoCore.DSASM.MemoryRegion.kMemStack)
{
ProtoCore.DSASM.SymbolNode symbolnode = new ProtoCore.DSASM.SymbolNode(
ident,
ProtoCore.DSASM.Constants.kInvalidIndex,
ProtoCore.DSASM.Constants.kInvalidIndex,
funcIndex,
datatype,
datatype,
size,
datasize,
true,
codeBlock.symbolTable.runtimeIndex,
region);
symbolnode.codeBlockId = codeBlock.codeBlockId;
if (this.isEmittingImportNode)
symbolnode.ExternLib = compileStateTracker.CurrentDSFileName;
int symbolindex = ProtoCore.DSASM.Constants.kInvalidIndex;
if (ProtoCore.DSASM.Constants.kInvalidIndex != codeBlock.symbolTable.IndexOf(symbolnode))
{
buildStatus.LogSemanticError("redefinition of identifier '" + ident + "'");
}
else
{
int locOffset = localProcedure.localCount;
locOffset = localProcedure.localCount;
symbolnode.index = -1 - ProtoCore.DSASM.StackFrame.kStackFrameSize - (locOffset + argOffset);
++argOffset;
symbolindex = codeBlock.symbolTable.Append(symbolnode);
}
return symbolindex;
}
示例13: Allocate
private ProtoCore.DSASM.SymbolNode Allocate(
string ident,
int funcIndex,
ProtoCore.Type datatype,
int size = 1,
int datasize = ProtoCore.DSASM.Constants.kPrimitiveSize,
ImperativeNode nodeArray = null,
ProtoCore.DSASM.MemoryRegion region = ProtoCore.DSASM.MemoryRegion.kMemStack)
{
if (compileStateTracker.ClassTable.IndexOf(ident) != ProtoCore.DSASM.Constants.kInvalidIndex)
buildStatus.LogSemanticError(ident + " is a class name, can't be used as a variable.");
ProtoCore.DSASM.SymbolNode symbolnode = new ProtoCore.DSASM.SymbolNode(
ident,
ProtoCore.DSASM.Constants.kInvalidIndex,
ProtoCore.DSASM.Constants.kInvalidIndex,
funcIndex,
datatype,
compileStateTracker.TypeSystem.BuildTypeObject((int)PrimitiveType.kTypeVar, false),
size,
datasize,
false,
codeBlock.symbolTable.runtimeIndex,
region,
false,
null,
globalClassIndex,
ProtoCore.DSASM.AccessSpecifier.kPublic,
false,
codeBlock.codeBlockId);
if (this.isEmittingImportNode)
symbolnode.ExternLib = compileStateTracker.CurrentDSFileName;
Debug.Assert(ProtoCore.DSASM.Constants.kInvalidIndex == symbolnode.symbolTableIndex);
if (null == nodeArray)
{
AllocateVar(symbolnode);
}
else
{
AllocateArray(symbolnode, nodeArray);
}
// This is to handle that a variable is defined in a language
// block which defined in a function, so the variable's scope
// is that language block instead of function
if (IsInLanguageBlockDefinedInFunction())
{
symbolnode.classScope = Constants.kGlobalScope;
symbolnode.functionIndex = Constants.kGlobalScope;
}
int symbolindex = ProtoCore.DSASM.Constants.kInvalidIndex;
if (ProtoCore.DSASM.Constants.kInvalidIndex != globalClassIndex && !IsInLanguageBlockDefinedInFunction())
{
symbolindex = compileStateTracker.ClassTable.ClassNodes[globalClassIndex].symbols.Append(symbolnode);
}
else
{
// Do not import global symbols from external libraries
//if (this.isEmittingImportNode && core.IsParsingPreloadedAssembly)
//{
// bool importGlobalSymbolFromLib = !string.IsNullOrEmpty(symbolnode.ExternLib) &&
// symbolnode.functionIndex == -1 && symbolnode.classScope == -1;
// if (importGlobalSymbolFromLib)
// {
// return symbolnode;
// }
//}
symbolindex = codeBlock.symbolTable.Append(symbolnode);
}
// TODO Jun: Set the symbol table index of the first local variable of 'funcIndex'
// This will no longer required once the functiontable is refactored to include a symbol table
// if the current codeblock is a while block, the procedureTable will be null
if (null != localProcedure && null == localProcedure.firstLocal && !IsInLanguageBlockDefinedInFunction())
{
localProcedure.firstLocal = symbolnode.index;
}
if (ProtoCore.DSASM.MemoryRegion.kMemHeap == symbolnode.memregion)
{
EmitInstrConsole(ProtoCore.DSASM.kw.alloca, symbolindex.ToString());
EmitAlloc(symbolindex);
}
symbolnode.symbolTableIndex = symbolindex;
return symbolnode;
}
示例14: EmitBinaryExpressionNode
private void EmitBinaryExpressionNode(ImperativeNode node, ref ProtoCore.Type inferedType, bool isBooleanOp = false)
{
if (!IsParsingGlobal() && !IsParsingGlobalFunctionBody())
return;
bool isBooleanOperation = false;
BinaryExpressionNode b = node as BinaryExpressionNode;
ProtoCore.Type leftType = new ProtoCore.Type();
leftType.UID = (int)ProtoCore.PrimitiveType.kTypeVar;
ProtoCore.Type rightType = new ProtoCore.Type();
rightType.UID = (int)ProtoCore.PrimitiveType.kTypeVar;
if (ProtoCore.DSASM.Operator.assign != b.Optr)
{
isBooleanOperation = ProtoCore.DSASM.Operator.lt == b.Optr
|| ProtoCore.DSASM.Operator.gt == b.Optr
|| ProtoCore.DSASM.Operator.le == b.Optr
|| ProtoCore.DSASM.Operator.ge == b.Optr
|| ProtoCore.DSASM.Operator.eq == b.Optr
|| ProtoCore.DSASM.Operator.nq == b.Optr
|| ProtoCore.DSASM.Operator.and == b.Optr
|| ProtoCore.DSASM.Operator.or == b.Optr;
DfsTraverse(b.LeftNode, ref inferedType, isBooleanOperation);
leftType.UID = inferedType.UID;
leftType.IsIndexable = inferedType.IsIndexable;
}
// (Ayush) in case of PostFixNode, only traverse the identifier now. Post fix operation will be applied later.
#if ENABLE_INC_DEC_FIX
if (b.RightNode is PostFixNode)
DfsTraverse((b.RightNode as PostFixNode).Identifier, ref inferedType, isBooleanOperation);
else
{
#endif
if ((ProtoCore.DSASM.Operator.assign == b.Optr) && (b.RightNode is LanguageBlockNode))
{
inferedType.UID = (int)ProtoCore.PrimitiveType.kTypeVar;
inferedType.IsIndexable = false;
}
DfsTraverse(b.RightNode, ref inferedType, isBooleanOperation);
#if ENABLE_INC_DEC_FIX
}
#endif
rightType.UID = inferedType.UID;
rightType.IsIndexable = inferedType.IsIndexable;
BinaryExpressionNode rightNode = b.RightNode as BinaryExpressionNode;
if ((rightNode != null) && (ProtoCore.DSASM.Operator.assign == rightNode.Optr))
DfsTraverse(rightNode.LeftNode, ref inferedType);
if (b.Optr != ProtoCore.DSASM.Operator.assign)
{
isBooleanOp = false;
//if post fix, now traverse the post fix
#if ENABLE_INC_DEC_FIX
if (b.RightNode is PostFixNode)
EmitPostFixNode(b.RightNode, ref inferedType);
#endif
return;
}
if (b.LeftNode is IdentifierNode)
{
IdentifierNode t = b.LeftNode as IdentifierNode;
ProtoCore.DSASM.SymbolNode symbolnode = null;
string s = t.Value;
bool isReturn = (s == ProtoCore.DSDefinitions.Keyword.Return);
if (isReturn)
{
EmitReturnStatement(node, inferedType);
}
else
{
{
// check whether the variable name is a function name
bool isAccessibleFp;
int realType;
ProtoCore.DSASM.ProcedureNode procNode = null;
if (globalClassIndex != ProtoCore.DSASM.Constants.kGlobalScope)
{
procNode = compileState.ClassTable.ClassNodes[globalClassIndex].GetMemberFunction(t.Name, null, globalClassIndex, out isAccessibleFp, out realType);
}
if (procNode == null)
{
procNode = compileState.GetFirstVisibleProcedure(t.Name, null, codeBlock);
}
}
bool isAccessible = false;
bool isAllocated = VerifyAllocation(t.Value, globalClassIndex, out symbolnode, out isAccessible);
int runtimeIndex = (!isAllocated) ? codeBlock.symbolTable.runtimeIndex : symbolnode.runtimeTableIndex;
// TODO Jun: Update mechanism work in progress - a flag to manually enable update
//.........这里部分代码省略.........
示例15: DfsEmitArraySize
private void DfsEmitArraySize(ImperativeNode node)
{
// s = size * ( i * j * k..n )
if (node is ArrayNode)
{
ArrayNode array = node as ArrayNode;
ProtoCore.Type type = new ProtoCore.Type();
type.UID = (int)ProtoCore.PrimitiveType.kInvalidType;
type.IsIndexable = false;
DfsTraverse(array.Expr, ref type);
if (array.Type is ArrayNode)
{
DfsEmitArraySize(array.Type);
}
}
else
{
Debug.Assert(false, "ast error – check ast construction");
}
}