Example #1
0
 public static new object ActivateFixed(IokeObject self, IokeObject ctx, IokeObject message, object obj)
 {
     AliasMethod am = (AliasMethod)self.data;
     IokeObject realSelf = am.realSelf;
     switch(am.realMethod.type) {
     case IokeData.TYPE_DEFAULT_METHOD:
         return DefaultMethod.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_DEFAULT_MACRO:
         return DefaultMacro.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_DEFAULT_SYNTAX:
         return DefaultSyntax.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_LEXICAL_MACRO:
         return LexicalMacro.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_NATIVE_METHOD:
         return NativeMethod.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_METHOD_PROTOTYPE:
         return Method.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_LEXICAL_BLOCK:
         return LexicalBlock.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_ALIAS_METHOD:
         return AliasMethod.ActivateFixed(realSelf, ctx, message, obj);
     case IokeData.TYPE_NONE:
     default:
         return IokeData.ActivateFixed(realSelf, ctx, message, obj);
     }
 }
Example #2
0
 public AliasMethod(string name, IokeData realMethod, IokeObject realSelf)
     : base(IokeData.TYPE_ALIAS_METHOD)
 {
     this.name = name;
     this.realMethod = realMethod;
     this.realSelf = realSelf;
 }
Example #3
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 #4
0
 public object ConvertToMimic(object on, IokeObject message, IokeObject context, bool signal)
 {
     object firstResult = first.ConvertToMimic(on, message, context, false);
     if(firstResult == context.runtime.nul) {
         return second.ConvertToMimic(on, message, context, signal);
     } else {
         return firstResult;
     }
 }
Example #5
0
 public object ConvertToMimic(object on, IokeObject message, IokeObject context, bool signal)
 {
     if(on == context.runtime.nil) {
         return on;
     } else if(signal) {
         return context.runtime.nil.ConvertToThis(on, message, context);
     } else {
         return context.runtime.nul;
     }
 }
Example #6
0
        private static void ReplaceAllCaseNames(IokeObject when, IokeObject context, IokeObject message, IokeObject caseMimic)
        {
            string theName = "case:" + Message.GetName(when);
            if(caseMimic.Cells.ContainsKey(theName)) {
                Message.SetName(when, theName);

                foreach(object arg in when.Arguments) {
                    ReplaceAllCaseNames(IokeObject.As(arg, context), context, message, caseMimic);
                }
            }
        }
Example #7
0
File: Symbol.cs Project: fronx/ioke
 public override void CheckMimic(IokeObject obj, IokeObject m, IokeObject context)
 {
     IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
                                                                  m,
                                                                  context,
                                                                  "Error",
                                                                  "CantMimicOddball"), context).Mimic(m, context);
     condition.SetCell("message", m);
     condition.SetCell("context", context);
     condition.SetCell("receiver", obj);
     context.runtime.ErrorCondition(condition);
 }
Example #8
0
        public static IokeObject TransformWhenStatement(object when, IokeObject context, IokeObject message, IokeObject caseMimic)
        {
            string outerName = Message.GetName(when);

            if(caseMimic.Cells.ContainsKey("case:" + outerName)) {
                IokeObject cp = Message.DeepCopy(when);
                ReplaceAllCaseNames(cp, context, message, caseMimic);
                return cp;
            }

            return IokeObject.As(when, context);
        }
