Example #1
0
 public IokeParser(Runtime runtime, TextReader reader, IokeObject context, IokeObject message)
 {
     this.runtime = runtime;
     this.reader = reader;
     this.context = context;
     this.message = message;
 }
Example #2
0
        public IokeObject(Runtime runtime, string documentation, IokeData data)
        {
            this.runtime = runtime;
            this.documentation = documentation;
            this.data = data;

            this.mimics = new SaneList<IokeObject>();
            this.cells = new SaneDictionary<string, object>();
        }
Example #3
0
        public LexicalContext(Runtime runtime, object ground, string documentation, IokeObject message, IokeObject surroundingContext)
            : base(runtime, documentation)
        {
            this.ground = IokeObject.GetRealContext(ground);
            this.message = message;
            this.surroundingContext = surroundingContext;

            Kind = "LexicalContext";
        }
Example #4
0
        public Message(Runtime runtime, string name, object arg1, Type type)
        {
            this.type = type;
            this.name = name;
            this.arguments = new SaneArrayList();
            this.file = ((IokeSystem)IokeObject.dataOf(runtime.System)).CurrentFile;

            if(arg1 != null) {
                arguments.Add(arg1);
            }
        }
Example #5
0
        public Message(Runtime runtime, string name, object arg1, bool isTerm)
        {
            this.isTerminator = isTerm;
            this.name = name;
            this.arguments = new SaneArrayList();
            this.file = ((IokeSystem)IokeObject.dataOf(runtime.System)).CurrentFile;

            if(arg1 != null) {
                arguments.Add(arg1);
            }
        }
Example #6
0
File: Levels.cs Project: fronx/ioke
        public Levels(IokeObject msg, IokeObject context, IokeObject message)
        {
            this.runtime = context.runtime;
            this._context = context;
            this._message = message;

            IokeObject opTable = IokeObject.As(msg.FindCell(_message, _context, "OperatorTable"), null);
            if(opTable == runtime.nul) {
                opTable = runtime.NewFromOrigin();
                opTable.Kind = "Message OperatorTable";
                runtime.Message.SetCell("OperatorTable", opTable);
                opTable.SetCell("precedenceLevelCount", runtime.NewNumber(OP_LEVEL_MAX));
            }

            this.operatorTable = GetOpTable(opTable, "operators", new BinaryOpTableCreator());
            this.trinaryOperatorTable = GetOpTable(opTable, "trinaryOperators", new TrinaryOpTableCreator());
            this.invertedOperatorTable = GetOpTable(opTable, "invertedOperators", new InvertedOpTableCreator());
            this.stack = new SaneList<Level>();
            this.Reset();
        }
Example #7
0
 public IokeObject(Runtime runtime, string documentation)
     : this(runtime, documentation, IokeData.None)
 {
 }
Example #8
0
 public static IokeObject Create(Runtime runtime)
 {
     IokeObject bm = new IokeObject(runtime, "Benchmark is a module that makes it easy to test the time code takes to run");
     Init(bm);
     return bm;
 }
Example #9
0
 public IDictionary Create(Runtime runtime)
 {
     IDictionary table = new SaneHashtable();
     foreach(OpArity ot in DEFAULT_ASSIGNMENT_OPERATORS.Values) {
         table[runtime.GetSymbol(ot.name)] = runtime.NewNumber(ot.arity);
     }
     return table;
 }
Example #10
0
 public Message(Runtime runtime, string name)
     : this(runtime, name, null, false)
 {
 }
Example #11
0
 public static Message Wrap(string name, object cachedResult, Runtime runtime)
 {
     Message m = new Message(runtime, name);
     m.cached = cachedResult;
     return m;
 }
