Browse Source

Fix leak, improve AutoTest, remove block

* Aubio test no longer leaks memory
* AutoTest now prints which tests it is performing, and stops as soon
as a test fails
* Converted all (block) to (scope)
windows-imgui
Macoy Madson 9 months ago
parent
commit
2d414992ed
  1. 1
      src/Aubio.cake
  2. 12
      src/AutoTest.cake
  3. 42
      src/Math.cake
  4. 18
      test/src/VocalGame.cake

1
src/Aubio.cake

@ -76,6 +76,7 @@
(del_fvec buffer)
(del_fvec detected-pitch)
(del_aubio_pitch pitch-detection)
(del_aubio_source sound-source)
(return 0))
;;

12
src/AutoTest.cake

@ -5,6 +5,8 @@
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "ComptimeHelpers.cake")
(c-import "<stdio.h>")
;; This is completely replaced by find-add-tests
(defun main (&return int) (return 0))
@ -36,9 +38,17 @@
(var function-name-token Token (deref (field function-pair second)))
(set (field function-name-token type) TokenType_Symbol)
(set (field function-name-token contents) (field function-pair first))
(var function-name-string-token Token function-name-token)
(set (field function-name-string-token type) TokenType_String)
(tokenize-push test-body
(fprintf stderr "\n------------- %s\n" (token-splice-addr
function-name-string-token))
(set num-errors (+ num-errors
((token-splice-addr function-name-token))))))
((token-splice-addr function-name-token))))
(when num-errors
(fprintf stderr "error: %s failed\n" (token-splice-addr
function-name-string-token))
(return 1))))
(var main-definition (* (<> std::vector Token)) (new (<> std::vector Token)))
(call-on push_back (field environment comptimeTokens) main-definition)

42
src/Math.cake

@ -270,27 +270,27 @@
;; (Logf "found %s, outputting %s\n" (call-on c_str invocation-name) (call-on c_str underlying-func-name))
(if arguments
(block
(var invocation-statement (const ([] CStatementOperation))
(array
(array KeywordNoSpace (call-on c_str underlying-func-name) -1)
(array OpenParen null -1)
(array ExpressionList null 1)
(array CloseParen null -1)
(array SmartEndStatement null -1)))
(return (CStatementOutput environment context tokens startTokenIndex
invocation-statement (array-size invocation-statement)
output)))
(block
(var invocation-statement (const ([] CStatementOperation))
(array
(array KeywordNoSpace (call-on c_str underlying-func-name) -1)
(array OpenParen null -1)
(array CloseParen null -1)
(array SmartEndStatement null -1)))
(return (CStatementOutput environment context tokens startTokenIndex
invocation-statement (array-size invocation-statement)
output)))))
(scope
(var invocation-statement (const ([] CStatementOperation))
(array
(array KeywordNoSpace (call-on c_str underlying-func-name) -1)
(array OpenParen null -1)
(array ExpressionList null 1)
(array CloseParen null -1)
(array SmartEndStatement null -1)))
(return (CStatementOutput environment context tokens startTokenIndex
invocation-statement (array-size invocation-statement)
output)))
(scope
(var invocation-statement (const ([] CStatementOperation))
(array
(array KeywordNoSpace (call-on c_str underlying-func-name) -1)
(array OpenParen null -1)
(array CloseParen null -1)
(array SmartEndStatement null -1)))
(return (CStatementOutput environment context tokens startTokenIndex
invocation-statement (array-size invocation-statement)
output)))))
;; When encountering references of (alias), output C function invocation underlyingFuncName()
;; output-aliased-c-function-invocation actually does the work

18
test/src/VocalGame.cake

@ -141,10 +141,10 @@
;; Loop playback
(if g-audio-is-recording
(set mono-sample 127) ;; Silence
(block ;; Else, play the recording
(var recording-index int (+ (/ i num-channels) g-audio-looper-read-head))
(set recording-index (mod recording-index g-audio-looper-buffer-size))
(set mono-sample (at recording-index g-audio-looper-buffer))))
(scope ;; Else, play the recording
(var recording-index int (+ (/ i num-channels) g-audio-looper-read-head))
(set recording-index (mod recording-index g-audio-looper-buffer-size))
(set mono-sample (at recording-index g-audio-looper-buffer))))
;; Channels are interleaved, e.g. LRLR, not LLRR
(var channel int 0)
@ -257,11 +257,11 @@
SDL_AUDIO_ALLOW_SAMPLES_CHANGE
SDL_AUDIO_ALLOW_CHANNELS_CHANGE)))
(if (>= output-device-id valid-device-start-num)
(block (set selected-output-device device-name)
(set (deref output-device-spec-out) obtained-output-spec))
(block (sdl-print-error)
(sdl-audio-free-device-list devices num-devices)
(return false))))
(scope (set selected-output-device device-name)
(set (deref output-device-spec-out) obtained-output-spec))
(scope (sdl-print-error)
(sdl-audio-free-device-list devices num-devices)
(return false))))
(var selected-input-device (* (const char)) nullptr)
(var obtained-input-spec SDL_AudioSpec (array 0))

Loading…
Cancel
Save