Exemple #1
0
 public override void Setup()
 {
     // Specify some of the requirements of IDE.
     fsr = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Exemple #2
0
        internal static ProtoCore.Core TestRunnerRunOnly(string code)
        {
            ProtoCore.Core core;
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner();


            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;

            string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\";

            options.IncludeDirectories.Add(testPath);

            core = new ProtoCore.Core(options);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new ProtoScriptTestRunner();

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.Execute(code, core);

            return(core);
        }
        internal static ProtoCore.Core DebugRunnerRunOnly(string code)
        {
            ProtoCore.Core core;
            DebugRunner    fsr;

            ProtoScript.Config.RunConfiguration runnerConfig;
            string testPath = @"..\..\..\Scripts\Debugger\";

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;

            core = new ProtoCore.Core(options);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.PreStart(code, runnerConfig);
            DebugRunner.VMState vms = null;

            vms = fsr.Run();

            return(core);
        }
        string GetFFIObjectStringValue(string dsVariable, int startBlock = 1, int arrayIndex = -1)
        {
            var helper     = DLLFFIHandler.GetModuleHelper(FFILanguage.CSharp);
            var marshaller = helper.GetMarshaller(TestFrameWork.testCore);
            Obj val        = testMirror.GetFirstValue(dsVariable, startBlock);

            ProtoCore.DSASM.StackValue sv;

            if (val.Payload == null)
            {
                return(null);
            }
            else if (val.Payload is DsasmArray)
            {
                DsasmArray arr = val.Payload as DsasmArray;
                Assert.IsTrue((arrayIndex >= 0 && arrayIndex < arr.members.Length), "Invalid array index for FFIObjectOutOfScope verification.");
                sv = arr.members[arrayIndex].DsasmValue;
            }
            else
            {
                sv = val.DsasmValue;
            }

            return(marshaller.GetStringValue(sv));
        }
        private void SetupCommonRunner(bool inDebugMode)
        {
            var options = new ProtoCore.Options();

            options.Verbose             = GetDisplayOutput();
            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            options.IDEDebugMode        = inDebugMode;
            AppendSearchPaths(options);

            this.core = new ProtoCore.Core(options);
            this.core.CurrentDSFileName = options.RootModulePathName;
            this.core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(this.core));
            this.core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(this.core));

            // Get configuration from host app
            var configurations = Solution.Current.ExecutionSession.HostApplication.Configurations;

            if (configurations != null)
            {
                foreach (var item in configurations)
                {
                    this.core.Configurations[item.Key] = item.Value;
                }
            }

            IOutputStream messageList = Solution.Current.GetMessage(false);

            this.core.RuntimeStatus.MessageHandler = messageList;

            workerParams.RegularRunMirror = null;
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            asynchronousExecution = Solution.Current.Asynchronous;
        }
Exemple #6
0
        internal static ProtoCore.Core DebugRunnerRunOnly(string code, out RuntimeCore runtimeCore)
        {
            ProtoCore.Core core;
            DebugRunner    fsr;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode     = ProtoCore.ExecutionMode.Serial;
            options.GCTempVarsOnDebug = false;

            string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\";

            options.IncludeDirectories.Add(testPath);

            core = new ProtoCore.Core(options);
            core.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(core));

            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.PreStart(code);
            DebugRunner.VMState vms = null;

            vms         = fsr.Run();
            runtimeCore = fsr.runtimeCore;
            return(core);
        }
Exemple #7
0
        internal static ProtoCore.Core TestRunnerRunOnly(string code, out RuntimeCore runtimeCore)
        {
            ProtoCore.Core core;
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScriptRunner();

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode = ProtoCore.ExecutionMode.Serial;

            string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\";

            options.IncludeDirectories.Add(testPath);

            core = new ProtoCore.Core(options);
            core.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(core));

            fsr = new ProtoScriptRunner();

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            runtimeCore = fsr.Execute(code, core);

            return(core);
        }