Example #12
0
        public static IokeObject FromTree(Runtime runtime, ITree tree)
        {
            //             Console.Error.WriteLine(" fromTree(" + tree.ToStringTree() + ")");
            Message m = null;
            int argStart = 0;

            if(!tree.IsNil) {
                switch(tree.Type) {
                case iokeParser.RegexpLiteral: {
                    string s = tree.Text;
                    char first = s[0];
                    char second = s[1];
                    char last = s[s.Length-1];
                    if(first == '#' && last != '{') {
                        if(second == 'r') {
                            int lastIndex = s.LastIndexOf(']');
                            m = new Message(runtime, "internal:createRegexp", s.Substring(3, lastIndex-3));
                            m.arguments.Add(s.Substring(lastIndex+1));
                        } else {
                            int lastIndex = s.LastIndexOf('/');
                            m = new Message(runtime, "internal:createRegexp", s.Substring(2, lastIndex-2));
                            m.arguments.Add(s.Substring(lastIndex+1));
                        }
                        m.Line = tree.Line;
                        m.Position = tree.CharPositionInLine;
                        return runtime.CreateMessage(m);
                    } else if(first == '}' && last == '{') {
                        m = new Message(runtime, "internal:createText", s.Substring(1, s.Length-3), Type.MIDDLE_RE_INTERPOLATION);
                        m.Line = tree.Line;
                        m.Position = tree.CharPositionInLine;
                        return runtime.CreateMessage(m);
                    } else if(first == '}') {
                        int lastIndex = s.LastIndexOf('/');
                        if(lastIndex == -1) {
                            lastIndex = s.LastIndexOf(']');
                        }
                        m = new Message(runtime, "internal:createText", s.Substring(1, lastIndex-1), Type.END_RE_INTERPOLATION);
                        m.arguments.Add(s.Substring(lastIndex+1));
                        m.Line = tree.Line;
                        m.Position = tree.CharPositionInLine;
                        return runtime.CreateMessage(m);
                    } else {
                        m = new Message(runtime, "internal:createText", s.Substring(2, s.Length-4), Type.START_RE_INTERPOLATION);
                        m.Line = tree.Line;
                        m.Position = tree.CharPositionInLine;
                        return runtime.CreateMessage(m);
                    }
                }
                case iokeParser.StringLiteral: {
                    string s = tree.Text;
                    char first = s[0];
                    char last = s[s.Length-1];
                    if(first == '"' && last == '"') {
                        m = new Message(runtime, "internal:createText", s.Substring(1, s.Length-2));
                        m.Line = tree.Line;
                        m.Position = tree.CharPositionInLine;
                        return runtime.CreateMessage(m);
                    } else if(first == '#' && last == ']') {
                        m = new Message(runtime, "internal:createText", s.Substring(2, s.Length-3));
                        m.Line = tree.Line;
                        m.Position = tree.CharPositionInLine;
                        return runtime.CreateMessage(m);
                    } else {
                        if(first == '}' && (last == '"' || last == ']')) { // This is an ending
                            m = new Message(runtime, "internal:createText", s.Substring(1, s.Length-2), Type.END_INTERPOLATION);
                            m.Line = tree.Line;
                            m.Position = tree.CharPositionInLine;
                            return runtime.CreateMessage(m);
                        } else if(first == '"') { // This is a beginning
                            m = new Message(runtime, "internal:createText", s.Substring(1, s.Length-3), Type.START_INTERPOLATION);
                            m.Line = tree.Line;
                            m.Position = tree.CharPositionInLine;
                            return runtime.CreateMessage(m);
                        } else if(first == '#') { // This is a beginning
                            m = new Message(runtime, "internal:createText", s.Substring(2, s.Length-4), Type.START_INTERPOLATION);
                            m.Line = tree.Line;
                            m.Position = tree.CharPositionInLine;
                            return runtime.CreateMessage(m);
                        } else { // This is in the middle
                            m = new Message(runtime, "internal:createText", s.Substring(1, s.Length-3), Type.MIDDLE_INTERPOLATION);
                            m.Line = tree.Line;
                            m.Position = tree.CharPositionInLine;
                            return runtime.CreateMessage(m);
                        }
                    }
                }
                case iokeParser.NumberLiteral:
                    m = new Message(runtime, "internal:createNumber", tree.Text);
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                case iokeParser.DecimalLiteral:
                    m = new Message(runtime, "internal:createDecimal", tree.Text);
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                case iokeParser.UnitLiteral: {
                    string text = tree.Text;
                    int ending = text.Length-1;
                    while(!Char.IsDigit(text[ending])) {
                        ending--;
                    }
                    Message mex = new Message(runtime, "internal:createNumber", text.Substring(0, ending+1));
                    mex.Line = tree.Line;
                    mex.Position = tree.CharPositionInLine;
                    m = new Message(runtime, "internal:createUnit", runtime.CreateMessage(mex));
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                }
                case iokeParser.UnitDecimalLiteral: {
                    string text = tree.Text;
                    int ending = text.Length-1;
                    while(!Char.IsDigit(text[ending])) {
                        ending--;
                    }
                    Message mex = new Message(runtime, "internal:createDecimal", text.Substring(0, ending+1));
                    mex.Line = tree.Line;
                    mex.Position = tree.CharPositionInLine;
                    m = new Message(runtime, "internal:createUnit", mex);
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                }
                case iokeParser.Identifier:
                    m = new Message(runtime, tree.Text);
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                case iokeParser.Terminator:
                    m = new Message(runtime, ".", null, Type.TERMINATOR);
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                case iokeParser.Comma:
                    m = new Message(runtime, ",", null, Type.SEPARATOR);
                    m.Line = tree.Line;
                    m.Position = tree.CharPositionInLine;
                    return runtime.CreateMessage(m);
                case iokeParser.MESSAGE: {
                    string text = tree.GetChild(0).Text;
                    m = new Message(runtime, text);
                    int count = tree.ChildCount;
                    argStart = 1;
                    if(count > 1) {
                        int diff = tree.GetChild(1).CharPositionInLine - (tree.CharPositionInLine+text.Length);
                        if(diff != 0) {
                            m.type = Type.DETACH;
                        }
                        argStart = 2;
                    }

                    break;
                }
                default:
                    Console.Error.WriteLine("ERROR: Can't handle " + tree + " : " + tree.Type);
                    return null;
                }

                m.Line = tree.Line;
                m.Position = tree.CharPositionInLine;
            }

            IokeObject mx = m == null ? (IokeObject)null : runtime.CreateMessage(m);

            object head = null;
            IList<IokeObject> currents = new SaneList<IokeObject>();

            IList<IList<IokeObject>> oldCurrents = new SaneList<IList<IokeObject>>();
            IList<object> oldHeads = new SaneList<object>();
            IList<IokeObject> oldMx = new SaneList<IokeObject>();

            for(int i=argStart,j=tree.ChildCount; i<j; i++) {
                IokeObject created = FromTree(runtime, tree.GetChild(i));

                switch(Message.typeOf(created)) {
                case Type.START_INTERPOLATION:{
                    Message mvv = new Message(runtime, "internal:concatenateText");
                    mvv.Line = tree.Line;
                    mvv.Position = tree.CharPositionInLine;
                    oldCurrents.Insert(0, currents);
                    oldHeads.Insert(0, head);
                    oldMx.Insert(0, mx);

                    currents = new SaneList<IokeObject>();
                    head = created;
                    mx = runtime.CreateMessage(mvv);

                    created = runtime.CreateMessage(new Message(runtime, ",", null, Type.SEPARATOR));
                    break;
                }
                case Type.START_RE_INTERPOLATION:{
                    Message mvv = new Message(runtime, "internal:compositeRegexp");
                    mvv.Line = tree.Line;
                    mvv.Position = tree.CharPositionInLine;
                    oldCurrents.Insert(0, currents);
                    oldHeads.Insert(0, head);
                    oldMx.Insert(0, mx);

                    currents = new SaneList<IokeObject>();
                    head = created.Arguments[0];
                    mx = runtime.CreateMessage(mvv);

                    created = runtime.CreateMessage(new Message(runtime, ",", null, Type.SEPARATOR));
                    break;
                }
                case Type.MIDDLE_INTERPOLATION:
                    mx.Arguments.Add(head);

                    currents.Clear();
                    head = created;

                    created = runtime.CreateMessage(new Message(runtime, ",", null, Type.SEPARATOR));
                    break;
                case Type.MIDDLE_RE_INTERPOLATION:
                    mx.Arguments.Add(head);

                    currents.Clear();
                    head = created.Arguments[0];

                    created = runtime.CreateMessage(new Message(runtime, ",", null, Type.SEPARATOR));
                    break;
                case Type.END_INTERPOLATION:
                    mx.Arguments.Add(head);
                    mx.Arguments.Add(created);

                    currents = oldCurrents[0];
                    oldCurrents.RemoveAt(0);

                    head = oldHeads[0];
                    oldHeads.RemoveAt(0);

                    created = mx;

                    mx = oldMx[0];
                    oldMx.RemoveAt(0);

                    break;
                case Type.END_RE_INTERPOLATION:
                    mx.Arguments.Add(head);
                    mx.Arguments.Add(created.Arguments[0]);
                    mx.Arguments.Add(created.Arguments[1]);

                    currents = oldCurrents[0];
                    oldCurrents.RemoveAt(0);

                    head = oldHeads[0];
                    oldHeads.RemoveAt(0);

                    created = mx;

                    mx = oldMx[0];
                    oldMx.RemoveAt(0);
                    break;
                }

                if(Message.typeOf(created) == Type.TERMINATOR && head == null && currents.Count == 0) {
                    continue;
                }

                if(Message.typeOf(created) == Type.SEPARATOR && mx != null) {
                    mx.Arguments.Add(head);
                    currents.Clear();
                    head = null;
                } else {
                    if(Message.typeOf(created) == Type.TERMINATOR && currents.Count > 1) {
                        while(currents.Count > 1) {
                            currents.RemoveAt(0);
                        }
                    }
                    Message.SetPrev(created, currents.Count > 0 ? currents[0] : null);

                    if(head == null && Message.typeOf(created) != Type.TERMINATOR) {
                        head = created;
                    }

                    if(currents.Count > 0) {
                        Message.SetNextOfLast(currents[0], created);
                        currents[0] = created;
                    } else {
                        currents.Insert(0, created);
                    }
                }
            }

            if(mx != null && head != null) {
                mx.Arguments.Add(head);
            }

            return mx == null ? (IokeObject)head : mx;
        }
