/// <summary> /// Implements Class#allocate feature. /// </summary> public void BuildObjectAllocation(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args, string /*!*/ methodName) { // check for empty arguments (handles splat correctly): var argsBuilder = new ArgsBuilder(0, 0, 0, false); argsBuilder.AddCallArguments(metaBuilder, args); if (!metaBuilder.Error) { metaBuilder.Result = MakeAllocatorCall(args, () => Ast.Constant(Name)); } }
public static RuleGenerator /*!*/ GetException() { return(new RuleGenerator((metaBuilder, args, name) => { Debug.Assert(args.Target is Exception); // 1 optional parameter (exceptionArg): var argsBuilder = new ArgsBuilder(0, 0, 1, false); argsBuilder.AddCallArguments(metaBuilder, args); if (!metaBuilder.Error) { if (argsBuilder.ExplicitArgumentCount == 0) { metaBuilder.Result = args.TargetExpression; } else { RubyClass cls = args.RubyContext.GetClassOf(args.Target); var classExpression = AstUtils.Constant(cls); args.SetTarget(classExpression, cls); ParameterExpression messageVariable = null; // RubyOps.MarkException(new <exception-type>(GetClrMessage(<class>, #message = <message>))) if (cls.BuildAllocatorCall(metaBuilder, args, () => Ast.Call(null, new Func <RubyClass, object, string>(GetClrMessage).Method, classExpression, Ast.Assign(messageVariable = metaBuilder.GetTemporary(typeof(object), "#message"), AstUtils.Box(argsBuilder[0])) ) )) { // ReinitializeException(<result>, #message) metaBuilder.Result = Ast.Call(null, new Func <RubyContext, Exception, object, Exception>(ReinitializeException).Method, AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)), metaBuilder.Result, messageVariable ?? AstUtils.Box(argsBuilder[0]) ); } else { metaBuilder.SetError(Methods.MakeAllocatorUndefinedError.OpCall(Ast.Convert(args.TargetExpression, typeof(RubyClass)))); } } } })); }