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 new static object ActivateFixed(IokeObject self, IokeObject dynamicContext, IokeObject message, object on) { LexicalBlock lb = (LexicalBlock)self.data; IokeObject c = self.runtime.NewLexicalContext(on, "Lexical activation context", lb.context); lb.arguments.AssignArgumentValues(c, dynamicContext, message, on); return(self.runtime.interpreter.Evaluate(lb.message, c, on, c)); }
public static object ActivateWithCallAndDataFixed(IokeObject self, IokeObject dynamicContext, IokeObject message, object on, object call, IDictionary <string, object> data) { LexicalBlock lb = (LexicalBlock)self.data; IokeObject c = self.runtime.NewLexicalContext(on, "Lexical activation context", lb.context); foreach (var d in data) { string s = d.Key; c.SetCell(s.Substring(0, s.Length - 1), d.Value); } lb.arguments.AssignArgumentValues(c, dynamicContext, message, on, ((Call)IokeObject.dataOf(call))); return(self.runtime.interpreter.Evaluate(lb.message, c, on, c)); }
public IokeObject NewLexicalBlock(string doc, IokeObject tp, LexicalBlock impl) { IokeObject obj = tp.AllocateCopy(null, null); obj.SetDocumentation(doc, null, null); obj.MimicsWithoutCheck(tp); obj.Data = impl; return obj; }
public override void Init(IokeObject obj) { obj.Kind = "LexicalBlock"; obj.RegisterMethod(obj.runtime.NewNativeMethod("takes two evaluated arguments, where this first one is a list of messages which will be used as the arguments and the code, and the second is the context where this lexical scope should be created in", new NativeMethod("createFrom", DefaultArgumentsDefinition.builder() .WithRequiredPositional("messageList") .WithRequiredPositional("lexicalContext") .Arguments, (method, _context, _message, on, outer) => { Runtime runtime = _context.runtime; var positionalArgs = new SaneArrayList(); outer.ArgumentsDefinition.GetEvaluatedArguments(_context, _message, on, positionalArgs, new SaneDictionary <string, object>()); var args = IokeList.GetList(positionalArgs[0]); IokeObject ground = IokeObject.As(positionalArgs[1], _context); IokeObject code = IokeObject.As(args[args.Count - 1], _context); DefaultArgumentsDefinition def = DefaultArgumentsDefinition.CreateFrom(args, 0, args.Count - 1, _message, on, _context); return(runtime.NewLexicalBlock(null, runtime.LexicalBlock, new LexicalBlock(ground, def, code))); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("invokes the block with the arguments provided, returning the result of the last expression in the block", new NativeMethod("call", DefaultArgumentsDefinition.builder() .WithRestUnevaluated("arguments") .Arguments, (method, _context, _message, on, outer) => { return(Interpreter.Activate(IokeObject.As(on, _context), _context, _message, on)); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the full code of this lexical block, as a Text", new TypeCheckingNativeMethod.WithNoArguments("code", obj, (method, on, args, keywords, _context, _message) => { IokeObject objx = IokeObject.As(on, _context); string x = objx.IsActivatable ? "x" : ""; string argstr = ((LexicalBlock)IokeObject.dataOf(on)).arguments.GetCode(); return(_context.runtime.NewText("fn" + x + "(" + argstr + Message.Code(((LexicalBlock)IokeObject.dataOf(on)).message) + ")")); }))); 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 list of the keywords this block takes", new TypeCheckingNativeMethod.WithNoArguments("keywords", obj, (method, on, args, keywords, _context, _message) => { var keywordList = new SaneArrayList(); foreach (string keyword in ((LexicalBlock)IokeObject.dataOf(on)).arguments.Keywords) { keywordList.Add(_context.runtime.GetSymbol(keyword.Substring(0, keyword.Length - 1))); } return(_context.runtime.NewList(keywordList)); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns a list of the argument names the positional arguments this block takes", new TypeCheckingNativeMethod.WithNoArguments("argumentNames", obj, (method, on, args, keywords, _context, _message) => { var names = new SaneArrayList(); foreach (var arg in ((LexicalBlock)IokeObject.dataOf(on)).arguments.Arguments) { if (!(arg is DefaultArgumentsDefinition.KeywordArgument)) { names.Add(_context.runtime.GetSymbol(arg.Name)); } } return(_context.runtime.NewList(names)); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns the message chain for this block", new TypeCheckingNativeMethod.WithNoArguments("message", obj, (method, on, args, keywords, _context, _message) => { return(((AssociatedCode)IokeObject.dataOf(on)).Code); }))); 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(LexicalBlock.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(LexicalBlock.GetNotice(on))); }))); obj.RegisterMethod(obj.runtime.NewNativeMethod("returns idiomatically formatted code for this lexical block", new TypeCheckingNativeMethod.WithNoArguments("formattedCode", obj, (method, on, args, keywords, _context, message) => { return(_context.runtime.NewText(((AssociatedCode)IokeObject.dataOf(on)).FormattedCode(method))); }))); }