mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 00:57:44 -04:00
Add case
macro for switch-case constructs (#362)
This commit is contained in:
parent
9fbbe1a79c
commit
496f8a3fbb
|
@ -353,6 +353,20 @@
|
|||
`(none)
|
||||
)
|
||||
|
||||
(defmacro case (switch &rest cases)
|
||||
"A switch-case construct. switch is saved onto a local variable and compared against each case, sequentially.
|
||||
else can be used as the default case, but it must be the last one."
|
||||
|
||||
(with-gensyms (sw)
|
||||
`(let ((sw ,switch))
|
||||
(cond ,@(apply
|
||||
(lambda (x) `(,@(if (eq? (first x) 'else) `(else ,@(rest x)) `((= sw ,(first x)) ,@(rest x)))))
|
||||
cases)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;
|
||||
;; Math Macros
|
||||
;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -531,7 +545,7 @@
|
|||
;; (Fake) MIPS Macros
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; these are macros for MIPS instructions which we may want to keep in the source code for
|
||||
;; these are macros for MIPS instructions which we may want to keep in the source code for
|
||||
;; readibility/curiosity/documentation, but will not translate into any actual instructions at all
|
||||
|
||||
;; A macro that generates a macro for the specified instruction
|
||||
|
|
Loading…
Reference in a new issue