170 likes | 287 Views
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
E N D
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 • Conversion bool <> int • Basic STDOUT (bool, int) • Support for infinite nested structures • Variable/function scoping implemented
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 -.-
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
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
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
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
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)
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
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)
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)
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)
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
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
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)
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)