Example #1
0
        public static void Init(IokeObject obj)
        {
            Runtime runtime = obj.runtime;
            obj.Kind = "Mixins";

            obj.SetCell("=",         runtime.Base.Cells["="]);
            obj.SetCell("==",        runtime.Base.Cells["=="]);
            obj.SetCell("cell",      runtime.Base.Cells["cell"]);
            obj.SetCell("cell=",     runtime.Base.Cells["cell="]);
            obj.SetCell("cell?",     runtime.Base.Cells["cell?"]);
            obj.SetCell("cells",     runtime.Base.Cells["cells"]);
            obj.SetCell("cellNames", runtime.Base.Cells["cellNames"]);
            obj.SetCell("mimic",     runtime.Base.Cells["mimic"]);

            IokeObject comparing = new IokeObject(obj.runtime, "allows different objects to be compared, based on the spaceship operator being available");
            comparing.MimicsWithoutCheck(obj);
            Comparing.Init(comparing);
            obj.RegisterCell("Comparing", comparing);

            IokeObject enumerable = new IokeObject(obj.runtime, "adds lots of helpful methods that can be done on enumerable methods. based on the 'each' method being available on the self.");
            enumerable.MimicsWithoutCheck(obj);
            Enumerable.Init(enumerable);
            obj.RegisterCell("Enumerable", enumerable);

            IokeObject sequenced = new IokeObject(obj.runtime, "something that is sequenced can return a Sequence over itself. it also allows several other methods to be defined in terms of that sequence. A Sequenced object is Enumerable, since all Enumerable operations can be defined in terms of sequencing.");
            sequenced.MimicsWithoutCheck(obj);
            sequenced.MimicsWithoutCheck(enumerable);
            Sequenced.Init(sequenced);
            obj.RegisterCell("Sequenced", sequenced);
        }
Example #2
0
        public static void Init(IokeObject obj)
        {
            Runtime runtime = obj.runtime;

            obj.Kind = "Mixins";

            obj.SetCell("=", runtime.Base.body.Get("="));
            obj.SetCell("==", runtime.Base.body.Get("=="));
            obj.SetCell("cell", runtime.Base.body.Get("cell"));
            obj.SetCell("cell=", runtime.Base.body.Get("cell="));
            obj.SetCell("cell?", runtime.Base.body.Get("cell?"));
            obj.SetCell("cells", runtime.Base.body.Get("cells"));
            obj.SetCell("cellNames", runtime.Base.body.Get("cellNames"));
            obj.SetCell("mimic", runtime.Base.body.Get("mimic"));

            IokeObject comparing = new IokeObject(obj.runtime, "allows different objects to be compared, based on the spaceship operator being available");

            comparing.MimicsWithoutCheck(obj);
            Comparing.Init(comparing);
            obj.RegisterCell("Comparing", comparing);

            IokeObject enumerable = new IokeObject(obj.runtime, "adds lots of helpful methods that can be done on enumerable methods. based on the 'each' method being available on the self.");

            enumerable.MimicsWithoutCheck(obj);
            Enumerable.Init(enumerable);
            obj.RegisterCell("Enumerable", enumerable);

            IokeObject sequenced = new IokeObject(obj.runtime, "something that is sequenced can return a Sequence over itself. it also allows several other methods to be defined in terms of that sequence. A Sequenced object is Enumerable, since all Enumerable operations can be defined in terms of sequencing.");

            sequenced.MimicsWithoutCheck(obj);
            sequenced.MimicsWithoutCheck(enumerable);
            Sequenced.Init(sequenced);
            obj.RegisterCell("Sequenced", sequenced);
        }
