コード例 #1
0
ファイル: DebugRunner.cs プロジェクト: joespiff/Dynamo
        /// <summary>
        /// Setup to run with customised launch options
        /// </summary>
        /// <returns>Ready to run?</returns>
        /// 
        private bool _PreStart(string code, string fileName)
        {
            this.code = code;
            if (null == core)
            {
                core = new ProtoCore.Core(new ProtoCore.Options { IDEDebugMode = true });
                core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
                core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));

            }


            if (null != fileName)
            {
                core.CurrentDSFileName = Path.GetFullPath(fileName);
                core.Options.RootModulePathName = Path.GetFullPath(fileName);
            }

            //Run the compilation process
            if (Compile(out resumeBlockID))
            {
                inited = true;
                runtimeCore = CreateRuntimeCore(core);

                FirstExec();
                diList = BuildReverseIndex();
                return true;
            }
            else
            {
                inited = false;
                return false;
            }
        }
コード例 #2
0
        public void TestClassUsageInImpeartive()
        {
            ProtoCore.Core 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));
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            ExecutionMirror mirror = fsr.Execute(
            @"
            class foo
            {
            m : var;
            constructor Create(a1 : int)
            {
            m = a1;
            }
            }
            x;y;
            [Imperative]
            {
            p = foo.Create(16);
            x = p.m;

            p.m = 32;
            y = p.m;
            }
            "
            , core, out compileState);
            Assert.IsTrue((Int64)mirror.GetValue("x", 0).Payload == 16);
            Assert.IsTrue((Int64)mirror.GetValue("y", 0).Payload == 32);
        }
コード例 #3
0
 public void Setup()
 {
     Console.WriteLine("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));
 }
コード例 #4
0
ファイル: DebugRunner.cs プロジェクト: joespiff/Dynamo
 public DebugRunner(ProtoCore.Core core)
 {
     this.core = core;
     this.core.Options.IDEDebugMode = true;
     RegisteredBreakpoints = new List<Breakpoint>();
     executionsuspended = false;
 }
コード例 #5
0
ファイル: GCTest.cs プロジェクト: whztt07/Dynamo
 public void Setup()
 {
     ProtoCore.Options options = new ProtoCore.Options();
     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));
 }
コード例 #6
0
ファイル: CoreDump.cs プロジェクト: Benglin/designscript
 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));
     coreRunner = new ProtoScript.Runners.ProtoScriptTestRunner();
 }
コード例 #7
0
ファイル: ModifierStack.cs プロジェクト: RobertiF/Dynamo
 public void Setup()
 {
     core = new ProtoCore.Core(new ProtoCore.Options());
     core.Options.ExecutionMode = ProtoCore.ExecutionMode.Serial;
     core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
     core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
 }
コード例 #8
0
ファイル: BuildStatus.cs プロジェクト: Benglin/designscript
        //  logs all errors and warnings by default
        //
        public BuildStatus(Core core,bool warningAsError, System.IO.TextWriter writer = null, bool errorAsWarning = false)
        {
            this.core = core;
            //this.errorCount = 0;
            //this.warningCount = 0;
            warnings = new List<BuildData.WarningEntry>();

            errors = new List<BuildData.ErrorEntry>();
            this.warningAsError = warningAsError;
            this.errorAsWarning = errorAsWarning;

            if (writer != null)
            {
                consoleOut = System.Console.Out;
                System.Console.SetOut(writer);
            }

            // Create a default console output stream, and this can
            // be overwritten in IDE by assigning it a different value.
            this.MessageHandler = new ConsoleOutputStream();
            if (core.Options.WebRunner)
            {
                this.WebMsgHandler = new WebOutputStream(core);
            }
        }
コード例 #9
0
        public ExpressionInterpreterRunner(ProtoCore.Core core, ProtoLanguage.CompileStateTracker compileState)
        {
            Core = core;
            core.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter;

            this.compileState = compileState;
            compileState.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter; ;
        }
コード例 #10
0
ファイル: DebugRunner.cs プロジェクト: TheChosen0ne/Dynamo
 public DebugRunner(ProtoCore.Core core)
 {
     this.core = core;
     this.core.Options.IDEDebugMode = true;
     RegisteredBreakpoints = new List<Breakpoint>();
     core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;
     executionsuspended = false;
 }
コード例 #11
0
ファイル: FFITests.cs プロジェクト: samuto/designscript
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            ProtoLanguage.CompileStateTracker compileState = null;
            fsr.Execute(scriptCode, core, out compileState);
        }

        public void TestScriptFile(string filename)
        {
            ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options());
コード例 #12
0
ファイル: FFITests.cs プロジェクト: samuto/designscript
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
            //DLLFFIHandler.Env = ProtoFFI.CPPModuleHelper.GetEnv();
            //DLLFFIHandler.Register(FFILanguage.CPlusPlus, new ProtoFFI.PInvokeModuleHelper());
        }

        public void TestScript(string scriptCode)
        {
            ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options());
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
コード例 #13
0
ファイル: ProtoTestBase.cs プロジェクト: ankushraizada/Dynamo
        public virtual void Setup()
        {
            core = new ProtoCore.Core(new ProtoCore.Options());
            core.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(core));

            // This is set when a test is executed 
            runtimeCore = null;
        }
