Bugfix for const expressions

This commit is contained in:
Jan Wedekind (Dr) 2024-10-15 22:27:53 +01:00
parent bd5a4d9175
commit 632374f8d4
3 changed files with 6 additions and 1 deletions

View file

@ -606,7 +606,7 @@
(defn const
"Gets the value of a constant stored in `symbol-or-addr`."
[symbol-or-addr type]
(mem/deserialize (.address (ensure-symbol symbol-or-addr)) [::mem/pointer type]))
(mem/deserialize (ensure-symbol symbol-or-addr) [::mem/pointer type]))
(s/def ::defconst-args
(s/cat :var-name simple-symbol?

View file

@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
const int c = 42;
int add_numbers(int a, int b) {
return a + b;
}

View file

@ -10,6 +10,9 @@
(t/deftest can-load-symbols
(t/is (not (nil? (ffi/find-symbol "add_numbers")))))
(t/deftest can-fetch-constant
(t/is (ffi/const "c" ::mem/int) 42))
(t/deftest can-call-primitive-fns
(t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))