Example #13
0
 public Message(Runtime runtime, string name)
     : this(runtime, name, null, Type.MESSAGE)
 {
 }
Example #14
0
 public BooleanGivingRestart(string name, bool[] place, bool value, Runtime runtime)
     : base(name)
 {
     this.place = place;
     this.value = value;
     this.runtime = runtime;
 }
Example #15
0
 public static IList<string> Glob(Runtime runtime, string text)
 {
     return runtime.globber.PushGlob(runtime.CurrentWorkingDirectory, text, 0);
 }
Example #16
0
File: Hook.cs Project: goking/ioke
        public static void Init(Runtime runtime)
        {
            IokeObject obj = new IokeObject(runtime, "A hook allow you to observe what happens to a specific object. All hooks have Hook in their mimic chain.");
            obj.Kind = "Hook";
            obj.MimicsWithoutCheck(runtime.Origin);
            runtime.IokeGround.RegisterCell("Hook", obj);

            obj.RegisterMethod(runtime.NewNativeMethod("Takes one or more arguments to hook into and returns a new Hook connected to them.",
                                                       new TypeCheckingNativeMethod("into", TypeCheckingArgumentsDefinition.builder()
                                                                                    .ReceiverMustMimic(obj)
                                                                                    .WithRequiredPositional("firstConnected")
                                                                                    .WithRest("restConnected")
                                                                                    .Arguments,
                                                                                    (method, on, args, keywords, context, message) => {
                                                                                        IokeObject hook = obj.AllocateCopy(context, message);
                                                                                        hook.MimicsWithoutCheck(obj);

                                                                                        IList objs = new SaneArrayList();
                                                                                        foreach(object o in args) {
                                                                                            objs.Add(IokeObject.As(o, context));
                                                                                        }
                                                                                        Hook h = new Hook(objs);
                                                                                        hook.Data = h;
                                                                                        h.Rewire(hook);
                                                                                        return hook;
                                                                                    })));

            obj.RegisterMethod(runtime.NewNativeMethod("returns the objects this hook is connected to",
                                                       new TypeCheckingNativeMethod.WithNoArguments("connectedObjects", obj,
                                                                                                    (method, on, args, keywords, context, message) => {
                                                                                                        Hook h = (Hook)IokeObject.dataOf(on);
                                                                                                        IList l = new SaneArrayList(h.connected);
                                                                                                        return method.runtime.NewList(l);
                                                                                                    })));

            obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument and will add that to the list of connected objects",
                                                       new TypeCheckingNativeMethod("hook!", TypeCheckingArgumentsDefinition.builder()
                                                                                    .ReceiverMustMimic(obj)
                                                                                    .WithRequiredPositional("objectToHookInto")
                                                                                    .Arguments,
                                                                                    (method, on, args, keywords, context, message) => {
                                                                                        Hook h = (Hook)IokeObject.dataOf(on);
                                                                                        h.connected.Add(IokeObject.As(args[0], context));
                                                                                        h.Rewire(IokeObject.As(on, context));
                                                                                        return on;
                                                                                    })));
        }
