public static object ActivateWithDataFixed(IokeObject self, IokeObject dynamicContext, IokeObject message, object on, IDictionary <string, object> data) { LexicalMacro lm = (LexicalMacro)self.data; if (lm.code == null) { IokeObject condition = IokeObject.As(IokeObject.GetCellChain(dynamicContext.runtime.Condition, message, dynamicContext, "Error", "Invocation", "NotActivatable"), dynamicContext).Mimic(message, dynamicContext); condition.SetCell("message", message); condition.SetCell("context", dynamicContext); condition.SetCell("receiver", on); condition.SetCell("method", self); condition.SetCell("report", dynamicContext.runtime.NewText("You tried to activate a method without any code - did you by any chance activate the LexicalMacro kind by referring to it without wrapping it inside a call to cell?")); dynamicContext.runtime.ErrorCondition(condition); return(null); } IokeObject c = self.runtime.NewLexicalContext(on, "Lexical macro activation context", lm.context); c.SetCell("outerScope", lm.context); c.SetCell("call", dynamicContext.runtime.NewCallFrom(c, message, dynamicContext, IokeObject.As(on, dynamicContext))); foreach (var d in data) { string s = d.Key; c.SetCell(s.Substring(0, s.Length - 1), d.Value); } return(self.runtime.interpreter.Evaluate(lm.code, c, on, c)); }
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)); } }
public override void Init(IokeObject obj) { obj.Kind = "LexicalMacro"; obj.SetActivatable(true); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the name of the lecro", new NativeMethod.WithNoArguments("name", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); return(_context.runtime.NewText(((LexicalMacro)IokeObject.dataOf(on)).name)); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("activates this lecro 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 lecro", new NativeMethod.WithNoArguments("message", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); return(((AssociatedCode)IokeObject.dataOf(on)).Code); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the code for the argument definition", new NativeMethod.WithNoArguments("argumentsCode", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); return(_context.runtime.NewText(((AssociatedCode)IokeObject.dataOf(on)).ArgumentsCode)); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a text inspection of the object", new NativeMethod.WithNoArguments("inspect", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); return(_context.runtime.NewText(LexicalMacro.GetInspect(on))); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("Returns a brief text inspection of the object", new NativeMethod.WithNoArguments("notice", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); return(_context.runtime.NewText(LexicalMacro.GetNotice(on))); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the full code of this lecro, as a Text", new NativeMethod.WithNoArguments("code", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); IokeData data = IokeObject.dataOf(on); if (data is LexicalMacro) { return(_context.runtime.NewText(((LexicalMacro)data).CodeString(on))); } else { return(_context.runtime.NewText(((AliasMethod)data).CodeString)); } }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns idiomatically formatted code for this lecro", new NativeMethod.WithNoArguments("formattedCode", (method, _context, message, on, outer) => { outer.ArgumentsDefinition.GetEvaluatedArguments(_context, message, on, new SaneArrayList(), new SaneDictionary <string, object>()); return(_context.runtime.NewText(((AssociatedCode)IokeObject.dataOf(on)).FormattedCode(method))); }))); }