Example #9
0
        public override void Init(IokeObject obj)
        {
            obj.Kind = "Symbol";

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns true if the left hand side symbol is equal to the right hand side symbol.",
                                                       new TypeCheckingNativeMethod("==", TypeCheckingArgumentsDefinition.builder()
                                                                                    .ReceiverMustMimic(obj.runtime.Symbol)
                                                                                    .WithRequiredPositional("other")
                                                                                    .Arguments,
                                                                                    (method, on, args, keywords, context, message) => {
                                                                                        object other = args[0];
                                                                                        return on == other ? context.runtime.True : context.runtime.False;
                                                                                    })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a text representation of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("asText", obj,
                                                                                                        (method, on, args, keywords, context, message) => {
                                                                                                            return method.runtime.NewText(Symbol.GetText(on));
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a text inspection of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("inspect", obj,
                                                                                                        (method, on, args, keywords, context, message) => {
                                                                                                            return method.runtime.NewText(Symbol.GetInspect(on));
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a brief text inspection of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("notice", obj,
                                                                                                        (method, on, args, keywords, context, message) => {
                                                                                                            return method.runtime.NewText(Symbol.GetInspect(on));
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("compares this symbol against the argument, returning -1, 0 or 1 based on which one is lexically larger",
                                                           new TypeCheckingNativeMethod ("<=>", TypeCheckingArgumentsDefinition.builder()
                                                                                         .ReceiverMustMimic(obj)
                                                                                         .WithRequiredPositional("other")
                                                                                         .Arguments,
                                                                                         (method, on, args, keywords, context, message) => {
                                                                                                 object arg = args[0];

                                                                                                 if(!(IokeObject.dataOf(arg) is Symbol)) {
                                                                                                     arg = IokeObject.ConvertToSymbol(arg, message, context, false);
                                                                                                     if(!(IokeObject.dataOf(arg) is Symbol)) {
                                                                                                         // Can't compare, so bail out
                                                                                                         return context.runtime.nil;
                                                                                                     }
                                                                                                 }
                                                                                                 return context.runtime.NewNumber(string.CompareOrdinal(Symbol.GetText(on), Symbol.GetText(arg)));
                                                                                             })));
        }
Example #10
0
        public static void Init(IokeObject obj)
        {
            Runtime runtime = obj.runtime;
            obj.Kind = "Origin";

            obj.RegisterMethod(runtime.NewNativeMethod("Prints a text representation and a newline to standard output", new NativeMethod.WithNoArguments("println", (method, context, message, on, outer) => {
                            Interpreter.Send(runtime.printlnMessage, context, Interpreter.Send(runtime.outMessage, context, runtime.System), on);
                            return runtime.nil;
                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("Prints a text representation to standard output", new NativeMethod.WithNoArguments("print", (method, context, message, on, outer) => {
                            Interpreter.Send(runtime.printMessage, context, Interpreter.Send(runtime.outMessage, context, runtime.System), on);
                            return runtime.nil;
                        })));
        }
Example #11
0
File: Method.cs Project: fronx/ioke
        public override object Activate(IokeObject self, IokeObject context, IokeObject message, object on)
        {
            IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
                                                                         message,
                                                                         context,
                                                                         "Error",
                                                                         "Invocation",
                                                                         "NotActivatable"), context).Mimic(message, context);
            condition.SetCell("message", message);
            condition.SetCell("context", context);
            condition.SetCell("receiver", on);
            condition.SetCell("method", self);
            condition.SetCell("report", context.runtime.NewText("You tried to activate a method without any code - did you by any chance activate the Method kind by referring to it without wrapping it inside a call to cell?"));
            context.runtime.ErrorCondition(condition);

            return self.runtime.nil;
        }
Example #12
0
File: Method.cs Project: fronx/ioke
        public override void Init(IokeObject obj)
        {
            obj.Kind = "Method";
            obj.RegisterCell("activatable", obj.runtime.True);

            obj.RegisterMethod(obj.runtime.NewNativeMethod("activates this method with the arguments given to call",
                                                           new NativeMethod("call", DefaultArgumentsDefinition.builder()
                                                                            .WithRestUnevaluated("arguments")
                                                                            .Arguments,
                                                                            (method, _context, message, on, outer) => {
                                                                                return IokeObject.As(on, _context).Activate(_context, message, _context.RealContext);
                                                                            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the name of the method",
                                                           new TypeCheckingNativeMethod.WithNoArguments("name", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                                                                                                            return _context.runtime.NewText(((Method)IokeObject.dataOf(on)).name);
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a text inspection of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("inspect", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                                                                                                            return _context.runtime.NewText(Method.GetInspect(on));
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a brief text inspection of the object",
                                                           new TypeCheckingNativeMethod.WithNoArguments("notice", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                                                                                                            return _context.runtime.NewText(Method.GetNotice(on));
                                                                                                        })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the full code of this method, as a Text",
                                                           new TypeCheckingNativeMethod.WithNoArguments("code", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                                                                                                            IokeData data = IokeObject.dataOf(on);
                                                                                                            if(data is Method) {
                                                                                                                return _context.runtime.NewText(((Method)data).CodeString);
                                                                                                            } else {
                                                                                                                return _context.runtime.NewText(((AliasMethod)data).CodeString);
                                                                                                            }
                                                                                                        })));
        }
Example #13
0
        public static void Init(IokeObject obj)
        {
            obj.Kind = "DefaultBehavior Case";

            obj.RegisterMethod(obj.runtime.NewNativeMethod("takes one argument that should evaluate to a value, zero or more whenAndThen pairs and one optional else clause. will first evaluate the initial value, then check each whenAndThen pair against this value. if the when part of a pair returns true, then return the result of evaluating the then part. if no pair matches and no else clause is present, returns nil. if an else clause is there, it should be the last one. each whenAndThen pair is comprised of two arguments, where the first is the when argument and the second is the then argument. the when part will be evaluated and the result of this evaluation will be sent a === message with the value as argument.",
                                                           new NativeMethod("case", DefaultArgumentsDefinition.builder()
                                                                            .WithRequiredPositional("value")
                                                                            .WithRestUnevaluated("whensAndThens")
                                                                            .WithOptionalPositionalUnevaluated("elseCode")
                                                                            .Arguments,
                                                                            (method, context, message, on, outer) => {
                                                                                outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
                                                                                Runtime runtime = context.runtime;

                                                                                var args = message.Arguments;
                                                                                int argCount = args.Count;
                                                                                int index = 0;
                                                                                IokeObject msg = IokeObject.As(args[index++], context);
                                                                                object value = ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
                                                                                argCount--;

                                                                                while(argCount > 1) {
                                                                                    msg = TransformWhenStatement(args[index++], context, message, obj);
                                                                                    object when = ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
                                                                                    if(IokeObject.IsObjectTrue(((Message)IokeObject.dataOf(runtime.eqqMessage)).SendTo(runtime.eqqMessage, context, when, value))) {
                                                                                        msg = IokeObject.As(args[index++], context);
                                                                                        return ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
                                                                                    } else {
                                                                                        index++;
                                                                                    }
                                                                                    argCount -= 2;
                                                                                }

                                                                                if(argCount == 1) {
                                                                                    msg = IokeObject.As(args[index++], context);
                                                                                    return ((Message)IokeObject.dataOf(msg)).EvaluateCompleteWithoutExplicitReceiver(msg, context, context.RealContext);
                                                                                }

                                                                                return runtime.nil;
                                                                            })));
        }
Example #14
0
        public static void Init(IokeObject obj)
        {
            obj.Kind = "Condition";

            IokeObject conditionDefault = obj.Mimic(null, null);
            conditionDefault.Kind = "Condition Default";
            obj.SetCell("Default", conditionDefault);

            IokeObject conditionWarning = obj.Mimic(null, null);
            conditionWarning.Kind = "Condition Warning";
            obj.SetCell("Warning", conditionWarning);

            IokeObject conditionWarningDefault = conditionWarning.Mimic(null, null);
            conditionWarningDefault.Kind = "Condition Warning Default";
            conditionWarning.SetCell("Default", conditionWarningDefault);

            IokeObject conditionError = obj.Mimic(null, null);
            conditionError.Kind = "Condition Error";
            obj.SetCell("Error", conditionError);

            IokeObject conditionErrorDefault = conditionError.Mimic(null, null);
            conditionErrorDefault.Kind = "Condition Error Default";
            conditionError.SetCell("Default", conditionErrorDefault);
        }
Example #15
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 #16
0
File: Symbol.cs Project: fronx/ioke
 public override string ToString(IokeObject obj)
 {
     return text;
 }
Example #17
0
 public static void Init(IokeObject obj)
 {
     obj.Kind = "Mixins Sequenced";
 }
Example #18
0
 public override IokeObject TryConvertToText(IokeObject self, IokeObject m, IokeObject context)
 {
     return(self.runtime.NewText(GetText()));
 }
Example #19
0
 public static void Init(IokeObject obj)
 {
     obj.Kind = "Mixins Enumerable";
 }
Example #20
0
 public override string ToString(IokeObject obj)
 {
     return(text);
 }
Example #21
0
        private void ParseText(int indicator)
        {
            StringBuilder sb     = new StringBuilder();
            bool          dquote = indicator == '"';

            int l = lineNumber; int cc = currentCharacter - 1;

            if (!dquote)
            {
                Read();
            }

            int       rr;
            string    name = "internal:createText";
            ArrayList args = new SaneArrayList();

            while (true)
            {
                switch (rr = Peek())
                {
                case -1:
                    Fail("Expected end of text, found EOF");
                    break;

                case '"':
                    Read();
                    if (dquote)
                    {
                        args.Add(sb.ToString());
                        Message m = new Message(runtime, "internal:createText");
                        m.Line     = l;
                        m.Position = cc;
                        IokeObject mm = runtime.CreateMessage(m);
                        if (!name.Equals("internal:createText"))
                        {
                            for (int i = 0; i < args.Count; i++)
                            {
                                object o = args[i];
                                if (o is string)
                                {
                                    Message mx = new Message(runtime, "internal:createText", o);
                                    mx.Line     = l;
                                    mx.Position = cc;
                                    IokeObject mmx = runtime.CreateMessage(mx);
                                    args[i] = mmx;
                                }
                            }
                            Message.SetName(mm, name);
                        }
                        Message.SetArguments(mm, args);
                        top.Add(mm);
                        return;
                    }
                    else
                    {
                        sb.Append((char)rr);
                    }
                    break;

                case ']':
                    Read();
                    if (!dquote)
                    {
                        args.Add(sb.ToString());
                        Message m = new Message(runtime, "internal:createText");
                        m.Line     = l;
                        m.Position = cc;
                        IokeObject mm = runtime.CreateMessage(m);
                        if (!name.Equals("internal:createText"))
                        {
                            for (int i = 0; i < args.Count; i++)
                            {
                                object o = args[i];
                                if (o is string)
                                {
                                    Message mx = new Message(runtime, "internal:createText", o);
                                    mx.Line     = l;
                                    mx.Position = cc;
                                    IokeObject mmx = runtime.CreateMessage(mx);
                                    args[i] = mmx;
                                }
                            }
                            Message.SetName(mm, name);
                        }
                        Message.SetArguments(mm, args);
                        top.Add(mm);
                        return;
                    }
                    else
                    {
                        sb.Append((char)rr);
                    }
                    break;

                case '#':
                    Read();
                    if ((rr = Peek()) == '{')
                    {
                        Read();
                        args.Add(sb.ToString());
                        sb   = new StringBuilder();
                        name = "internal:concatenateText";
                        args.Add(ParseMessageChain());
                        ReadWhiteSpace();
                        ParseCharacter('}');
                    }
                    else
                    {
                        sb.Append((char)'#');
                    }
                    break;

                case '\\':
                    Read();
                    ParseDoubleQuoteEscape(sb);
                    break;

                default:
                    Read();
                    sb.Append((char)rr);
                    break;
                }
            }
        }
Example #22
0
File: Symbol.cs Project: fronx/ioke
 public override IokeObject ConvertToSymbol(IokeObject self, IokeObject m, IokeObject context, bool signalCondition)
 {
     return self;
 }
Example #23
0
File: Method.cs Project: fronx/ioke
 public Method(IokeObject context)
     : this((string)null)
 {
 }
Example #24
0
        public IokeObject ParseFully()
        {
            IokeObject result = ParseMessageChain();

            return(result);
        }
Example #25
0
        public static void Init(IokeObject obj)
        {
            Runtime runtime = obj.runtime;
            obj.Kind = "DefaultBehavior Assignment";

            obj.RegisterMethod(runtime.NewNativeMethod("expects one argument, which is the unevaluated name of the cell to work on. will retrieve the current value of this cell, call 'succ' to that value and then send = to the current receiver with the name and the resulting value.",
                                                       new NativeMethod("++", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
                                                                            IokeObject nameMessage = (IokeObject)(Message.GetArguments(message)[0]);
                                                                            string name = nameMessage.Name;
                                                                            object current = IokeObject.As(on, context).Perform(context, message, name);
                                                                            object value = ((Message)IokeObject.dataOf(runtime.succMessage)).SendTo(runtime.succMessage, context, current);
                                                                            return ((Message)IokeObject.dataOf(runtime.setValueMessage)).SendTo(runtime.setValueMessage, context, on, nameMessage, value);
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects one argument, which is the unevaluated name of the cell to work on. will retrieve the current value of this cell, call 'pred' to that value and then send = to the current receiver with the name and the resulting value.",
                                                       new NativeMethod("--", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
                                                                            IokeObject nameMessage = (IokeObject)(Message.GetArguments(message)[0]);
                                                                            string name = nameMessage.Name;
                                                                            object current = IokeObject.As(on, context).Perform(context, message, name);
                                                                            object value = ((Message)IokeObject.dataOf(runtime.predMessage)).SendTo(runtime.predMessage, context, current);
                                                                            return ((Message)IokeObject.dataOf(runtime.setValueMessage)).SendTo(runtime.setValueMessage, context, on, nameMessage, value);
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. if that cell doesn't exist or the value it contains is not true, that cell will be set to the second argument, otherwise nothing will happen. the second argument will NOT be evaluated if the place is not assigned. the result of the expression is the value of the cell. it will use = for this assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("||=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("else")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.FindCell(on, message, context, name);
                                                                                if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
                                                                                    return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
                                                                                } else {
                                                                                    return val;
                                                                                }
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
                                                                                    return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
                                                                                } else {
                                                                                    return val;
                                                                                }
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. if that cell exist and the value it contains is a true one, that cell will be set to the second argument, otherwise nothing will happen. the second argument will NOT be evaluated if the place is not assigned. the result of the expression is the value of the cell. it will use = for this assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("&&=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("then")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.FindCell(on, message, context, name);
                                                                                if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
                                                                                    return val;
                                                                                } else {
                                                                                    return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
                                                                                }
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                if(val == context.runtime.nul || !IokeObject.IsObjectTrue(val)) {
                                                                                    return val;
                                                                                } else {
                                                                                    return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, Message.GetArguments(message)[1]);
                                                                                }
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the + method will be called on it. finally, the result of the call to + will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("+=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("addend")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.plusMessage)).SendTo(context.runtime.plusMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.plusMessage)).SendTo(context.runtime.plusMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the - method will be called on it. finally, the result of the call to - will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("-=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("subtrahend")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.minusMessage)).SendTo(context.runtime.minusMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.minusMessage)).SendTo(context.runtime.minusMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the * method will be called on it. finally, the result of the call to * will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("*=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("multiplier")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.multMessage)).SendTo(context.runtime.multMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.multMessage)).SendTo(context.runtime.multMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the / method will be called on it. finally, the result of the call to / will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("/=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("divisor")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.divMessage)).SendTo(context.runtime.divMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.divMessage)).SendTo(context.runtime.divMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the % method will be called on it. finally, the result of the call to % will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("%=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("divisor")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.modMessage)).SendTo(context.runtime.modMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.modMessage)).SendTo(context.runtime.modMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the ** method will be called on it. finally, the result of the call to ** will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("**=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("exponent")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.expMessage)).SendTo(context.runtime.expMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.expMessage)).SendTo(context.runtime.expMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the & method will be called on it. finally, the result of the call to & will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("&=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("other")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.binAndMessage)).SendTo(context.runtime.binAndMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.binAndMessage)).SendTo(context.runtime.binAndMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the | method will be called on it. finally, the result of the call to | will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("|=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("other")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.binOrMessage)).SendTo(context.runtime.binOrMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.binOrMessage)).SendTo(context.runtime.binOrMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the ^ method will be called on it. finally, the result of the call to ^ will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("^=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("other")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.binXorMessage)).SendTo(context.runtime.binXorMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.binXorMessage)).SendTo(context.runtime.binXorMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the << method will be called on it. finally, the result of the call to << will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod("<<=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("other")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.lshMessage)).SendTo(context.runtime.lshMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.lshMessage)).SendTo(context.runtime.lshMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));

            obj.RegisterMethod(runtime.NewNativeMethod("expects two arguments, the first unevaluated, the second evaluated. the first argument should be the name of a cell. the value of that cell will be retreived and then the >> method will be called on it. finally, the result of the call to >> will be assigned to the same name in the current scope. it will use = for this assignment. the result of the expression is the same as the result of the assignment. this method also work together with forms such as []=.",
                                                       new NativeMethod(">>=", DefaultArgumentsDefinition.builder()
                                                                        .WithRequiredPositionalUnevaluated("place")
                                                                        .WithRequiredPositional("other")
                                                                        .Arguments,
                                                                        (method, context, message, on, outer) => {
                                                                            outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);

                                                                            IokeObject m1 = IokeObject.As(Message.GetArguments(message)[0], context);
                                                                            string name = m1.Name;

                                                                            if(m1.Arguments.Count == 0) {
                                                                                object val = IokeObject.GetCell(on, message, context, name);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.rshMessage)).SendTo(context.runtime.rshMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            } else {
                                                                                object val = ((Message)IokeObject.dataOf(m1)).SendTo(m1, context, on);
                                                                                object result = ((Message)IokeObject.dataOf(context.runtime.rshMessage)).SendTo(context.runtime.rshMessage, context, val, Message.GetArguments(message)[1]);
                                                                                return ((Message)IokeObject.dataOf(context.runtime.setValueMessage)).SendTo(context.runtime.setValueMessage, context, on, m1, context.runtime.CreateMessage(Message.Wrap(IokeObject.As(result, context))));
                                                                            }
                                                                        })));
        }
