1 / 17

LOL6502 Compiler

LOL6502 Compiler. I CAN HAS LOLCODE?. Things for the Day. Summary of the Project The Stack Machine – Expanded 6502 Assembly Output LOLCODE examples… by you Demonstration Conclusions, Future Goals. What’s featured?. 17-bit integers All math operations ensure correct sign

lenore
Download Presentation

LOL6502 Compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LOL6502 Compiler I CAN HAS LOLCODE?

  2. Things for the Day • Summary of the Project • The Stack Machine – Expanded • 6502 Assembly Output • LOLCODE examples… by you • Demonstration • Conclusions, Future Goals

  3. What’s featured? • 17-bit integers • All math operations ensure correct sign • Conversion bool <> int • Basic STDOUT (bool, int) • Support for infinite nested structures • Variable/function scoping implemented

  4. What’s missing? • math_mul, math_div • Floats, Strings, heap operations • to_int, to bool (partial) • STDIN, STDOUT (partial) • Any sort of sane error checking and testing -.-

  5. Overall • Standard Library 70% complete, needs conversion functions (1.4KB code ;_;) • Strings/heap are a total mess, needs clarification • STDIO – missing a lot of functionality • Macro Compiler – does not need changing, save for missing features

  6. Of Stack Machines • Three basic registers: SP, FP, HP • One global stack used for all operations • Machine-specific instructions: push_var/sp/fp, pop_var/fp, stack_swap, inc/dec_sp • Conversion instructions:to_bool, to_int, to_float, to_string, to_undef

  7. Of Stack Machines • LOLCODE instructions implemented on a near 1:1 basis • Examples (LOL = IR = SM)SUM OF = ADD = math_addWON OF = XOR = bool_xorBOTH SAEM = EQUAL = comp_equal

  8. Of Stack Machines • Almost all operations operate on the stack • We avoid the headaches of: register allocation, spilling, any sort of memory operations • Variables are stored on stack, and offset from the FP • Functions make use of a record for calling

  9. Of Stack Machines • A push_var, will copy the contents of a variable onto the stack • Results of an instruction are saved on the stack • Why is this better? No instructions have side effects on variables save for the ASSIGN instruction (pop_var)

  10. Of Stack Machines • A function call will push space for a return value, the current FP value, and args • Resets SP and pops the SP onto the FP • Jumps to the correct procedure • Does stuff, returns, pops the saved FP back into the FP • Removes return value if function exited

  11. Of Stack Machines • All conditionals and loops create a temporary local scope for each case • Macro compiler ensures these FP offsets are managed properly (at compile time) • At the time, unable to limit scope of a function body (will fix later)

  12. ASM Output • SM compiler spits out tons of ASM code and STDLIB instructions • i.e. Conditionals/Loops will print out ASM code to facilitate structure • STDLIB is oodles upon oodles of ASM that manipulate the virtual stack (all handwritten mind you)

  13. ASM Output • Indirect indexed addressing is the mode used for almost every major instruction • In theory, there should be an infinite amount of nested operations available • However, most instructions use JSR, which push machine SP to machine stack • Machine stack limited to one page (256B)

  14. LOLCODE Examples • Demonstrate the compiler and simulator using examples provided by you • ADD, SUB, MOD, MAX, MIN, AND, OR, XOR, NOT, EQUAL, IAND, IOR • Supports int/bool, STDOUT of those two types • IF-THEN-ELSE, SWITCH-CASE, FOR LOOP • VAR DEF, FUNC DEF, FUNC CALL • ASSIGN, EXPLICIT/IMPLICIT casting

  15. Conclusions • This was a fun, if long and grueling project • Developing a compiler from start to finish provided a lot of knowledge into the complexities of compiler construction • Creating a virtual stack machine was insightful in compiling an otherwise interpreted language

  16. Conclusions • Wrote a lot of ASM – went crazy with the STDLIB. • Rewrote the SM twice – better each time, but still requires work • Did not plan accordingly to include heaps/strings (just ran out of time)

  17. Future Goals • Finish up the formalization and implementation of heaps/strings • Finish implementing the STDIO for more useful examples • Finish the type conversions at run time, and allow for error recovery • Create a game in LOLCODE to 6502 • Write my own 6502 emulator with advanced features (bitmapped graphics, etc)

More Related