Example #17
0
        public static void InitRuntime(IokeObject obj)
        {
            obj.Kind = "Runtime";

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the node id for the runtime it's called on",
                                                           new TypeCheckingNativeMethod.WithNoArguments("nodeId", obj,
                                                                                                        (method, on, args, keywords, context, message) => {
                                                                                                            Runtime r = (Runtime)IokeObject.dataOf(on);
                                                                                                            return method.runtime.NewNumber(r.id);
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("creates a new runtime and returns that. be careful using this since it will result in some fairly strange behavior if used incorrectly. it will not copy the state of this runtime, but just create a new one from scratch.",
                                                           new TypeCheckingNativeMethod.WithNoArguments("create", obj,
                                                                                                        (method, on, args, keywords, context, message) => {
                                                                                                            Runtime r = new Runtime(method.runtime.Out, method.runtime.In, method.runtime.Error);
                                                                                                            r.Init();
                                                                                                            IokeObject o = method.runtime._Runtime.AllocateCopy(null, null);
                                                                                                            o.MimicsWithoutCheck(method.runtime._Runtime);
                                                                                                            o.Data = r;
                                                                                                            return o;
                                                                                                        })));
        }
Example #18
0
File: Text.cs Project: fronx/ioke
 public EvaluatingMessage(Runtime runtime, string name, DoEvaluation code)
     : base(runtime, name)
 {
     this.code = code;
 }
Example #19
0
        public void Become(IokeObject other, IokeObject message, IokeObject context)
        {
            CheckFrozen("become!", message, context);

            this.runtime = other.runtime;
            this.documentation = other.documentation;
            this.cells = other.cells;
            this.mimics = other.mimics;
            this.data = other.data;
            this.frozen = other.frozen;
        }
Example #20
0
 public Message(Runtime runtime, string name, object arg1)
     : this(runtime, name, arg1, Type.MESSAGE)
 {
 }
Example #21
0
        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;
            }
        }