Example #26
0
 public static IokeObject Create(Runtime runtime)
 {
     IokeObject rl = new IokeObject(runtime, "Readline is a module allows access to the readline native functionality");
     Readline.Init(rl);
     return rl;
 }
Example #27
0
 public static void Init(IokeObject obj)
 {
     obj.Kind = "Handler";
 }
Example #28
0
 public override object Activate(IokeObject self, IokeObject context, IokeObject message, object on)
 {
     return realMethod.Activate(realSelf, context, message, on);
 }
Example #29
0
File: Symbol.cs Project: fronx/ioke
 public override IokeObject TryConvertToText(IokeObject self, IokeObject m, IokeObject context)
 {
     return self.runtime.NewText(GetText());
 }
Example #30
0
 public override IokeObject ConvertToText(IokeObject self, IokeObject m, IokeObject context, bool signalCondition)
 {
     return(self.runtime.NewText(GetText()));
 }
Example #31
0
 public object ConvertToMimic(object on, IokeObject message, IokeObject context, bool signal)
 {
     return on;
 }
Example #32
0
File: Symbol.cs Project: fronx/ioke
 public override IokeObject ConvertToText(IokeObject self, IokeObject m, IokeObject context, bool signalCondition)
 {
     return self.runtime.NewText(GetText());
 }
