mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
4f537d4a71
This sets up the C Kernel for Jak 3, and makes it possible to build and load code built with `goalc --jak3`. There's not too much interesting here, other than they switched to a system where symbol IDs (unique numbers less than 2^14) are generated at compile time, and those get included in the object file itself. This is kind of annoying, since it means all tools that produce a GOAL object file need to work together to assign unique symbol IDs. And since the symbol IDs can't conflict, and are only a number between 0 and 2^14, you can't just hash and hope for no collisions. We work around this by ignoring the IDs and re-assigning our own. I think this is very similar to what the C Kernel did on early builds of Jak 3 which supported loading old format level files, which didn't have the IDs included. As far as I can tell, this shouldn't cause any problems. It defeats all of their fancy tricks to save memory by not storing the symbol string, but we don't care.
38 lines
806 B
Common Lisp
38 lines
806 B
Common Lisp
;;
|
|
;; Compiler Setup for Jak 3
|
|
;;
|
|
|
|
;; load kernel type definitions.
|
|
;; these types/functions are provided by Jak 3's runtime.
|
|
(asm-file "goal_src/jak3/kernel-defs.gc")
|
|
|
|
;; load jak 3 project
|
|
(load-project "goal_src/jak3/game.gp")
|
|
|
|
(defmacro basic? (obj)
|
|
;; todo, make this more efficient
|
|
`(= 4 (logand (the integer ,obj) #b111))
|
|
)
|
|
|
|
(defmacro pair? (obj)
|
|
;; todo, make this more efficient
|
|
;`(= 2 (logand (the integer ,obj) #b111))
|
|
`(< (shl (the-as int ,obj) 62) 0)
|
|
)
|
|
|
|
(defmacro not-pair? (obj)
|
|
`(>= (shl (the-as int ,obj) 62) 0)
|
|
)
|
|
|
|
(defmacro binteger? (obj)
|
|
`(zero? (logand (the integer ,obj) #b111))
|
|
)
|
|
|
|
(defmacro rtype-of (obj)
|
|
`(cond ((binteger? ,obj) binteger)
|
|
((pair? ,obj) pair)
|
|
((basic? ,obj) (-> (the basic ,obj) type))
|
|
(else symbol)
|
|
)
|
|
)
|