public static void CreateOrGetOpTables(IokeParser parser) { var runtime = parser.runtime; IokeObject opTable = IokeObject.As(IokeObject.FindCell(runtime.Message, "OperatorTable"), null); if (opTable == runtime.nul) { opTable = runtime.NewFromOrigin(); opTable.Kind = "Message OperatorTable"; runtime.Message.SetCell("OperatorTable", opTable); } var tmpOperatorTable = GetOpTable(parser, opTable, "operators", new BinaryOpTableCreator()); var tmpTrinaryOperatorTable = GetOpTable(parser, opTable, "trinaryOperators", new TrinaryOpTableCreator()); var tmpInvertedOperatorTable = GetOpTable(parser, opTable, "invertedOperators", new InvertedOpTableCreator()); foreach (DictionaryEntry entry in tmpOperatorTable) { AddOpEntry(Symbol.GetText(entry.Key), Number.IntValue(entry.Value).intValue(), parser.operatorTable); } foreach (DictionaryEntry entry in tmpTrinaryOperatorTable) { AddOpArity(Symbol.GetText(entry.Key), Number.IntValue(entry.Value).intValue(), parser.trinaryOperatorTable); } foreach (DictionaryEntry entry in tmpInvertedOperatorTable) { AddOpEntry(Symbol.GetText(entry.Key), Number.IntValue(entry.Value).intValue(), parser.invertedOperatorTable); } }
private static IDictionary GetOpTable(IokeParser parser, IokeObject opTable, string name, OpTableCreator creator) { IokeObject operators = IokeObject.As(IokeObject.FindCell(opTable, name), null); if (operators != parser.runtime.nul && (IokeObject.dataOf(operators) is Dict)) { return(Dict.GetMap(operators)); } else { IDictionary result = creator.Create(parser.runtime); opTable.SetCell(name, parser.runtime.NewDict(result)); return(result); } }
public static IokeObject NewFromStream(Runtime runtime, TextReader reader, IokeObject message, IokeObject context) { try { IokeParser parser = new IokeParser(runtime, reader, context, message); IokeObject m = parser.ParseFully(); if(m == null) { Message mx = new Message(runtime, ".", null, true); mx.Line = 0; mx.Position = 0; return runtime.CreateMessage(mx); } return m; } catch(ControlFlow cf) { // Pass through! throw cf; } catch(Exception e) { runtime.ReportNativeException(e, message, context); return null; } }
private static IDictionary GetOpTable(IokeParser parser, IokeObject opTable, string name, OpTableCreator creator) { IokeObject operators = IokeObject.As(opTable.FindCell(parser.message, parser.context, name), null); if(operators != parser.runtime.nul && (IokeObject.dataOf(operators) is Dict)) { return Dict.GetMap(operators); } else { IDictionary result = creator.Create(parser.runtime); opTable.SetCell(name, parser.runtime.NewDict(result)); return result; } }
public static void CreateOrGetOpTables(IokeParser parser) { var runtime = parser.runtime; IokeObject opTable = IokeObject.As(runtime.Message.FindCell(parser.message, parser.context, "OperatorTable"), null); if(opTable == runtime.nul) { opTable = runtime.NewFromOrigin(); opTable.Kind = "Message OperatorTable"; runtime.Message.SetCell("OperatorTable", opTable); } var tmpOperatorTable = GetOpTable(parser, opTable, "operators", new BinaryOpTableCreator()); var tmpTrinaryOperatorTable = GetOpTable(parser, opTable, "trinaryOperators", new TrinaryOpTableCreator()); var tmpInvertedOperatorTable = GetOpTable(parser, opTable, "invertedOperators", new InvertedOpTableCreator()); foreach(DictionaryEntry entry in tmpOperatorTable) { AddOpEntry(Symbol.GetText(entry.Key), Number.IntValue(entry.Value).intValue(), parser.operatorTable); } foreach(DictionaryEntry entry in tmpTrinaryOperatorTable) { AddOpArity(Symbol.GetText(entry.Key), Number.IntValue(entry.Value).intValue(), parser.trinaryOperatorTable); } foreach(DictionaryEntry entry in tmpInvertedOperatorTable) { AddOpEntry(Symbol.GetText(entry.Key), Number.IntValue(entry.Value).intValue(), parser.invertedOperatorTable); } }