1 / 13

LOLCODE to 6502 Compiler

LOLCODE to 6502 Compiler. HOW DUZ I PUSH YR POP? MAH TABLES IZ A STACKZ LDA #$1337 ; WAT U SAY?. Of VM’s and SM’s: Problem. LOLCODE is a dynamic, interpreted language The 6502 is an 8-bit, 3 register, limited CPU Instruction sets inherently different and perpendicular How to solve this?.

arlais
Download Presentation

LOLCODE to 6502 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. LOLCODE to 6502 Compiler HOW DUZ I PUSH YR POP? MAH TABLES IZ A STACKZ LDA #$1337 ; WAT U SAY?

  2. Of VM’s and SM’s: Problem • LOLCODE is a dynamic, interpreted language • The 6502 is an 8-bit, 3 register, limited CPU • Instruction sets inherently different and perpendicular • How to solve this?

  3. Of VM’s and SM’s: Solution • Use a virtual machine built on top of the 6502 • Create a custom instruction set for the LOLCODE IR tree – SM assembly • Create a custom stack machine to execute instructions on a ‘stack’ • Abstracts memory addressing with stack

  4. Of SM’s and VM’s: Emulate? • LOL SM is not a pure emulated stack machine • Only stack/heap/frame are emulated • Why? Emulating an entire machine is slow, snail pace on the 6502 • End result: bastardization of emulation and pure 6502 assembly

  5. Of SM’s and VM’s: The Machine • What is the machine then? • Stack, Heap, ‘IT’ register, Frames • SP (stack pointer), FP (frame pointer), HP (heap pointer) • Most instructions operate on stack • Strings (objects) operate on heap • Function calls manipulate frame

  6. Of SM’s and VM’s: Limitations • The 6502 CPU limits what we can do, and forces workarounds • Absolute addressing is not possible with the stack • Stack must be indirectly referenced with an offset counter (no negative offsets) • Operations using the SP are tricky

  7. Of VM’s and SM’s: Example • LOLCODEnum R SUM OF 0 AN 1numnum IZ NOW A TROOF

  8. Of SM’s and VM’s: Example • LOLCODE IRASSIGN |- ID:num |- ADD |- INT:0 |- INT:1ASSIGN |- ID:IT |- ID:numRECAST |- ID:num |- LTBOOL

  9. Of SM’s and VM’s: Example • SM Assemblypush_const:0push_const:1pop_var:numpush_var:numpop_itpush_var:numto_boolpop_var:num

  10. Of SM’s and VM’s: Example • 6502 Assembly pop_var: ; X is offset of var, known at compile TAX ; push the X register onto stack PHA LDX #$1 JMP dec_sp ; decrement the SP by 3 bytes PLA ; pop the X register off the stack TXA LDY #$0 LDA (SP), Y ; grab first byte off SM stack STA (FP, X) ; store into FP + offset X INX ; go to next byte INY ; go to next byte ; Repeat for next two bytes

  11. Compiler Report: Progress • Most LOLCODE IR converted into a mix of macro SM, and pure assembly • 75% done when realized that current OffsetTable counter was broken • Rewrote table, but have to rewrite most of the conversions • Now supports local variables/new frames

  12. Compiler Report: Progress • Several macro instructions already written in 6502 assembly • Variable type conversions still need to finish (because they are tricky) • String/heap operations require more analysis (creation/deletion) • Math operations require clarification

  13. Compiler Report: The Last Mile • All LOLCODE IR converted to macro instructions (big) • All SM assembly written in 6502 ASM (bigger) • Actual heap/string/stdio working with garbage collection (small) • Code examples (tiny)

More Related