Example #33
0
 public static string GetInspect(object on)
 {
     return(((Symbol)(IokeObject.dataOf(on))).Inspect(on));
 }
Example #34
0
        private void ParseRegexpLiteral(int indicator)
        {
            StringBuilder sb    = new StringBuilder();
            bool          slash = indicator == '/';

            int l = lineNumber; int cc = currentCharacter - 1;

            Read();

            if (!slash)
            {
                ParseCharacter('[');
            }

            int       rr;
            string    name = "internal:createRegexp";
            ArrayList args = new SaneArrayList();

            while (true)
            {
                switch (rr = Peek())
                {
                case -1:
                    Fail("Expected end of regular expression, found EOF");
                    break;

                case '/':
                    Read();
                    if (slash)
                    {
                        args.Add(sb.ToString());
                        Message m = new Message(runtime, "internal:createRegexp");
                        m.Line     = l;
                        m.Position = cc;
                        IokeObject mm = runtime.CreateMessage(m);
                        if (!name.Equals("internal:createRegexp"))
                        {
                            Message.SetName(mm, name);
                        }
                        Message.SetArguments(mm, args);

                        sb = new StringBuilder();
                        while (true)
                        {
                            switch (rr = Peek())
                            {
                            case 'x': goto case 's';

                            case 'i': goto case 's';

                            case 'u': goto case 's';

                            case 'm': goto case 's';

                            case 's':
                                Read();
                                sb.Append((char)rr);
                                break;

                            default:
                                args.Add(sb.ToString());
                                top.Add(mm);
                                return;
                            }
                        }
                    }
                    else
                    {
                        sb.Append((char)rr);
                    }
                    break;

                case ']':
                    Read();
                    if (!slash)
                    {
                        args.Add(sb.ToString());
                        Message m = new Message(runtime, "internal:createRegexp");
                        m.Line     = l;
                        m.Position = cc;
                        IokeObject mm = runtime.CreateMessage(m);
                        if (!name.Equals("internal:createRegexp"))
                        {
                            Message.SetName(mm, name);
                        }
                        Message.SetArguments(mm, args);
                        sb = new StringBuilder();
                        while (true)
                        {
                            switch (rr = Peek())
                            {
                            case 'x': goto case 's';

                            case 'i': goto case 's';

                            case 'u': goto case 's';

                            case 'm': goto case 's';

                            case 's':
                                Read();
                                sb.Append((char)rr);
                                break;

                            default:
                                args.Add(sb.ToString());
                                top.Add(mm);
                                return;
                            }
                        }
                    }
                    else
                    {
                        sb.Append((char)rr);
                    }
                    break;

                case '#':
                    Read();
                    if ((rr = Peek()) == '{')
                    {
                        Read();
                        args.Add(sb.ToString());
                        sb   = new StringBuilder();
                        name = "internal:compositeRegexp";
                        args.Add(ParseMessageChain());
                        ReadWhiteSpace();
                        ParseCharacter('}');
                    }
                    else
                    {
                        sb.Append((char)'#');
                    }
                    break;

                case '\\':
                    Read();
                    ParseRegexpEscape(sb);
                    break;

                default:
                    Read();
                    sb.Append((char)rr);
                    break;
                }
            }
        }