コード例 #14
0
ファイル: ProtoScriptTest.cs プロジェクト: RobertiF/Dynamo
        public void BasicInfrastructureTest()
        {
            ProtoCore.Core 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));
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            fsr.Execute(
@"
[Imperative]
コード例 #15
0
ファイル: ClassUtilsTest.cs プロジェクト: heegwon/Dynamo
 public void Setup()
 {
     Console.WriteLine("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.Env = ProtoFFI.CPPModuleHelper.GetEnv();
     //DLLFFIHandler.Register(FFILanguage.CPlusPlus, new ProtoFFI.PInvokeModuleHelper());
 }
コード例 #16
0
ファイル: MultiLanugageBasic.cs プロジェクト: RobertiF/Dynamo
    a = 3;
    b = 4;
}
", core);
        }
        [Test]
        public void TestSingleLanguageAssociative()
        {
            ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options());
コード例 #17
0
        /// <summary>
        /// Create a mirror for a given executive
        /// </summary>
        /// <param name="exec"></param>
        public ExecutionMirror(ProtoCore.DSASM.Executive exec, ProtoCore.Core coreObj)
        {
            Debug.Assert(exec != null, "Can't mirror a null executive");

            core = coreObj;
            MirrorTarget = exec;

            LoadPropertyFilters();
        }
コード例 #18
0
ファイル: MultiLanugageBasic.cs プロジェクト: RobertiF/Dynamo
 }
 [Test]
 public void TestMultLanguageAssociativeImperative()
 {
     ProtoCore.Core 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));
     ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
     fsr.Execute(
コード例 #19
0
ファイル: MultiLanugageBasic.cs プロジェクト: RobertiF/Dynamo
[Associative]
{
    a = [Imperative]
        {
            return= 5;
        }
    b = 4;
}
", core);
        }
コード例 #20
0
ファイル: CSFFITest.cs プロジェクト: RobertiF/Dynamo
 public ProtoCore.Core Setup()
 {
     ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options());
     core.Options.ExecutionMode = ProtoCore.ExecutionMode.Serial;
     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());
     CLRModuleType.ClearTypes();
     return core;
 }
コード例 #21
0
ファイル: FFITests.cs プロジェクト: samuto/designscript
            Obj o = mirror.GetValue("a");
            Assert.IsTrue((Int64)o.Payload == 24);
        }

        [SetUp]
        public void Setup()
        {
            Console.WriteLine("Setup");
            core = new ProtoCore.Core(new ProtoCore.Options());

            core.Configurations.Add(ConfigurationKeys.GeometryFactory, "DSGeometry.dll");
            core.Configurations.Add(ConfigurationKeys.PersistentManager, "DSGeometry.dll");
コード例 #22
0
ファイル: ProtoScriptTest.cs プロジェクト: RobertiF/Dynamo
        public void ParserFailTest2()
        {
            ProtoCore.Core 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));
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            //@TODO: What exception should this throw
            Assert.Throws(typeof(ProtoCore.Exceptions.CompileErrorsOccured), () =>
            {
                fsr.Execute(
    @"
[
{
コード例 #23
0
ファイル: TestFunction.cs プロジェクト: heegwon/Dynamo
 public void Setup()
 {
     // Specify some of the requirements of IDE.
     ProtoCore.Options 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 ProtoScript.Runners.DebugRunner(core);
 }
コード例 #24
0
        public override void Init()
        {
            base.Init();

            var options = new ProtoCore.Options();
            options.RootModulePathName = string.Empty;
            libraryServicesCore = new ProtoCore.Core(options);
            libraryServicesCore.Executives.Add(ProtoCore.Language.kAssociative,
                new ProtoAssociative.Executive(libraryServicesCore));
            libraryServicesCore.Executives.Add(ProtoCore.Language.kImperative,
                new ProtoImperative.Executive(libraryServicesCore));

            libraryServices = new LibraryServices(libraryServicesCore);
        }
コード例 #25
0
ファイル: EventTest.cs プロジェクト: algobasket/Dynamo
 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();
 }
コード例 #26
0
        private ProtoCore.Core SetupTestCore(string csStateName)
        {
            ProtoCore.CallsiteExecutionState.filename = csStateName;
            RemoveTestCallsiteStateFile(ProtoCore.CallsiteExecutionState.GetThisSessionFileName());
            ProtoCore.Core testCore = new ProtoCore.Core(new ProtoCore.Options());
            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.EnableCallsiteExecutionState = true;

            return testCore;
        }
コード例 #27
0
ファイル: SetValueTests.cs プロジェクト: RobertiF/Dynamo
 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();
 }
コード例 #28
0
ファイル: FFITests.cs プロジェクト: samuto/designscript
        public static void TestMinFac()
        {
            Assert.Ignore("Testing old C++ FFI. Ignored");
            String code =
            @"[Associative] 
             { 
               external (""factorial"") def factorial : int (num4 : int); 
               a = factorial(4); 
             }
            ";
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            ProtoCore.Core 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));

            ProtoLanguage.CompileStateTracker compileState = null;
コード例 #29
0
ファイル: ProtoRunner.cs プロジェクト: sh4nnongoh/Dynamo
        public void PreStart(String source, Dictionary<string, Object> context)
        {
            ProtoCore.Options options = new ProtoCore.Options();
            options.ExecutionMode = ProtoCore.ExecutionMode.Serial;


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

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

            ExecutionContext = new ProtoCore.CompileTime.Context(source, context);

            Runner = new ProtoScriptRunner();
        }
コード例 #30
0
ファイル: GraphBuilder.cs プロジェクト: ankushraizada/Dynamo
        /// Checks if the string in code block node is a literal or an identifier or has multiple lines of code.
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static SnapshotNodeType AnalyzeString(string code)
        {
            SnapshotNodeType type = SnapshotNodeType.None;
            if (!code.EndsWith(";")) code += ";";
            List<ProtoCore.AST.Node> n = new List<ProtoCore.AST.Node>();

            try
            {
                ProtoCore.Options options = new ProtoCore.Options();
                options.RootModulePathName = string.Empty;

                ProtoCore.Core 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));
                core.IsParsingPreloadedAssembly = false;
                core.IsParsingCodeBlockNode = true;
                core.ParsingMode = ProtoCore.ParseMode.AllowNonAssignment;

                System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(code));
                ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
                ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core);

                p.Parse();
                ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockNode = p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode;
                n = p.GetParsedASTList(codeBlockNode);
            }
            catch (Exception)
            {
                //if syntax return SnapshotNodeType as None
                return SnapshotNodeType.CodeBlock;
            }

            if (n.Count > 1 || n.Count == 0)
                type = SnapshotNodeType.CodeBlock;
            else if (n[0] is ProtoCore.AST.AssociativeAST.BinaryExpressionNode)
                type = SnapshotNodeType.CodeBlock;
            else if (n[0] is ProtoCore.AST.AssociativeAST.IdentifierNode)
                type = SnapshotNodeType.Identifier;
            else if (n[0] is ProtoCore.AST.AssociativeAST.IntNode || n[0] is ProtoCore.AST.AssociativeAST.DoubleNode || n[0] is ProtoCore.AST.AssociativeAST.StringNode || n[0] is ProtoCore.AST.AssociativeAST.FunctionCallNode || n[0] is ProtoCore.AST.AssociativeAST.RangeExprNode)
                type = SnapshotNodeType.Literal;
            else type = SnapshotNodeType.CodeBlock;
            return type;
        }