Example #3
0
        public static void Init(IokeObject bm)
        {
            Runtime runtime = bm.runtime;

            bm.Kind = "Benchmark";
            runtime.Ground.SetCell("Benchmark", bm);
            bm.MimicsWithoutCheck(runtime.Origin);

            bm.RegisterMethod(runtime.NewNativeMethod("expects two optional numbers, x (default 10) and y (default 1), and a block of code to run, and will run benchmark this block x times, while looping y times in each benchmark. after each loop will print the timings for this loop",
                                                      new NativeMethod("report", DefaultArgumentsDefinition.builder()
                                                                       .WithOptionalPositional("repetitions", "10")
                                                                       .WithOptionalPositional("loops", "1")
                                                                       .WithRequiredPositionalUnevaluated("code")
                                                                       .Arguments,
                                                                       (method, context, message, on, outer) => {
                outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
                int count       = message.Arguments.Count;
                int bmRounds    = 10;
                long iterations = 1;
                int index       = 0;
                if (count > 1)
                {
                    bmRounds = ((Number)IokeObject.dataOf(IokeObject.ConvertToNumber(Interpreter.GetEvaluatedArgument(message, index, context), message, context))).AsNativeInteger();
                    index++;
                    if (count > 2)
                    {
                        iterations = ((Number)IokeObject.dataOf(IokeObject.ConvertToNumber(Interpreter.GetEvaluatedArgument(message, index, context), message, context))).AsNativeLong();
                        index++;
                    }
                }

                for (int i = 0; i < bmRounds; i++)
                {
                    long before = System.DateTime.Now.Ticks;
                    for (int j = 0; j < iterations; j++)
                    {
                        Interpreter.GetEvaluatedArgument(message, index, context);
                    }
                    long after = System.DateTime.Now.Ticks;
                    long time  = after - before;
                    long secs  = time / 10000000;
                    long rest  = time % 10000000;

                    string theCode = Message.ThisCode(((IokeObject)message.Arguments[index]));

                    Interpreter.Send(context.runtime.printlnMessage, context, Interpreter.Send(context.runtime.outMessage, context, context.runtime.System), context.runtime.NewText(string.Format("{0,-32} {1:d6}.{2:d9}", theCode, secs, rest)));
                }

                return(context.runtime.nil);
            })));
        }
Example #4
0
File: Mixins.cs Project: fronx/ioke
        public static void Init(IokeObject obj)
        {
            Runtime runtime = obj.runtime;
            obj.Kind = "Mixins";

            obj.SetCell("=",         runtime.Base.Cells["="]);
            obj.SetCell("==",        runtime.Base.Cells["=="]);
            obj.SetCell("cell",      runtime.Base.Cells["cell"]);
            obj.SetCell("cell=",     runtime.Base.Cells["cell="]);
            obj.SetCell("cell?",     runtime.Base.Cells["cell?"]);
            obj.SetCell("cells",     runtime.Base.Cells["cells"]);
            obj.SetCell("cellNames", runtime.Base.Cells["cellNames"]);
            obj.SetCell("mimic",     runtime.Base.Cells["mimic"]);

            IokeObject comparing = new IokeObject(obj.runtime, "allows different objects to be compared, based on the spaceship operator being available");
            comparing.MimicsWithoutCheck(obj);
            Comparing.Init(comparing);
            obj.RegisterCell("Comparing", comparing);

            IokeObject enumerable = new IokeObject(obj.runtime, "adds lots of helpful methods that can be done on enumerable methods. based on the 'each' method being available on the self.");
            enumerable.MimicsWithoutCheck(obj);
            Enumerable.Init(enumerable);
            obj.RegisterCell("Enumerable", enumerable);
        }
Example #5
0
        public static void Init(IokeObject rl)
        {
            Runtime runtime = rl.runtime;
            rl.Kind = "Readline";
            rl.MimicsWithoutCheck(runtime.Origin);
            runtime.Ground.SetCell("Readline", rl);
            rl.SetCell("VERSION", runtime.NewText("Mono.Terminal.LineEditor wrapper"));

            ConsoleHolder holder = new ConsoleHolder();
            holder.history = new History("ioke", 10);

            IokeObject history = runtime.NewFromOrigin();
            rl.SetCell("HISTORY", history);

            rl.RegisterMethod(runtime.NewNativeMethod("will print a prompt to standard out and then try to read a line with working readline functionality. takes two arguments, the first is the string to prompt, the second is a boolean that says whether we should add the read string to history or not",
                                                      new NativeMethod("readline", DefaultArgumentsDefinition.builder()
                                                                       .WithRequiredPositional("prompt")
                                                                       .WithRequiredPositional("addToHistory?")
                                                                       .Arguments,
                                                                       (method, context, message, on, outer) => {
                                                                           var args = new SaneArrayList();
                                                                           outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
                                                                           object line = method.runtime.nil;
                                                                           try {
                                                                               if(holder.readline == null) {
                                                                                   InitReadline(method.runtime, holder);
                                                                               }
                                                                               string v = holder.readline.Edit(Text.GetText(args[0]), "");
                                                                               if(null != v) {
                                                                                   if(IokeObject.IsObjectTrue(args[1])) {
                                                                                       holder.history.Append(v);
                                                                                   }

                                                                                   line = method.runtime.NewText(v);
                                                                               }
                                                                           } catch(IOException e) {
                                                                               IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition,
                                                                                                                                            message,
                                                                                                                                            context,
                                                                                                                                            "Error",
                                                                                                                                            "IO"), context).Mimic(message, context);
                                                                               condition.SetCell("message", message);
                                                                               condition.SetCell("context", context);
                                                                               condition.SetCell("receiver", on);
                                                                               condition.SetCell("exceptionMessage", runtime.NewText(e.Message));
                                                                               var st = new System.Diagnostics.StackTrace(e);
                                                                               var ob = new SaneArrayList();
                                                                               foreach(var frame in st.GetFrames()) {
                                                                                   ob.Add(runtime.NewText(frame.ToString()));
                                                                               }
                                                                               condition.SetCell("exceptionStackTrace", runtime.NewList(ob));

                                                                               runtime.WithReturningRestart("ignore", context, ()=>{runtime.ErrorCondition(condition);});
                                                                           }
                                                                           return line;
                                                                       })));

            history.RegisterMethod(runtime.NewNativeMethod("will add a new line to the history",
                                                           new NativeMethod("<<", DefaultArgumentsDefinition.builder()
                                                                            .WithRequiredPositional("line")
                                                                            .Arguments,
                                                                            (method, context, message, on, outer) => {
                                                                                var args = new SaneArrayList();
                                                                                outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
                                                                                foreach(object o in args) {
                                                                                    holder.history.Append(Text.GetText(o));
                                                                                }
                                                                                return context.runtime.nil;
                                                                            })));
        }