Example #35
0
 public static string GetText(object on)
 {
     return(((Symbol)(IokeObject.dataOf(on))).GetText());
 }
Example #36
0
        private void PossibleOperator(IokeObject mx)
        {
            string name = Message.GetName(mx);

            if (IsUnary(name) || onlyUnaryOperators.Contains(name))
            {
                top.Add(mx);
                top.Push(-1, mx, Level.Type.UNARY);
                return;
            }

            if (operatorTable.ContainsKey(name))
            {
                var op = operatorTable[name];
                top.PopOperatorsTo(op.precedence);
                top.Add(mx);
                top.Push(op.precedence, mx, Level.Type.REGULAR);
            }
            else
            {
                if (trinaryOperatorTable.ContainsKey(name))
                {
                    var opa = trinaryOperatorTable[name];
                    if (opa.arity == 2)
                    {
                        IokeObject last = top.PrepareAssignmentMessage();
                        mx.Arguments.Add(last);
                        top.Add(mx);
                        top.Push(13, mx, Level.Type.ASSIGNMENT);
                    }
                    else
                    {
                        IokeObject last = top.PrepareAssignmentMessage();
                        mx.Arguments.Add(last);
                        top.Add(mx);
                    }
                }
                else
                {
                    if (invertedOperatorTable.ContainsKey(name))
                    {
                        var op = invertedOperatorTable[name];
                        top.PopOperatorsTo(op.precedence);
                        top.Add(mx);
                        top.Push(op.precedence, mx, Level.Type.INVERTED);
                    }
                    else
                    {
                        int possible = PossibleOperatorPrecedence(name);
                        if (possible != -1)
                        {
                            top.PopOperatorsTo(possible);
                            top.Add(mx);
                            top.Push(possible, mx, Level.Type.REGULAR);
                        }
                        else
                        {
                            top.Add(mx);
                        }
                    }
                }
            }
        }