Exemple #8
0
 public override void Setup()
 {
     base.Setup();
     runner = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Exemple #9
0
 public void Setup()
 {
     core = new ProtoCore.Core(new ProtoCore.Options());
     core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
     core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     DLLFFIHandler.Register(FFILanguage.CPlusPlus, new PInvokeModuleHelper());
 }
Exemple #10
0
        internal static ProtoCore.Core TestRunnerRunOnly(string includePath, string code,
                                                         Dictionary <int, List <string> > map, string geometryFactory,
                                                         string persistentManager, out ExecutionMirror mirror)
        {
            ProtoCore.Core core;
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner();


            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            options.WatchTestMode       = true;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            includePath = Path.GetDirectoryName(includePath);
            options.IncludeDirectories.Add(includePath);

            //StreamWriter sw = File.CreateText(executionLogFilePath);
            TextOutputStream fs = new TextOutputStream(map);

            core = new ProtoCore.Core(options);

            core.Configurations.Add(ConfigurationKeys.GeometryXmlProperties, true);
            //core.Configurations.Add(ConfigurationKeys.GeometryFactory, geometryFactory);
            //core.Configurations.Add(ConfigurationKeys.PersistentManager, persistentManager);

            // By specifying this option we inject a mock Executive ('InjectionExecutive')
            // that prints stackvalues at every assignment statement
            // by overriding the POP_handler instruction - pratapa
            //core.ExecutiveProvider = new InjectionExecutiveProvider();

            core.BuildStatus.MessageHandler = fs;

            core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

            //Run

            mirror = fsr.Execute(code, core);

            //sw.Close();

            return(core);
        }
Exemple #11
0
 public override void Setup()
 {
     // Specify some of the requirements of IDE.
     runnerConfig             = new ProtoScript.Config.RunConfiguration();
     runnerConfig.IsParrallel = false;
     fsr = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Exemple #12
0
 public override void Setup()
 {
     base.Setup();
     runconfig             = new ProtoScript.Config.RunConfiguration();
     runconfig.IsParrallel = false;
     runner = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Exemple #13
0
        /// <summary>
        /// Creates a default core
        /// </summary>
        /// <returns>ProtoCore.Core</returns>
        private static Core CreateCore()
        {
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();
            var core = new Core(new Options());

            core.Compilers.Add(Language.Associative, new ProtoAssociative.Compiler(core));
            core.ParsingMode = ParseMode.AllowNonAssignment;
            return(core);
        }
Exemple #14
0
        internal void TestRunnerRunOnly(string includePath, string code, Dictionary <int, List <string> > map /*, string executionLogFilePath*/)
        {
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner();


            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.

            core.Options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            core.Options.SuppressBuildOutput = false;
            core.Options.WatchTestMode       = true;
            core.Options.GCTempVarsOnDebug   = false;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            core.Options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            if (!String.IsNullOrEmpty(includePath))
            {
                includePath = Path.GetDirectoryName(includePath);
                core.Options.IncludeDirectories.Add(includePath);
            }

            //StreamWriter sw = File.CreateText(executionLogFilePath);
            TextOutputStream fs = new TextOutputStream(map);

            // By specifying this option we inject a mock Executive ('InjectionExecutive')
            // that prints stackvalues at every assignment statement
            // by overriding the POP_handler instruction - pratapa
            core.ExecutiveProvider = new InjectionExecutiveProvider();

            core.BuildStatus.MessageHandler   = fs;
            core.RuntimeStatus.MessageHandler = fs;

            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

            //Run

            Mirror = fsr.Execute(code, core);

            //sw.Close();
            core.Cleanup();
        }
Exemple #15
0
        public void Setup()
        {
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            core_ = new ProtoCore.Core(options);
            core_.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core_));
            core_.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core_));
            runconfig_             = new ProtoScript.Config.RunConfiguration();
            runconfig_.IsParrallel = false;
            runner_ = new DebugRunner(core_);
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();
        }
Exemple #16
0
        public void Setup()
        {
            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            core = new ProtoCore.Core(options);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();
        }
