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 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); }
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 ProtoCore.AST.AssociativeAST.ArgumentSignatureNode ParseArgumentSignature(MethodBase method) { ProtoCore.AST.AssociativeAST.ArgumentSignatureNode argumentSignature = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); ParameterInfo[] parameters = method.GetParameters(); foreach (var parameter in parameters) { argumentSignature.AddArgument(ParseArgumentDeclaration(parameter.Name, parameter.ParameterType)); } return(argumentSignature); }
public ArgumentSignatureNode(ArgumentSignatureNode rhs) : base(rhs) { Arguments = new List<VarDeclNode>(); foreach (VarDeclNode aNode in rhs.Arguments) { VarDeclNode newNode = new VarDeclNode(aNode); Arguments.Add(newNode); } }
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); }
// 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); }
private ProtoCore.AST.AssociativeAST.ArgumentSignatureNode ParseArgumentSignature(MethodBase method) { ProtoCore.AST.AssociativeAST.ArgumentSignatureNode argumentSignature = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); ParameterInfo[] parameters = method.GetParameters(); foreach (var parameter in parameters) argumentSignature.AddArgument(ParseArgumentDeclaration(parameter.Name, parameter.ParameterType)); return argumentSignature; }
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); }
public String GetFunctionSignatureString(string functionName, ProtoCore.Type returnType, ArgumentSignatureNode signature, bool isConstructor = false) { StringBuilder functionSig = new StringBuilder(isConstructor ? "\nconstructor " : "\ndef "); functionSig.Append(functionName); functionSig.Append(":"); functionSig.Append(String.IsNullOrEmpty(returnType.Name) ? core.TypeSystem.GetType(returnType.UID) : returnType.Name); if (returnType.rank < 0) { functionSig.Append("[]..[]"); } else { for (int k = 0; k < returnType.rank; ++k) { functionSig.Append("[]"); } } functionSig.Append("("); for (int i = 0; i < signature.Arguments.Count; ++i) { var arg = signature.Arguments[i]; functionSig.Append(arg.NameNode.Name); functionSig.Append(":"); if (arg.ArgumentType.UID < 0) { functionSig.Append("invalid"); } else if (arg.ArgumentType.UID == 0 && !String.IsNullOrEmpty(arg.ArgumentType.Name)) { functionSig.Append(arg.ArgumentType.Name); } else { functionSig.Append(core.TypeSystem.GetType(arg.ArgumentType.UID)); } if (arg.ArgumentType.rank < 0) { functionSig.Append("[]..[]"); } else { for (int k = 0; k < arg.ArgumentType.rank; ++k) { functionSig.Append("[]"); } } if (i < signature.Arguments.Count - 1) { functionSig.Append(", "); } } functionSig.Append(")\n"); return functionSig.ToString(); }
private FunctionDefinitionNode EmitSetterFunction(ProtoCore.DSASM.SymbolNode prop, ProtoCore.Type argType) { var argument = new ProtoCore.AST.AssociativeAST.VarDeclNode() { Access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic, NameNode =AstFactory.BuildIdentifier(Constants.kTempArg), ArgumentType = argType }; var argumentSingature = new ArgumentSignatureNode(); argumentSingature.AddArgument(argument); FunctionDefinitionNode setter = new FunctionDefinitionNode { Name = ProtoCore.DSASM.Constants.kSetterPrefix + prop.name, Signature = argumentSingature, Pattern = null, ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0), FunctionBody = new CodeBlockNode(), IsExternLib = false, IsDNI = false, ExternLibName = null, Access = prop.access, IsStatic = prop.isStatic, IsAutoGenerated = true }; // property = %tmpArg var propIdent = new TypedIdentifierNode(); propIdent.Name = propIdent.Value = prop.name; propIdent.datatype = prop.datatype; var tmpArg =AstFactory.BuildIdentifier(Constants.kTempArg); var assignment = AstFactory.BuildBinaryExpression(propIdent, tmpArg, Operator.assign); setter.FunctionBody.Body.Add(assignment); // return = null; var returnNull = AstFactory.BuildReturnStatement(new NullNode()); setter.FunctionBody.Body.Add(returnNull); return setter; }
private ArgumentSignatureNode ParseArgumentSignature(MethodBase method) { ArgumentSignatureNode argumentSignature = new ArgumentSignatureNode(); ParameterInfo[] parameters = method.GetParameters(); foreach (var parameter in parameters) { var paramNode = ParseArgumentDeclaration(parameter.Name, parameter.ParameterType); if (parameter.IsDefined(typeof(Autodesk.DesignScript.Runtime.ArbitraryDimensionArrayImportAttribute), false)) { var argType = paramNode.ArgumentType; argType.rank = ProtoCore.DSASM.Constants.kArbitraryRank; paramNode.ArgumentType = argType; } if (parameter.IsOptional) { var lhs = paramNode.NameNode; var defaultValue = parameter.DefaultValue; if (defaultValue != null) { var rhs = AstFactory.BuildPrimitiveNodeFromObject(defaultValue); paramNode.NameNode = AstFactory.BuildBinaryExpression(lhs, rhs, ProtoCore.DSASM.Operator.assign); } } argumentSignature.AddArgument(paramNode); } argumentSignature.IsVarArg = parameters.Any() && parameters.Last().GetCustomAttributes(typeof(ParamArrayAttribute), false).Any(); return argumentSignature; }
private void EmitSetterForMemVar(ProtoCore.AST.AssociativeAST.ClassDeclNode cnode, ProtoCore.DSASM.SymbolNode memVar) { var argument = new ProtoCore.AST.AssociativeAST.VarDeclNode() { memregion = ProtoCore.DSASM.MemoryRegion.kMemStack, access = ProtoCore.DSASM.AccessSpecifier.kPublic, NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode() { Value = ProtoCore.DSASM.Constants.kTempArg, Name = ProtoCore.DSASM.Constants.kTempArg, datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false) }, ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar } }; var argumentSingature = new ArgumentSignatureNode(); argumentSingature.AddArgument(argument); FunctionDefinitionNode setter = new FunctionDefinitionNode() { Name = ProtoCore.DSASM.Constants.kSetterPrefix + memVar.name, Singnature = argumentSingature, Pattern = null, ReturnType = core.TypeSystem.BuildTypeObject((int)PrimitiveType.kTypeNull, false), FunctionBody = new CodeBlockNode(), IsExternLib = false, IsDNI = false, ExternLibName = null, access = memVar.access, IsStatic = memVar.isStatic }; // property = %tmpArg setter.FunctionBody.Body.Add(new BinaryExpressionNode() { // return = property; LeftNode = new IdentifierNode() { Value = memVar.name, Name = memVar.name, datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false) }, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new IdentifierNode() { Value = ProtoCore.DSASM.Constants.kTempArg, Name = ProtoCore.DSASM.Constants.kTempArg, datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false) } }); // return = null; setter.FunctionBody.Body.Add(new BinaryExpressionNode() { LeftNode = new IdentifierNode() { Value = ProtoCore.DSDefinitions.Kw.kw_return, Name = ProtoCore.DSDefinitions.Kw.kw_return, datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeReturn, false) }, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new NullNode() }); cnode.funclist.Add(setter); }
// 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.kPublic; 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.kPublic, 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); }
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); }
void Associative_ArgumentSignatureDefinition(out ProtoCore.AST.AssociativeAST.AssociativeNode argumentSign) { ProtoCore.AST.AssociativeAST.ArgumentSignatureNode argumentSignature = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode(); Expect(12); NodeUtils.SetNodeLocation(argumentSignature, t); ProtoCore.AST.AssociativeAST.AssociativeNode arg; if (la.kind == 1) { if (NotDefaultArg()) { Associative_ArgDecl(out arg); argumentSignature.AddArgument(arg as ProtoCore.AST.AssociativeAST.VarDeclNode); while (la.kind == 52) { if (NotDefaultArg()) { ExpectWeak(52, 17); Associative_ArgDecl(out arg); argumentSignature.AddArgument(arg as ProtoCore.AST.AssociativeAST.VarDeclNode); } else break; } } } if (la.kind == 1 || la.kind == 52) { if (la.kind == 52) { Get(); } Associative_DefaultArgDecl(out arg); argumentSignature.AddArgument(arg as ProtoCore.AST.AssociativeAST.VarDeclNode); while (la.kind == 52) { Get(); Associative_DefaultArgDecl(out arg); argumentSignature.AddArgument(arg as ProtoCore.AST.AssociativeAST.VarDeclNode); } } Expect(13); argumentSign = argumentSignature; }