Browse Source

Got dictionary working a bit

windows-imgui
Macoy Madson 9 months ago
parent
commit
62254386aa
  1. 59
      src/Dictionary.cake

59
src/Dictionary.cake

@ -1,22 +1,10 @@
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "CHelpers.cake" "Dependencies.cake")
(import &comptime-only "CHelpers.cake")
;; TODO: Make this an "infect" to the importer rather than having to be global
(add-c-search-directory-global "Dependencies/stb")
;; TODO: Remove once importing this module no longer changes all compile commands
(add-build-config-label "STB")
;; Enforce only defining the implemention once
(comptime-cond
('stb-ds-defined)
(true
(c-preprocessor-define STB_DS_IMPLEMENTATION)
(comptime-define-symbol 'stb-ds-defined)))
(c-import &with-decls "stb_ds.h"
&with-defs "stb_ds.h")
(import &comptime-only "STB.cake")
(use-stb-ds clone-stb-headers-dictionary)
(comptime-cond
('auto-test
@ -26,25 +14,30 @@
key (* char)
value (* (const char)))
(var my-dictionary (* dictionary-entry) null)
;; (sh_new_strdup my-dictionary)
(when (shgetp_null my-dictionary "Test")
(fprintf stderr "Expected not to get entry back\n")
(return 1))
(sh_new_arena my-dictionary)
;; (when (shgetp_null my-dictionary "Test")
;; (fprintf stderr "Expected not to get entry back\n")
;; (return 1))
;; TODO Memory leak
(var my-entry dictionary-entry (array (strdup "cakelisp") "a programming language"))
(shputs my-dictionary my-entry)
(var returned-entry (* dictionary-entry) (shgetp_null my-dictionary "cakelisp"))
;; (var my-entry dictionary-entry (array (strdup "cakelisp") "a programming language"))
;; (shputs my-dictionary my-entry)
(shput my-dictionary "cakelisp" "a programming language")
(shput my-dictionary "gamelib" "a helpful library")
(var keys ([] (* (const char))) (array "cakelisp" "gamelib"))
(each-in-array keys i
(var returned-entry-copy (* (const char)) (shget my-dictionary (at i keys)))
(unless returned-entry-copy
(fprintf stderr "Expected to get string back. Length: %ld\n" (shlen my-dictionary))
(return 1))
(fprintf stderr "what is %s? %s\n" (at i keys) returned-entry-copy))
;; (var returned-entry (* dictionary-entry) (shgetp_null my-dictionary "cakelisp"))
;; (unless (and returned-entry (path returned-entry > key) (path returned-entry > value))
;; (fprintf stderr "Expected to get valid entry back\n")
;; (return 1))
(fprintf stderr "what is %s? %s\n"
(path returned-entry > key)
(path returned-entry > value))
;; (fprintf stderr "Expected to get valid entry back. Length: %ld\n" (shlen my-dictionary))
;; (return 1))
;; (fprintf stderr "what is %s? %s\n"
;; (path returned-entry > key)
;; (path returned-entry > value))
(shfree my-dictionary)
(return 0))))
(add-c-search-directory-module "Dependencies/stb")
(add-dependency-git-submodule clone-stb-headers-dictionary
"https://github.com/nothings/stb"
"Dependencies/stb")

Loading…
Cancel
Save