Browse Source

Update Cakelisp for macros, auto null

* Moved some macros out of GameLib and into Cakelisp
* Replaced nullptr with Cakelisp's fancy null
* Added UpdateBuildCakelisp.sh so I don't get confused when I break
things forgetting to build
master
Macoy Madson 2 months ago
parent
commit
ca6d722f3a
7 changed files with 14 additions and 65 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -1
      Dependencies/cakelisp
  3. +5
    -0
      UpdateBuildCakelisp.sh
  4. +2
    -0
      src/AutoTest.cake
  5. +0
    -60
      src/Macros.cake
  6. +1
    -1
      src/OgreCore.cake
  7. +4
    -3
      src/SDL.cake

+ 1
- 0
.gitignore View File

@ -40,6 +40,7 @@ lib/
test/ogreApp
test/output/
test/autoTest
*.blend1


+ 1
- 1
Dependencies/cakelisp

@ -1 +1 @@
Subproject commit 49b5319f2576a3d8f0aa183de1736a7689855984
Subproject commit 1283eff806c1dca16472fe6d931e66da6c2fc522

+ 5
- 0
UpdateBuildCakelisp.sh View File

@ -0,0 +1,5 @@
#!/bin/sh
cd Dependencies/cakelisp
# I got bit by updating but forgetting to rebuild
git pull && ./BuildAndRunTests.sh

+ 2
- 0
src/AutoTest.cake View File

@ -63,3 +63,5 @@
(return true))
(add-compile-time-hook post-references-resolved find-add-tests)
(set-cakelisp-option executable-output "test/autoTest")

+ 0
- 60
src/Macros.cake View File

@ -2,66 +2,6 @@
(import &comptime-only "../Dependencies/cakelisp/runtime/Macros.cake")
;; Creates forward declarations in header files.
;; Example usage:
;; (forward-declare (namespace Ogre (class item) (struct my-struct)))
;; Outputs namespace Ogre { class item; struct my-struct;}
(defgenerator forward-declare ()
;; TODO: Support global vs local?
(var is-global bool true)
(var output-dest (& (<> std::vector StringOutput))
(? is-global (field output header) (field output source)))
(var end-invocation-index int (FindCloseParenTokenIndex tokens startTokenIndex))
(var start-body-index int (+ 2 startTokenIndex))
(var current-index int start-body-index)
(var namespace-stack (<> std::vector int))
(while (< current-index end-invocation-index)
(var current-token (& (const Token)) (at current-index tokens))
;; Invocations
(when (= TokenType_OpenParen (field current-token type))
(var invocation-token (& (const Token)) (at (+ 1 current-index) tokens))
(cond
((= 0 (on-call (field invocation-token contents) compare "namespace"))
(unless (< (+ 3 current-index) end-invocation-index)
(ErrorAtToken invocation-token "missing name or body arguments")
(return false))
(var namespace-name-token (& (const Token)) (at (+ 2 current-index) tokens))
(addStringOutput output-dest "namespace"
StringOutMod_SpaceAfter (addr invocation-token))
(addStringOutput output-dest (field namespace-name-token contents)
StringOutMod_None (addr namespace-name-token))
(addLangTokenOutput output-dest StringOutMod_OpenBlock (addr namespace-name-token))
(on-call namespace-stack push_back (FindCloseParenTokenIndex tokens current-index)))
((or (= 0 (on-call (field invocation-token contents) compare "class"))
(= 0 (on-call (field invocation-token contents) compare "struct")))
(unless (< (+ 2 current-index) end-invocation-index)
(ErrorAtToken invocation-token "missing name argument")
(return false))
(var type-name-token (& (const Token)) (at (+ 2 current-index) tokens))
(unless (ExpectTokenType "forward-declare" type-name-token TokenType_Symbol)
(return false))
(addStringOutput output-dest (field invocation-token contents)
StringOutMod_SpaceAfter (addr invocation-token))
(addStringOutput output-dest (field type-name-token contents)
StringOutMod_None (addr type-name-token))
(addLangTokenOutput output-dest StringOutMod_EndStatement (addr type-name-token)))
(true
(ErrorAtToken invocation-token "unknown forward-declare type")
(return false))))
(when (= TokenType_CloseParen (field current-token type))
(for-in close-block-index int namespace-stack
(when (= close-block-index current-index)
(addLangTokenOutput output-dest StringOutMod_CloseBlock
(addr (at current-index tokens))))))
;; TODO: Support function calls so we can do this recursively?
;; (set current-index
;; (getNextArgument tokens current-index end-invocation-index))
(incr current-index))
(return true))
(defmacro command-add-string-argument ()
(destructure-arguments new-argument-index)
(quick-token-at new-argument new-argument-index)


+ 1
- 1
src/OgreCore.cake View File

@ -90,7 +90,7 @@
(return mesh-handle))
(defun ogre-node-from-item (mesh-handle mesh-handle &return scene-node)
(var new-scene-node scene-node (array nullptr))
(var new-scene-node scene-node (array null))
(var scene-manager (* (in Ogre SceneManager)) (ogreGetSceneManager))
(var root-scene-node (* Ogre::SceneNode) (on-call-ptr scene-manager getRootSceneNode))
(when root-scene-node


+ 4
- 3
src/SDL.cake View File

@ -1,6 +1,7 @@
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(import &comptime-only "Macros.cake")
(import &comptime-only "Dependencies/cakelisp/runtime/Macros.cake")
(c-import "stdio.h"
"SDL.h"
@ -42,18 +43,18 @@
;; TODO: Automatically promote this if no main is defined. Separate target instead?
(defun test--sdl-main (&return int)
(printf "Hello, SDL!\n")
(var window (* SDL_Window) nullptr)
(var window (* SDL_Window) null)
(unless (sdl-initialize (addr window)) (return 1))
;; (var window-surface (* SDL_Surface) (SDL_GetWindowSurface window))
(var exit-reason (* (const char)) nullptr)
(var exit-reason (* (const char)) null)
(while (not exit-reason)
(var event SDL_Event)
(while (SDL_PollEvent (addr event))
(when (= (field event type) SDL_QUIT)
(set exit-reason "Window event")))
(var currentKeyStates (* (const Uint8)) (SDL_GetKeyboardState nullptr))
(var currentKeyStates (* (const Uint8)) (SDL_GetKeyboardState null))
(when (at SDL_SCANCODE_ESCAPE currentKeyStates)
(set exit-reason "Escape pressed"))
(SDL_UpdateWindowSurface window))


Loading…
Cancel
Save