コード例 #1
0
 public UserFunction(ParseNode originalNode)
 {
     codePart     = new CodePart();
     functions    = new Dictionary <int, UserFunctionCodeFragment>();
     newFunctions = new List <UserFunctionCodeFragment>();
     OriginalNode = originalNode;
 }
コード例 #2
0
ファイル: CodeTree.cs プロジェクト: Roy-Ermers/TES-30
        public void AddBlock(CodePart part)
        {
            if (LastRoutine)
            {
                AddRoutineBlock(part); return;
            }
            var       Caller = LastCaller;
            CodeBlock Block  = new CodeBlock()
            {
                Part           = part.CreateEmpty(),
                CodeTree       = this,
                IsRoutineBlock = Caller.IsRoutineBlock
            };
            var p = Caller.Location;

            Block.Location = Caller.IsRoutineBlock ? new Point(p.X + Caller.Width + 15, p.Y) : new Point(p.X, p.Y + Caller.Height + 15);
            TreeNode <CodePart> node;

            if (Tree.value == Caller.Part)
            {
                node = Tree.AddChild(Block.Part);
            }
            else
            {
                node = Tree.FindChild(Tree, Caller.Part).Parent.AddChild(Block.Part);
            }
            Block.Node = node;
            Controls.Add(Block);
            Block.Invalidate();
            ActiveControl = Block;
        }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: erendrake/kRISC
        public CodePart Compile(ParseTree tree, Context context)
        {
            _part    = new CodePart();
            _context = context;

            try
            {
                if (tree.Nodes.Count > 0)
                {
                    PreProcess(tree);
                    CompileProgram(tree);
                }
            }
            catch (Exception e)
            {
                if (_lastNode != null)
                {
                    throw new Exception(string.Format("Error parsing {0}: {1}", ConcatenateNodes(_lastNode), e.Message));
                }
                else
                {
                    throw;
                }
            }

            return(_part);
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: gisikw/KOS
        public CodePart Compile(int startLineNum, ParseTree tree, Context context, CompilerOptions options)
        {
            InitCompileFlags();

            part = new CodePart();
            this.context = context;
            this.options = options;
            this.startLineNum = startLineNum;

            ++context.NumCompilesSoFar;

            try
            {
                if (tree.Nodes.Count > 0)
                {
                    PreProcess(tree);
                    CompileProgram(tree);
                }
            }
            catch (KOSException kosException)
            {
                if (lastNode != null)
                {
                    throw;  // TODO something more sophisticated will go here that will
                    // attach source/line information to the exception before throwing it upward.
                    // that's why this seemingly pointless "catch and then throw again" is here.
                }
                SafeHouse.Logger.Log("Exception in Compiler: " + kosException.Message);
                SafeHouse.Logger.Log(kosException.StackTrace);
                throw;  // throw it up in addition to logging the stack trace, so the kOS terminal will also give the user some message.
            }

            return part;
        }
コード例 #5
0
ファイル: UserFunction.cs プロジェクト: Whitecaribou/KOS
 public UserFunction(ParseNode originalNode)
 {
     codePart = new CodePart();
     functions = new Dictionary<int, UserFunctionCodeFragment>();
     newFunctions = new List<UserFunctionCodeFragment>();
     OriginalNode = originalNode;
 }
コード例 #6
0
ファイル: Compiler.cs プロジェクト: ElasticRaven/KOS
        public CodePart Compile(ParseTree tree, Context context, CompilerOptions options)
        {
            _part = new CodePart();
            _context = context;
            _options = options;

            try
            {
                if (tree.Nodes.Count > 0)
                {
                    PreProcess(tree);
                    CompileProgram(tree);
                }
            }
            catch (Exception e)
            {
                if (_lastNode != null)
                {
                    throw new Exception(string.Format("Error parsing {0}: {1}", ConcatenateNodes(_lastNode), e.Message));
                }
                else
                {
                    throw;
                }
            }

            return _part;
        }
コード例 #7
0
ファイル: Lock.cs プロジェクト: victorb/KOS
        public CodePart GetNewFunctionsCodePart()
        {
            var newFunctionsPart = new CodePart();

            foreach (LockFunction function in newFunctions)
            {
                newFunctionsPart.FunctionsCode.AddRange(function.Code);
            }

            ClearNewFunctions();
            return(newFunctionsPart);
        }
コード例 #8
0
ファイル: Helpers.cs プロジェクト: WazWaz/KOS
        public CodePart GetCodePart()
        {
            CodePart mergedPart = new CodePart();
            mergedPart.InitializationCode = _codePart.InitializationCode;
            mergedPart.MainCode = _codePart.MainCode;

            foreach (LockFunction function in _functions.Values)
            {
                mergedPart.FunctionsCode.AddRange(function.Code);
            }

            return mergedPart;
        }
コード例 #9
0
        public CodePart GetCodePart()
        {
            CodePart mergedPart = new CodePart();

            mergedPart.InitializationCode = _codePart.InitializationCode;
            mergedPart.MainCode           = _codePart.MainCode;

            foreach (LockFunction function in _functions.Values)
            {
                mergedPart.FunctionsCode.AddRange(function.Code);
            }

            return(mergedPart);
        }
コード例 #10
0
        public override List <CodePart> Compile(string filePath, int startLineNum, string scriptText, string contextId, CompilerOptions options)
        {
            List <CodePart> parts = null;

            // make the code lowercase
            scriptText = MakeLowerCase(scriptText);
            scriptText = ReplaceIdentifiers(scriptText);

            //if (contextId != "interpreter") parts = _cache.GetFromCache(scriptText);

            // if parts is null means the code doesn't exists in the cache
            if (parts == null)
            {
                parts = new List <CodePart>();
                ParseTree parseTree = parser.Parse(scriptText);
                if (parseTree.Errors.Count == 0)
                {
                    var compiler = new Compiler();
                    LoadContext(contextId);

                    // TODO: handle compile errors (e.g. wrong run parameter count)
                    CodePart mainPart = compiler.Compile(startLineNum, parseTree, currentContext, options);

                    // add locks and triggers
                    parts.AddRange(currentContext.Locks.GetNewParts());
                    parts.AddRange(currentContext.Triggers.GetNewParts());
                    parts.AddRange(currentContext.Subprograms.GetNewParts());

                    parts.Add(mainPart);

                    AssignSourceId(parts, filePath);

                    //if (contextId != "interpreter") _cache.AddToCache(scriptText, parts);
                }
                else
                {
                    // TODO: Come back here and check on the possiblity of reporting more
                    // errors than just the first one.  It appears that TinyPG builds a
                    // whole array of error messages so people could see multiple syntax
                    // errors in one go if we supported the reporting of it.  It may be that
                    // it was deliberately not done because it might be too verbose that way
                    // for the small text terminal.

                    ParseError error = parseTree.Errors[0];
                    throw new KOSParseException(error, scriptText);
                }
            }

            return(parts);
        }
コード例 #11
0
        public override List <CodePart> Compile(string scriptText, string contextId)
        {
            List <CodePart> parts = null;

            // make the code lowercase
            scriptText = MakeLowerCase(scriptText);

            // TODO: I don't like that the compiler has to know about the interpreter
            if (contextId != "interpreter")
            {
                parts = _cache.GetFromCache(scriptText);
            }

            // if parts is null means the code doesn't exists in the cache
            if (parts == null)
            {
                parts = new List <CodePart>();
                ParseTree parseTree = _parser.Parse(scriptText);
                if (parseTree.Errors.Count == 0)
                {
                    Compiler compiler = new Compiler();
                    LoadContext(contextId);

                    // TODO: handle compile errors (e.g. wrong run parameter count)
                    CodePart mainPart = compiler.Compile(parseTree, _currentContext);

                    // add locks and triggers
                    parts.AddRange(_currentContext.Locks.GetNewParts());
                    parts.AddRange(_currentContext.Triggers.GetNewParts());

                    parts.Add(mainPart);

                    AssignInstructionId(parts);

                    // TODO: I don't like that the compiler has to know about the interpreter
                    if (contextId != "interpreter")
                    {
                        _cache.AddToCache(scriptText, parts);
                    }
                }
                else
                {
                    ParseError error = parseTree.Errors[0];
                    RaiseParseException(scriptText, error.Line, error.Position);
                }
            }

            return(parts);
        }
コード例 #12
0
ファイル: Helpers.cs プロジェクト: kevin-ye/KOS
        public CodePart GetCodePart()
        {
            var mergedPart = new CodePart
                {
                    InitializationCode = codePart.InitializationCode,
                    MainCode = codePart.MainCode
                };

            foreach (LockFunction function in functions.Values)
            {
                mergedPart.FunctionsCode.AddRange(function.Code);
            }

            return mergedPart;
        }
コード例 #13
0
ファイル: Lock.cs プロジェクト: victorb/KOS
        public CodePart GetCodePart()
        {
            var mergedPart = new CodePart
            {
                InitializationCode = codePart.InitializationCode,
                MainCode           = codePart.MainCode
            };

            foreach (LockFunction function in functions.Values)
            {
                mergedPart.FunctionsCode.AddRange(function.Code);
            }

            return(mergedPart);
        }
コード例 #14
0
ファイル: CodeTree.cs プロジェクト: Roy-Ermers/TES-30
        void AddRoutineBlock(CodePart part)
        {
            var       Caller = LastCaller;
            CodeBlock Block  = new CodeBlock()
            {
                Part           = part.CreateEmpty(),
                CodeTree       = this,
                IsRoutineBlock = true
            };
            var p = Caller.Location;

            Block.Location = new Point(p.X + Caller.Width + 15, p.Y);
            Block.Node     = Tree.FindChild(Tree, Caller.Part).AddChild(Block.Part);
            Controls.Add(Block);
            Block.Invalidate();
            ActiveControl = Block;
        }
コード例 #15
0
ファイル: Compiler.cs プロジェクト: KSP-KOS/KOS
        public CodePart Compile(int startLineNum, ParseTree tree, Context context, CompilerOptions options)
        {
            InitCompileFlags();

            part = new CodePart();
            this.context = context;
            this.options = options;
            this.startLineNum = startLineNum;

            ++context.NumCompilesSoFar;

            if (tree.Nodes.Count > 0)
            {
                PreProcess(tree);
                CompileProgram(tree);
            }
            return part;
        }
コード例 #16
0
        public override List <CodePart> Compile(string filePath, int startLineNum, string scriptText, string contextId, CompilerOptions options)
        {
            List <CodePart> parts = null;

            // make the code lowercase
            scriptText = MakeLowerCase(scriptText);
            scriptText = ReplaceIdentifiers(scriptText);

            //if (contextId != "interpreter") parts = _cache.GetFromCache(scriptText);

            // if parts is null means the code doesn't exists in the cache
            if (parts == null)
            {
                parts = new List <CodePart>();
                ParseTree parseTree = parser.Parse(scriptText);
                if (parseTree.Errors.Count == 0)
                {
                    var compiler = new Compiler();
                    LoadContext(contextId);

                    // TODO: handle compile errors (e.g. wrong run parameter count)
                    CodePart mainPart = compiler.Compile(startLineNum, parseTree, currentContext, options);

                    // add locks and triggers
                    parts.AddRange(currentContext.Locks.GetNewParts());
                    parts.AddRange(currentContext.Triggers.GetNewParts());
                    parts.AddRange(currentContext.Subprograms.GetNewParts());

                    parts.Add(mainPart);

                    AssignSourceId(parts, filePath);

                    //if (contextId != "interpreter") _cache.AddToCache(scriptText, parts);
                }
                else
                {
                    ParseError error = parseTree.Errors[0];
                    RaiseParseException(scriptText, error.Line, error.Position);
                }
            }

            return(parts);
        }
コード例 #17
0
 public Lock()
 {
     _codePart  = new CodePart();
     _functions = new Dictionary <int, LockFunction>();
 }
コード例 #18
0
ファイル: Trigger.cs プロジェクト: Whitecaribou/KOS
 public Trigger()
 {
     codePart = new CodePart();
 }
コード例 #19
0
 public Trigger()
 {
     _codePart = new CodePart();
 }
コード例 #20
0
 protected override void AddEndOfProgram(CodePart linkedObject, bool isMainProgram)
 {
     linkedObject.MainCode.Add(new OpcodeEOF());
 }
コード例 #21
0
ファイル: Subprogram.cs プロジェクト: stephengeorgewest/KOS-1
 public Subprogram(string subprogramName)
 {
     codePart          = new CodePart();
     SubprogramName    = subprogramName;
     PointerIdentifier = string.Format("$program-{0}*", subprogramName);
 }
コード例 #22
0
 public ScriptFile(string Code)
 {
     code  = Code;
     asm   = BuildAssembly();
     Class = (CodePart)Activator.CreateInstance(FindDerivedTypes(asm, typeof(CodePart)).First());
 }
コード例 #23
0
ファイル: Subprogram.cs プロジェクト: Whitecaribou/KOS
 public Subprogram(string subprogramName)
 {
     codePart = new CodePart();
     SubprogramName = subprogramName;
     PointerIdentifier = string.Format("$program-{0}*", subprogramName);
 }
コード例 #24
0
ファイル: Helpers.cs プロジェクト: kevin-ye/KOS
 public Lock()
 {
     codePart = new CodePart();
     functions = new Dictionary<int, LockFunction>();
     newFunctions = new List<LockFunction>();
 }
コード例 #25
0
ファイル: UserFunction.cs プロジェクト: Whitecaribou/KOS
        public CodePart GetNewFunctionsCodePart()
        {
            var newFunctionsPart = new CodePart();

            foreach (UserFunctionCodeFragment function in newFunctions)
            {
                newFunctionsPart.FunctionsCode.AddRange(function.Code);
            }

            ClearNewFunctions();
            return newFunctionsPart;
        }
コード例 #26
0
 protected override void AddInitializationCode(CodePart linkedObject, CodePart part)
 {
     linkedObject.MainCode.AddRange(part.InitializationCode);
 }
コード例 #27
0
ファイル: Lock.cs プロジェクト: victorb/KOS
 public Lock()
 {
     codePart     = new CodePart();
     functions    = new Dictionary <int, LockFunction>();
     newFunctions = new List <LockFunction>();
 }
コード例 #28
0
 protected override void AddEndOfProgram(CodePart linkedObject, bool isMainProgram)
 {
     linkedObject.MainCode.Add(new OpcodeEOF());
 }
コード例 #29
0
 protected override void AddInitializationCode(CodePart linkedObject, CodePart part)
 {
     linkedObject.MainCode.AddRange(part.InitializationCode);
 }
コード例 #30
0
ファイル: Helpers.cs プロジェクト: kevin-ye/KOS
        public CodePart GetNewFunctionsCodePart()
        {
            var newFunctionsPart = new CodePart();

            foreach (LockFunction function in newFunctions)
            {
                newFunctionsPart.FunctionsCode.AddRange(function.Code);
            }

            ClearNewFunctions();
            return newFunctionsPart;
        }