Exemplo n.º 1
0
 public void TeardownCompilerEngine()
 {
     engine = null;
     sctx = null;
     target = null;
     root = null;
 }
Exemplo n.º 2
0
        public IndirectCallContext(StackContext originalSctx,
            Engine parentEngine,
            Application parentApplication,
            IEnumerable<string> importedNamespaces,
            IIndirectCall callable,
            PValue[] args)
        {
            if (parentEngine == null)
                throw new ArgumentNullException("parentEngine");
            if (parentApplication == null)
                throw new ArgumentNullException("parentApplication");
            if (importedNamespaces == null)
                throw new ArgumentNullException("importedNamespaces");
            if (callable == null)
                throw new ArgumentNullException("callable");
            if (args == null)
                throw new ArgumentNullException("args");

            _engine = parentEngine;
            _application = parentApplication;
            _importedNamespaces = (importedNamespaces as SymbolCollection) ??
                new SymbolCollection(importedNamespaces);
            _callable = callable;
            _arguments = args;
            _originalStackContext = originalSctx;
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            Application = new Application(ApplicationName);
            Engine = new Engine();
            Loader = new Loader(Engine, Application);

            Dependencies = new List<string>();
            Root = new NullContext(Engine, Application, new string[0]);

            var slnPath = Environment.CurrentDirectory;
            while (Directory.Exists(slnPath) && !File.Exists(Path.Combine(slnPath, "Prexonite.sln")))
                slnPath = Path.Combine(slnPath, @".." + Path.DirectorySeparatorChar);

            if (Directory.Exists(slnPath))
            {
                var psrTestsPath =
                    Path.GetFullPath(Path.Combine(slnPath, @"PrexoniteTests\psr-tests"));
                Console.WriteLine("inferred psr-tests path: " + psrTestsPath, "Engine.Path");
                Engine.Paths.Add(psrTestsPath);

                var prxPath = Path.GetFullPath(Path.Combine(slnPath, @"Prx"));
                Console.WriteLine("inferred prx path: " + prxPath, "Engine.Path");
                Engine.Paths.Add(prxPath);
            }
            else
            {
                Console.WriteLine("CANNOT INFER solution PATH: " + slnPath, "Engine.Path");
            }
        }
Exemplo n.º 4
0
 public IndirectCallContext(Engine parentEngine,
     Application parentApplication,
     IEnumerable<string> importedNamespaces,
     IIndirectCall callable,
     PValue[] args)
     : this(null, parentEngine, parentApplication, importedNamespaces, callable, args)
 {
 }
Exemplo n.º 5
0
 public TestStackContext(Engine engine, Application app)
 {
     if (engine == null)
         throw new ArgumentNullException("engine");
     if (app == null)
         throw new ArgumentNullException("app");
     _engine = engine;
     _implementation = app.CreateFunction();
 }
Exemplo n.º 6
0
 private CilFunctionContext(Engine parentEngine, Application parentApplication,
     SymbolCollection importedNamespaces)
 {
     if (parentEngine == null)
         throw new ArgumentNullException("parentEngine");
     this.parentEngine = parentEngine;
     if (parentApplication == null)
         throw new ArgumentNullException("parentApplication");
     this.parentApplication = parentApplication;
     if (importedNamespaces == null)
         throw new ArgumentNullException("importedNamespaces");
     this.importedNamespaces = importedNamespaces;
 }
Exemplo n.º 7
0
        public NullContext(Engine parentEngine, Application parentApplication, IEnumerable<string> importedNamespaces)
        {
            if (parentEngine == null)
                throw new ArgumentNullException("parentEngine");
            if (parentApplication == null)
                throw new ArgumentNullException("parentApplication");
            if (importedNamespaces == null)
                throw new ArgumentNullException("importedNamespaces");

            this.parentEngine = parentEngine;
            this.parentApplication = parentApplication;
            this.importedNamespaces = (importedNamespaces as SymbolCollection) ??
                new SymbolCollection(importedNamespaces);
        }
Exemplo n.º 8
0
 protected  List<Instruction> GetInstructions(string assemblerCode)
 {
     var app = new Application("getInstructions");
     var opt = new LoaderOptions(engine, app);
     opt.UseIndicesLocally = false;
     var ldr = new Loader(opt);
     ldr.LoadFromString("function MyAssemblerFunction does asm {" + assemblerCode + "\n}");
     if (ldr.ErrorCount != 0)
     {
         Console.WriteLine("--------------- Assembler Code --------------------");
         Console.WriteLine(assemblerCode);
         Console.WriteLine("---------------- End Asm Code ---------------------");
         foreach (var error in ldr.Errors)
             Assert.Fail(string.Format("Error in the expected assembler code: {0}", error));
     }
     return app.Functions["MyAssemblerFunction"].Code;
 }
Exemplo n.º 9
0
       public void SimpleLinkUnlink()
       {
           var a1 = new Application();
           var a2 = new Application();

           Assert.That(a1.IsLinked,Is.False,"a1 should not be linked initially");
           Assert.That(a2.IsLinked, Is.False,"a2 should not be linked initially");

           Application.Link(a1,a2);

           Assert.That(a1.IsLinked, Is.True,"a1 should be linked");
           Assert.That(a2.IsLinked, Is.True,"a2 should be linked");

           a1.Unlink();

           Assert.That(a1.IsLinked,Is.False,"a1 should not be linked afterwards");
           Assert.That(a2.IsLinked, Is.False, "a2 should not be linked afterwards");
       }
