public UserFunction(ParseNode originalNode) { codePart = new CodePart(); functions = new Dictionary <int, UserFunctionCodeFragment>(); newFunctions = new List <UserFunctionCodeFragment>(); OriginalNode = originalNode; }
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; }
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); }
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; }
public UserFunction(ParseNode originalNode) { codePart = new CodePart(); functions = new Dictionary<int, UserFunctionCodeFragment>(); newFunctions = new List<UserFunctionCodeFragment>(); OriginalNode = originalNode; }
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; }
public CodePart GetNewFunctionsCodePart() { var newFunctionsPart = new CodePart(); foreach (LockFunction function in newFunctions) { newFunctionsPart.FunctionsCode.AddRange(function.Code); } ClearNewFunctions(); return(newFunctionsPart); }
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; }
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); }
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); }
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); }
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; }
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); }
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; }
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; }
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); }
public Lock() { _codePart = new CodePart(); _functions = new Dictionary <int, LockFunction>(); }
public Trigger() { codePart = new CodePart(); }
public Trigger() { _codePart = new CodePart(); }
protected override void AddEndOfProgram(CodePart linkedObject, bool isMainProgram) { linkedObject.MainCode.Add(new OpcodeEOF()); }
public Subprogram(string subprogramName) { codePart = new CodePart(); SubprogramName = subprogramName; PointerIdentifier = string.Format("$program-{0}*", subprogramName); }
public ScriptFile(string Code) { code = Code; asm = BuildAssembly(); Class = (CodePart)Activator.CreateInstance(FindDerivedTypes(asm, typeof(CodePart)).First()); }
public Lock() { codePart = new CodePart(); functions = new Dictionary<int, LockFunction>(); newFunctions = new List<LockFunction>(); }
public CodePart GetNewFunctionsCodePart() { var newFunctionsPart = new CodePart(); foreach (UserFunctionCodeFragment function in newFunctions) { newFunctionsPart.FunctionsCode.AddRange(function.Code); } ClearNewFunctions(); return newFunctionsPart; }
protected override void AddInitializationCode(CodePart linkedObject, CodePart part) { linkedObject.MainCode.AddRange(part.InitializationCode); }
public Lock() { codePart = new CodePart(); functions = new Dictionary <int, LockFunction>(); newFunctions = new List <LockFunction>(); }
public CodePart GetNewFunctionsCodePart() { var newFunctionsPart = new CodePart(); foreach (LockFunction function in newFunctions) { newFunctionsPart.FunctionsCode.AddRange(function.Code); } ClearNewFunctions(); return newFunctionsPart; }