Example #22
0
        public static void Main(string[] args)
        {
            string current = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string iokeHome = new FileInfo(current).Directory.Parent.FullName;
            string iokeLib = Path.Combine(iokeHome, "lib");

            Runtime r = new Runtime(new FunctionalOperatorShufflerFactory());
            r.Init();

            IokeObject context = r.Ground;
            Message mx = new Message(r, ".", null, true);
            mx.Line = 0;
            mx.Position = 0;
            IokeObject message = r.CreateMessage(mx);

            string cwd = null;

            var scripts = new SaneList<string>();
            var loadDirs = new SaneList<string>();
            bool debug = false;

            try {
                int start = 0;
                bool done = false;
                bool readStdin = false;
                bool printedSomething = false;

                for(;!done && start<args.Length;start++) {
                    string arg = args[start];
                    if(arg.Length > 0) {
                        if(arg[0] != '-') {
                            done = true;
                            break;
                        } else {
                            if(arg.Equals("--")) {
                                done = true;
                            } else if(arg.Equals("-d")) {
                                debug = true;
                                r.Debug = true;
                            } else if(arg.StartsWith("-e")) {
                                if(arg.Length == 2) {
                                    scripts.Add(args[++start]);
                                } else {
                                    scripts.Add(arg.Substring(2));
                                }
                            } else if(arg.StartsWith("-I")) {
                                if(arg.Length == 2) {
                                    loadDirs.Add(args[++start]);
                                } else {
                                    loadDirs.Add(arg.Substring(2));
                                }
                            } else if(arg.Equals("-h") || arg.Equals("--help")) {
                                Console.Error.Write(HELP);
                                return;
                            } else if(arg.Equals("--version")) {
                                Console.Error.WriteLine(getVersion());
                                printedSomething = true;
                            } else if(arg.Equals("--copyright")) {
                                Console.Error.Write(COPYRIGHT);
                                printedSomething = true;
                            } else if(arg.Equals("-")) {
                                readStdin = true;
                            } else if(arg[1] == 'C') {
                                if(arg.Length == 2) {
                                    cwd = args[++start];
                                } else {
                                    cwd = arg.Substring(2);
                                }
                            } else {
                                IokeObject condition = IokeObject.As(IokeObject.GetCellChain(r.Condition,
                                                                                             message,
                                                                                             context,
                                                                                             "Error",
                                                                                             "CommandLine",
                                                                                             "DontUnderstandOption"), null).Mimic(message, context);
                                condition.SetCell("message", message);
                                condition.SetCell("context", context);
                                condition.SetCell("receiver", context);
                                condition.SetCell("option", r.NewText(arg));
                                r.ErrorCondition(condition);
                            }
                        }
                    }
                }

                if(cwd != null) {
                    r.CurrentWorkingDirectory = cwd;
                }

                ((IokeSystem)IokeObject.dataOf(r.System)).CurrentProgram = "-e";

                string lib = Environment.GetEnvironmentVariable("ioke.lib");
                if(lib == null) {
                    lib = iokeLib;
                }
                ((IokeSystem)IokeObject.dataOf(r.System)).AddLoadPath(lib + "/ioke");
                ((IokeSystem)IokeObject.dataOf(r.System)).AddLoadPath("lib/ioke");

                foreach(string ss in loadDirs) {
                    ((IokeSystem)IokeObject.dataOf(r.System)).AddLoadPath(ss);
                }

                foreach(string script in scripts) {
                    r.EvaluateStream("-e", new StringReader(script), message, context);
                }

                if(readStdin) {
                    ((IokeSystem)IokeObject.dataOf(r.System)).CurrentProgram = "<stdin>";
                    r.EvaluateStream("<stdin>", Console.In, message, context);
                }

                if(args.Length > start) {
                    if(args.Length > (start+1)) {
                        for(int i=start+1,j=args.Length; i<j; i++) {
                            r.AddArgument(args[i]);
                        }
                    }
                    string file = args[start];
                    if(file.StartsWith("\"")) {
                        file = file.Substring(1, file.Length-1);
                    }

                    if(file.Length > 1 && file[file.Length-1] == '"') {
                        file = file.Substring(0, file.Length-1);
                    }

                    ((IokeSystem)IokeObject.dataOf(r.System)).CurrentProgram = file;
                    r.EvaluateFile(file, message, context);
                } else {
                    if(!readStdin && scripts.Count == 0 && !printedSomething) {
                        r.EvaluateString("use(\"builtin/iik\"). IIk mainLoop", message, context);
                    }
                }

                r.TearDown();

            } catch(ControlFlow.Exit e) {
                int exitVal = e.ExitValue;
                try {
                    r.TearDown();
                } catch(ControlFlow.Exit e2) {
                    exitVal = e2.ExitValue;
                }
                Environment.Exit(exitVal);
            } catch(ControlFlow e) {
                string name = e.GetType().FullName;
                System.Console.Error.WriteLine("unexpected control flow: " + name.Substring(name.LastIndexOf(".") + 1).ToLower());
                if(debug) {
                    System.Console.Error.WriteLine(e);
                }
                Environment.Exit(1);
            }
        }