Exemplo n.º 10
0
 public void CreateModuleNameCommand()
 {
     var cmd = CreateModuleName.Instance;
     var eng = new Engine();
     var app = new Application("cmnc");
     var sctx = new NullContext(eng, app, Enumerable.Empty<string>());
     var rawMn = cmd.Run(sctx, new[] {sctx.CreateNativePValue(new MetaEntry(new MetaEntry[]{"sys","1.0"}))});
     Assert.That(rawMn.Value,Is.InstanceOf<ModuleName>());
     var mn = (ModuleName) rawMn.Value;
     Assert.That(mn.Id,Is.EqualTo("sys"));
     Assert.That(mn.Version,Is.EqualTo(new Version(1,0)));
 }
Exemplo n.º 11
0
        public void DryCrossModuleCall()
        {
            var m1 = Module.Create(new ModuleName("dragon", new Version(1, 2)));
            var m2 = Module.Create(new ModuleName("std", new Version(1, 3, 1)));

            var a1 = new Application(m1);
            var a2 = new Application(m2);

            var f1 = a1.CreateFunction(Application.DefaultEntryFunction);

            var f2 = a2.CreateFunction("sayHello");

            f1.Code.Add(new Instruction(OpCode.func, 0, f2.Id, m2.Name));
            f1.Code.Add(new Instruction(OpCode.ret_value));

            const string helloModules = "Hello Modules";
            f2.Code.Add(new Instruction(OpCode.ldc_string,helloModules));
            f2.Code.Add(new Instruction(OpCode.ret_value));

            Console.WriteLine("=========== Module {0} ==========", m1.Name);
            a1.Store(Console.Out);
            Console.WriteLine();
            Console.WriteLine("=========== Module {0} ==========", m2.Name);
            a2.Store(Console.Out);

            var eng = new Engine();

            try
            {
                a1.Run(eng);
                Assert.Fail("Should not succeed as applications are not linked.");
            }
            catch (PrexoniteRuntimeException e)
            {
                Console.WriteLine("EXPECTED EXCEPTION");
                Console.WriteLine(e.Message);
                Console.WriteLine("END OF EXPECTED EXCEPTION");
            }

            Application.Link(a1, a2);
            var r = a1.Run(eng);
            Expect(r.Value,Is.InstanceOf<string>());
            Expect(r.Value,Is.EqualTo(helloModules));
        }
Exemplo n.º 12
0
            public override void CopyTo(Application[] array, int arrayIndex)
            {
                if (_application == null)
                    return;

                if (array == null)
                    throw new ArgumentNullException("array");
                if (arrayIndex < 0 || array.Length <= arrayIndex)
                    throw new ArgumentOutOfRangeException("arrayIndex", arrayIndex,
                        "Index is outside of the arrays bounds.");

                array[arrayIndex] = _application;
            }
Exemplo n.º 13
0
 public override bool TryGetApplication(ModuleName moduleName,
     out Application application)
 {
     if (_application == null || !_application.Module.Name.Equals(moduleName))
     {
         application = null;
         return false;
     }
     else
     {
         application = _application;
         return true;
     }
 }
Exemplo n.º 14
0
 internal override void _Clear()
 {
     _application = null;
 }
Exemplo n.º 15
0
 internal override void _Link(Application application)
 {
     if (!Equals(_application, application))
         throw new NotSupportedException(
             "Cannot link other applications into a singleton compound");
 }
Exemplo n.º 16
0
            public SingletonCompound(Application application)
            {
                if (application == null)
                    throw new ArgumentNullException("application");

                _application = application;
            }
Exemplo n.º 17
0
 public static void Link(Application application1, Application application2)
 {
     if (application1 == null)
         throw new ArgumentNullException("application1");
     if (application2 == null)
         throw new ArgumentNullException("application2");
     
     if (application1.IsLinkedTo(application2))
         return; //nothing to do.
     
     if(application1.IsLinked && application2.IsLinked)
     {
         if (application1.Compound.Count > application2.Compound.Count)
             application2._linkInto(application1.Compound);
         else
             application1._linkInto(application2.Compound);
     }
     else if(application1.IsLinked || (application1._compound != null && !(application1._compound is SingletonCompound)))
     {
         application2._linkInto(application1.Compound);
     }
     else if(application2.IsLinked || (application2._compound != null && !(application2._compound is SingletonCompound)))
     {
         application1._linkInto(application2.Compound);
     }
     else
     {
         Debug.Assert(application1.Compound is SingletonCompound, "Link(a,_): `a` is assumed to be part of a singleton compound.");
         if(application1._compound != null)
             application1._compound._Clear();
         application1._compound = ApplicationCompound.Create();
         application1._compound._Link(application1);
         application2._linkInto(application1._compound);
     }
 }
Exemplo n.º 18
0
 private static void _runApplication(Engine engine, Application app, IEnumerable<string> args)
 {
     app.Run(engine, args.Select(engine.CreateNativePValue).ToArray());
 }
Exemplo n.º 19
0
 public void IncludeAll(Application application)
 {
     if (application == null)
         throw new ArgumentNullException("application");
     foreach (var function in application.Functions)
         if (function.Meta[BenchmarkKey])
             Include(function);
 }
Exemplo n.º 20
0
 internal override void _Unlink(Application application)
 {
     if (Equals(application, _application))
         _application = null;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Determines whether this application is linked to the specified application.
 /// </summary>
 /// <param name="application">The application to look for.</param>
 /// <returns>True if the two applications are linked, false otherwise.</returns>
 public bool IsLinkedTo(Application application)
 {
     if (application == null)
         return false;
     else
         return IsLinked && _compound == application._compound;
 }
Exemplo n.º 22
0
 public void SetupCompilerEngine()
 {
     engine = new Engine();
     target = new Application("testApplication");
     sctx = new TestStackContext(engine, target);
 }