Exemple #17
0
        internal static ProtoCore.Core DebugRunnerStepOver(string code, out RuntimeCore runtimeCore)
        {
            //Internal setup

            ProtoCore.Core core;
            DebugRunner    fsr;

            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            options.GCTempVarsOnDebug   = false;

            string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\";

            options.IncludeDirectories.Add(testPath);

            core = new ProtoCore.Core(options);
            core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));


            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.PreStart(code, runnerConfig);
            DebugRunner.VMState vms = null;

            while (!fsr.isEnded)
            {
                vms = fsr.StepOver();
            }

            runtimeCore = fsr.runtimeCore;
            return(core);
        }
Exemple #18
0
        private ProtoCore.Core SetupTestCore()
        {
            testCore = new ProtoCore.Core(new ProtoCore.Options());
            testCore.Configurations.Add(ConfigurationKeys.GeometryFactory, "DSGeometry.dll");
            testCore.Configurations.Add(ConfigurationKeys.PersistentManager, "DSGeometry.dll");
            testCore.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(testCore));
            testCore.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(testCore));

            // this setting is to fix the random failure of replication test case
            testCore.Options.ExecutionMode = ProtoCore.ExecutionMode.Serial;
            testCore.Options.Verbose       = true;
//            testCore.Options.kDynamicCycleThreshold = 5;

            //FFI registration and cleanup
            DLLFFIHandler.Register(FFILanguage.CPlusPlus, new ProtoFFI.PInvokeModuleHelper());
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();
            mErrorMessage = string.Empty;
            if (cfgImport)
            {
                testImport = cfgImport;
            }
            else
            {
                testImport = false;
            }
            Console.WriteLine("CONFIG:\t" + cfgImport);
            Console.WriteLine("CONFIG:\t" + cfgDebug);
            if (cfgDebug)
            {
                testImport = cfgDebug;
            }
            else
            {
                testDebug = false;
            }

            return(testCore);
        }
Exemple #19
0
        internal static void DebugRunnerStepIn(string includePath, string code, /*string logFile*/ Dictionary <int, List <string> > map, bool watchNestedMode = false)
        {
            //Internal setup
            ProtoCore.Core core;
            DebugRunner    fsr;

            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            options.GCTempVarsOnDebug   = false;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            if (!String.IsNullOrEmpty(includePath))
            {
                includePath = Path.GetDirectoryName(includePath);
                options.IncludeDirectories.Add(includePath);
            }


            core = new ProtoCore.Core(options);

            // Use the InjectionExecutive to overload POP and POPM
            // as we still need the symbol names and line nos. in debug mode for comparisons
            core.ExecutiveProvider = new InjectionExecutiveProvider();

            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

            //Run
            fsr.PreStart(code, runnerConfig);

            //StreamReader log = new StreamReader(logFile);

            //bool isPrevBreakAtPop = false;
            int    lineAtPrevBreak = -1;
            string symbolName      = null;

            DebugRunner.VMState vms = null;

            while (!fsr.isEnded)
            {
                vms = fsr.LastState;

                OpCode    opCode = OpCode.NONE;
                DebugInfo debug  = null;
                if (vms != null)
                {
                    // check if previous break is a POP
                    // if so, get the line no. and LHS
                    opCode = fsr.CurrentInstruction.opCode;
                    debug  = fsr.CurrentInstruction.debug;

                    if (opCode == ProtoCore.DSASM.OpCode.POP)
                    {
                        //isPrevBreakAtPop = true;
                        lineAtPrevBreak = vms.ExecutionCursor.StartInclusive.LineNo;
                    }
                }

                DebugRunner.VMState currentVms = fsr.Step();

                //if (isPrevBreakAtPop)

                if (debug != null)
                {
                    // Do not do the verification for imported DS files, for which the FilePath is non null
                    if (debug.Location.StartInclusive.SourceLocation.FilePath == null)
                    {
                        if (opCode == ProtoCore.DSASM.OpCode.POP)
                        {
                            VerifyWatch_Run(lineAtPrevBreak, core.DebugProps.CurrentSymbolName, core, map, watchNestedMode);
                        }
                        // if previous breakpoint was at a CALLR
                        else if (opCode == ProtoCore.DSASM.OpCode.CALLR)
                        {
                            if (core.DebugProps.IsPopmCall)
                            {
                                int ci = (int)currentVms.mirror.MirrorTarget.rmem.GetAtRelative(ProtoCore.DSASM.StackFrame.kFrameIndexClass).opdata;
                                VerifyWatch_Run(InjectionExecutive.callrLineNo, core.DebugProps.CurrentSymbolName, core, map, watchNestedMode, ci);
                            }
                        }
                    }
                }
                //isPrevBreakAtPop = false;
            }
            core.Cleanup();
        }