Example #23
0
 public static Message Wrap(object cachedResult, Runtime runtime)
 {
     return Wrap("cachedResult", cachedResult, runtime);
 }
Example #24
0
File: Levels.cs Project: fronx/ioke
 public IDictionary Create(Runtime runtime)
 {
     IDictionary table = new SaneHashtable();
     foreach(OpTable ot in defaultTrinaryOperators) {
         table[runtime.GetSymbol(ot.name)] = runtime.NewNumber(ot.precedence);
     }
     return table;
 }
Example #25
0
 public Message(Runtime runtime, string name, object arg1)
     : this(runtime, name, arg1, false)
 {
 }
Example #26
0
        public static IokeObject NewFromStream(Runtime runtime, TextReader reader, IokeObject message, IokeObject context)
        {
            try {
                iokeParser parser = new iokeParser(new CommonTokenStream(new iokeLexer(new ANTLRReaderStream(reader))));
            //                  Console.Error.WriteLine("parseFully ...");
                ITree t = parser.parseFully();
            //                  Console.Error.WriteLine("t: " + t.ToStringTree());

                if(t == null) {
                    Message mx = new Message(runtime, ".", null, Type.TERMINATOR);
                    mx.Line = 0;
                    mx.Position = 0;
                    return runtime.CreateMessage(mx);
                }

                IokeObject m = FromTree(runtime, t);
            //                  Console.Error.WriteLine("m: " + m);

            //                 Console.Error.WriteLine("m1: " + m);
                OpShuffle(m);
            //                 Console.Error.WriteLine("m2: " + m);

                return m;
            } catch(Exception e) {
                runtime.ReportNativeException(e, message, context);
                return null;
            }
        }
Example #27
0
 Message(Runtime runtime, string name, bool isTerm)
     : this(runtime, name, null, isTerm)
 {
 }
Example #28
0
 public IDictionary Create(Runtime runtime)
 {
     IDictionary table = new SaneHashtable();
     foreach(OpEntry ot in DEFAULT_INVERTED_OPERATORS.Values) {
         table[runtime.GetSymbol(ot.name)] = runtime.NewNumber(ot.precedence);
     }
     return table;
 }
Example #29
0
File: Range.cs Project: goking/ioke
            public RangeIterator(IokeObject start, IokeObject end, bool inclusive, bool inverted, IokeObject context, IokeObject message)
            {
                this.runtime = context.runtime;
                this.start = start;
                this.end = end;
                this.inclusive = inclusive;
                this.context = context;
                //                this.message = message;

                messageToSend = runtime.succMessage;
                if(inverted) {
                    messageToSend = runtime.predMessage;
                }
            }
Example #30
0
 Message(Runtime runtime, string name, Type type)
     : this(runtime, name, null, type)
 {
 }