コード例 #31
0
ファイル: NodeToCode.cs プロジェクト: rafatahmed/Dynamo
 public IdentifierVisitor(Action <IdentifierNode> func, ProtoCore.Core core)
 {
     identFunc = func;
     this.core = core;
 }
コード例 #32
0
 public CompilationServices(ProtoCore.Core core)
 {
     compilationCore = core;
 }
コード例 #33
0
        /// <summary>
        /// A CodeBlock represents a body of DS code
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="type"></param>
        /// <param name="langId"></param>
        /// <param name="cbID"></param>
        /// <param name="symbols"></param>
        /// <param name="procTable"></param>
        /// <param name="isBreakableBlock"></param>
        /// <param name="core"></param>
        public CodeBlock(Guid guid, CodeBlockType type, ProtoCore.Language langId, int cbID, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoCore.Core core = null)
        {
            this.guid = guid;
            blockType = type;

            parent   = null;
            children = new List <CodeBlock>();

            language    = langId;
            instrStream = new InstructionStream(langId, core);

            symbolTable    = symbols;
            procedureTable = procTable;

            isBreakable = isBreakableBlock;
            core.CompleteCodeBlockList.Add(this);
            this.codeBlockId = core.CompleteCodeBlockList.Count - 1;

            symbols.RuntimeIndex = this.codeBlockId;

            if (core.ProcNode != null)
            {
                core.ProcNode.ChildCodeBlocks.Add(codeBlockId);
            }
        }
コード例 #34
0
 /// <summary>
 ///  Returns class mirror that can be reflected upon
 ///  The ClassMirror is intended to be used at statically at compile time
 /// </summary>
 /// <returns></returns>
 public static ClassMirror Reflect(string className, ProtoCore.Core core)
 {
     return(new ClassMirror(className, core));
 }