Exemple #20
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library"></param>
        public bool ImportLibrary(string library)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                string errorMessage = Properties.Resources.InvalidLibraryFormat;
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryHasBeenLoaded, library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            if (!pathManager.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryPathCannotBeFound, library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

                var functionTable = LibraryManagementCore.CodeBlockList[0].procedureTable;
                var classTable    = LibraryManagementCore.ClassTable;

                int functionNumber = functionTable.procList.Count;
                int classNumber    = classTable.ClassNodes.Count;

                CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library);


                if (LibraryManagementCore.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format(Properties.Resources.LibraryBuildError, library);
                    Log(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in LibraryManagementCore.BuildStatus.Errors)
                    {
                        Log(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                    return(false);
                }

                LoadLibraryMigrations(library);

                var loadedClasses = classTable.ClassNodes.Skip(classNumber);
                foreach (var classNode in loadedClasses)
                {
                    ImportClass(library, classNode);
                }

                var loadedFunctions = functionTable.procList.Skip(functionNumber);
                foreach (var globalFunction in loadedFunctions)
                {
                    ImportProcedure(library, globalFunction);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message));
                return(false);
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));

            // After a library is loaded, update the library core data with the liveRunner core data
            UpdateLibraryCoreData();
            return(true);
        }
Exemple #21
0
        public string GetClassTrace(StackValue val, Heap heap, int langblock, bool forPrint)
        {
            if (!formatParams.ContinueOutputTrace())
            {
                return("...");
            }

            RuntimeMemory rmem       = MirrorTarget.rmem;
            Executable    exe        = MirrorTarget.exe;
            ClassTable    classTable = MirrorTarget.RuntimeCore.DSExecutable.classTable;

            int classtype = val.metaData.type;

            if (classtype < 0 || (classtype >= classTable.ClassNodes.Count))
            {
                formatParams.RestoreOutputTraceDepth();
                return(string.Empty);
            }

            ClassNode classnode = classTable.ClassNodes[classtype];

            if (classnode.IsImportedClass)
            {
                var helper     = DLLFFIHandler.GetModuleHelper(FFILanguage.CSharp);
                var marshaller = helper.GetMarshaller(runtimeCore);
                var strRep     = marshaller.GetStringValue(val);
                formatParams.RestoreOutputTraceDepth();
                return(strRep);
            }
            else
            {
                var obj = heap.ToHeapObject <DSObject>(val);

                List <string> visibleProperties = null;
                if (null != propertyFilter)
                {
                    if (!propertyFilter.TryGetValue(classnode.Name, out visibleProperties))
                    {
                        visibleProperties = null;
                    }
                }

                StringBuilder classtrace = new StringBuilder();
                if (classnode.Symbols != null && classnode.Symbols.symbolList.Count > 0)
                {
                    bool firstPropertyDisplayed = false;
                    for (int n = 0; n < obj.Count; ++n)
                    {
                        SymbolNode symbol   = classnode.Symbols.symbolList[n];
                        string     propName = symbol.name;

                        if ((null != visibleProperties) && visibleProperties.Contains(propName) == false)
                        {
                            continue; // This property is not to be displayed.
                        }
                        if (firstPropertyDisplayed)
                        {
                            classtrace.Append(", ");
                        }

                        string propValue = "";
                        if (symbol.isStatic)
                        {
                            var        staticSymbol = exe.runtimeSymbols[langblock].symbolList[symbol.symbolTableIndex];
                            StackValue staticProp   = rmem.GetSymbolValue(staticSymbol);
                            propValue = GetStringValue(staticProp, heap, langblock, forPrint);
                        }
                        else
                        {
                            propValue = GetStringValue(obj.GetValueFromIndex(symbol.index, runtimeCore), heap, langblock, forPrint);
                        }
                        classtrace.Append(string.Format("{0} = {1}", propName, propValue));
                        firstPropertyDisplayed = true;
                    }
                }
                else
                {
                    var stringValues = obj.Values.Select(x => GetStringValue(x, heap, langblock, forPrint))
                                       .ToList();

                    for (int n = 0; n < stringValues.Count(); ++n)
                    {
                        if (0 != n)
                        {
                            classtrace.Append(", ");
                        }

                        classtrace.Append(stringValues[n]);
                    }
                }

                formatParams.RestoreOutputTraceDepth();
                if (classtype >= (int)ProtoCore.PrimitiveType.MaxPrimitive)
                {
                    if (forPrint)
                    {
                        return(string.Format("{0}{{{1}}}", classnode.Name, classtrace.ToString()));
                    }
                    else
                    {
                        string tempstr = (string.Format("{0}({1})", classnode.Name, classtrace.ToString()));
                        return(tempstr);
                    }
                }

                return(classtrace.ToString());
            }
        }
