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 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 static object ConstructRubyStruct(IConstructor ctor, string className, Node node) { MappingNode mapping = node as MappingNode; if (mapping == null) { throw new ConstructorException("can only construct struct from mapping node"); } RubyScope scope = ctor.Scope; RubyModule module; RubyClass cls; if (scope.RubyContext.TryGetModule(scope.GlobalScope, className, out module)) { cls = module as RubyClass; if (cls == null) { throw new ConstructorException("Struct type name must be Ruby class"); } } else { RubyModule structModule = scope.RubyContext.GetModule(typeof(RubyStruct)); cls = RubyUtils.GetConstant(scope, structModule, className, false) as RubyClass; if (cls == null) { throw new ConstructorException(String.Format("Cannot find struct class \"{0}\"", className)); } } RubyStruct newStruct = RubyStruct.Create(cls); foreach (var pair in ctor.ConstructMapping(mapping)) { RubyStructOps.SetValue(newStruct, SymbolTable.StringToId(pair.Key.ToString()), pair.Value); } return(newStruct); }
public static object GetConstantValue(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol] string /*!*/ constantName) { return(RubyUtils.GetConstant(scope, self, constantName, true)); }