Exemplo n.º 1
0
        /// <summary>
        /// A function can be invoked if the 'this' value (called self) is supplied.
        /// A FunctionObject is created and then called.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="env"></param>
        /// <param name="funcs"></param>
        /// <returns></returns>
        public HeronValue Invoke(HeronValue self, VM vm, HeronValue[] args)
        {
            // TODO: in theory we can optimize this
            FunctionValue fo = new FunctionValue(self, this);

            return(fo.Apply(vm, args));
        }
Exemplo n.º 2
0
        protected void CallConstructor(VM vm, HeronValue[] args, ModuleInstance mi, ClassInstance ci)
        {
            // First we are going to invoke the auto-constructor
            GetAutoConstructor().Invoke(ci, vm, new HeronValue[] { });

            List <FunctionDefn> ctorlist = new List <FunctionDefn>(GetMethods("Constructor"));

            if (ctorlist == null)
            {
                return;
            }
            ctors = new FunDefnListValue(ci, "Constructor", ctorlist);
            if (ctors.Count == 0)
            {
                if (args.Length > 0)
                {
                    throw new Exception("No constructors have been defined and default constructor accepts no arguments");
                }
                else
                {
                    return;
                }
            }

            FunctionValue o = ctors.Resolve(vm, args);

            if (o == null)
            {
                throw new Exception("No matching constructor could be found");
            }

            o.Apply(vm, args);
        }
Exemplo n.º 3
0
        public override HeronValue Apply(VM vm, HeronValue[] args)
        {
            Debug.Assert(functions.Count > 0);
            FunctionValue o = Resolve(vm, args);

            if (o == null)
            {
                throw new Exception("Could not resolve function '" + name + "' with arguments " + ArgsToString(args));
            }
            return(o.Apply(vm, args));
        }