mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-04 01:25:04 +03:00
fix: Pointer str & prn (#1060)
* fix: Make `str` work for (Pointer a) types * test: Make sure that the Pointer.str compiles * fix: Remove test case, keep function around to make sure it compiles
This commit is contained in:
parent
dd19c049c6
commit
40d55562df
@ -461,9 +461,13 @@
|
||||
)
|
||||
|
||||
(defmodule Pointer
|
||||
(register str (Fn [(Ptr a)] String) "Pointer_str")
|
||||
(register strp (Fn [(Ptr a)] String) "Pointer_strp")
|
||||
|
||||
(defn str [a] (Pointer.strp a))
|
||||
(implements str Pointer.str)
|
||||
(defn prn [a] (Pointer.str a))
|
||||
|
||||
(defn prn [a] (Pointer.strp a))
|
||||
(implements prn Pointer.prn)
|
||||
)
|
||||
|
||||
(defndynamic build-str* [forms]
|
||||
@ -474,4 +478,4 @@
|
||||
(list 'ref (list 'String.append (list 'ref (list 'str (car forms))) (build-str* (cdr forms)))))))
|
||||
|
||||
(defmacro str* [:rest forms]
|
||||
(list 'copy (build-str* forms)))
|
||||
(list 'copy (build-str* forms)))
|
||||
|
@ -362,7 +362,7 @@ int String_index_MINUS_of(const String *s, char c) {
|
||||
return String_index_MINUS_of_MINUS_from(s, c, -1);
|
||||
}
|
||||
|
||||
String Pointer_str(void *in) {
|
||||
String Pointer_strp(void *in) {
|
||||
int size = snprintf(NULL, 0, "%p", in) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
sprintf(buffer, "%p", in);
|
||||
|
@ -10,6 +10,12 @@
|
||||
(defn ref-to-ptr [r]
|
||||
(the (Ptr a) (Unsafe.coerce (the (Ref a) r))))
|
||||
|
||||
;; Just make sure the 'str' for a Pointer compiles
|
||||
;; (testing out its contents is platform specific)
|
||||
(defn pointer-to-str []
|
||||
(let [p (the (Ptr CChar) NULL)]
|
||||
(str p)))
|
||||
|
||||
; these tests are sadly a little unsafe
|
||||
(deftest test
|
||||
(assert-equal test
|
||||
@ -42,5 +48,5 @@
|
||||
(to-value (ref-to-ptr &123))
|
||||
123
|
||||
"Pointer.to-value works as expected"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user