Exemple #22
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library">The library to be loaded</param>
        /// <param name="isExplicitlyImportedLib">Indicates if the library has been imported using the "File | ImportLibrary" command</param>
        internal bool ImportLibrary(string library, bool isExplicitlyImportedLib = false)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                string errorMessage = Properties.Resources.InvalidLibraryFormat;
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryHasBeenLoaded, library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            // Copy the library path so that the path can be reported in the case of a failure
            // to resolve the library path. If there is a failure "library" is set to null.
            string path = library;

            if (!pathManager.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryPathCannotBeFound, path);

                // In the case that a library was explicitly imported using the "File|Import Library" command
                // set the load failed args to not throw an exception if the load fails. This can happen after using
                // File|Import Library and then moving or deleting the library.
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(path, errorMessage,
                                                                   throwOnFailure: !isExplicitlyImportedLib));

                return(false);
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

                var functionTable = LibraryManagementCore.CodeBlockList[0].procedureTable;
                var classTable    = LibraryManagementCore.ClassTable;

                int functionNumber = functionTable.Procedures.Count;
                int classNumber    = classTable.ClassNodes.Count;

                CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library);


                if (LibraryManagementCore.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format(Properties.Resources.LibraryBuildError, library);
                    Log(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in LibraryManagementCore.BuildStatus.Errors)
                    {
                        Log(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    throw new Exception(errorMessage);
                }

                LoadLibraryMigrations(library);

                var loadedClasses = classTable.ClassNodes.Skip(classNumber);
                foreach (var classNode in loadedClasses)
                {
                    ImportClass(library, classNode);
                }

                var loadedFunctions = functionTable.Procedures.Skip(functionNumber);
                foreach (var globalFunction in loadedFunctions)
                {
                    ImportProcedure(library, globalFunction);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message,
                                                                   throwOnFailure: !isExplicitlyImportedLib));
                return(false);
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));

            // After a library is loaded, update the library core data with the liveRunner core data
            UpdateLibraryCoreData();
            return(true);
        }
