// method: internal RubyMethodInfo(RubyMethodBody/*!*/ body, RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule, RubyMemberFlags flags) : base(flags, declaringModule) { Assert.NotNull(body, declaringModule); _body = body; _declaringScope = declaringScope; }
private static object CreateDefaultStream(UnaryOpStorage /*!*/ newStorage, RubyScope /*!*/ scope, RubyModule /*!*/ yamlModule) { object streamClass = RubyUtils.GetConstant(scope.GlobalScope, yamlModule, "Stream", false); var newSite = newStorage.GetCallSite("new"); return(newSite.Target(newSite, streamClass)); }
public static object Evaluate(RubyScope /*!*/ scope, object self, [NotNull] MutableString /*!*/ code, [Optional, NotNull] MutableString file, [DefaultParameterValue(1)] int line) { RubyClass singleton = scope.RubyContext.GetOrCreateSingletonClass(self); return(RubyUtils.Evaluate(code, scope, self, singleton, file, line)); }
public static object YamlAs(RubyScope /*!*/ scope, RubyModule /*!*/ self, object tag) { RubyModule yamlModule; scope.RubyContext.TryGetModule(scope.GlobalScope, "YAML", out yamlModule); return(RubyYaml.TagClass(yamlModule, tag, self)); }
public static object ConstructRubyTimestampYMD(IConstructor ctor, Node node) { ScalarNode scalar = node as ScalarNode; if (scalar == null) { throw new ConstructorException("Can only contruct timestamp from scalar node."); } Match match = SafeConstructor.YMD_REGEXP.Match(scalar.Value); if (match.Success) { int year_ymd = int.Parse(match.Groups[1].Value); int month_ymd = int.Parse(match.Groups[2].Value); int day_ymd = int.Parse(match.Groups[3].Value); RubyModule module; RubyScope scope = ctor.Scope; if (scope.RubyContext.TryGetModule(scope.GlobalScope, "Date", out module)) { return(_New.Target(_New, scope.RubyContext, module, year_ymd, month_ymd, day_ymd)); } else { throw new ConstructorException("Date class not found."); } } throw new ConstructorException("Invalid tag:yaml.org,2002:timestamp#ymd value."); }
internal Proc(ProcKind kind, object self, RubyScope /*!*/ scope, BlockDispatcher /*!*/ dispatcher) { Assert.NotNull(scope, dispatcher); _kind = kind; _self = self; _scope = scope; _dispatcher = dispatcher; }
private static RubyModule /*!*/ SetVisibility(RubyScope /*!*/ scope, object /*!*/ self, object[] /*!*/ methodNames, RubyMethodAttributes attributes) { Assert.NotNull(scope, self, methodNames); RubyClass cls = scope.RubyContext.GetClassOf(self); ModuleOps.SetMethodAttributes(scope, cls, methodNames, attributes); return(cls); }
// method: internal RubyMethodInfo(RubyMethodBody /*!*/ body, RubyScope /*!*/ declaringScope, RubyModule /*!*/ declaringModule, RubyMemberFlags flags) : base(flags, declaringModule) { Assert.NotNull(body, declaringModule); _body = body; _declaringScope = declaringScope; }
public static object /*!*/ Load(RubyScope /*!*/ scope, RubyModule /*!*/ self, MutableString /*!*/ libraryName) { object loaded; scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded); Debug.Assert(loaded != null); return(loaded); }
public static Proc /*!*/ DefineMethod(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ methodName, [NotNull] Proc /*!*/ block) { var visibility = GetDefinedMethodVisibility(scope, self, methodName); var info = Proc.ToLambdaMethodInfo(block, methodName, visibility, self); self.AddMethod(scope.RubyContext, methodName, info); return(info.Lambda); }
public static object Evaluate(RubyScope /*!*/ scope, BlockParam block, RubyModule /*!*/ self, [NotNull] MutableString /*!*/ code, [Optional, NotNull] MutableString file, [DefaultParameterValue(1)] int line) { if (block != null) { throw RubyExceptions.CreateArgumentError("wrong number of arguments"); } return(RubyUtils.Evaluate(code, scope, self, self, file, line)); }
private static RubyModule GetModule(RubyScope scope, String className) { RubyModule module; if (!scope.RubyContext.TryGetModule(scope.GlobalScope, className, out module)) { throw RubyExceptions.CreateNameError(className); } return(module); }
public static object MethodMissing(RubyScope /*!*/ scope, BlockParam block, string /*!*/ self, [NotNull] RubySymbol /*!*/ name, params object[] /*!*/ args) { if (name.EndsWith('=') || name.EndsWith('!')) { throw RubyExceptions.CreateTypeError("Mutating method `{0}' called for an immutable string (System::String)", name); } // TODO: forward to MutableString until we implement the methods here: return(KernelOps.SendMessageOpt(scope, block, ToStr(self), name.ToString(), args)); }
public static object LoadFile(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path) { using (RubyFile file = new RubyFile(self.Context, path.ConvertToString(), IOMode.Default)) { foreach (object obj in MakeConstructor(scope.GlobalScope, file.GetReadableStream())) { return(obj); } } return(null); }
public static Proc /*!*/ DefineMethod(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol] string /*!*/ methodName, [NotNull] Proc /*!*/ method) { // MRI: ignores ModuleFunction scope flag (doesn't create singleton method). // MRI 1.8: uses private visibility if module_function is applied (bug). // MFI 1.9: uses public visibility as we do, unless the name is special. var visibility = RubyUtils.GetSpecialMethodVisibility(scope.Visibility, methodName); self.AddMethod(methodName, Proc.ToLambdaMethodInfo(method.ToLambda(), methodName, visibility, self)); return(method); }
public static object DumpStream(UnaryOpStorage /*!*/ newStorage, BinaryOpStorage /*!*/ addStorage, UnaryOpStorage /*!*/ emitStorage, RubyScope /*!*/ scope, RubyModule /*!*/ self, params object[] /*!*/ args) { object io = CreateDefaultStream(newStorage, scope, self); AddDocumentsToStream(addStorage, args, io); var emitSite = emitStorage.GetCallSite("emit"); return(emitSite.Target(emitSite, io)); }
public static Proc /*!*/ DefineMethod(RubyScope /*!*/ scope, RubyModule /*!*/ self, [NotNull] ClrName /*!*/ methodName, [NotNull] Proc /*!*/ block) { var result = DefineMethod(scope, self, methodName.MangledName, block); if (methodName.HasMangledName) { self.AddMethodAlias(methodName.ActualName, methodName.MangledName); } return(result); }
public static MutableString /*!*/ ReadLine(RubyScope /*!*/ scope, StringIO /*!*/ self, [DefaultProtocol, NotNull] Union <MutableString, int> separatorOrLimit) { if (separatorOrLimit.IsFixnum()) { return(ReadLine(scope, self, scope.RubyContext.InputSeparator, separatorOrLimit.Fixnum())); } else { return(ReadLine(scope, self, separatorOrLimit.String(), -1)); } }
// TODO: public due to partial trust // implements Class#new public static object CreateAnonymousClass(RubyScope /*!*/ scope, BlockParam body, RubyClass /*!*/ self, [Optional] RubyClass superClass) { RubyContext ec = scope.RubyContext; RubyModule owner = scope.GetInnerMostModule(); // MRI is inconsistent here, it triggers "inherited" event after the body of the method is evaluated. // In all other cases the order is event first, body next. RubyClass newClass = ec.DefineClass(owner, null, superClass ?? ec.ObjectClass); return((body != null) ? RubyUtils.EvaluateInModule(newClass, body, newClass) : newClass); }
internal static void SetMethodAttributes(RubyScope /*!*/ scope, RubyModule /*!*/ module, string /*!*/[] /*!*/ methodNames, RubyMethodAttributes attributes) { if (methodNames.Length == 0) { scope.GetMethodAttributesDefinitionScope().MethodAttributes = attributes; } else { SetMethodAttributes(module, methodNames, attributes); } }
public static MutableString Gets(RubyScope /*!*/ scope, RubyIO /*!*/ self, [DefaultProtocol] MutableString separator) { MutableString result = self.ReadLineOrParagraph(separator); KernelOps.Taint(scope.RubyContext, result); scope.GetInnerMostClosureScope().LastInputLine = result; scope.RubyContext.InputProvider.IncrementLastInputLineNumber(); return(result); }
public static Proc /*!*/ CreateNew(RubyScope /*!*/ scope, RubyClass /*!*/ self) { RubyMethodScope methodScope = scope.GetInnerMostMethodScope(); if (methodScope == null || methodScope.BlockParameter == null) { throw RubyExceptions.CreateArgumentError("tried to create Proc object without a block"); } return(CreateNew(self, methodScope.BlockParameter)); }
public static object DumpStream(RubyScope /*!*/ scope, RubyModule /*!*/ self, [NotNull] params object[] args) { object streamClass = RubyUtils.GetConstant(scope, self, _Stream, false); object stream = _New.Target(_New, scope.RubyContext, streamClass as RubyModule, null); foreach (object arg in args) { _Add.Target(_Add, scope.RubyContext, stream, arg); } return(_Emit.Target(_Emit, scope.RubyContext, stream)); }
public static object LoadStream(RubyScope /*!*/ scope, RubyModule /*!*/ self, object io) { RubyConstructor rc = MakeConstructor(scope, CheckYamlPort(io)); object streamClass = RubyUtils.GetConstant(scope, self, _Stream, false); object stream = _New.Target(_New, scope.RubyContext, streamClass as RubyModule, null); foreach (object doc in rc) { _Add.Target(_Add, scope.RubyContext, stream, doc); } return(stream); }
public void InitializeLibrary(RubyScope scope) { KernelOps.Require(scope, this, MutableString.CreateAscii("json/common")); _maxNesting = scope.RubyContext.CreateAsciiSymbol("max_nesting"); _allowNan = scope.RubyContext.CreateAsciiSymbol("allow_nan"); _jsonCreatable = scope.RubyContext.CreateAsciiSymbol("json_creatable?"); _jsonCreate = scope.RubyContext.CreateAsciiSymbol("json_create"); _createId = scope.RubyContext.CreateAsciiSymbol("create_id"); _createAdditions = scope.RubyContext.CreateAsciiSymbol("create_additions"); _chr = scope.RubyContext.CreateAsciiSymbol("chr"); }
public static MutableString /*!*/ ReadLine(RubyScope /*!*/ scope, StringIO /*!*/ self, [DefaultProtocol] MutableString separator, [DefaultProtocol] int limit) { // no dynamic call, modifies $_ scope variable: MutableString result = Gets(scope, self, separator, limit); if (result == null) { throw new EOFError("end of file reached"); } return(result); }
// method: internal RubyMethodInfo(object/*!*/ ast, Delegate/*!*/ method, RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule, string/*!*/ definitionName, int mandatory, int optional, bool hasUnsplatParameter, RubyMemberFlags flags) : base(flags, declaringModule) { Assert.NotNull(ast, method, declaringModule, definitionName); _ast = ast; _method = method; _mandatoryParamCount = mandatory; _optionalParamCount = optional; _hasUnsplatParameter = hasUnsplatParameter; _definitionName = definitionName; _declaringScope = declaringScope; }
public static RubyModule /*!*/ CopyMethodsToModuleSingleton(RubyScope /*!*/ scope, RubyModule /*!*/ self, [NotNull] params object[] /*!*/ methodNames) { // This is an important restriction for correct super calls in module functions (see RubyOps.DefineMethod). // MRI has it wrong. It checks just here and not in method definition. if (self.IsClass) { throw RubyExceptions.CreateTypeError("module_function must be called for modules"); } // overwrites visibility to public: SetMethodAttributes(scope, self, methodNames, RubyMethodAttributes.ModuleFunction); return(self); }
public ParserEngineState(Parser parser, RubyScope scope, MutableString source) { Parser = parser; Scope = scope; OriginalSource = source; Source = source.ConvertToString(); CreateID = Helpers.GetCreateId(scope); AllowNaN = DEFAULT_ALLOW_NAN; MaxNesting = DEFAULT_MAX_NESTING; CurrentNesting = 0; Memo = 0; }
internal Delegate GetDelegate(RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule) { if (_delegate == null) { lock (this) { if (_delegate == null) { // TODO: remove options AstGenerator gen = new AstGenerator(declaringScope.RubyContext, new RubyCompilerOptions(), _document, _encoding, false); MSA.LambdaExpression lambda = _ast.TransformBody(gen, declaringScope, declaringModule); _delegate = RubyScriptCode.CompileLambda(lambda, declaringScope.RubyContext); } } } return _delegate; }
public static MutableString Gets(RubyScope /*!*/ scope, RubyIO /*!*/ self, [DefaultProtocol] MutableString separator) { MutableString result = self.ReadLineOrParagraph(separator); if (result != null) { result.IsTainted = true; } scope.GetInnerMostClosureScope().LastInputLine = result; scope.RubyContext.InputProvider.LastInputLineNumber = ++self.LineNumber; return(result); }
public static MutableString Gets(RubyScope /*!*/ scope, StringIO /*!*/ self, [DefaultProtocol] MutableString separator) { var content = self.GetReadableContent(); int position = self._position; MutableString result = ReadLine(content, separator, ref position); self._position = position; scope.GetInnerMostClosureScope().LastInputLine = result; self._lineNumber++; return(result); }
public static RubyArray /*!*/ GetLexicalModuleNesting(RubyScope /*!*/ scope, RubyModule /*!*/ self) { RubyArray result = new RubyArray(); while (scope != null) { // Ruby 1.9: the anonymous module doesn't show up if (scope.Module != null) { result.Add(scope.Module); } scope = (RubyScope)scope.Parent; } return(result); }
internal RubyMethodScope(RubyScope/*!*/ parent, RubyModule/*!*/ declaringModule, string/*!*/ definitionName, Proc blockParameter, RuntimeFlowControl/*!*/ runtimeFlowControl, object selfObject) : base(parent, runtimeFlowControl, selfObject) { _declaringModule = declaringModule; _definitionName = definitionName; _blockParameter = blockParameter; MethodAttributes = RubyMethodAttributes.PublicInstance; }
internal RubyModuleScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame, RubyModule module, bool isEval) : base(parent, frame) { _module = module; _isEval = isEval; }
// "method_missing" on main singleton in DLR Scope bound code. // Might be called via a site -> needs to be public in partial trust. public static object TopMethodMissing(RubyScope/*!*/ localScope, BlockParam block, object/*!*/ self, SymbolId name, [NotNull]params object[]/*!*/ args) { Assert.NotNull(localScope, self); Debug.Assert(!localScope.IsEmpty); Scope globalScope = localScope.GlobalScope.Scope; Debug.Assert(globalScope != null); // TODO: error when arguments non-empty, block != null, ... if (args.Length == 0) { object value; if (globalScope.TryGetName(name, out value)) { return value; } string str = SymbolTable.IdToString(name); string unmangled = RubyUtils.TryUnmangleName(str); if (unmangled != null && globalScope.TryGetName(SymbolTable.StringToId(unmangled), out value)) { return value; } if (str == "scope") { return self; } } else if (args.Length == 1) { string str = SymbolTable.IdToString(name); if (str.LastCharacter() == '=') { SymbolId plainName = SymbolTable.StringToId(str.Substring(0, str.Length - 1)); globalScope.SetName(plainName, args[0]); return args[0]; } } // TODO: call super throw RubyExceptions.CreateMethodMissing(localScope.RubyContext, self, SymbolTable.IdToString(name)); }
internal RubyBlockScope(RubyScope/*!*/ parent, RuntimeFlowControl/*!*/ runtimeFlowControl, BlockParam/*!*/ blockFlowControl, object selfObject) : base(parent, runtimeFlowControl, selfObject) { Assert.NotNull(blockFlowControl); _blockFlowControl = blockFlowControl; }
// "method_missing" on main singleton in DLR Scope bound code. // Might be called via a site -> needs to be public in partial trust. public static object TopMethodMissing(RubyScope/*!*/ localScope, BlockParam block, object/*!*/ self, SymbolId name, [NotNull]params object[]/*!*/ args) { return ScopeMethodMissing(localScope.RubyContext, localScope.GlobalScope.Scope, block, self, name, args); }
internal RubyMethodScope(RubyScope/*!*/ parent, RubyMethodInfo/*!*/ method, Proc blockParameter, RuntimeFlowControl/*!*/ runtimeFlowControl, object selfObject) : base(parent, runtimeFlowControl, selfObject) { _method = method; _blockParameter = blockParameter; MethodAttributes = RubyMethodAttributes.PublicInstance; }
internal RubyMethodScope(MutableTuple locals, SymbolId[]/*!*/ variableNames, RubyScope/*!*/ parent, RubyModule/*!*/ declaringModule, string/*!*/ definitionName, object selfObject, Proc blockParameter, InterpretedFrame interpretedFrame) { Assert.NotNull(parent, declaringModule, definitionName); // RuntimeFlowControl: _activeFlowControlScope = this; // RubyScope: _parent = parent; _top = parent.Top; _selfObject = selfObject; _methodAttributes = RubyMethodAttributes.PublicInstance; _locals = locals; _variableNames = variableNames; InterpretedFrame = interpretedFrame; // RubyMethodScope: _declaringModule = declaringModule; _definitionName = definitionName; _blockParameter = blockParameter; InitializeRfc(blockParameter); SetDebugName("method " + definitionName + ((blockParameter != null) ? "&" : null)); }
internal RubyModuleEvalScope(RubyScope/*!*/ parent, RubyModule module, object selfObject) { Assert.NotNull(parent); // RuntimeFlowControl: _activeFlowControlScope = parent.FlowControlScope; // RubyScope: _parent = parent; _top = parent.Top; _selfObject = selfObject; _methodAttributes = RubyMethodAttributes.PrivateInstance; // RubyModuleScope: _module = module; InLoop = parent.InLoop; InRescue = parent.InRescue; MethodAttributes = RubyMethodAttributes.PublicInstance; SetEmptyLocals(); }
internal RubyBlockScope(RubyScope/*!*/ parent, RuntimeFlowControl/*!*/ runtimeFlowControl, object selfObject) : base(parent, runtimeFlowControl, selfObject) { }
internal RubyModuleScope(RubyScope/*!*/ parent, RubyModule module, bool isEval, RuntimeFlowControl/*!*/ runtimeFlowControl, object selfObject) : base(parent, runtimeFlowControl, selfObject) { _module = module; _isEval = isEval; MethodAttributes = RubyMethodAttributes.PublicInstance; }
internal RubyMethodScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame, RubyMethodInfo/*!*/ method, Proc blockParameter) : base(parent, frame) { _method = method; _blockParameter = blockParameter; }
private static VisibilityContext GetVisibilityContext(RubyCallSignature callSignature, RubyScope scope) { return callSignature.HasImplicitSelf || !callSignature.HasScope ? new VisibilityContext(callSignature.IsInteropCall ? RubyMethodAttributes.Public : RubyMethodAttributes.VisibilityMask) : new VisibilityContext(scope.SelfImmediateClass); }
internal RubyFileInitializerScope(MutableTuple locals, string[]/*!*/ variableNames, RubyScope/*!*/ parent) { // RuntimeFlowControl: _activeFlowControlScope = parent.FlowControlScope; // RubyScope: _parent = parent; _top = parent.Top; _selfObject = parent.SelfObject; _methodAttributes = RubyMethodAttributes.PublicInstance; _locals = locals; _variableNames = variableNames; InLoop = parent.InLoop; InRescue = parent.InRescue; }
internal RubyBlockScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame) : base(parent, frame) { }
// method_missing on main singleton in DLR Scope bound code. // Might be called via a site -> needs to be public in partial trust. public static object TopMethodMissing(RubyScope/*!*/ scope, BlockParam block, object/*!*/ self, SymbolId name, [NotNull]params object[]/*!*/ args) { Assert.NotNull(scope, self); Debug.Assert(!scope.IsEmpty); Scope globalScope = scope.GlobalScope.Scope; Debug.Assert(globalScope != null); // TODO: error when arguments non-empty, block != null, ... // TODO: name-mangling if (args.Length == 0) { object value; if (globalScope.TryGetName(name, out value)) { return value; } } else if (args.Length == 1) { string str = SymbolTable.IdToString(name); if (str.Length > 0 && str[str.Length - 1] == '=') { SymbolId plainName = SymbolTable.StringToId(str.Substring(0, str.Length - 1)); globalScope.SetName(plainName, args[0]); return args[0]; } } // TODO: call super throw RubyExceptions.CreateMethodMissing(scope.RubyContext, self, SymbolTable.IdToString(name)); }