Skip to content

Instantly share code, notes, and snippets.

@larsen
Created April 7, 2021 09:52
Show Gist options
  • Select an option

  • Save larsen/fa8897091b195c0f9d8b09ac1acdeb0c to your computer and use it in GitHub Desktop.

Select an option

Save larsen/fa8897091b195c0f9d8b09ac1acdeb0c to your computer and use it in GitHub Desktop.
synacor macro expansion
(instr :halt 0 ()
(setf (halt cpu) t))
VIENE ESPANSO IN
(PROGN
(DEFMETHOD EXEC! ((OPCODE (EQL 0)) (CPU CPU))
(INCPC! CPU)
(LET ()
(SETF (HALT CPU) T)))
(DEFMETHOD DISASSEMBLE-INSTRUCTION
((OPCODE (EQL 0)) (CPU CPU) &KEY INSTRUCTION-POINTER)
(LET* ((PC (OR INSTRUCTION-POINTER (PC CPU)))
(INSTRUCTION-SIZE (+ 1 (LENGTH 'NIL)))
(FORMAT-STRING (DISASSEMBLE-FORMAT-STRING INSTRUCTION-SIZE))
(FORMAT-ARGS
(DISASSEMBLE-FORMAT-ARGS OPCODE :HALT INSTRUCTION-SIZE CPU)))
(VALUES (APPLY #'FORMAT NIL FORMAT-STRING FORMAT-ARGS)
(+ INSTRUCTION-SIZE PC)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment