Ejemplo n.º 1
0
        public static object ActivateWithCallAndData(IokeObject receiver, IokeObject context, IokeObject message, object obj, object c, IDictionary <string, object> d1)
        {
            switch (receiver.data.type)
            {
            case IokeData.TYPE_DEFAULT_METHOD:
                return(DefaultMethod.ActivateWithCallAndDataFixed(receiver, context, message, obj, c, d1));

            case IokeData.TYPE_DEFAULT_MACRO:
                return(DefaultMacro.ActivateWithCallAndDataFixed(receiver, context, message, obj, c, d1));

            case IokeData.TYPE_DEFAULT_SYNTAX:
                return(DefaultSyntax.ActivateWithCallAndDataFixed(receiver, context, message, obj, c, d1));

            case IokeData.TYPE_LEXICAL_MACRO:
                return(LexicalMacro.ActivateWithCallAndDataFixed(receiver, context, message, obj, c, d1));

            case IokeData.TYPE_NATIVE_METHOD:
                return(NativeMethod.ActivateFixed(receiver, context, message, obj));

            case IokeData.TYPE_METHOD_PROTOTYPE:
                return(Method.ActivateFixed(receiver, context, message, obj));

            case IokeData.TYPE_LEXICAL_BLOCK:
                return(LexicalBlock.ActivateWithCallAndDataFixed(receiver, context, message, obj, c, d1));

            case IokeData.TYPE_ALIAS_METHOD:
                return(AliasMethod.ActivateFixed(receiver, context, message, obj));

            case IokeData.TYPE_NONE:
            default:
                return(IokeData.ActivateFixed(receiver, context, message, obj));
            }
        }
Ejemplo n.º 2
0
        public static object ActivateWithDataFixed(IokeObject self, IokeObject context, IokeObject message, object on, IDictionary <string, object> data)
        {
            DefaultMacro dm = (DefaultMacro)self.data;

            if (dm.code == null)
            {
                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 DefaultMacro kind by referring to it without wrapping it inside a call to cell?"));
                context.runtime.ErrorCondition(condition);
                return(null);
            }

            IokeObject c = context.runtime.Locals.Mimic(message, context);

            c.SetCell("self", on);
            c.SetCell("@", on);
            c.RegisterMethod(c.runtime.NewNativeMethod("will return the currently executing macro receiver", new NativeMethod.WithNoArguments("@@",
                                                                                                                                              (method, _context, _message, _on, outer) => {
                outer.ArgumentsDefinition.GetEvaluatedArguments(_context, _message, _on, new SaneArrayList(), new SaneDictionary <string, object>());
                return(self);
            })));
            c.SetCell("currentMessage", message);
            c.SetCell("surroundingContext", context);
            c.SetCell("call", context.runtime.NewCallFrom(c, message, context, IokeObject.As(on, context)));

            foreach (var d in data)
            {
                string s = d.Key;
                c.SetCell(s.Substring(0, s.Length - 1), d.Value);
            }

            try {
                return(context.runtime.interpreter.Evaluate(dm.code, c, on, c));
            } catch (ControlFlow.Return e) {
                if (e.context == c)
                {
                    return(e.Value);
                }
                else
                {
                    throw e;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Init(IokeObject obj)
        {
            obj.Kind = "DefaultMacro";
            obj.SetActivatable(true);

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



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


            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the message chain for this macro",
                                                           new TypeCheckingNativeMethod.WithNoArguments("message", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                return(((DefaultMacro)IokeObject.dataOf(on)).Code);
            })));


            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the code for the argument definition",
                                                           new TypeCheckingNativeMethod.WithNoArguments("argumentsCode", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                return(_context.runtime.NewText(((AssociatedCode)IokeObject.dataOf(on)).ArgumentsCode));
            })));

            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(DefaultMacro.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(DefaultMacro.GetNotice(on)));
            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the full code of this macro, as a Text",
                                                           new TypeCheckingNativeMethod.WithNoArguments("code", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                IokeData data = IokeObject.dataOf(on);
                if (data is DefaultMacro)
                {
                    return(_context.runtime.NewText(((DefaultMacro)data).CodeString));
                }
                else
                {
                    return(_context.runtime.NewText(((AliasMethod)data).CodeString));
                }
            })));

            obj.RegisterMethod(obj.runtime.NewNativeMethod("returns idiomatically formatted code for this macro",
                                                           new TypeCheckingNativeMethod.WithNoArguments("formattedCode", obj,
                                                                                                        (method, on, args, keywords, _context, message) => {
                return(_context.runtime.NewText(((AssociatedCode)IokeObject.dataOf(on)).FormattedCode(method)));
            })));
        }