Example #6
0
        public static void Init(IokeObject rl)
        {
            Runtime runtime = rl.runtime;

            rl.Kind = "Readline";
            rl.MimicsWithoutCheck(runtime.Origin);
            runtime.Ground.SetCell("Readline", rl);
            rl.SetCell("VERSION", runtime.NewText("Mono.Terminal.LineEditor wrapper"));

            ConsoleHolder holder = new ConsoleHolder();

            holder.history = new History("ioke", 10);

            IokeObject history = runtime.NewFromOrigin();

            rl.SetCell("HISTORY", history);

            rl.RegisterMethod(runtime.NewNativeMethod("will print a prompt to standard out and then try to read a line with working readline functionality. takes two arguments, the first is the string to prompt, the second is a boolean that says whether we should add the read string to history or not",
                                                      new NativeMethod("readline", DefaultArgumentsDefinition.builder()
                                                                       .WithRequiredPositional("prompt")
                                                                       .WithRequiredPositional("addToHistory?")
                                                                       .Arguments,
                                                                       (method, context, message, on, outer) => {
                var args = new SaneArrayList();
                outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary <string, object>());
                object line = method.runtime.nil;
                try {
                    if (holder.readline == null)
                    {
                        InitReadline(method.runtime, holder);
                    }
                    string v = holder.readline.Edit(Text.GetText(args[0]), "");
                    if (null != v)
                    {
                        if (IokeObject.IsObjectTrue(args[1]))
                        {
                            holder.history.Append(v);
                        }

                        line = method.runtime.NewText(v);
                    }
                } catch (IOException e) {
                    IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition,
                                                                                 message,
                                                                                 context,
                                                                                 "Error",
                                                                                 "IO"), context).Mimic(message, context);
                    condition.SetCell("message", message);
                    condition.SetCell("context", context);
                    condition.SetCell("receiver", on);
                    condition.SetCell("exceptionMessage", runtime.NewText(e.Message));
                    var st = new System.Diagnostics.StackTrace(e);
                    var ob = new SaneArrayList();
                    foreach (var frame in st.GetFrames())
                    {
                        ob.Add(runtime.NewText(frame.ToString()));
                    }
                    condition.SetCell("exceptionStackTrace", runtime.NewList(ob));

                    runtime.WithReturningRestart("ignore", context, () => { runtime.ErrorCondition(condition); });
                }
                return(line);
            })));

            history.RegisterMethod(runtime.NewNativeMethod("will add a new line to the history",
                                                           new NativeMethod("<<", DefaultArgumentsDefinition.builder()
                                                                            .WithRequiredPositional("line")
                                                                            .Arguments,
                                                                            (method, context, message, on, outer) => {
                var args = new SaneArrayList();
                outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary <string, object>());
                foreach (object o in args)
                {
                    holder.history.Append(Text.GetText(o));
                }
                return(context.runtime.nil);
            })));
        }