コード例 #35
0
            /// <summary>
            /// Compares two nodeSearchElements - general rules of the sort as follows:
            /// If all return types of the two searchElements are the same, they are equal.
            /// If any return type of both searchElements is an exact match for our input type, they are equal.
            /// If a searchElement is null, it is larger than the other element.
            /// If a single searchElement's return type list contains an exact match it is smaller.
            /// If the minimum type distance between a searchElements return types and our inputType than this searchElement is smaller. (closer)
            /// If the minimim type distances are the same the searchElements are equal.
            /// </summary>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="typeNameToCompareTo"></param>
            /// <param name="core"></param>
            /// <returns></returns>
            private int CompareNodeSearchElementByTypeDistance(NodeSearchElement x, NodeSearchElement y, string typeNameToCompareTo, ProtoCore.Core core)
            {
                /*
                 * -1	x precedes y.
                 * 0 x and y are equal
                 * 1	x is after y.
                 */
                var none       = new string[] { Resources.NoneString };
                var xTypeNames = x.OutputParameters;
                var yTypeNames = y.OutputParameters;

                //if either element is a ztsearchElement then just use the type name (this strips off the rank)
                if (x is ZeroTouchSearchElement xzt)
                {
                    xTypeNames = new string[] { xzt.Descriptor.ReturnType.Name };
                }
                // for non ZT nodes, we don't have concrete return types, so we need to parse the typename.
                else
                {
                    //if inputPortType is an array, lets just use the class name to match
                    xTypeNames = xTypeNames.Select(type => (ParserUtils.ParseWithCore($"dummyName:{ type};", core).
                                                            CodeBlockNode.Children().ElementAt(0) as TypedIdentifierNode).datatype.Name);
                }
                if (y is ZeroTouchSearchElement yzt)
                {
                    yTypeNames = new string[] { yzt.Descriptor.ReturnType.Name };
                }
                // for non ZT nodes, we don't have concrete return types, so we need to parse the typename.
                else
                {
                    yTypeNames = yTypeNames.Select(type => (ParserUtils.ParseWithCore($"dummyName:{ type};", core).
                                                            CodeBlockNode.Children().ElementAt(0) as TypedIdentifierNode).datatype.Name);
                }

                if (xTypeNames.SequenceEqual(yTypeNames))
                {
                    return(0);
                }

                // x and y are equal because both typeLists contain an exact match
                if (xTypeNames.Any(xType => xType == typeNameToCompareTo) && (yTypeNames.Any(yType => yType == typeNameToCompareTo)))
                {
                    return(0);
                }

                // null is further away, so x is at the end of list.
                if (xTypeNames.SequenceEqual(none))
                {
                    return(1);
                }
                // null is further away, so y is at the end of the list.
                if (yTypeNames.SequenceEqual(none))
                {
                    return(-1);
                }

                // x precedes y because it contains an exact match
                if (xTypeNames.Any(xType => xType == typeNameToCompareTo))
                {
                    return(-1);
                }
                //  y precedes x because it contains an exact match
                if (yTypeNames.Any(yType => yType == typeNameToCompareTo))
                {
                    return(1);
                }

                var xminDistance = xTypeNames.Select(name => GetTypeDistance(typeNameToCompareTo, name, core)).Min();
                var yminDistance = yTypeNames.Select(name => GetTypeDistance(typeNameToCompareTo, name, core)).Min();

                //if distance of x to currentSelectedType is greater than y distance
                //then x is further away
                if (xminDistance > yminDistance)
                {
                    return(1);
                }
                if (xminDistance == yminDistance)
                {
                    return(0);
                }
                // distance2 < distance 1
                // x precedes y
                return(-1);
            }
コード例 #36
0
 /// <summary>
 /// This consutructor is for instantiating a Runtime mirror object where we already have the mirrorData
 /// </summary>
 /// <param name="mirrorData"></param>
 /// <param name="core"></param>
 public RuntimeMirror(MirrorData mirrorData, ProtoCore.RuntimeCore runtimeCoreReflect, ProtoCore.Core staticCore = null)
     : base(runtimeCoreReflect, staticCore)
 {
     Validity.Assert(this.runtimeCore != null);
     TargetExecutive     = runtimeCoreReflect.CurrentExecutive.CurrentDSASMExec;
     deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, runtimeCoreReflect);
     this.mirrorData     = mirrorData;
 }
コード例 #37
0
 public ExpressionInterpreterRunner(ProtoCore.Core core)
 {
     Core          = core;
     core.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter;
 }
コード例 #38
0
ファイル: PInvokeFFI.cs プロジェクト: ssnkamali/Dynamo
 public override FFIObjectMarshler GetMarshaller(ProtoCore.Core core)
 {
     return(null);
 }
コード例 #39
0
 protected MirrorObject(ProtoCore.RuntimeCore runtimeCore, ProtoCore.Core staticCore = null)
 {
     this.runtimeCore        = runtimeCore;
     MirrorObject.staticCore = staticCore;
 }
コード例 #40
0
 public CodeCompletionServices(ProtoCore.Core core)
 {
     this.core = core;
 }
コード例 #41
0
        public bool Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = string.Empty;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;


                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                context.SetData(string.Empty, new Dictionary <string, object>(), null);
                ProtoCore.Language id = globalBlock.language;


                ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                codeblock.Body.AddRange(astList);

                core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock);

                core.BuildStatus.ReportBuildResult();

                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(buildSucceeded);
        }
コード例 #42
0
        /// <summary>
        /// Compile and execute the given list of ASTs
        /// </summary>
        /// <param name="astList"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        public ExecutionMirror Execute(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, bool isTest = true)
        {
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(astList, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                Execute(core, blockId, new ProtoCore.CompileTime.Context(), new ProtoCore.Runtime.Context());
                if (!isTest)
                {
                    core.Heap.Free();
                }
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }

            if (isTest && !core.Options.CompileToLib)
            {
                return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core));
            }

            return(null);
        }