Exemple #23
0
        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            var opts = new Options();

            if (args.Length == 0)
            {
                opts.WebRunner = false;
            }
            else
            {
                opts.WebRunner = true;
            }
            opts.ExecutionMode = ExecutionMode.Serial;

            ProtoCore.Core core = new Core(opts);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));


            if (!opts.WebRunner)
            {
                ProtoScriptTestRunner runner = new ProtoScriptTestRunner();
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
                ExecutionMirror mirror = runner.LoadAndExecute(@"..\..\..\Scripts\defectverify.ds", core);
                string          str    = mirror.GetCoreDump();
                //Console.WriteLine(str);
            }
            else //if (arg)
            {
                // @TODO(Gemeng): Do set "core.ExecutionLog" to some file :)

                ProtoScriptWebRunner runner = new ProtoScriptWebRunner();
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
                ExecutionMirror mirror = runner.LoadAndExecute(args[0], core);
                if (null != mirror)
                {
                    string str = mirror.GetCoreDump();
                    // core.coreDumpWriter.WriteLine(str);
                }

                // @TODO(Gemeng): 'coreDumpWriter' has been removed, instead of
                // doing that we should create an output file stream here with a
                // file name, and then write the "str" content into it.
                //
                // core.coreDumpWriter.Close();
            }


            //runner.LoadAndExecute(@"..\..\..\Scripts\array.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\arrayargs.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class2.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class3.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class4.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class5.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class6.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class7.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class8.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class9.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\class10.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\demo.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\expr.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\fusionarray.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\replication.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\simple.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\simple2.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\functionoverload.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\classfunctionoverload.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\inheritance.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\inheritance2.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\update.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\null.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\forloop.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\blockassign_imperative.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\blockassign_associative.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\test.ds", core);
            //runner.LoadAndExecute(@"..\..\..\Scripts\importtest.ds", core);

            //ExecutionMirror mirror = null;



            //string str = mirror.GetCoreDump();
            long ms = sw.ElapsedMilliseconds;

            sw.Stop();

            if (!opts.WebRunner)
            {
                Console.WriteLine(ms);
                Console.ReadLine();
            }
        }
Exemple #24
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library"></param>
        public void ImportLibrary(string library, ILogger logger)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                const string errorMessage = "Invalid library format.";
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format("Library {0} has been loaded.", library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            if (!DynamoPathManager.Instance.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format("Cannot find library path: {0}.", library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                int globalFunctionNumber = GraphUtilities.GetGlobalMethods(string.Empty).Count;

                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
                IList <ClassNode> importedClasses = GraphUtilities.GetClassesForAssembly(library);

                if (GraphUtilities.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format("Build error for library: {0}", library);
                    logger.LogWarning(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in GraphUtilities.BuildStatus.Errors)
                    {
                        logger.LogWarning(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                    return;
                }

                foreach (ClassNode classNode in importedClasses)
                {
                    ImportClass(library, classNode);
                }

                // GraphUtilities.GetGlobalMethods() ignores input and just
                // return all global functions. The workaround is to get
                // new global functions after importing this assembly.
                List <ProcedureNode> globalFunctions = GraphUtilities.GetGlobalMethods(string.Empty);
                for (int i = globalFunctionNumber; i < globalFunctions.Count; ++i)
                {
                    ImportProcedure(library, globalFunctions[i]);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message));
                return;
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));
        }
Exemple #25
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library"></param>
        public void ImportLibrary(string library, ILogger logger)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                const string errorMessage = "Invalid library format.";
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format("Library {0} has been loaded.", library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            if (!DynamoPathManager.Instance.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format("Cannot find library path: {0}.", library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

                var functionTable = libraryManagementCore.CodeBlockList[0].procedureTable;
                var classTable    = libraryManagementCore.ClassTable;

                int functionNumber = functionTable.procList.Count;
                int classNumber    = classTable.ClassNodes.Count;

                CompilerUtils.TryLoadAssemblyIntoCore(libraryManagementCore, library);

                if (libraryManagementCore.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format("Build error for library: {0}", library);
                    logger.LogWarning(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in libraryManagementCore.BuildStatus.Errors)
                    {
                        logger.LogWarning(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                    return;
                }

                var loadedClasses = classTable.ClassNodes.Skip(classNumber);
                foreach (var classNode in loadedClasses)
                {
                    ImportClass(library, classNode);
                }

                var loadedFunctions = functionTable.procList.Skip(functionNumber);
                foreach (var globalFunction in loadedFunctions)
                {
                    ImportProcedure(library, globalFunction);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message));
                return;
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));
        }