Ejemplo n.º 1
0
 public override void Bundle(iObject argument, ArgumentBundle bundle)
 {
     foreach (var item in (Array)argument)
     {
         bundle.Splat.Add(item);
     }
 }
Ejemplo n.º 2
0
 public override void Bundle(iObject argument, ArgumentBundle bundle)
 {
     foreach (var pair in (Hash)argument)
     {
         var array = (Array)pair;
         bundle.Keywords[array[0]] = array[1];
     }
 }
        public override iObject Bind(ArgumentBundle bundle)
        {
            if (Parameter.Position >= bundle.Splat.Count)
            {
                throw new ArgumentError(
                          $"required parameter `{Parameter.Name}' with index {Parameter.Position} was not passed");
            }

            return(bundle.Splat[Parameter.Position]);
        }
Ejemplo n.º 4
0
 public CallFrame(CallSite callSite,
                  iObject instance,
                  ArgumentBundle arguments = null,
                  CallFrame caller         = null)
 {
     CallSite  = callSite;
     Instance  = instance;
     Caller    = caller ?? Current;
     Arguments = arguments ?? new ArgumentBundle();
     Locals    = new LinkedDictionary <Symbol, LocalVariable>();
 }
Ejemplo n.º 5
0
        public override iObject Bind(ArgumentBundle bundle)
        {
            var value = bundle.Keywords[new Symbol(Parameter.Name)];

            if (value != null)
            {
                return(value);
            }

            throw new ArgumentError(
                      $"required keyword parameter `{Parameter.Name}' with index {Parameter.Position} was not passed");
        }
        public override iObject Bind(ArgumentBundle bundle)
        {
            var value = bundle.Keywords[new Symbol(Parameter.Name)];

            if (value != null)
            {
                return(value);
            }

            var defaultValue = Parameter.Parameter.HasDefaultValue
                ? Object.Box(Parameter.Parameter.DefaultValue)
                : null;

            return(defaultValue);
        }
        public override iObject Bind(ArgumentBundle bundle)
        {
            var available = bundle.Splat.Count - Method.ParameterCounter.Required;

            if (available > 0 && Parameter.Position < bundle.Splat.Count)
            {
                return(bundle.Splat[Parameter.Position]);
            }

            var defaultValue = Parameter.Parameter.HasDefaultValue
                ? Object.Box(Parameter.Parameter.DefaultValue)
                : null;

            return(defaultValue);
        }
Ejemplo n.º 8
0
        public override iObject Bind(ArgumentBundle bundle)
        {
            var numParameters = Method.ParameterCounter.Required
                                + Method.ParameterCounter.Optional
                                + (Method.ParameterCounter.HasRest ? 1 : 0);

            var splatPosition = bundle.Splat.Count + numParameters - Parameter.Position - 2;

            if (splatPosition < 0 || splatPosition >= bundle.Splat.Count)
            {
                throw new ArgumentError(
                          $"required parameter `{Parameter.Name}' with index {Parameter.Position} not passed");
            }

            return(bundle.Splat[splatPosition]);
        }
        public override iObject Bind(ArgumentBundle bundle)
        {
            var parameters    = Method.Parameters.Where(p => p.IsKeyRequired || p.IsKeyOptional);
            var keysToExclude = new HashSet <Symbol>(parameters.Select(p => new Symbol(p.Name)));

            var keys = new HashSet <Symbol>(bundle.Keywords.Keys.Cast <Symbol>());

            keys.RemoveWhere(key => keysToExclude.Contains(key));

            var rest = new Hash(keys.Count);

            foreach (var key in keys)
            {
                rest[key] = bundle.Keywords[key];
            }

            return(rest);
        }
Ejemplo n.º 10
0
        public override iObject Bind(ArgumentBundle bundle)
        {
            var begin = Method.ParameterCounter.PrefixRequired + Method.ParameterCounter.Optional;
            var end   = bundle.Splat.Count - Method.ParameterCounter.SuffixRequired;
            var count = end - begin;

            if (count <= 0)
            {
                return(new Array());
            }

            var values = bundle.Splat.Skip(begin).Take(count);
            var result = new Array(values);

            var hasKeyRestParameter = Method.ParameterCounter.HasKeyRest;
            var restIncludesKeyRest = bundle.HasKeyArguments != hasKeyRestParameter;

            if (restIncludesKeyRest)
            {
                result.Add(bundle.Keywords.Duplicate());
            }

            return(result);
        }
Ejemplo n.º 11
0
 public abstract void Bundle(iObject argument, ArgumentBundle bundle);
Ejemplo n.º 12
0
            public override void Bundle(iObject argument, ArgumentBundle bundle)
            {
                var labeledArg = (Array)argument;

                bundle.Keywords[labeledArg[0]] = labeledArg[1];
            }
Ejemplo n.º 13
0
 public override iObject Bind(ArgumentBundle bundle)
 => bundle.Block ?? new NilClass();
Ejemplo n.º 14
0
 public override void Bundle(iObject argument, ArgumentBundle bundle)
 {
     bundle.Block = argument;
 }
Ejemplo n.º 15
0
 public static CallFrame Push(CallSite callSite,
                              iObject instance,
                              ArgumentBundle arguments = null)
 => Current = new CallFrame(callSite, instance, arguments);
Ejemplo n.º 16
0
 public override void Bundle(iObject argument, ArgumentBundle bundle)
 {
     bundle.Splat.Add(argument);
 }
Ejemplo n.º 17
0
 public abstract iObject Bind(ArgumentBundle bundle);