コード例 #43
0
        private bool Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, ProtoCore.CompileTime.Context context)
        {
            bool buildSucceeded = false;

            if (astList.Count <= 0)
            {
                // Nothing to compile
                buildSucceeded = true;
            }
            else
            {
                try
                {
                    //defining the global Assoc block that wraps the entire .ds source file
                    ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                    globalBlock.Language = ProtoCore.Language.Associative;
                    globalBlock.Code     = string.Empty;

                    //passing the global Assoc wrapper block to the compiler
                    context.SetData(string.Empty, new Dictionary <string, object>(), null);
                    ProtoCore.Language id = globalBlock.Language;


                    ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                    codeblock.Body.AddRange(astList);

                    int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
                    core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock);

                    core.BuildStatus.ReportBuildResult();

                    buildSucceeded = core.BuildStatus.BuildSucceeded;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            return(buildSucceeded);
        }
コード例 #44
0
            public RuntimeMirror(string varname, int blockDecl, ProtoCore.RuntimeCore runtimeCore, ProtoCore.Core staticCore = null)
                : base(runtimeCore, staticCore)
            {
                TargetExecutive     = runtimeCore.CurrentExecutive.CurrentDSASMExec;
                deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, runtimeCore);

                Validity.Assert(this.runtimeCore != null);

                variableName     = varname;
                blockDeclaration = blockDecl;
                StackValue svData = deprecateThisMirror.GetValue(variableName, blockDeclaration).DsasmValue;

                mirrorData = new MirrorData(staticCore, this.runtimeCore, svData);
            }
コード例 #45
0
ファイル: Reflection.cs プロジェクト: santom/designscript
            /// <summary>
            ///  Returns class mirror that can be reflected upon
            ///  The ClassMirror is intended to be used at statically at compile time
            /// </summary>
            /// <returns></returns>
            //public static ClassMirror Reflect(string className, ProtoCore.Core core)
            //{
            //    return new ClassMirror(className, core);
            //}

            public static LibraryMirror Reflect(string assemblyName, ProtoCore.Core core)
            {
                return(new LibraryMirror(assemblyName, core));
            }
コード例 #46
0
 public LibraryMirror(string libName, ProtoCore.Core core)
     : base(core, libName)
 {
     LibraryName = libName;
 }
コード例 #47
0
        /// <summary>
        /// Parse simple RHS expression
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static ProtoCore.AST.AssociativeAST.AssociativeNode ParseRHSExpression(string expression, ProtoCore.Core core)
        {
            if (string.IsNullOrEmpty(expression))
            {
                throw new ArgumentException("expression");
            }

            if (core == null)
            {
                throw new ArgumentException("core");
            }

            var currentParsingMode = core.ParsingMode;
            var currentParsingFlag = core.IsParsingCodeBlockNode;

            core.ParsingMode            = ProtoCore.ParseMode.AllowNonAssignment;
            core.IsParsingCodeBlockNode = true;

            ProtoCore.AST.Node astNode = null;
            try
            {
                expression = expression.Trim();
                if (!expression.EndsWith(";"))
                {
                    expression += ";";
                }

                expression = "__dummy = " + expression;
                astNode    = ParserUtils.ParseWithCore(expression, core);
            }
            catch (ProtoCore.BuildHaltException ex)
            {
            }

            core.ParsingMode            = currentParsingMode;
            core.IsParsingCodeBlockNode = currentParsingFlag;

            if (astNode == null)
            {
                return(null);
            }

            var cbn = astNode as ProtoCore.AST.AssociativeAST.CodeBlockNode;

            if (cbn != null && cbn.Body.Any())
            {
                var expr = cbn.Body[0] as ProtoCore.AST.AssociativeAST.BinaryExpressionNode;
                if (expr != null)
                {
                    return(expr.RightNode);
                }
            }

            return(null);
        }
コード例 #48
0
        /// <summary>
        /// Compile and execute the given list of ASTs
        /// </summary>
        /// <param name="astList"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        public ExecutionMirror Execute(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, bool isTest = true)
        {
            ProtoCore.RuntimeCore runtimeCore = null;
            bool succeeded = CompileAndGenerateExe(astList, core, new ProtoCore.CompileTime.Context());

            if (succeeded)
            {
                runtimeCore = ExecuteVM(core);
                if (!isTest)
                {
                    runtimeCore.RuntimeMemory.Heap.Free();
                }
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }

            if (isTest)
            {
                return(new ExecutionMirror(runtimeCore.CurrentExecutive.CurrentDSASMExec, runtimeCore));
            }

            return(null);
        }