Example #37
0
 public static void Init(IokeObject obj)
 {
     obj.Kind = "Mixins Comparing";
 }
Example #38
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 #39
0
 public override IokeObject ConvertToSymbol(IokeObject self, IokeObject m, IokeObject context, bool signalCondition)
 {
     return(self);
 }
Example #40
0
 public Method(IokeObject context, int type)
     : this((string)null, type)
 {
 }
Example #41
0
        private void ParseOperatorChars(int indicator)
        {
            int l = lineNumber; int cc = currentCharacter - 1;

            StringBuilder sb = new StringBuilder();

            sb.Append((char)indicator);
            int rr;

            while (true)
            {
                rr = Peek();
                switch (rr)
                {
                case '+': goto case '#';

                case '-': goto case '#';

                case '*': goto case '#';

                case '%': goto case '#';

                case '<': goto case '#';

                case '>': goto case '#';

                case '!': goto case '#';

                case '?': goto case '#';

                case '~': goto case '#';

                case '&': goto case '#';

                case '|': goto case '#';

                case '^': goto case '#';

                case '$': goto case '#';

                case '=': goto case '#';

                case '@': goto case '#';

                case '\'': goto case '#';

                case '`': goto case '#';

                case ':': goto case '#';

                case '#':
                    Read();
                    sb.Append((char)rr);
                    break;

                case '/':
                    if (indicator != '#')
                    {
                        Read();
                        sb.Append((char)rr);
                        break;
                    }
                    goto default;

                default:
                    Message m = new Message(runtime, sb.ToString());
                    m.Line     = l;
                    m.Position = cc;
                    IokeObject mx = runtime.CreateMessage(m);

                    if (rr == '(')
                    {
                        Read();
                        IList args = ParseCommaSeparatedMessageChains();
                        ParseCharacter(')');
                        Message.SetArguments(mx, args);
                        top.Add(mx);
                    }
                    else
                    {
                        PossibleOperator(mx);
                    }
                    return;
                }
            }
        }