mirror of
https://github.com/open-goal/jak-project
synced 2026-05-31 01:16:12 -04:00
Add case macro for switch-case constructs (#362)
This commit is contained in:
+15
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user