コード例 #49
0
ファイル: TestFrameWork.cs プロジェクト: tylerputnam/Dynamo
        /// <summary>
        /// Method to run an inline Ds script.
        /// </summary>
        /// <param name="sourceCode">The String contains the ds codes</param>
        /// <returns></returns>
        public virtual ExecutionMirror RunScriptSource(string sourceCode, string errorstring = "", string includePath = "")
        {
            if (testImport)
            {
                Guid g;
                g = Guid.NewGuid();

                StackTrace trace  = new StackTrace();
                int        caller = 2;

                string tempPath  = System.IO.Path.GetTempPath();
                string import    = @"testImport\";
                string importDir = Path.Combine(tempPath, import);

                if (!Directory.Exists(importDir))
                {
                    System.IO.Directory.CreateDirectory(importDir);
                }


                string importFileName = (g.ToString() + ".ds");
                createDSFile(importFileName, importDir, sourceCode);

                return(testMirror = RunScriptFile(importDir, importFileName));
            }
            else if (testDebug)
            {
                Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
                if (!String.IsNullOrEmpty(includePath))
                {
                    if (System.IO.Directory.Exists(includePath))
                    {
                        testCore.Options.IncludeDirectories.Add(includePath);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Path: {0} does not exist.", includePath));
                    }
                }

                StringReader file = new StringReader(sourceCode);
                WatchTestFx.GeneratePrintStatements(file, ref map);

                WatchTestFx fx = new WatchTestFx();
                testCore = fx.TestCore;
                fx.CompareRunAndWatchResults("", sourceCode, map);
                testMirror = fx.Mirror;

                return(testMirror);
            }
            else
            {
                SetupTestCore();
                if (!String.IsNullOrEmpty(includePath))
                {
                    if (System.IO.Directory.Exists(includePath))
                    {
                        testCore.Options.IncludeDirectories.Add(includePath);
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Path: {0} does not exist.", includePath));
                    }
                }
                testMirror = runner.Execute(sourceCode, testCore, out testRuntimeCore);

                if (dumpDS)
                {
                    String fileName   = TestContext.CurrentContext.Test.Name + ".ds";
                    String folderName = TestContext.CurrentContext.Test.FullName;

                    string[] substrings = folderName.Split('.');

                    string path = "..\\..\\..\\test\\core\\dsevaluation\\DSFiles\\";
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    createDSFile(fileName, path, sourceCode);
                }

                SetErrorMessage(errorstring);
                return(testMirror);
            }
        }
コード例 #50
0
 public ExpressionInterpreterRunner(ProtoCore.Core core, ProtoCore.RuntimeCore runtimeCore)
 {
     Core             = core;
     this.runtimeCore = runtimeCore;
 }
コード例 #51
0
 internal NodeSearchElementComparer(string typeNameToCompareTo, ProtoCore.Core core)
 {
     this.typeNameToCompareTo = typeNameToCompareTo;
     this.core = core;
 }
コード例 #52
0
 /// <summary>
 ///  Returns a library mirror that can be reflected upon
 ///  The LibraryMirror is  used for static reflection of classes etc.
 /// </summary>
 /// <returns></returns>
 public static LibraryMirror Reflect(string assemblyName, IList <ProtoCore.DSASM.ClassNode> classNodes, ProtoCore.Core core)
 {
     return(new LibraryMirror(core, assemblyName, classNodes));
 }
コード例 #53
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));
 }
コード例 #54
0
 /// <summary>
 /// Experimental constructor that takes in a core object
 /// </summary>
 /// <param name="sv"></param>
 public MirrorData(ProtoCore.Core core, StackValue sv)
 {
     this.core = core;
     svData    = sv;
 }
コード例 #55
0
ファイル: NodeToCode.cs プロジェクト: rafatahmed/Dynamo
        /// <summary>
        /// Renumber variables used in astNode.
        /// </summary>
        /// <param name="astNode"></param>
        /// <param name="numberingMap"></param>
        /// <param name="variableMap"></param>
        private static void VariableNumbering(
            ProtoCore.Core core,
            AssociativeNode astNode,
            NodeModel node,
            Dictionary <string, NumberingState> numberingMap,
            Dictionary <string, string> renamingMap,
            Dictionary <string, string> inputMap,
            Dictionary <string, string> outputMap,
            HashSet <string> mappedVariables)
        {
            Action <IdentifierNode> func = n =>
            {
                var ident = n.Value;

                // This ident is from external non-code block node's output
                // port, or it is from a temporary variable in code block node,
                // it is not necessary to do renumbering because the name is
                // unique.
                if (inputMap.ContainsKey(ident) || /*IsTempVarFromCodeBlockNode(ident, renamingMap)*/ renamingMap.ContainsKey(ident))
                {
                    return;
                }

                NumberingState ns;
                if (numberingMap.TryGetValue(ident, out ns))
                {
                    // ident already defined somewhere else. So we continue to
                    // bump its ID until numbered variable won't conflict with
                    // all existing variables.
                    if (ns.IsNewSession)
                    {
                        ns.BumpID();
                        while (mappedVariables.Contains(ns.NumberedVariable))
                        {
                            ns.BumpID();
                        }

                        ns.IsNewSession = false;
                    }
                    // ident already defined somewhere else, but we already
                    // renumber this variable, so continue to use re-numbered
                    // one.
                }
                else
                {
                    // It is a new variable. But we need to check if some other
                    // variables are renamed to this one because of renumbering.
                    // If there is confliction, continue to bump its ID.
                    ns = new NumberingState(ident);
                    numberingMap[ident] = ns;

                    while (mappedVariables.Contains(ns.NumberedVariable))
                    {
                        ns.BumpID();
                    }
                }

                if (ns.ID != 0)
                {
                    var numberedVar = ns.NumberedVariable;
                    n.Name = n.Value = numberedVar;

                    // If this variable is numbered, and it is also output to
                    // other node, we should remap the output variable to
                    // this re-numbered variable.
                    string name = string.Format("{0}%{1}", ident, node.GUID);
                    if (renamingMap.ContainsKey(name))
                    {
                        var mappedName = renamingMap[name];
                        renamingMap[mappedName] = numberedVar;

                        // Record in output map.
                        if (outputMap.ContainsKey(mappedName))
                        {
                            outputMap[mappedName] = numberedVar;
                        }
                    }
                }

                // If this one is not the variable that going to be renamed, then
                // add to mapped variable set
                if (!renamingMap.ContainsKey(ns.NumberedVariable))
                {
                    mappedVariables.Add(ns.NumberedVariable);
                }
            };

            IdentifierVisitor visitor = new IdentifierVisitor(func, core);

            astNode.Accept(visitor);
        }
