Пример #1
0
        /// <summary>
        /// Instantiates a module, evaluates the meta function, then
        /// evaluates the main function.
        /// </summary>
        /// <param name="m"></param>
        public void RunModule(ModuleDefn m)
        {
            ModuleInstance mi = m.Instantiate(this, new HeronValue[] { }, null) as ModuleInstance;

            if (RunMeta(mi))
            {
                // Re-instantiate,
                mi = m.Instantiate(this, new HeronValue[] { }, null) as ModuleInstance;
            }
            RunMain(mi);
        }
Пример #2
0
        public override HeronValue Instantiate(VM vm, HeronValue[] args, ModuleInstance m)
        {
            if (m != null)
            {
                throw new Exception("A module cannot belong to a module");
            }
            ModuleInstance r = new ModuleInstance(this);

            AddFields(r, m);
            foreach (Import i in imports)
            {
                ModuleDefn     importModDef   = vm.LookupModuleDefn(i.module);
                HeronValue[]   importArgs     = vm.EvalList(i.args).ToArray();
                ModuleInstance importInstance = importModDef.Instantiate(vm, args, null) as ModuleInstance;
                if (importInstance == null)
                {
                    throw new Exception("Failed to create loaded module instance");
                }
                r.imports.Add(i.alias, importInstance);
            }
            CallConstructor(vm, args, m, r);
            return(r);
        }
Пример #3
0
 /// <summary>
 /// Instantiates a module, evaluates the meta function, then 
 /// evaluates the main function. 
 /// </summary>
 /// <param name="m"></param>
 public void RunModule(ModuleDefn m)
 {
     ModuleInstance mi = m.Instantiate(this, new HeronValue[] { }, null) as ModuleInstance;
     if (RunMeta(mi))
     {
         // Re-instantiate, 
         mi = m.Instantiate(this, new HeronValue[] { }, null) as ModuleInstance;
     }
     RunMain(mi);
 }