private static void InsertBinaryOperationMethod(Core core, CodeBlockNode root, Operator op, PrimitiveType r, PrimitiveType op1, PrimitiveType op2, int retRank = 0, int op1rank = 0, int op2rank = 0) { FunctionDefinitionNode funcDefNode = new FunctionDefinitionNode(); funcDefNode.access = CompilerDefinitions.AccessModifier.kPublic; funcDefNode.IsAssocOperator = true; funcDefNode.IsBuiltIn = true; funcDefNode.Name = Op.GetOpFunction(op); funcDefNode.ReturnType = new Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r, rank = retRank }; ArgumentSignatureNode args = new ArgumentSignatureNode(); args.AddArgument(new VarDeclNode() { Access = CompilerDefinitions.AccessModifier.kPublic, NameNode = AstFactory.BuildIdentifier(DSASM.Constants.kLHS), ArgumentType = new Type { Name = core.TypeSystem.GetType((int)op1), UID = (int)op1, rank = op1rank } }); args.AddArgument(new VarDeclNode() { Access = CompilerDefinitions.AccessModifier.kPublic, NameNode = AstFactory.BuildIdentifier(DSASM.Constants.kRHS), ArgumentType = new Type { Name = core.TypeSystem.GetType((int)op2), UID = (int)op2, rank = op2rank } }); funcDefNode.Signature = args; CodeBlockNode body = new CodeBlockNode(); var lhs = AstFactory.BuildIdentifier(DSASM.Constants.kLHS); var rhs = AstFactory.BuildIdentifier(DSASM.Constants.kRHS); var binaryExpr = AstFactory.BuildBinaryExpression(lhs, rhs, op); body.Body.Add(AstFactory.BuildReturnStatement(binaryExpr)); funcDefNode.FunctionBody = body; root.Body.Add(funcDefNode); }
private ProtoCore.AST.AssociativeAST.CodeBlockNode ImportDesignScriptFile(string designScriptFile, string typeName, string alias) { string curDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.GetDirectoryName(designScriptFile)); ProtoCore.AST.AssociativeAST.CodeBlockNode importCodeblockNode = null; try { ProtoCore.DesignScriptParser.Scanner scanner = new ProtoCore.DesignScriptParser.Scanner(designScriptFile); ProtoCore.DesignScriptParser.Parser parser = new ProtoCore.DesignScriptParser.Parser(scanner, _coreObj, true); parser.ImportModuleHandler = this; //System.IO.StringWriter parseErrors = new System.IO.StringWriter(); //parser.errors.errorStream = parseErrors; parser.Parse(); //if (parseErrors.ToString() != String.Empty) //_coreObj.BuildStatus.LogSyntaxError(parseErrors.ToString()); //_coreObj.BuildStatus.errorCount += parser.errors.count; importCodeblockNode = (ProtoCore.AST.AssociativeAST.CodeBlockNode)parser.root; } finally { Directory.SetCurrentDirectory(curDirectory); } return(importCodeblockNode); }
private static void InsertBuiltInMethods(Core core, CodeBlockNode root) { Lang.BuiltInMethods builtInMethods = new Lang.BuiltInMethods(core); foreach (Lang.BuiltInMethods.BuiltInMethod method in builtInMethods.Methods) { root.Body.Add(GenerateBuiltInMethodSignatureNode(method)); } }
public static void InsertPredefinedAndBuiltinMethods(Core core, CodeBlockNode root) { if (DSASM.InterpreterMode.Normal == core.Options.RunMode) { InsertPredefinedMethod(core, root); InsertBuiltInMethods(core, root); } }
private static void InsertInlineConditionOperationMethod(Core core, ProtoCore.AST.Node root, PrimitiveType condition, PrimitiveType r) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.Compiler.AccessSpecifier.kPublic; funcDefNode.Name = ProtoCore.DSASM.Constants.kInlineCondition; funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r }; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.Compiler.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%condition"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)condition), UID = (int)condition } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.Compiler.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%trueExp"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.Compiler.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%falseExp"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r } }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.IdentifierNode con = BuildAssocIdentifier(core, "%condition"); ProtoCore.AST.AssociativeAST.IdentifierNode t = BuildAssocIdentifier(core, "%trueExp"); ProtoCore.AST.AssociativeAST.IdentifierNode f = BuildAssocIdentifier(core, "%falseExp"); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.InlineConditionalNode() { ConditionExpression = con, TrueExpression = t, FalseExpression = f } }); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
private static void InsertBinaryOperationMethod(Core core, ProtoCore.AST.Node root, Operator op, PrimitiveType r, PrimitiveType op1, PrimitiveType op2, int retRank = 0, int op1rank = 0, int op2rank = 0) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.Compiler.AccessSpecifier.kPublic; funcDefNode.IsAssocOperator = true; funcDefNode.IsBuiltIn = true; funcDefNode.Name = Op.GetOpFunction(op); funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r, rank = retRank }; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.Compiler.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kLHS), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)op1), UID = (int)op1, rank = op1rank } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.Compiler.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kRHS), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)op2), UID = (int)op2, rank = op2rank } }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.IdentifierNode lhs = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kLHS); ProtoCore.AST.AssociativeAST.IdentifierNode rhs = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kRHS); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = lhs, RightNode = rhs, Optr = op } }); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
private ProtoCore.AST.AssociativeAST.CodeBlockNode MergeCodeBlockNode(ref ProtoCore.AST.AssociativeAST.ImportNode importedNode, ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockNode) { if (codeBlockNode == null || codeBlockNode.Body == null || importedNode == null) { return(codeBlockNode); } ProtoCore.AST.AssociativeAST.CodeBlockNode importedCodeBlock = importedNode.CodeNode; if (importedCodeBlock == null) { importedNode.CodeNode = codeBlockNode; return(codeBlockNode); } foreach (var item in codeBlockNode.Body) { ProtoCore.AST.AssociativeAST.ClassDeclNode classNode = item as ProtoCore.AST.AssociativeAST.ClassDeclNode; if (classNode != null) { ProtoCore.AST.AssociativeAST.ClassDeclNode importedClass = null; if (TryGetClassNode(importedCodeBlock, classNode.className, out importedClass)) { bool dummyClassNode = IsEmptyClassNode(classNode); bool dummyImportClass = IsEmptyClassNode(importedClass); Validity.Assert(dummyImportClass || dummyClassNode, string.Format("{0} is imported more than once!!", classNode.className)); if (dummyImportClass && !dummyClassNode) { importedNode.CodeNode.Body.Remove(importedClass); importedNode.CodeNode.Body.Add(classNode); } } else { importedNode.CodeNode.Body.Add(classNode); } } else { importedNode.CodeNode.Body.Add(item); //TODO other conflict resolution needs to be done here. } } return(importedNode.CodeNode); }
public static bool TryGetClassNode(ProtoCore.AST.AssociativeAST.CodeBlockNode node, string typeName, out ProtoCore.AST.AssociativeAST.ClassDeclNode classNode) { classNode = null; //Traverse thru the code block and check if this type is already available if (node == null || node.Body == null) { return(false); } foreach (var item in node.Body) { ProtoCore.AST.AssociativeAST.ClassDeclNode clsnode = item as ProtoCore.AST.AssociativeAST.ClassDeclNode; if (clsnode != null && clsnode.className == typeName) { classNode = clsnode; return(true); } } return(false); }
// The following methods are used to insert methods to the bottom of the AST and convert operator to these method calls // to support replication on operators private static void InsertUnaryOperationMethod(Core core, CodeBlockNode root, UnaryOperator op, PrimitiveType r, PrimitiveType operand) { FunctionDefinitionNode funcDefNode = new FunctionDefinitionNode(); funcDefNode.Access = CompilerDefinitions.AccessModifier.Public; funcDefNode.IsAssocOperator = true; funcDefNode.IsBuiltIn = true; funcDefNode.Name = Op.GetUnaryOpFunction(op); funcDefNode.ReturnType = new Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r }; ArgumentSignatureNode args = new ArgumentSignatureNode(); args.AddArgument(new VarDeclNode() { Access = CompilerDefinitions.AccessModifier.Public, NameNode = AstFactory.BuildIdentifier("%param"), ArgumentType = new Type { Name = core.TypeSystem.GetType((int)operand), UID = (int)operand } }); funcDefNode.Signature = args; CodeBlockNode body = new CodeBlockNode(); IdentifierNode param = AstFactory.BuildIdentifier("%param"); body.Body.Add(AstFactory.BuildReturnStatement(new UnaryExpressionNode() { Expression = param, Operator = op })); funcDefNode.FunctionBody = body; root.Body.Add(funcDefNode); }
internal ImportNode Compile(ImportModuleHandler importer) { ImportNode impNode = null; ProtoCore.AST.AssociativeAST.CodeBlockNode code = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); foreach (var item in mData) { SortedSet <Type> types = GetTypesForImport(item.Value.Data); foreach (var type in types) { if (CLRObjectMarshler.IsMarshaledAsNativeType(type)) { continue; } ImportNode node = importer.Import(type.Assembly.Location, type.FullName, ""); if (impNode != null && node != null) { impNode.CodeNode.Body.AddRange(node.CodeNode.Body); } else { impNode = node; } } if (impNode == null) { impNode = new ImportNode() { ModuleName = "ExternalContext", CodeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode() } } ; impNode.CodeNode.Body.Add(ContextDataMethodCallNode(item.Value)); } return(impNode); }
// The following methods are used to insert methods to the bottom of the AST and convert operator to these method calls // to support replication on operators private static void InsertUnaryOperationMethod(Core core, ProtoCore.AST.Node root, UnaryOperator op, PrimitiveType r, PrimitiveType operand) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic; funcDefNode.IsAssocOperator = true; funcDefNode.IsBuiltIn = true; funcDefNode.Name = Op.GetUnaryOpFunction(op); funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r }; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic, NameNode = BuildAssocIdentifier(core, "%param"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)operand), UID = (int)operand } }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.IdentifierNode param = BuildAssocIdentifier(core, "%param"); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.UnaryExpressionNode() { Expression = param, Operator = op } }); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
public ProtoCore.AST.AssociativeAST.ImportNode Import(string moduleName, string typeName, string alias, int line = -1, int col = -1) { curLine = line; curCol = col; moduleName = moduleName.Replace("\"", String.Empty); ProtoCore.AST.AssociativeAST.ImportNode node = new ProtoCore.AST.AssociativeAST.ImportNode(); node.ModuleName = moduleName; string modulePathFileName = FileUtils.GetDSFullPathName(moduleName, _coreObj.Options); // Tracking directory paths for all imported DS files during preload assembly stage so that they can be accessed by Graph compiler before execution - pratapa if (_coreObj.IsParsingPreloadedAssembly) { string dirName = Path.GetDirectoryName(modulePathFileName); if (!string.IsNullOrEmpty(dirName) && !_coreObj.Options.IncludeDirectories.Contains(dirName)) _coreObj.Options.IncludeDirectories.Add(dirName); } if (string.IsNullOrEmpty(typeName)) { //Check if moduleName is a type name with namespace. Type type = Type.GetType(moduleName); if (type != null) { typeName = type.FullName; modulePathFileName = type.Assembly.Location; } } if (modulePathFileName == null || !File.Exists(modulePathFileName)) { System.Diagnostics.Debug.Write(@"Cannot import file: '" + modulePathFileName); _coreObj.LogWarning(ProtoCore.BuildData.WarningID.FileNotFound, string.Format(Resources.kFileNotFound, modulePathFileName)); return null; } node.ModulePathFileName = modulePathFileName; node.CodeNode = null; if (typeName.Length > 0) node.Identifiers.Add(typeName); ProtoCore.AST.AssociativeAST.ImportNode importedNode = null; if (TryGetImportNode(modulePathFileName, typeName, out importedNode)) { node.HasBeenImported = true; return node; } ProtoCore.AST.AssociativeAST.CodeBlockNode codeNode = null; if (importedNode == null) codeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); else codeNode = importedNode.CodeNode; try { codeNode = ImportCodeBlock(modulePathFileName, typeName, alias, codeNode); } catch (System.Exception ex) { if (ex.InnerException != null) _coreObj.BuildStatus.LogSemanticError(ex.InnerException.Message); _coreObj.BuildStatus.LogSemanticError(ex.Message); } //Cache the codeblock of root import node. CodeBlockNode rootImportCodeBlock = mRootImportNode.CodeNode; mRootImportNode.CodeNode = new CodeBlockNode(); //reset with the new one. //Remove all empty nodes and add to root import node. codeNode.Body.RemoveAll(AddToRootImportNodeIfEmpty); if (mRootImportNode.CodeNode.Body.Count == 0) //empty mRootImportNode.CodeNode = rootImportCodeBlock; //reset the old one. if (importedNode != null) { //module has import node, but type is not imported yet. //MergeCodeBlockNode(ref importedNode, codeBlockNode); //update existing import node and return null. importedNode.CodeNode = codeNode; return null; } node.CodeNode = codeNode; mModuleTable.Add(modulePathFileName, node); return node; }
private CodeBlockNode ImportCodeBlock(string importModuleName, string typeName, string alias, CodeBlockNode refNode) { DLLModule dllModule = null; string extension = System.IO.Path.GetExtension(importModuleName).ToLower(); if (extension == ".dll" || extension == ".exe") { try { dllModule = DLLFFIHandler.GetModule(importModuleName); } catch { _coreObj.LogSemanticError(string.Format(Resources.FailedToImport, importModuleName), _coreObj.CurrentDSFileName, curLine, curCol); } } CodeBlockNode codeBlockNode = refNode; if (null != dllModule) { codeBlockNode = dllModule.ImportCodeBlock(typeName, alias, refNode); Type type = dllModule.GetExtensionAppType(); if (type != null) { _coreObj.AddDLLExtensionAppType(type); } } else if (extension == ".ds") { string origDSFile = _coreObj.CurrentDSFileName; _coreObj.CurrentDSFileName = System.IO.Path.GetFullPath(importModuleName); codeBlockNode = ImportDesignScriptFile(_coreObj.CurrentDSFileName, typeName, alias); _coreObj.CurrentDSFileName = origDSFile; } return codeBlockNode; }
void Hydrogen(out Node codeBlockNode) { ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); NodeUtils.SetNodeStartLocation(codeblock, t); ProtoCore.AST.AssociativeAST.AssociativeNode node = null; ProtoFFI.ImportModuleHandler imh = null; if (core.IsParsingPreloadedAssembly) { imh = core.ImportHandler; } else { imh = this.ImportModuleHandler; } bool rootImport = (null == imh) ? true : false; while (la.kind == 34) { ProtoCore.AST.AssociativeAST.AssociativeNode importNode = null; Import_Statement(out importNode); if (null != importNode) (codeblock as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(importNode); } imh = null; if (core.IsParsingPreloadedAssembly) { imh = core.ImportHandler; } else imh = ImportModuleHandler; if(null != core.ContextDataManager) { if (imh == null) imh = new ProtoFFI.ImportModuleHandler(core); ProtoCore.AST.AssociativeAST.AssociativeNode importNode = null; importNode = core.ContextDataManager.Compile(imh); if (null != importNode) (codeblock as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(importNode); } if (rootImport && null != imh && imh.RootImportNode.CodeNode.Body.Count != 0) (codeblock as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(imh.RootImportNode); if (rootImport && core.IsParsingPreloadedAssembly && !builtinMethodsLoaded) { CoreUtils.InsertPredefinedAndBuiltinMethods(core, codeblock); core.ImportNodes = codeblock; } while (StartOf(1)) { if (IsNotAttributeFunctionClass()) { Associative_Statement(out node); } else { List<ProtoCore.AST.AssociativeAST.AssociativeNode> attrs = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); if (la.kind == 10) { Associative_AttributeDeclaration(out attrs); } if (la.kind == 27) { Associative_functiondecl(out node, attrs); } else if (la.kind == 25) { Associative_classdecl(out node, attrs); } else SynErr(67); } if (null != node) { (codeblock as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(node); stmtsParsed++; } } if (la.val == "if") SynErr(String.Format(Resources.UseInlineConditional, la.val)); if ((la.val == "for")||(la.val == "while")) SynErr(String.Format(Resources.ValidForImperativeBlockOnly, la.val)); codeBlockNode = codeblock; // We look ahead (la) here instead of looking at the current token (t) // because when we get here at the end of a language block, "t" would // have been pointing to the ending token of the last statement in the // language block. What we really need here is the closing bracket '}' // character, and that's conveniently residing in the look ahead token. // NodeUtils.SetNodeEndLocation(codeblock, la); }
public Parser(Scanner scanner, ProtoCore.Core coreObj, bool _builtinMethodsLoaded = false) { this.scanner = scanner; errors = new Errors(); errors.core = coreObj; core = coreObj; builtinMethodsLoaded = _builtinMethodsLoaded; commentNode = new CodeBlockNode(); }
void Associative_FunctionalMethodBodySingleLine(out ProtoCore.AST.AssociativeAST.AssociativeNode funcBody) { funcBody = null; ProtoCore.AST.AssociativeAST.CodeBlockNode functionBody = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.BinaryExpressionNode binaryExpr = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(); binaryExpr.LeftNode = ProtoCore.Utils.CoreUtils.BuildAssocIdentifier(core, "return", ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.AssociativeNode expr; Associative_Expression(out expr); binaryExpr.RightNode = expr; binaryExpr.Optr = Operator.assign; NodeUtils.SetNodeLocation(binaryExpr, expr, expr); List<ProtoCore.AST.AssociativeAST.AssociativeNode> body = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); body.Add(binaryExpr); functionBody.Body =body; funcBody = functionBody; if (la.val != ";") SynErr(Resources.SemiColonExpected); Expect(21); }
/// <summary> /// Does the first pass of compilation and returns a list of wanrnings in compilation /// </summary> /// <param name="code"></param> /// <param name="core"></param> /// <param name="blockId"></param> /// <returns></returns> public static ProtoCore.BuildStatus PreCompile(string code, Core core, CodeBlockNode codeBlock, out int blockId) { blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.Language = ProtoCore.Language.Associative; globalBlock.Code = code; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.Language; core.Compilers[id].Compile(out blockId, null, globalBlock, context, codeBlockNode: codeBlock); core.BuildStatus.ReportBuildResult(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (!(ex is ProtoCore.BuildHaltException)) { throw ex; } } return core.BuildStatus; }
/// <summary> /// Compiles a collection of Dynamo nodes into a function definition for a custom node. /// </summary> /// <param name="def"></param> /// <param name="funcBody"></param> /// <param name="outputs"></param> /// <param name="parameters"></param> public void CompileCustomNodeDefinition( CustomNodeDefinition def, IEnumerable<NodeModel> funcBody, List<AssociativeNode> outputs, IEnumerable<string> parameters) { OnAstNodeBuilding(def.FunctionId); var functionBody = new CodeBlockNode(); functionBody.Body.AddRange(CompileToAstNodes(funcBody, false)); if (outputs.Count > 1) { /* rtn_array = {}; * rtn_array[key0] = out0; * rtn_array[key1] = out1; * ... * return = rtn_array; */ // return array, holds all outputs string rtnName = "__temp_rtn_" + def.FunctionId.ToString().Replace("-", String.Empty); functionBody.Body.Add( AstFactory.BuildAssignment( AstFactory.BuildIdentifier(rtnName), AstFactory.BuildExprList(new List<string>()))); // indexers for each output IEnumerable<AssociativeNode> indexers = def.ReturnKeys != null ? def.ReturnKeys.Select(AstFactory.BuildStringNode) as IEnumerable<AssociativeNode> : Enumerable.Range(0, outputs.Count).Select(AstFactory.BuildIntNode); functionBody.Body.AddRange( outputs.Zip( indexers, (outputId, indexer) => // for each outputId and return key // pack the output into the return array AstFactory.BuildAssignment(AstFactory.BuildIdentifier(rtnName, indexer), outputId))); // finally, return the return array functionBody.Body.Add(AstFactory.BuildReturnStatement(AstFactory.BuildIdentifier(rtnName))); } else { // For single output, directly return that identifier or null. AssociativeNode returnValue = outputs.Count == 1 ? outputs[0] : new NullNode(); functionBody.Body.Add(AstFactory.BuildReturnStatement(returnValue)); } Type allTypes = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar); //Create a new function definition var functionDef = new FunctionDefinitionNode { Name = def.FunctionName.Replace("-", string.Empty), Signature = new ArgumentSignatureNode { Arguments = parameters.Select(param => AstFactory.BuildParamNode(param, allTypes)).ToList() }, FunctionBody = functionBody, ReturnType = allTypes }; OnAstNodeBuilt(def.FunctionId, new[] { functionDef }); }
/// <summary> /// API used by external host to build AST for any function call /// </summary> /// <param name="type"></param> /// <param name="hostInstancePtr"></param> /// <param name="functionName"></param> /// <param name="userDefinedArgs"></param> /// <param name="primitiveArgs"></param> /// <param name="formatString"></param> /// <param name="core"></param> /// <param name="symbolName"></param> /// <param name="code"></param> /// <returns></returns> public static AssociativeNode BuildAST(string type, long hostInstancePtr, string functionName, List<IntPtr> userDefinedArgs, List<string> primitiveArgs, string formatString, ProtoCore.Core core, ref string symbolName, ref string code) { symbolName = string.Empty; List<AssociativeNode> astNodes = new List<AssociativeNode>(); FunctionDotCallNode dotCall = null; BinaryExpressionNode bNode = null; ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCallNode = null; List<AssociativeNode> argNodes = new List<AssociativeNode>(); if (userDefinedArgs != null) { foreach (var arg in userDefinedArgs) { dotCallNode = CreateEntityNode((long)arg, core); bNode = CreateAssignmentNode(dotCallNode); argNodes.Add(bNode); } astNodes.AddRange(argNodes); } List<ProtoCore.AST.AssociativeAST.AssociativeNode> args = CreateArgs(formatString, primitiveArgs, argNodes); if (hostInstancePtr != 0) { dotCallNode = CreateEntityNode(hostInstancePtr, core); bNode = CreateAssignmentNode(dotCallNode); astNodes.Add(bNode); dotCall = CreateFunctionCallNode((bNode.LeftNode as IdentifierNode).Value, functionName, args, core); } else { dotCall = CreateFunctionCallNode(type, functionName, args, core); } bNode = CreateAssignmentNode(dotCall); if (bNode.LeftNode is IdentifierNode) { symbolName = (bNode.LeftNode as IdentifierNode).Value; } astNodes.Add(bNode); CodeBlockNode codeBlockNode = new CodeBlockNode(); codeBlockNode.Body = astNodes; ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(astNodes); code = codeGen.GenerateCode(); return codeBlockNode; }
public int Emit(CodeBlockNode codeblocknode) { bool isTopBlock = null == codeBlock.parent; if (!isTopBlock) { // If this is an inner block where there can be no classes, we can start at parsing at the global function state compilePass = ProtoCore.DSASM.AssociativeCompilePass.kGlobalFuncSig; } if (codeBlock.parent != null) CodeRangeTable.AddCodeBlockRangeEntry(codeBlock.codeBlockId, codeblocknode.line, codeblocknode.col, codeblocknode.endLine, codeblocknode.endCol, core.CurrentDSFileName); else CodeRangeTable.AddCodeBlockRangeEntry(codeBlock.codeBlockId, 0, 0, int.MaxValue, int.MaxValue, core.CurrentDSFileName); ProtoCore.Type inferedType = new ProtoCore.Type(); while (ProtoCore.DSASM.AssociativeCompilePass.kDone != compilePass) { foreach (AssociativeNode node in codeblocknode.Body) { inferedType = new ProtoCore.Type(); inferedType.UID = (int)ProtoCore.PrimitiveType.kTypeVar; inferedType.IsIndexable = false; // // TODO Jun: Handle stand alone language blocks // Integrate the subPass into a proper pass // if (node is LanguageBlockNode) { // Build a binaryn node with a temporary lhs for every stand-alone language block IdentifierNode iNode = new IdentifierNode() { Value = ProtoCore.DSASM.Constants.kTempLangBlock, Name = ProtoCore.DSASM.Constants.kTempLangBlock, datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false) }; BinaryExpressionNode langBlockNode = new BinaryExpressionNode(); langBlockNode.LeftNode = iNode; langBlockNode.Optr = ProtoCore.DSASM.Operator.assign; langBlockNode.RightNode = node; DfsTraverse(langBlockNode, ref inferedType, false, null, ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier); //DfsTraverse(node, ref inferedType, false, null, ProtoCore.DSASM.AssociativeSubCompilePass.kNone); } else { DfsTraverse(node, ref inferedType, false, null, ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier); } } compilePass++; // We have compiled all classes if (compilePass == ProtoCore.DSASM.AssociativeCompilePass.kGlobalScope && isTopBlock) { EmitFunctionCallToInitStaticProperty(codeblocknode.Body); } } core.InferedType = inferedType; return codeBlock.codeBlockId; }
public void GraphILTest_Assign03_astInput() { //////////////////////////////////////////////////////////////////// // Adds nodes => a = 10; c = 20; b = a + c; // Creates 3 separate Subtrees //////////////////////////////////////////////////////////////////// List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); // Build the AST trees ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("a"), new ProtoCore.AST.AssociativeAST.IntNode(10), ProtoCore.DSASM.Operator.assign); astList.Add(assign1); ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("c"), new ProtoCore.AST.AssociativeAST.IntNode(20), ProtoCore.DSASM.Operator.assign); astList.Add(assign2); ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign3 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("b"), new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("a"), new ProtoCore.AST.AssociativeAST.IdentifierNode("c"), ProtoCore.DSASM.Operator.add), ProtoCore.DSASM.Operator.assign); astList.Add(assign3); // update graph with ast input CodeBlockNode cNode = new CodeBlockNode(); cNode.Body = astList; liveRunner = new ProtoScript.Runners.LiveRunner(); liveRunner.UpdateGraph(cNode); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("b"); Assert.IsTrue((Int64)mirror.GetData().Data == 30); }
public CodeBlockNode(CodeBlockNode rhs) : base(rhs) { Body = new List<AssociativeNode>(); foreach (AssociativeNode aNode in rhs.Body) { AssociativeNode newNode = NodeUtils.Clone(aNode); Body.Add(newNode); } }
public void TestBuildAST_01() { //============================================== // // import("ProtoGeometry.dll"); // p = Point.Bycoordinates(0.0, 2.0, 1.0); // xval = p.X; // //============================================== //============================================== // Build the import Nodes //============================================== ProtoScript.Runners.ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner(); List<string> libs = new List<string>(); libs.Add("ProtoGeometry.dll"); liveRunner.ResetVMAndImportLibrary(libs); string type = "Point"; long hostInstancePtr = 0; string functionName = "ByCoordinates"; List<IntPtr> userDefinedArgs = null; List<string> primitiveArgs = new List<string>(); primitiveArgs.Add("0"); primitiveArgs.Add("2"); primitiveArgs.Add("1"); string formatString = "ddd"; string symbolName = ""; string code = ""; AssociativeNode assign1 = ASTCompilerUtils.BuildAST(type, hostInstancePtr, functionName, userDefinedArgs, primitiveArgs, formatString, liveRunner.Core, ref symbolName, ref code); liveRunner.UpdateGraph(assign1); primitiveArgs.Clear(); primitiveArgs.Add("10"); primitiveArgs.Add("0"); primitiveArgs.Add("0"); functionName = "Translate"; AssociativeNode assign2 = ASTCompilerUtils.BuildAST(symbolName, hostInstancePtr, functionName, userDefinedArgs, primitiveArgs, formatString, liveRunner.Core, ref symbolName, ref code); liveRunner.UpdateGraph(assign2); //============================================== // Build a binary expression to retirieve the x property // xval = p.X; //============================================== List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); ProtoCore.AST.AssociativeAST.IdentifierListNode identListNode = new ProtoCore.AST.AssociativeAST.IdentifierListNode(); identListNode.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode(symbolName); identListNode.Optr = ProtoCore.DSASM.Operator.dot; identListNode.RightNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("X"); ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("xval"), identListNode, ProtoCore.DSASM.Operator.assign); astList.Add(stmt2); //============================================== // // import("ProtoGeometry.dll"); // p = Point.Bycoordinates(0.0, 20.0, 1.0); // q = p.Translate(10.0, 0.0, 0.0); // xval = p.X; // //============================================== // update graph CodeBlockNode cNode = new CodeBlockNode(); cNode.Body = astList; liveRunner.UpdateGraph(cNode); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("xval"); Assert.IsTrue((double)mirror.GetData().Data == 10.0); }
void Associative_LanguageBlock(out ProtoCore.AST.AssociativeAST.AssociativeNode node) { node = null; ProtoCore.AST.AssociativeAST.LanguageBlockNode langblock = new ProtoCore.AST.AssociativeAST.LanguageBlockNode(); Expect(8); NodeUtils.SetNodeLocation(langblock, t); Expect(1); if( 0 == t.val.CompareTo(ProtoCore.DSASM.kw.imperative)) { langblock.codeblock.language = ProtoCore.Language.kImperative; } else if( 0 == t.val.CompareTo(ProtoCore.DSASM.kw.associative)) { langblock.codeblock.language = ProtoCore.Language.kAssociative; } else { langblock.codeblock.language = ProtoCore.Language.kInvalid; errors.SemErr(t.line, t.col, String.Format(Resources.InvalidLanguageBlockIdentifier, t.val)); } while (WeakSeparator(48,5,6) ) { if (IsLanguageBlockProperty()) { Expect(1); string key = t.val; Expect(49); Expect(4); if ("fingerprint" == key) { langblock.codeblock.fingerprint = t.val; langblock.codeblock.fingerprint = langblock.codeblock.fingerprint.Remove(0,1); langblock.codeblock.fingerprint = langblock.codeblock.fingerprint.Remove(langblock.codeblock.fingerprint.Length-1,1); } else if ("version" == key) { langblock.codeblock.version = t.val; langblock.codeblock.version = langblock.codeblock.version.Remove(0,1); langblock.codeblock.version = langblock.codeblock.version.Remove(langblock.codeblock.version.Length-1,1); } } else if (la.kind == 1) { ProtoCore.AST.AssociativeAST.AssociativeNode attr = null; Associative_Attribute(out attr); if (attr != null) langblock.Attributes.Add(attr); } else SynErr(83); } Expect(9); Expect(46); Node codeBlockNode = null; if (langblock.codeblock.language == ProtoCore.Language.kAssociative || langblock.codeblock.language == ProtoCore.Language.kInvalid) { Hydrogen(out codeBlockNode); } else if (langblock.codeblock.language == ProtoCore.Language.kImperative ) { Imperative(out codeBlockNode); } else SynErr(84); if (langblock.codeblock.language == ProtoCore.Language.kInvalid ) { int openCurlyBraceCount = 0, closeCurlyBraceCount = 0; ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockInvalid = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.AssociativeNode validBlockInInvalid = null; while (closeCurlyBraceCount <= openCurlyBraceCount) { if (la.kind == 8) { Associative_LanguageBlock(out validBlockInInvalid); codeBlockInvalid.Body.Add(validBlockInInvalid); } else if (la.kind == 46) { Get(); openCurlyBraceCount++; } else if (la.kind == 47) { Get(); closeCurlyBraceCount++; } else if (la.kind == 0) { Get(); Expect(47); break; } else if (StartOf(13)) { Get(); } else SynErr(85); } codeBlockNode = codeBlockInvalid; } else if (la.kind == 47) { Get(); } else SynErr(86); langblock.CodeBlockNode = codeBlockNode; node = langblock; }
private static void InsertDotMemVarMethod(Core core, ProtoCore.AST.Node root) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic; funcDefNode.Name = ProtoCore.DSASM.Constants.kDotArgMethodName; funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar }; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kLHS), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kRHS), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeInt), UID = (int)PrimitiveType.kTypeInt } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%rhsDimExprList"), ArgumentType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 1) }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%rhsDim"), ArgumentType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 0) }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.DotFunctionBodyNode dotNode = new ProtoCore.AST.AssociativeAST.DotFunctionBodyNode(args.Arguments[0].NameNode, args.Arguments[1].NameNode, args.Arguments[2].NameNode, args.Arguments[3].NameNode); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = dotNode}); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
public void GraphILTest_FFIClassUsage_02_astInput() { ProtoScript.Runners.ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner(); List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); //============================================== // Build the import Nodes //============================================== List<string> libs = new List<string>(); libs.Add("ProtoGeometry.dll"); List<LibraryMirror> libMirrors = liveRunner.ResetVMAndImportLibrary(libs); //============================================== // Build the constructor call nodes // Point.ByCoordinates(10,10,10) //============================================== ProtoCore.AST.AssociativeAST.FunctionCallNode constructorCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode(); constructorCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("ByCoordinates"); List<ProtoCore.AST.AssociativeAST.AssociativeNode> listArgs = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(10.0)); listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(10.0)); listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(10.0)); constructorCall.FormalArguments = listArgs; string className = "Point"; ProtoCore.AST.AssociativeAST.IdentifierNode inode = new ProtoCore.AST.AssociativeAST.IdentifierNode(className); ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCall = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(inode, constructorCall, liveRunner.Core); //============================================== // Build the binary expression // p = Point.ByCoordinates(10,10,10) //============================================== ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("p"), dotCall, ProtoCore.DSASM.Operator.assign); astList.Add(stmt1); //============================================== // Translate the point // newPoint = p.Translate(1,2,3); //============================================== ProtoCore.AST.AssociativeAST.FunctionCallNode functionCallTranslate = new ProtoCore.AST.AssociativeAST.FunctionCallNode(); functionCallTranslate.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("Translate"); listArgs = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(1.0)); listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(2.0)); listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(3.0)); functionCallTranslate.FormalArguments = listArgs; //ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCallTranslate = new ProtoCore.AST.AssociativeAST.FunctionDotCallNode("p", functionCallTranslate); className = "p"; inode = new ProtoCore.AST.AssociativeAST.IdentifierNode(className); ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCallTranslate = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(inode, functionCallTranslate, liveRunner.Core); //============================================== // Build the binary expression //============================================== ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("newPoint"), dotCallTranslate, ProtoCore.DSASM.Operator.assign); astList.Add(stmt2); //============================================== // Build a binary expression to retirieve the x property // xval = newPoint.X //============================================== ProtoCore.AST.AssociativeAST.IdentifierListNode identListNode = new ProtoCore.AST.AssociativeAST.IdentifierListNode(); identListNode.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("newPoint"); identListNode.Optr = ProtoCore.DSASM.Operator.dot; identListNode.RightNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("X"); ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt3 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("xval"), identListNode, ProtoCore.DSASM.Operator.assign); astList.Add(stmt3); //============================================== // // import ("ProtoGeometry.dll"); // p = Point.Bycoordinates(10.0, 10.0, 10.0); // newPoint = p.Translate(1.0,2.0,3.0); // xval = newPoint.X; // //============================================== // update graph CodeBlockNode cNode = new CodeBlockNode(); cNode.Body = astList; liveRunner.UpdateGraph(cNode); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("xval"); Assert.IsTrue((double)mirror.GetData().Data == 11.0); }
private static void InsertInlineConditionOperationMethod(Core core, ProtoCore.AST.Node root, PrimitiveType condition, PrimitiveType r) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic; funcDefNode.Name = ProtoCore.DSASM.Constants.kInlineCondition; funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r }; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%condition"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)condition), UID = (int)condition } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%trueExp"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r } }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, "%falseExp"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r } }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.IdentifierNode con = BuildAssocIdentifier(core, "%condition"); ProtoCore.AST.AssociativeAST.IdentifierNode t = BuildAssocIdentifier(core, "%trueExp"); ProtoCore.AST.AssociativeAST.IdentifierNode f = BuildAssocIdentifier(core, "%falseExp"); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.InlineConditionalNode() { ConditionExpression = con, TrueExpression = t, FalseExpression = f } }); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
internal ImportNode Compile(ImportModuleHandler importer) { ImportNode impNode = null; ProtoCore.AST.AssociativeAST.CodeBlockNode code = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); foreach (var item in mData) { SortedSet<Type> types = GetTypesForImport(item.Value.Data); foreach (var type in types) { if (CLRObjectMarshler.IsMarshaledAsNativeType(type)) continue; ImportNode node = importer.Import(type.Assembly.Location, type.FullName, ""); if (impNode != null && node != null) impNode.CodeNode.Body.AddRange(node.CodeNode.Body); else impNode = node; } if (impNode == null) impNode = new ImportNode() { ModuleName="ExternalContext", CodeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode() }; impNode.CodeNode.Body.Add(ContextDataMethodCallNode(item.Value)); } return impNode; }
void Associative_FunctionalMethodBodySingleLine(out ProtoCore.AST.AssociativeAST.AssociativeNode funcBody) { funcBody = null; ProtoCore.AST.AssociativeAST.CodeBlockNode functionBody = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.BinaryExpressionNode binaryExpr = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(); IdentifierNode returnNode = AstFactory.BuildIdentifier("return"); returnNode.datatype = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Return, 0); binaryExpr.LeftNode = returnNode; ProtoCore.AST.AssociativeAST.AssociativeNode expr; Associative_Expression(out expr); binaryExpr.RightNode = expr; binaryExpr.Optr = Operator.assign; NodeUtils.SetNodeLocation(binaryExpr, expr, expr); List<ProtoCore.AST.AssociativeAST.AssociativeNode> body = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); body.Add(binaryExpr); functionBody.Body =body; funcBody = functionBody; if (la.val != ";") SynErr(Resources.SemiColonExpected); Expect(23); }
private static bool CompileCodeBlockAST(Core core, ParseParam parseParams) { var unboundIdentifiers = new Dictionary<int, List<VariableLine>>(); ProtoCore.BuildStatus buildStatus = null; try { int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; bool parsingPreloadFlag = core.IsParsingPreloadedAssembly; bool parsingCbnFlag = core.IsParsingPreloadedAssembly; core.IsParsingPreloadedAssembly = false; core.IsParsingCodeBlockNode = true; core.ResetForPrecompilation(); var astNodes = parseParams.ParsedNodes; // Lookup namespace resolution map in elementResolver to rewrite // partial classnames with their fully qualified names in ASTs // before passing them for pre-compilation. If partial class is not found in map, // update Resolution map in elementResolver with fully resolved name from compiler. var reWrittenNodes = ElementRewriter.RewriteElementNames(core.ClassTable, parseParams.ElementResolver, astNodes, core.BuildStatus.LogSymbolConflictWarning); // Clone a disposable copy of AST nodes for PreCompile() as Codegen mutates AST's // while performing SSA transforms and we want to keep the original AST's var codeblock = new CodeBlockNode(); var nodes = reWrittenNodes.OfType<AssociativeNode>().Select(NodeUtils.Clone).ToList(); codeblock.Body.AddRange(nodes); buildStatus = PreCompile(string.Empty, core, codeblock, out blockId); core.IsParsingCodeBlockNode = parsingCbnFlag; core.IsParsingPreloadedAssembly = parsingPreloadFlag; parseParams.AppendErrors(buildStatus.Errors); parseParams.AppendWarnings(buildStatus.Warnings); if (buildStatus.ErrorCount > 0) { return false; } IEnumerable<BuildData.WarningEntry> warnings = buildStatus.Warnings; // Get the unboundIdentifiers from the warnings GetInputLines(parseParams.ParsedNodes, warnings, unboundIdentifiers); foreach (KeyValuePair<int, List<VariableLine>> kvp in unboundIdentifiers) { foreach (VariableLine vl in kvp.Value) parseParams.AppendUnboundIdentifier(vl.displayName, vl.variable); } return true; } catch (Exception) { buildStatus = null; return false; } }
public Parser(Scanner scanner, ProtoLanguage.CompileStateTracker cs, bool _builtinMethodsLoaded = false) { this.scanner = scanner; errors = new Errors(); errors.compileState = cs; this.compileState = cs; builtinMethodsLoaded = _builtinMethodsLoaded; commentNode = new CodeBlockNode(); }
// The following methods are used to insert methods to the bottom of the AST and convert operator to these method calls // to support replication on operators private static void InsertUnaryOperationMethod(Core core, ProtoCore.AST.Node root, UnaryOperator op, PrimitiveType r, PrimitiveType operand) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic; funcDefNode.IsAssocOperator = true; funcDefNode.IsBuiltIn = true; funcDefNode.Name = Op.GetUnaryOpFunction(op); funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r }; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic, NameNode = BuildAssocIdentifier(core, "%param"), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)operand), UID = (int)operand } }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.IdentifierNode param = BuildAssocIdentifier(core, "%param"); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.UnaryExpressionNode() { Expression = param, Operator = op } }); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
public ProtoCore.AST.AssociativeAST.ImportNode Import(string moduleName, string typeName, string alias, int line = -1, int col = -1) { curLine = line; curCol = col; moduleName = moduleName.Replace("\"", String.Empty); ProtoCore.AST.AssociativeAST.ImportNode node = new ProtoCore.AST.AssociativeAST.ImportNode(); node.ModuleName = moduleName; string modulePathFileName = FileUtils.GetDSFullPathName(moduleName, _coreObj.Options); // Tracking directory paths for all imported DS files during preload assembly stage so that they can be accessed by Graph compiler before execution - pratapa if (_coreObj.IsParsingPreloadedAssembly) { string dirName = Path.GetDirectoryName(modulePathFileName); if (!string.IsNullOrEmpty(dirName) && !_coreObj.Options.IncludeDirectories.Contains(dirName)) { _coreObj.Options.IncludeDirectories.Add(dirName); } } if (string.IsNullOrEmpty(typeName)) { //Check if moduleName is a type name with namespace. Type type = Type.GetType(moduleName); if (type != null) { typeName = type.FullName; modulePathFileName = type.Assembly.Location; } } if (modulePathFileName == null || !File.Exists(modulePathFileName)) { System.Diagnostics.Debug.Write(@"Cannot import file: '" + modulePathFileName); _coreObj.LogWarning(ProtoCore.BuildData.WarningID.kFileNotFound, string.Format(Resources.kFileNotFound, modulePathFileName)); return(null); } node.ModulePathFileName = modulePathFileName; node.CodeNode = null; if (typeName.Length > 0) { node.Identifiers.Add(typeName); } ProtoCore.AST.AssociativeAST.ImportNode importedNode = null; if (TryGetImportNode(modulePathFileName, typeName, out importedNode)) { node.HasBeenImported = true; return(node); } ProtoCore.AST.AssociativeAST.CodeBlockNode codeNode = null; if (importedNode == null) { codeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); } else { codeNode = importedNode.CodeNode; } try { codeNode = ImportCodeBlock(modulePathFileName, typeName, alias, codeNode); } catch (System.Exception ex) { if (ex.InnerException != null) { _coreObj.BuildStatus.LogSemanticError(ex.InnerException.Message); } _coreObj.BuildStatus.LogSemanticError(ex.Message); } //Cache the codeblock of root import node. CodeBlockNode rootImportCodeBlock = mRootImportNode.CodeNode; mRootImportNode.CodeNode = new CodeBlockNode(); //reset with the new one. //Remove all empty nodes and add to root import node. codeNode.Body.RemoveAll(AddToRootImportNodeIfEmpty); if (mRootImportNode.CodeNode.Body.Count == 0) //empty { mRootImportNode.CodeNode = rootImportCodeBlock; //reset the old one. } if (importedNode != null) { //module has import node, but type is not imported yet. //MergeCodeBlockNode(ref importedNode, codeBlockNode); //update existing import node and return null. importedNode.CodeNode = codeNode; return(null); } node.CodeNode = codeNode; mModuleTable.Add(modulePathFileName, node); return(node); }
public override CodeBlockNode ImportCodeBlock(string typeName, string alias, CodeBlockNode refNode) { Type[] types = GetTypes(typeName); Type exttype = typeof(IExtensionApplication); #if PARALLEL System.Threading.Tasks.Parallel.ForEach(types, type => { //For now there is no support for generic type. if (!type.IsGenericType && type.IsPublic && !exttype.IsAssignableFrom(type) && !CLRModuleType.SupressesImport(type)) { CLRModuleType importedType = CLRModuleType.GetInstance(type, this, alias); } }); #else foreach (var type in types) { //For now there is no support for generic type. if (!type.IsGenericType && type.IsPublic && !exttype.IsAssignableFrom(type) && !CLRModuleType.SupressesImport(type)) { CLRModuleType importedType = CLRModuleType.GetInstance(type, this, alias); Type[] nestedTypes = type.GetNestedTypes(); if (null != nestedTypes && nestedTypes.Length > 0) { foreach (var item in nestedTypes) { importedType = CLRModuleType.GetInstance(item, this, string.Empty); } } } } #endif CodeBlockNode node = new CodeBlockNode(); //Get all the types available on this module. //TODO: need to optimize for performance. List<CLRModuleType> moduleTypes = CLRModuleType.GetTypes((CLRModuleType mtype) => { return mtype.Module == this; }); foreach (var item in moduleTypes) { node.Body.Add(item.ClassNode); mTypes[item.FullName] = item; //update Type dictionary. } //Also add all the available empty class nodes. List<CLRModuleType> emptyTypes = CLRModuleType.GetEmptyTypes(); foreach (var item in emptyTypes) { item.EnsureDisposeMethod(this); node.Body.Add(item.ClassNode); } string ffidump = Environment.GetEnvironmentVariable("FFIDUMP"); if (string.Compare(ffidump, "1") == 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var item in node.Body) { sb.Append(item.ToString()); sb.AppendLine(); } using (System.IO.FileStream fs = new System.IO.FileStream(string.Format("{0}.ds", this.Name), System.IO.FileMode.Create)) { byte[] bytes = System.Text.Encoding.ASCII.GetBytes(sb.ToString()); fs.Write(bytes, 0, bytes.Length); } } return node; }
public void AddNodesToAST() { AstRootNode = new CodeBlockNode(); List<Node> rootNodes = FindRoots(); Validity.Assert(rootNodes.Count() > 0); // TODO Jun: Check with Aparajit, the relevance of this assert... //Validity.Assert(GraphUtilities.ImportNodes != null); // TODO: Aparajit: To check if the AST nodes for preloaded assemblies and built-ins need to be added to this AST /*foreach(AssociativeNode node in GraphUtilities.ImportNodes.Body) { (AstRootNode as CodeBlockNode).Body.Add(node); }*/ // First emit all the ImportNode's foreach (Node rNode in rootNodes) { ImportNode importNode = rNode as ImportNode; if (importNode != null) { AssociativeNode outNode = null; EmitImportNode(importNode, out outNode); (AstRootNode as CodeBlockNode).Body.Add(outNode); } else if (importNode == null) { AssociativeNode outNode = null; DFSTraverse(rNode, out outNode); (AstRootNode as CodeBlockNode).Body.Add(outNode); } } }
/// <summary> /// Create BinaryExpressionNode /// </summary> /// <param name="node"></param> /// <param name="outnode"></param> private void EmitBlockNode(Block node, out AssociativeNode outnode) { Validity.Assert(node != null); // TODO: Confirm that these children are returned in the order that they // appear in the code Dictionary <int, Node> childNodes = node.GetChildrenWithIndices(); // Parse program statement in node.Name string code = node.Name + ";"; ProtoCore.AST.AssociativeAST.CodeBlockNode commentNode = null; ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockNode = (ProtoCore.AST.AssociativeAST.CodeBlockNode)GraphUtilities.Parse(code, out commentNode); Validity.Assert(codeBlockNode != null); List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList = codeBlockNode.Body; Validity.Assert(astList.Count == 1); if (astList[0] is ProtoCore.AST.AssociativeAST.IdentifierNode) { ProtoCore.AST.AssociativeAST.BinaryExpressionNode ben = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(); ben.LeftNode = astList[0]; ben.Optr = ProtoCore.DSASM.Operator.assign; ProtoCore.AST.AssociativeAST.AssociativeNode statement = null; foreach (KeyValuePair <int, Node> kvp in childNodes) { DFSTraverse(kvp.Value, out statement); } ben.RightNode = statement; astList[0] = ben; } //I don't know what I am doing if (astList[0] is BinaryExpressionNode) { BinaryExpressionNode tempBen = astList[0] as BinaryExpressionNode; if (tempBen.LeftNode is IdentifierNode) { IdentifierNode identitiferNode = tempBen.LeftNode as IdentifierNode; if (identitiferNode.ArrayDimensions != null) { ArrayIndexerNode arrIndex = new ArrayIndexerNode(); arrIndex.ArrayDimensions = identitiferNode.ArrayDimensions; arrIndex.Array = identitiferNode; tempBen.LeftNode = arrIndex; } } if (tempBen.RightNode is IdentifierNode) { IdentifierNode identitiferNode = tempBen.RightNode as IdentifierNode; if (identitiferNode.ArrayDimensions != null) { ArrayIndexerNode arrIndex = new ArrayIndexerNode(); arrIndex.ArrayDimensions = identitiferNode.ArrayDimensions; arrIndex.Array = identitiferNode; tempBen.RightNode = arrIndex; } } astList[0] = tempBen; } //it should be correct, if not, debug? ProtoCore.AST.AssociativeAST.BinaryExpressionNode bNode = astList[0] as ProtoCore.AST.AssociativeAST.BinaryExpressionNode; Validity.Assert(bNode != null); bNode.Guid = node.Guid; //bNode.SplitFromUID = node.splitFomUint; // Child nodes are arguments to expression in bNode.RightNode. // Match child nodes with IdentifierNode's in bNode.RightNode - pratapa foreach (Node n in childNodes.Values) { AssociativeNode argNode = null; DFSTraverse(n, out argNode); // DFS traverse the bNode.RightNode and check for IdentifierNode's // and if their names match with the names of argNode, then replace // the IdentifierNode in bNode.RightNode with argNode BinaryExpressionNode ben = argNode as BinaryExpressionNode; Validity.Assert(ben != null); //ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(ben); AstCodeBlockTraverse sourceGen = new AstCodeBlockTraverse(ben); ProtoCore.AST.AssociativeAST.AssociativeNode right = bNode.RightNode; sourceGen.DFSTraverse(ref right); bNode.RightNode = right; } //(AstRootNode as CodeBlockNode).Body.Add(expressionNode); Validity.Assert(gc != null); gc.HandleNewNode(bNode); outnode = bNode; }
void Associative_LanguageBlock(out ProtoCore.AST.AssociativeAST.AssociativeNode node) { node = null; ProtoCore.AST.AssociativeAST.LanguageBlockNode langblock = new ProtoCore.AST.AssociativeAST.LanguageBlockNode(); Expect(10); NodeUtils.SetNodeLocation(langblock, t); Expect(1); if( 0 == t.val.CompareTo(ProtoCore.DSASM.kw.imperative)) { langblock.codeblock.Language = ProtoCore.Language.Imperative; } else if( 0 == t.val.CompareTo(ProtoCore.DSASM.kw.associative)) { langblock.codeblock.Language = ProtoCore.Language.Associative; } else { langblock.codeblock.Language = ProtoCore.Language.NotSpecified; errors.SemErr(t.line, t.col, String.Format(Resources.InvalidLanguageBlockIdentifier, t.val)); } Expect(11); Expect(45); Node codeBlockNode = null; if (langblock.codeblock.Language == ProtoCore.Language.Associative || langblock.codeblock.Language == ProtoCore.Language.NotSpecified) { Hydrogen(out codeBlockNode); } else if (langblock.codeblock.Language == ProtoCore.Language.Imperative ) { Imperative(out codeBlockNode); } else SynErr(82); if (langblock.codeblock.Language == ProtoCore.Language.NotSpecified) { int openCurlyBraceCount = 0, closeCurlyBraceCount = 0; ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockInvalid = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.AssociativeNode validBlockInInvalid = null; while (closeCurlyBraceCount <= openCurlyBraceCount) { if (la.kind == 10) { Associative_LanguageBlock(out validBlockInInvalid); codeBlockInvalid.Body.Add(validBlockInInvalid); } else if (la.kind == 45) { Get(); openCurlyBraceCount++; } else if (la.kind == 46) { Get(); closeCurlyBraceCount++; } else if (la.kind == 0) { Get(); Expect(46); break; } else if (StartOf(13)) { Get(); } else SynErr(83); } codeBlockNode = codeBlockInvalid; } else if (la.kind == 46) { Get(); } else SynErr(84); langblock.CodeBlockNode = codeBlockNode; node = langblock; }
private static void InsertBinaryOperationMethod(Core core, ProtoCore.AST.Node root, Operator op, PrimitiveType r, PrimitiveType op1, PrimitiveType op2, int retRank = 0, int op1rank = 0, int op2rank = 0) { ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode(); funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic; funcDefNode.IsAssocOperator = true; funcDefNode.IsBuiltIn = true; funcDefNode.Name = Op.GetOpFunction(op); funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r, rank = retRank}; ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kLHS), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)op1), UID = (int)op1, rank = op1rank} }); args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kRHS), ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)op2), UID = (int)op2, rank = op2rank} }); funcDefNode.Signature = args; ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn); ProtoCore.AST.AssociativeAST.IdentifierNode lhs = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kLHS); ProtoCore.AST.AssociativeAST.IdentifierNode rhs = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kRHS); body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = lhs, RightNode = rhs, Optr = op } }); funcDefNode.FunctionBody = body; (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode); }
void Associative_FunctionalMethodBodyMultiLine(out ProtoCore.AST.AssociativeAST.AssociativeNode funcBody) { ProtoCore.AST.AssociativeAST.CodeBlockNode functionBody = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); List<ProtoCore.AST.AssociativeAST.AssociativeNode> body = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); NodeUtils.SetNodeStartLocation(functionBody, la); Expect(45); Associative_StatementList(out body); functionBody.Body =body; Expect(46); NodeUtils.SetNodeEndLocation(functionBody, t); funcBody = functionBody; }