コード例 #56
0
        /// <summary>
        /// API used by external host to build AST for any function call
        /// </summary>
        /// <param name="type"></param>
        /// <param name="hostInstancePtr"></param>
        /// <param name="functionName"></param>
        /// <param name="userDefinedArgs"></param>
        /// <param name="primitiveArgs"></param>
        /// <param name="formatString"></param>
        /// <param name="core"></param>
        /// <param name="symbolName"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static AssociativeNode BuildAST(string type, long hostInstancePtr, string functionName, List <IntPtr> userDefinedArgs, List <string> primitiveArgs, string formatString, ProtoCore.Core core, ref string symbolName, ref string code)
        {
            symbolName = string.Empty;
            List <AssociativeNode> astNodes = new List <AssociativeNode>();
            FunctionDotCallNode    dotCall  = null;

            BinaryExpressionNode bNode = null;

            ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCallNode = null;
            List <AssociativeNode> argNodes = new List <AssociativeNode>();

            if (userDefinedArgs != null)
            {
                foreach (var arg in userDefinedArgs)
                {
                    dotCallNode = CreateEntityNode((long)arg, core);
                    bNode       = CreateAssignmentNode(dotCallNode);
                    argNodes.Add(bNode);
                }
                astNodes.AddRange(argNodes);
            }
            List <ProtoCore.AST.AssociativeAST.AssociativeNode> args = CreateArgs(formatString, primitiveArgs, argNodes);


            if (hostInstancePtr != 0)
            {
                dotCallNode = CreateEntityNode(hostInstancePtr, core);
                bNode       = CreateAssignmentNode(dotCallNode);
                astNodes.Add(bNode);

                dotCall = CreateFunctionCallNode((bNode.LeftNode as IdentifierNode).Value, functionName, args, core);
            }
            else
            {
                dotCall = CreateFunctionCallNode(type, functionName, args, core);
            }
            bNode = CreateAssignmentNode(dotCall);
            if (bNode.LeftNode is IdentifierNode)
            {
                symbolName = (bNode.LeftNode as IdentifierNode).Value;
            }
            astNodes.Add(bNode);

            CodeBlockNode codeBlockNode = new CodeBlockNode();

            codeBlockNode.Body = astNodes;


            ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(astNodes);
            code = codeGen.GenerateCode();

            return(codeBlockNode);
        }
