// Partitions // public static int GetPartitions(ExpressionVisitor Evaluator, HScriptParser.PartitionsContext context) { // Null then assume 1 partition // if (context == null) return 1; // If the expression is null, then max out cores // if (context.expression() == null) return Environment.ProcessorCount; // Otherwise, get the value // int cnt = (int)Evaluator.ToNode(context.expression()).Evaluate().valueINT; // Bound it // cnt = Math.Min(cnt, Environment.ProcessorCount * 2); cnt = Math.Max(cnt, 1); return cnt; }
// Where clause // public static Predicate GetWhere(ExpressionVisitor Evaluator, HScriptParser.Where_clauseContext context) { if (context == null) return Predicate.TrueForAll; return Evaluator.ToPredicate(context.expression()); }
// Lambdas // public static Lambda RenderLambda(Workspace Home, HScriptParser.LambdaGenericContext context) { // Get the name // string name = context.IDENTIFIER()[0].GetText(); // Get all the pointers // List<string> pointers = new List<string>(); for (int i = 1; i < context.IDENTIFIER().Count; i++) { string var_name = context.IDENTIFIER()[i].GetText(); pointers.Add(var_name); } // Get the expression // PointerExpressionVisitor pev = new PointerExpressionVisitor(pointers, Home); // Build the node // FNode node = pev.ToNode(context.expression()); // Build the lambda // Lambda mu = new Lambda(name, node, pointers); return mu; }
public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrix2DContext context) { string name = context.IDENTIFIER().GetText(); CellAffinity type = GetAffinity(context.type()); int rows = (int)Evaluator.ToNode(context.expression()[0]).Evaluate().valueINT; int cols = (int)Evaluator.ToNode(context.expression()[1]).Evaluate().valueINT; CellMatrix mat = new CellMatrix(rows, cols, type); Heap.Arrays.Reallocate(name, mat); }
// Heap allocations // public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareScalarContext context) { string name = context.IDENTIFIER().GetText(); CellAffinity type = GetAffinity(context.type()); Cell value = (context.ASSIGN() != null) ? Evaluator.ToNode(context.expression()).Evaluate() : new Cell(type); Heap.Scalars.Reallocate(name, value); }
internal static DeclareMatrixNode RenderDeclareNode(Workspace Home, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrix2DContext context) { string name = context.IDENTIFIER().GetText(); int row = (int)Evaluator.ToNode(context.expression()[0]).Evaluate().valueINT; int col = (int)Evaluator.ToNode(context.expression()[1]).Evaluate().valueINT; CellAffinity affinity = VisitorHelper.GetAffinity(context.type()); MNodeLiteral m = new MNodeLiteral(null, new Gidran.CellMatrix(row, 1, affinity)); return new DeclareMatrixNode(Home.GlobalHeap, name, m); }
internal static DeclareScalarNode RenderDeclareNode(Workspace Home, ExpressionVisitor Evaluator, HScriptParser.DeclareScalarContext context) { string name = context.IDENTIFIER().GetText(); FNode node = Evaluator.ToNode(context.expression()); return new DeclareScalarNode(Home.GlobalHeap, name, node); }
public static FNode ParseFNode(string Text, MemoryStruct LocalHeap, Workspace Home, string Alias, Schema Columns, Register Memory) { // Build text stream // AntlrInputStream ais = new AntlrInputStream(Text); HScriptLexer lex = new HScriptLexer(ais); // Build token tree // CommonTokenStream cts = new CommonTokenStream(lex); HScriptParser par = new HScriptParser(cts); // Build AST // IParseTree tree = par.expression(); // Visit each node getting the final node // ExpressionVisitor v = new ExpressionVisitor(LocalHeap, Home); v.AddSchema(Alias, Columns, Memory); return v.Visit(tree); }