本文整理汇总了C#中ProtoCore.DSASM.CodeBlock类的典型用法代码示例。如果您正苦于以下问题:C# CodeBlock类的具体用法?C# CodeBlock怎么用?C# CodeBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeBlock类属于ProtoCore.DSASM命名空间,在下文中一共展示了CodeBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeGen
public CodeGen(ProtoLanguage.CompileStateTracker coreObj, ProtoCore.DSASM.CodeBlock parentBlock = null)
: base(coreObj, parentBlock)
{
// dumpbytecode is optionally enabled
//
astNodes = new List<ImperativeNode>();
SetCompileOptions();
// Create a new symboltable for this block
// Set the new symbol table's parent
// Set the new table as a child of the parent table
codeBlock = new ProtoCore.DSASM.CodeBlock(
ProtoCore.DSASM.CodeBlockType.kLanguage,
ProtoCore.Language.kImperative,
compileStateTracker.CodeBlockIndex,
new ProtoCore.DSASM.SymbolTable("imperative lang block", compileStateTracker.RuntimeTableIndex),
new ProtoCore.DSASM.ProcedureTable(compileStateTracker.RuntimeTableIndex),
false,
compileStateTracker);
++compileStateTracker.CodeBlockIndex;
++compileStateTracker.RuntimeTableIndex;
if (null == parentBlock)
{
// This is a top level block
compileStateTracker.CodeBlockList.Add(codeBlock);
}
else
{
// This is a nested block
parentBlock.children.Add(codeBlock);
codeBlock.parent = parentBlock;
}
compileStateTracker.CompleteCodeBlockList.Add(codeBlock);
blockScope = 0;
// Bouncing to this language codeblock from a function should immediatlet se the first instruction as the entry point
if (ProtoCore.DSASM.Constants.kGlobalScope != globalProcIndex)
{
isEntrySet = true;
codeBlock.instrStream.entrypoint = 0;
}
backpatchMap = new BackpatchMap();
nodeBuilder = new NodeBuilder(compileStateTracker);
}
示例2: IsFunctionCodeBlock
public bool IsFunctionCodeBlock(CodeBlock cblock)
{
// Determine if the immediate block is a function block
// Construct blocks are ignored
Validity.Assert(null != cblock);
while (null != cblock)
{
if (CodeBlockType.Function == cblock.blockType)
{
return true;
}
else if (CodeBlockType.Language == cblock.blockType)
{
return false;
}
cblock = cblock.parent;
}
return false;
}
示例3: GetFirstVisibleSymbol
public SymbolNode GetFirstVisibleSymbol(string name, int classscope, int function, CodeBlock codeblock)
{
//
//
Validity.Assert(null != codeblock);
if (null == codeblock)
{
return null;
}
int symbolIndex = Constants.kInvalidIndex;
bool stillInsideFunction = function != Constants.kInvalidIndex;
CodeBlock searchBlock = codeblock;
// TODO(Jiong): Code Duplication, Consider moving this if else block inside the while loop
if (stillInsideFunction)
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, function);
if (function != Constants.kInvalidIndex &&
searchBlock.procedureTable != null &&
searchBlock.procedureTable.Procedures.Count > function && // Note: This check assumes we can not define functions inside a fucntion
symbolIndex == Constants.kInvalidIndex)
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, Constants.kInvalidIndex);
}
else
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, Constants.kInvalidIndex);
}
while (Constants.kInvalidIndex == symbolIndex)
{
// if the search block is of type function, it means our search has gone out of the function itself
// so, we should ignore the given function index and only search its parent block's global variable
if (searchBlock.blockType == CodeBlockType.Function)
stillInsideFunction = false;
searchBlock = searchBlock.parent;
if (null == searchBlock)
{
return null;
}
// Continue searching
if (stillInsideFunction)
{
// we are still inside a function, first search the local variable defined in this function
// if not found, then search the enclosing block by specifying the function index as -1
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, function);
// this check is to avoid unnecessary search
// for example if we have a for loop inside an imperative block which is further inside a function
// when we are searching inside the for loop or language block, there is no need to search twice
// we need to search twice only when we are searching directly inside the function,
if (function != Constants.kInvalidIndex &&
searchBlock.procedureTable != null &&
searchBlock.procedureTable.Procedures.Count > function && // Note: This check assumes we can not define functions inside a fucntion
symbolIndex == Constants.kInvalidIndex)
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, Constants.kInvalidIndex);
}
else
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, Constants.kInvalidIndex);
}
}
return searchBlock.symbolTable.symbolList[symbolIndex];
}
示例4: GetSymbolInFunction
public SymbolNode GetSymbolInFunction(string name, int classScope, int functionScope, CodeBlock codeBlock)
{
Validity.Assert(functionScope != Constants.kGlobalScope);
if (Constants.kGlobalScope == functionScope)
{
return null;
}
int symbolIndex = Constants.kInvalidIndex;
if (classScope != Constants.kGlobalScope)
{
//Search local variable for the class member function
symbolIndex = ClassTable.ClassNodes[classScope].Symbols.IndexOf(name, classScope, functionScope);
if (symbolIndex != Constants.kInvalidIndex)
{
return ClassTable.ClassNodes[classScope].Symbols.symbolList[symbolIndex];
}
//Search class members
symbolIndex = ClassTable.ClassNodes[classScope].Symbols.IndexOf(name, classScope, Constants.kGlobalScope);
if (symbolIndex != Constants.kInvalidIndex)
{
return ClassTable.ClassNodes[classScope].Symbols.symbolList[symbolIndex];
}
}
while (symbolIndex == Constants.kInvalidIndex &&
codeBlock != null &&
codeBlock.blockType != CodeBlockType.Function)
{
symbolIndex = codeBlock.symbolTable.IndexOf(name, classScope, functionScope);
if (symbolIndex != Constants.kInvalidIndex)
{
return codeBlock.symbolTable.symbolList[symbolIndex];
}
else
{
codeBlock = codeBlock.parent;
}
}
if (symbolIndex == Constants.kInvalidIndex &&
codeBlock != null &&
codeBlock.blockType == CodeBlockType.Function)
{
symbolIndex = codeBlock.symbolTable.IndexOf(name, classScope, functionScope);
if (symbolIndex != Constants.kInvalidIndex)
{
return codeBlock.symbolTable.symbolList[symbolIndex];
}
}
return null;
}
示例5: GetFunctionByName
public static ProcedureNode GetFunctionByName(string name, CodeBlock codeBlock)
{
if (null == codeBlock)
{
return null;
}
CodeBlock searchBlock = codeBlock;
while (null != searchBlock)
{
if (null == searchBlock.procedureTable)
{
searchBlock = searchBlock.parent;
continue;
}
// The class table is passed just to check for coercion values
var procNode = searchBlock.procedureTable.GetFunctionsByName(name).FirstOrDefault();
if (procNode != null)
return procNode;
searchBlock = searchBlock.parent;
}
return null;
}
示例6: BuildNewCodeBlock
private ProtoCore.DSASM.CodeBlock BuildNewCodeBlock(ProcedureTable procTable = null)
{
ProcedureTable pTable = procTable == null ? new ProtoCore.DSASM.ProcedureTable(core.RuntimeTableIndex) : procTable;
// Create a new symboltable for this block
// Set the new symbol table's parent
// Set the new table as a child of the parent table
ProtoCore.DSASM.CodeBlock cb = new ProtoCore.DSASM.CodeBlock(
context.guid,
ProtoCore.DSASM.CodeBlockType.kLanguage,
ProtoCore.Language.Associative,
core.CodeBlockIndex,
new ProtoCore.DSASM.SymbolTable("associative lang block", core.RuntimeTableIndex),
pTable,
false,
core);
++core.CodeBlockIndex;
++core.RuntimeTableIndex;
return cb;
}
示例7: 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
//.........这里部分代码省略.........
示例8: BfsBuildInstructionStreams
private void BfsBuildInstructionStreams(CodeBlock codeBlock, InstructionStream[] istreamList)
{
if (null != codeBlock)
{
if (CodeBlockType.Language == codeBlock.blockType || CodeBlockType.Function == codeBlock.blockType)
{
Validity.Assert(codeBlock.codeBlockId < RuntimeTableIndex);
istreamList[codeBlock.codeBlockId] = codeBlock.instrStream;
}
foreach (CodeBlock child in codeBlock.children)
{
BfsBuildInstructionStreams(child, istreamList);
}
}
}
示例9: GetFirstVisibleSymbol
public SymbolNode GetFirstVisibleSymbol(string name, int classscope, int function, CodeBlock codeblock)
{
//
//
Validity.Assert(null != codeblock);
if (null == codeblock)
{
return null;
}
int symbolIndex = ProtoCore.DSASM.Constants.kInvalidIndex;
bool stillInsideFunction = function != ProtoCore.DSASM.Constants.kInvalidIndex;
DSASM.CodeBlock searchBlock = codeblock;
// TODO(Jiong): Code Duplication, Consider moving this if else block inside the while loop
if (stillInsideFunction)
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, function);
if (function != ProtoCore.DSASM.Constants.kInvalidIndex &&
searchBlock.procedureTable != null &&
searchBlock.procedureTable.procList.Count > function && // Note: This check assumes we can not define functions inside a fucntion
symbolIndex == ProtoCore.DSASM.Constants.kInvalidIndex)
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, ProtoCore.DSASM.Constants.kInvalidIndex);
}
else
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, ProtoCore.DSASM.Constants.kInvalidIndex);
}
while (ProtoCore.DSASM.Constants.kInvalidIndex == symbolIndex)
{
// if the search block is of type function, it means our search has gone out of the function itself
// so, we should ignore the given function index and only search its parent block's global variable
if (searchBlock.blockType == DSASM.CodeBlockType.kFunction)
stillInsideFunction = false;
searchBlock = searchBlock.parent;
if (null != searchBlock)
{
// Continue searching
if (stillInsideFunction)
{
// we are still inside a function, first search the local variable defined in this function
// if not found, then search the enclosing block by specifying the function index as -1
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, function);
// this check is to avoid unnecessary search
// for example if we have a for loop inside an imperative block which is further inside a function
// when we are searching inside the for loop or language block, there is no need to search twice
// we need to search twice only when we are searching directly inside the function,
if (function != ProtoCore.DSASM.Constants.kInvalidIndex &&
searchBlock.procedureTable != null &&
searchBlock.procedureTable.procList.Count > function && // Note: This check assumes we can not define functions inside a fucntion
symbolIndex == ProtoCore.DSASM.Constants.kInvalidIndex)
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, ProtoCore.DSASM.Constants.kInvalidIndex);
}
else
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, ProtoCore.DSASM.Constants.kInvalidIndex);
}
}
else
{
// End of nested blocks
/*
// Not found? Look at the class scope
if (ProtoCore.DSASM.Constants.kInvalidIndex != classscope)
{
// Look at the class members and base class members
bool hasSymbol = false;
ProtoCore.DSASM.AddressType addrType = DSASM.AddressType.Invalid;
ProtoCore.DSASM.ClassNode cnode = classTable.list[classscope];
symbolIndex = cnode.GetFirstVisibleSymbol(name, classscope, function, out hasSymbol, out addrType);
if (ProtoCore.DSASM.Constants.kInvalidIndex != symbolIndex)
{
if (addrType == DSASM.AddressType.StaticMemVarIndex)
{
return codeBlockList[0].symbolTable.symbolList[symbolIndex];
}
else
{
return classTable.list[classscope].symbols.symbolList[symbolIndex];
}
}
// Look at the class constructors and functions
symbolIndex = classTable.list[classscope].symbols.IndexOf(name, classscope, function);
if (ProtoCore.DSASM.Constants.kInvalidIndex != symbolIndex)
{
return classTable.list[classscope].symbols.symbolList[symbolIndex];
}
}
// Not found? Look at the global scope
symbolIndex = searchBlock.symbolTable.IndexOf(name, ProtoCore.DSASM.Constants.kInvalidIndex, ProtoCore.DSASM.Constants.kGlobalScope);
if (ProtoCore.DSASM.Constants.kInvalidIndex == symbolIndex)
//.........这里部分代码省略.........
示例10: BfsBuildSequenceTable
private void BfsBuildSequenceTable(CodeBlock codeBlock, SymbolTable[] runtimeSymbols)
{
if (DSASM.CodeBlockType.kLanguage == codeBlock.blockType
|| DSASM.CodeBlockType.kFunction == codeBlock.blockType
|| DSASM.CodeBlockType.kConstruct == codeBlock.blockType)
{
Debug.Assert(codeBlock.symbolTable.runtimeIndex < RuntimeTableIndex);
runtimeSymbols[codeBlock.symbolTable.runtimeIndex] = codeBlock.symbolTable;
}
foreach (DSASM.CodeBlock child in codeBlock.children)
{
BfsBuildSequenceTable(child, runtimeSymbols);
}
}
示例11: BfsBuildProcedureTable
private void BfsBuildProcedureTable(CodeBlock codeBlock, ProcedureTable[] procTable)
{
if (DSASM.CodeBlockType.kLanguage == codeBlock.blockType || DSASM.CodeBlockType.kFunction == codeBlock.blockType)
{
Debug.Assert(codeBlock.procedureTable.runtimeIndex < RuntimeTableIndex);
procTable[codeBlock.procedureTable.runtimeIndex] = codeBlock.procedureTable;
}
foreach (DSASM.CodeBlock child in codeBlock.children)
{
BfsBuildProcedureTable(child, procTable);
}
}
示例12: BfsBuildInstructionStreams
private void BfsBuildInstructionStreams(CodeBlock codeBlock, InstructionStream[] istreamList)
{
if (null != codeBlock)
{
if (DSASM.CodeBlockType.kLanguage == codeBlock.blockType || DSASM.CodeBlockType.kFunction == codeBlock.blockType)
{
Debug.Assert(codeBlock.codeBlockId < CodeBlockIndex);
istreamList[codeBlock.codeBlockId] = codeBlock.instrStream;
}
foreach (DSASM.CodeBlock child in codeBlock.children)
{
BfsBuildInstructionStreams(child, istreamList);
}
}
}
示例13: IsFunctionCodeBlock
public bool IsFunctionCodeBlock(CodeBlock cblock)
{
// Determine if the immediate block is a function block
// Construct blocks are ignored
Debug.Assert(null != cblock);
while (null != cblock)
{
if (ProtoCore.DSASM.CodeBlockType.kFunction == cblock.blockType)
{
return true;
}
else if (ProtoCore.DSASM.CodeBlockType.kLanguage == cblock.blockType)
{
return false;
}
cblock = cblock.parent;
}
return false;
}
示例14: GetFirstVisibleSymbol
public SymbolNode GetFirstVisibleSymbol(string name, int classscope, int function, CodeBlock codeblock)
{
Validity.Assert(null != codeblock);
int symbolIndex = Constants.kInvalidIndex;
// For variables defined nested language block, their function index
// is always Constants.kGlobalScope
CodeBlock searchBlock = codeblock;
while (searchBlock != null)
{
// For imported node, it is possbile that the block is not the
// topmost block.
//
// For expression interpreter, as the code has been compiled, the
// outmost block wouldn't be function block (CodeBlockType.Function).
// CodeBlockType.Function is a temporary block type which is set when
// the compile is generating code for function defintion node and will
// be set back to Associative.
var isSearchBoundry = searchBlock.blockType == CodeBlockType.Function ||
(Options.RunMode == InterpreterMode.Expression && searchBlock.parent == null);
if (isSearchBoundry)
{
break;
}
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, Constants.kGlobalScope);
if (symbolIndex == Constants.kInvalidIndex)
{
searchBlock = searchBlock.parent;
}
else
{
return searchBlock.symbolTable.symbolList[symbolIndex];
}
}
// Search variable might be defined in function.
// If we are not in class defintion, then just stop here, otherwise
// we should search global block's symbol table.
if (searchBlock != null &&
(searchBlock.blockType == CodeBlockType.Function || (Options.RunMode == InterpreterMode.Expression && searchBlock.parent == null)) &&
classscope == Constants.kGlobalScope)
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, function);
}
return symbolIndex == Constants.kInvalidIndex ? null : searchBlock.symbolTable.symbolList[symbolIndex];
}
示例15: BfsBuildSequenceTable
private void BfsBuildSequenceTable(CodeBlock codeBlock, SymbolTable[] runtimeSymbols)
{
if (CodeBlockType.Language == codeBlock.blockType
|| CodeBlockType.Function == codeBlock.blockType
|| CodeBlockType.Construct == codeBlock.blockType)
{
Validity.Assert(codeBlock.symbolTable.RuntimeIndex < RuntimeTableIndex);
runtimeSymbols[codeBlock.symbolTable.RuntimeIndex] = codeBlock.symbolTable;
}
foreach (CodeBlock child in codeBlock.children)
{
BfsBuildSequenceTable(child, runtimeSymbols);
}
}