コード例 #57
0
ファイル: NodeToCode.cs プロジェクト: rafatahmed/Dynamo
        /// <summary>
        /// Compile a set of nodes to ASTs.
        ///
        /// Note:
        /// 1. Nodes should be a clique with regarding to convertibility and
        ///    selection state. That is, these nodes can be safely to be
        ///    converted into a single code block node. It shouldn't have
        ///    unconvertible or unselected node on any path (if there is) that
        ///    connects any two of these nodes, otherwise there will be
        ///    circular references between unconvertible/unselected node and
        ///    code block node.
        ///
        ///    To split arbitary node set into cliques, use
        ///    NodeToCodeUtils.GetCliques().
        ///
        /// 2. WorkspaceNodes are all nodes in current workspace. We need the
        ///    whole graph so that each to-be-converted node will have correct
        ///    order in the final code block node.
        /// </summary>
        /// <param name="core">Library core</param>
        /// <param name="astBuilder">Ast builder</param>
        /// <param name="workspaceNodes">The whole workspace nodes</param>
        /// <param name="nodes">Selected node that can be converted to a single code block node</param>
        /// <returns></returns>
        public static NodeToCodeResult NodeToCode(
            ProtoCore.Core core,
            AstBuilder astBuilder,
            IEnumerable <NodeModel> workspaceNodes,
            IEnumerable <NodeModel> nodes)
        {
            // The basic worflow is:
            //   1. Compile each node to get its cde in AST format
            //
            //   2. Variable numbering to avoid confliction. For example, two
            //      code block nodes both have assignment "y = x", we need to
            //      rename "y" to "y1" and "y2" respectively.
            //
            //   3. Variable remapping. For example, code block node
            //      "x = 1" connects to "a = b", where the second code block
            //      node will have initialization "b = x_guid" where "x_guid"
            //      is because of variable mappining in the first code block
            //      node. We should restore it to its original name.
            //
            //      Note in step 2 we may rename "x" to "xn".
            //
            //   4. Generate short name for long name variables. Typically they
            //      are from output ports from other nodes.
            //
            //   5. Do constant progation to optimize the generated code.
            #region Step 1 AST compilation

            var sortedGraph = AstBuilder.TopologicalSortForGraph(workspaceNodes);
            var sortedNodes = sortedGraph.Where(nodes.Contains);

            var allAstNodes = astBuilder.CompileToAstNodes(sortedNodes, AstBuilder.CompilationContext.NodeToCode, false);

            #endregion

            #region Step 2 Varialbe numbering

            // External inputs will be in input map
            // Internal non-cbn will be input map & output map
            // Internal cbn will be in renaming map and output map

            // Map from mapped variable to its original name. These variables
            // are from code block nodes that in the selection.
            Dictionary <string, string> renamingMap = null;;

            // Input variable to renamed input variable map
            Dictionary <string, string> inputMap = null;

            // Output variable to renamed output variable map
            Dictionary <string, string> outputMap = null;

            // Collect all inputs/outputs/candidate renaming variables
            GetInputOutputMap(nodes, out inputMap, out outputMap, out renamingMap);

            // Variable numbering map. Value field indicates current current
            // numbering value of the variable. For example, there are variables
            // t1, t2, ... tn and the ID of variable t's NumberingState is n.
            var numberingMap = new Dictionary <string, NumberingState>();

            // In this step, we'll renumber all variables that going to be in
            // the same code block node. That is,
            //
            //     "x = 1; y = x;"   and
            //     "x = 2; y = x;"
            //
            // Will be renumbered to
            //
            //    "x1 = 1; y1 = x1;" and
            //    "x2 = 2; y2 = x2;"
            var mappedVariables = new HashSet <string>();
            foreach (var t in allAstNodes)
            {
                // Reset variable numbering map
                foreach (var p in numberingMap)
                {
                    p.Value.IsNewSession = true;
                }

                foreach (var astNode in t.Item2)
                {
                    VariableNumbering(core, astNode, t.Item1, numberingMap, renamingMap, inputMap, outputMap, mappedVariables);
                }
            }

            renamingMap = renamingMap.Where(p => !p.Key.Contains("%"))
                          .ToDictionary(p => p.Key, p => p.Value);
            #endregion

            #region Step 3 Variable remapping
            foreach (var ts in allAstNodes)
            {
                foreach (var astNode in ts.Item2)
                {
                    VariableRemapping(core, astNode, renamingMap, outputMap, mappedVariables);
                }
            }
            #endregion

            #region Step 4 Generate short name
            var nameGenerator = new ShortNameGenerator();

            // temporary variables are double mapped.
            foreach (var key in outputMap.Keys.ToList())
            {
                if (key.StartsWith(Constants.kTempVarForNonAssignment) &&
                    outputMap[key].StartsWith(Constants.kTempVarForNonAssignment))
                {
                    string shortName = nameGenerator.GetNextName();
                    while (mappedVariables.Contains(shortName))
                    {
                        shortName = nameGenerator.GetNextName();
                    }

                    var tempVar = outputMap[key];
                    outputMap[key]     = shortName;
                    outputMap[tempVar] = shortName;

                    mappedVariables.Add(shortName);
                }
            }

            foreach (var ts in allAstNodes)
            {
                foreach (var astNode in ts.Item2)
                {
                    ShortNameMapping(core, astNode, inputMap, nameGenerator, mappedVariables);
                    foreach (var kvp in inputMap)
                    {
                        if (kvp.Value != String.Empty && outputMap.ContainsKey(kvp.Key))
                        {
                            outputMap[kvp.Key] = kvp.Value;
                        }
                    }
                    ShortNameMapping(core, astNode, outputMap, nameGenerator, mappedVariables);
                }
            }
            #endregion

            var result = new NodeToCodeResult(allAstNodes.SelectMany(x => x.Item2), inputMap, outputMap);
            return(result);
        }
コード例 #58
0
ファイル: Reflection.cs プロジェクト: santom/designscript
 /// <summary>
 ///  Returns a runtime mirror that can be reflected upon
 /// </summary>
 /// <returns></returns>
 public static RuntimeMirror Reflect(string varname, int blockDecl, ProtoCore.Core core)
 {
     return(new RuntimeMirror(varname, blockDecl, core));
 }
コード例 #59
0
        /// <summary>
        /// Compile and execute the source that is stored in the static context
        /// </summary>
        /// <param name="staticContext"></param>
        /// <param name="runtimeContext"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        public ExecutionMirror Execute(ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext, ProtoCore.Core core, bool isTest = true)
        {
            Validity.Assert(null != staticContext.SourceCode && String.Empty != staticContext.SourceCode);

            core.AddContextData(staticContext.GlobalVarList);

            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(staticContext, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                Validity.Assert(null != runtimeContext);
                Execute(core, blockId, staticContext, runtimeContext);
                if (!isTest)
                {
                    core.Heap.Free();
                }
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }

            if (isTest && !core.Options.CompileToLib)
            {
                return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core));
            }

            return(null);
        }
コード例 #60
0
 private ProtoCore.RuntimeCore CreateRuntimeCore(ProtoCore.Core core)
 {
     ProtoCore.RuntimeCore runtimeCore = new ProtoCore.RuntimeCore(core.Heap);
     runtimeCore.SetupForExecution(core, core.GlobOffset);
     return(runtimeCore);
 }