summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* Added PhiNode, RegionNode, IfNode, StopNodedibyendumajumdar2023-11-0110-15/+236
| | | | | No type compute yet Initial parsing logic for If statements
* Rename test class and dot diagramsdibyendumajumdar2023-11-012-2/+2
|
* Start on Chapter 5dibyendumajumdar2023-11-011-3/+5
|
* Start on Chapter 5dibyendumajumdar2023-11-0126-0/+2063
|
* Backport fix for set_def killing new_def (#21)XmiliaH2023-10-292-6/+11
|
* set_def might kill new_def in kill recursion caused by old_def being killed ↵XmiliaH2023-10-282-3/+12
| | | | (#18)
* Remove true and false from grammar as the parser does not recognise them (#17)XmiliaH2023-10-281-2/+0
|
* Applied fix for #12 to chapter 3 (#15)Dibyendu Majumdar2023-10-279-134/+287
| | | | ScopeNode added to chapter 3 Revised the description for Chapter 3 and 4 to include ScopeNode.
* Replace Parser scopes with ScopeNode (#14)Cliff Click2023-10-267-73/+191
| | | | | | | | | | | | | | | Fixes #12 * Replace Parser scopes with ScopeNode Basically move the Stack of HashMaps to a ScopeNode, with wrappers. The HashMap maps String names to Integer indices; inputs to the ScopeNode. This way, the ScopeNode keeps alive Nodes that are only alive because they are alive in the HashMap. Fix bug isDead -> isUnused in deadCodeElim. Support routines for adding/removing edges in ScopeNode. Set $ctrl to null after a Return; there is no control. Regression tests. * One more test case
* Add a description of proj nodes (#11)Dibyendu Majumdar2023-10-262-0/+13
| | | | | * Add a description of proj nodes * Add a description of proj nodes
* Revision of docs (#10)Dibyendu Majumdar2023-10-2113-338/+443
| | | | | | | | | * Port updates back to chapter 2 * Update older visuals to match new format * Update older visuals to match new format * update docs
* Add the second diagram that got lost. (#9)Dibyendu Majumdar2023-10-201-0/+4
|
* Chapter4 (#8)Cliff Click2023-10-2031-1/+2461
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial work on chapter 4. Updated language grammar for chapter 4 Enhanced Parser to implement comparison operators Parser now allows setting 'arg' as input parameter to program The StartNode now has a tuple as result with two values. We set up two projection nodes as output of Start - the first is bound to scope as '$ctrl' and second as 'arg'. Return node now obtains the ctrl input by looking up '$ctrl' in scope; thus it gets the projection node. Added TypeTuple - represents a tuple of values. This is the type of Start. Added BoolNode - for comparison operators. Added MultiNode - interface for nodes that generate tuple results. Start implements this interface. Added ProjNode - projections to extract values from Start node. Each projection takes a MultiNode and an index value. Initial writeup of chapter 4 in README. GraphVisualizer now searches node outputs as well to locate all nodes * Add TypeControl. The first member of Start's tuple is of TypeControl. Correct the projType() method * Quote port names in edges as unquoted $ctrl is not valid. Revise how we decide an edge is a control edge so that it works correctly for projections. * We used to compute initial type in Node but this is problematic for new node types such as ProjNode and BoolNode as the construction is not yet complete when Node calls compute(). So we have to move compute() call down to the sub type's constructor. Add some tests for comparison ops. * Describe the $ctrl name binding and how it represents the Ptri net model. Add a diagram to show why we need algebraic manipulation of expressions. * Implement a simplification for expressions such as (con1 + arg) + con2 -> arg + con3 con1 + (arg + con2) -> arg + con3 * Add diagram to show what the graph looks like post peephole * Explain projection nodes * Cleanup Chapter 4, add peepholes. Add like 6 peepholes. Replace the 2 prior ones with 1-liners. BoolNode: replace the switch with 6 1-line classes. Giant comment discussion on idealize() calling convention. TypeInteger shorten isTop and isBot, and use them instead of calling "equals()". * 2 more peeps, no tests yet * Cleanup Chapter 4 `peephole()` kills nodes killed by `idealize()` calls... and works recursively. This requires keeping "mid-peephole" nodes alive. The edge-swap code in Add and Mul now keeps their inputs alive mid-swap. MultiNode is a class, not an interface. Move the initial 'compute()' to peephole, instead of requiring each constructor to do it. Start and Constant remember their original types, even if the `_type` field changes. `kill()` flags nodes as DEAD. Print DEAD nodes with "DEAD". Change recursive `_print()` to a tik-tok style, so each individual print does not need to handle DEAD printing. This printing will soon need a "visit" bit to avoid infinite recursion. Projs pick up a debugging name. GraphViz: combine Multis and their Projs. Drop Constant inputs from Start. Fix coloring Control edges red. * minor WS cleanup * Cleaned up Node.peephole Use a smart DCE call after peephole. More comments. Tidy interfaces. * minor comment cleanup * But the proj nodes inside a table * No need to set column span on multi node as we put the proj nodes in a table * Update the dot diagrams * Rename method to make it more obvious to the reader * Start to add a description of peephole * Rename del() to delUse() and make it an instance method as it reads better that way. Add new method addUse() again to improve readability. Adjust removeDeadCode() to make the intention clear. * Update docs explaining how peephole works Update the diagrams * Fix errors * Add diagram to show what the graph looks like post peephole * 2 more peeps, no tests yet * Cleanup Chapter 4 `peephole()` kills nodes killed by `idealize()` calls... and works recursively. This requires keeping "mid-peephole" nodes alive. The edge-swap code in Add and Mul now keeps their inputs alive mid-swap. MultiNode is a class, not an interface. Move the initial 'compute()' to peephole, instead of requiring each constructor to do it. Start and Constant remember their original types, even if the `_type` field changes. `kill()` flags nodes as DEAD. Print DEAD nodes with "DEAD". Change recursive `_print()` to a tik-tok style, so each individual print does not need to handle DEAD printing. This printing will soon need a "visit" bit to avoid infinite recursion. Projs pick up a debugging name. GraphViz: combine Multis and their Projs. Drop Constant inputs from Start. Fix coloring Control edges red. * minor WS cleanup * Cleaned up Node.peephole Use a smart DCE call after peephole. More comments. Tidy interfaces. * minor comment cleanup * But the proj nodes inside a table * No need to set column span on multi node as we put the proj nodes in a table * Update the dot diagrams * Rename method to make it more obvious to the reader * Start to add a description of peephole * Rename del() to delUse() and make it an instance method as it reads better that way. Add new method addUse() again to improve readability. Adjust removeDeadCode() to make the intention clear. * Update docs explaining how peephole works Update the diagrams * Minor cleanups Split isUnused from isDead, with comments. Rename removeDeadCode back to deadCodeElim after discussion; matches the historical compiler wording. Fixup large javadoc example with a table. * match doc and code * Fix name of method * Fix name of method --------- Co-authored-by: dibyendumajumdar <mobile@majumdar.org.uk>
* Chapter 3 - add vars and lexical scope. (#7)Dibyendu Majumdar2023-10-0129-54/+1982
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Chapter 3 - add vars and lexical scope. * Fix typo * Overhaul graph viz Makes the scopes pointing into the graph being build more visually appealing. Constants are a printed with just the constant value. * Fix control edge color * Fix missing grouping operator parse Add a parens test. Shorten names 'Identifier' to 'Id' _lexer.match -> match require() passes a Node thru, so can be flow-coded. Uniform syntax error messages. Handy Lexer.toString for debugging. Drop Optional for null returns; less total code; less objects; less confusion. camelCase some fcns. * All parser helpers return Node, not void. Drop _ret. parseBlock and parseStatement now the same. * CLosely align chap2 and chap3 parsers Mostly whitespace aligned; dragged a few functions around to make more sense. I think the diff from Ch2 and Ch3 is down a few differences about what is a statement, plus all the symbol stuff for scopes and variables. * Add examples illustrating the symbol table creation. * Update docs and comments --------- Co-authored-by: Cliff Click <cliffc@acm.org>
* Apply changes from chapter 2 to chapter 1 (#5)Dibyendu Majumdar2023-09-295-201/+188
| | | Fix tests that check for exceptions
* Chapter 2 (#4)Dibyendu Majumdar2023-09-2634-22/+1694
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Start on Chapter 2. * Start on Chapter 2. * Refactor * Refactor * Initial attempt at peephole opt for add operation * cleanup unused import * Start on graph visualizer * Start on graph visualizer * Rework chapter 2 Add a short discourse on the Types, and provide a Bottom type. Make a final toString; require each Node to specify its special printing via label(). Add a recursing printer called print(); toString is used by default in the debugger and so cannot be recursive. Make the peephole rules based on a proper Type and idealize calls. Big comments about the Type computations. Every node picks up a _print, compute and idealize() call. Rename long arith ops Divide, UnaryMinus, Multiply, Subtract into shorter uniform-length names. Cleans up the parser where he does the precedence op parsing. Rework Parser: - Drop Token class, its all Strings except in the one place we know a number is coming - Embed the Lexer as a field in the Parser, instead of trying to pass it around everywhere in the Parser - StartNode becomes a read-only global, so we don't have to pass it around everywhere in the Parser AND optimizer. - Lexer matches on strings and returns strings. Match and consume *at the moment* instead of carrying around a current token/string and forcing the next-token after consuming the current one. - All parse subexpressions shrink by 1/2 after these changes. * Initial writeup of Chapter 2 * Initial writeup of Chapter 2 * Initial writeup of Chapter 2 * Initial writeup of Chapter 2 * Remove range * progress Chapter 2 Drop integer ranges. Broader lattice pic. Lots of prose changes in the readme. Fixed title in gviz dot generation. Fixed bug with peephole making redundant constants. * Implement compute for all the arithmetic node types Add a flag to switch off peephole so we can see the full graph Add post peephole graph to writeup * Implement compute for all the arithmetic node types Add a flag to switch off peephole so we can see the full graph Add post peephole graph to writeup * Fix bad path to the svg * Update pre-peephole diagram * Add dead code elimination ...and a set_def to proper update graph edges. * Update README.md * Cleanup the GraphVisualizer a bit. Update the graphs. Update the chapter list as chapter 3 deleted, and chapter 4 is now chapter 3. --------- Co-authored-by: Cliff Click <cliffc@acm.org>
* Merge pull request #3 from dibyendumajumdar/mainDibyendu Majumdar2023-09-1916-223/+687
|\ | | | | Chapter 1 implementation
| * Do not parse negative integers, - will be treated as unary operator.dibyendumajumdar2023-09-196-33/+32
| | | | | | | | | | | | Update the comments for Return node. Sync comments with README.
| * Parse standalone 0 as integerdibyendumajumdar2023-09-193-33/+30
| |
| * Merge branch 'main' of https://github.com/dibyendumajumdar/Simple into pr/2Cliff Click2023-09-191-0/+11
| |\
| | * Enable preview featuredibyendumajumdar2023-09-191-0/+3
| | |
| | * Enable preview featuredibyendumajumdar2023-09-191-0/+8
| | |
| * | Overhaul LexerCliff Click2023-09-193-278/+107
| |/ | | | | | | | | | | | | | | | | | | | | | | Switched to bytes from chars, since we'll be parsing files eventually and typically compilers parse bytes from files (and not Java chars). Added a 'peek' to handle bad leading `--123` numbers. Used simpler number parsing; doesn't do doubles (yet). Added a filter for punctuation. Prior setup didn't handle multi-char punctuation like relation tests "<=". Switched the "EOF" marker char from 0 to Char.MAX_VALUE; harder to make mistakes, and simplifies the WS test. Switch javadoc comments to plain comments on private functions. Added tests for broken keyword, broken numbers, negative numbers.
| * Fix a comp errorCliff Click2023-09-191-1/+1
| | | | | | | | missed one in the merge
| * Merge branch 'main' of https://github.com/dibyendumajumdar/Simple into pr/2Cliff Click2023-09-183-3/+7
| |\
| | * Update based on feedbackdibyendumajumdar2023-09-181-11/+11
| | |
| | * Remove opcodesdibyendumajumdar2023-09-187-39/+20
| | | | | | | | | | | | Make the IdGenerator an input to the Parser
| * | More edits to Chpt 1Cliff Click2023-09-188-125/+82
| | | | | | | | | | | | | | | | | | | | | | | | Add the Evil static global var, with appriopriate comments. Drop the singleton class, and every place it had to be passed. Much smaller code now, and will be a LOT smaller as the project grows. Drop the opcode; minor usages in prior implementations for performance, not needed here. Use the preview pattern match in test code to simplify.
| * | Make every effort to move the language level to 20 with previewCliff Click2023-09-183-6/+6
| |/ | | | | | | | | For pattern-match switch statements. Much nicer looking code. Also IDEAJ gave me huge grief, so I might have hit this with a larger hammer than needed.
| * Chapter 01 implementationdibyendumajumdar2023-09-186-105/+206
| |
| * Start on parserdibyendumajumdar2023-09-177-30/+278
| |
| * Revise description of Return node.dibyendumajumdar2023-09-171-0/+3
| |
| * Revise text and update diagram.dibyendumajumdar2023-09-174-78/+56
| | | | | | | | Remove the detail re inputs to a node from the diagram.
| * Add diagramdibyendumajumdar2023-09-171-0/+10
| |
| * Add diagramdibyendumajumdar2023-09-172-0/+80
| |
| * Revised textdibyendumajumdar2023-09-171-6/+5
| |
| * Fix typosdibyendumajumdar2023-09-172-2/+2
| |
| * Revised based on feedbackdibyendumajumdar2023-09-172-15/+18
| | | | | | | | Added descriptions of the nodes.
| * Initial definition of nodes that will be relevant for chapter 1.dibyendumajumdar2023-09-171-6/+29
| |
| * Initial definition of nodes that will be relevant for chapter 1.dibyendumajumdar2023-09-178-0/+196
| |
| * Revise description of Chapter 1.dibyendumajumdar2023-09-171-1/+1
| |
| * Revise grammar for chapter 1.dibyendumajumdar2023-09-172-24/+50
| | | | | | | | Start writing up Chapter 1.
* | Merge pull request #2 from dibyendumajumdar/mainCliff Click2023-09-0712-3/+648
|\| | | | | Initial framework for the project
| * Drop AST and parser and lexerdibyendumajumdar2023-09-076-776/+0
| |
| * Corrected READMEdibyendumajumdar2023-09-071-6/+1
| |
| * Renamed Ast to AST.dibyendumajumdar2023-09-072-42/+42
| |
| * Removed all external code.dibyendumajumdar2023-09-0725-9513/+335
| | | | | | | | | | | | Removed the common chapter. Reimplemented Lexer. Revised the list of chapters to something more accurate.
| * Avoid using Node as a type as the IR will need thisdibyendumajumdar2023-08-263-131/+130
| | | | | | | | | | So just extends the top level Ast class in all the subtypes. Also avoid holding reference to lexer in parser.
| * Update the lexer, parser and AST to match the language definition.dibyendumajumdar2023-08-2614-347/+258
| | | | | | | | | | | | Add toString() method on AST nodes so that we can easily check the results of parsing. Remove AA lexer Move the Ecstasy lexer classes to one package, except Handy
| * Added a grammar definition for chapter 01.dibyendumajumdar2023-08-253-1/+50
| |