mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Change semantics of bracketed tuple equality.
Comparison between different bracket and normal tuples will now take into account the delimiter type. This solves strange non-locality issues in the compiler due to this false equality, and is more consistent with Janet's otherwise strong equality philosophy.
This commit is contained in:
parent
75229332c8
commit
aa5c987a94
@ -2,6 +2,8 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## ??? - Unreleased
|
## ??? - Unreleased
|
||||||
|
- Change semantics around bracket tuples to no longer be equal to regular tuples.
|
||||||
|
- Add `index` argument to `ffi/write` for symmetry with `ffi/read`.
|
||||||
- Add `buffer/push-at`
|
- Add `buffer/push-at`
|
||||||
- Add `ffi/pointer-buffer` to convert pointers to buffers the cannot be reallocated. This
|
- Add `ffi/pointer-buffer` to convert pointers to buffers the cannot be reallocated. This
|
||||||
allows easier manipulation of FFI memory, memory mapped files, and buffer memory shared between threads.
|
allows easier manipulation of FFI memory, memory mapped files, and buffer memory shared between threads.
|
||||||
|
@ -1517,7 +1517,7 @@ JANET_CORE_FN(cfun_ffi_pointer_buffer,
|
|||||||
"Create a buffer from a pointer. The underlying memory of the buffer will not be "
|
"Create a buffer from a pointer. The underlying memory of the buffer will not be "
|
||||||
"reallocated or freed by the garbage collector, allowing unmanaged, mutable memory "
|
"reallocated or freed by the garbage collector, allowing unmanaged, mutable memory "
|
||||||
"to be manipulated with buffer functions. Attempts to resize or extend the buffer "
|
"to be manipulated with buffer functions. Attempts to resize or extend the buffer "
|
||||||
"beyond it's initial capacity will raise an error. As with many FFI functions, it is memory "
|
"beyond its initial capacity will raise an error. As with many FFI functions, this is memory "
|
||||||
"unsafe and can potentially allow out of bounds memory access. Returns a new buffer.") {
|
"unsafe and can potentially allow out of bounds memory access. Returns a new buffer.") {
|
||||||
janet_sandbox_assert(JANET_SANDBOX_FFI);
|
janet_sandbox_assert(JANET_SANDBOX_FFI);
|
||||||
janet_arity(argc, 2, 4);
|
janet_arity(argc, 2, 4);
|
||||||
|
@ -272,6 +272,7 @@ int janet_equals(Janet x, Janet y) {
|
|||||||
const Janet *t1 = janet_unwrap_tuple(x);
|
const Janet *t1 = janet_unwrap_tuple(x);
|
||||||
const Janet *t2 = janet_unwrap_tuple(y);
|
const Janet *t2 = janet_unwrap_tuple(y);
|
||||||
if (t1 == t2) break;
|
if (t1 == t2) break;
|
||||||
|
if (JANET_TUPLE_FLAG_BRACKETCTOR & (janet_tuple_flag(t1) ^ janet_tuple_flag(t2))) return 0;
|
||||||
if (janet_tuple_hash(t1) != janet_tuple_hash(t2)) return 0;
|
if (janet_tuple_hash(t1) != janet_tuple_hash(t2)) return 0;
|
||||||
if (janet_tuple_length(t1) != janet_tuple_length(t2)) return 0;
|
if (janet_tuple_length(t1) != janet_tuple_length(t2)) return 0;
|
||||||
push_traversal_node(janet_tuple_head(t1), janet_tuple_head(t2), 0);
|
push_traversal_node(janet_tuple_head(t1), janet_tuple_head(t2), 0);
|
||||||
@ -321,6 +322,7 @@ int32_t janet_hash(Janet x) {
|
|||||||
break;
|
break;
|
||||||
case JANET_TUPLE:
|
case JANET_TUPLE:
|
||||||
hash = janet_tuple_hash(janet_unwrap_tuple(x));
|
hash = janet_tuple_hash(janet_unwrap_tuple(x));
|
||||||
|
hash += (janet_tuple_flag(janet_unwrap_tuple(x)) & JANET_TUPLE_FLAG_BRACKETCTOR) ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
case JANET_STRUCT:
|
case JANET_STRUCT:
|
||||||
hash = janet_struct_hash(janet_unwrap_struct(x));
|
hash = janet_struct_hash(janet_unwrap_struct(x));
|
||||||
@ -412,6 +414,9 @@ int janet_compare(Janet x, Janet y) {
|
|||||||
case JANET_TUPLE: {
|
case JANET_TUPLE: {
|
||||||
const Janet *lhs = janet_unwrap_tuple(x);
|
const Janet *lhs = janet_unwrap_tuple(x);
|
||||||
const Janet *rhs = janet_unwrap_tuple(y);
|
const Janet *rhs = janet_unwrap_tuple(y);
|
||||||
|
if (JANET_TUPLE_FLAG_BRACKETCTOR & (janet_tuple_flag(lhs) ^ janet_tuple_flag(rhs))) {
|
||||||
|
return (janet_tuple_flag(lhs) & JANET_TUPLE_FLAG_BRACKETCTOR) ? 1 : -1;
|
||||||
|
}
|
||||||
push_traversal_node(janet_tuple_head(lhs), janet_tuple_head(rhs), 1);
|
push_traversal_node(janet_tuple_head(lhs), janet_tuple_head(rhs), 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@
|
|||||||
|
|
||||||
(assert (= 14 (sum (map inc @[1 2 3 4]))) "sum map")
|
(assert (= 14 (sum (map inc @[1 2 3 4]))) "sum map")
|
||||||
(def myfun (juxt + - * /))
|
(def myfun (juxt + - * /))
|
||||||
(assert (= '[2 -2 2 0.5] (myfun 2)) "juxt")
|
(assert (= [2 -2 2 0.5] (myfun 2)) "juxt")
|
||||||
|
|
||||||
# Case statements
|
# Case statements
|
||||||
(assert
|
(assert
|
||||||
|
@ -41,10 +41,10 @@
|
|||||||
|
|
||||||
# Looping idea
|
# Looping idea
|
||||||
(def xs
|
(def xs
|
||||||
(seq [x :in '[-1 0 1] y :in '[-1 0 1] :when (not= x y 0)] (tuple x y)))
|
(seq [x :in [-1 0 1] y :in [-1 0 1] :when (not= x y 0)] (tuple x y)))
|
||||||
(def txs (apply tuple xs))
|
(def txs (apply tuple xs))
|
||||||
|
|
||||||
(assert (= txs '[[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]) "nested seq")
|
(assert (= txs [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]) "nested seq")
|
||||||
|
|
||||||
# Generators
|
# Generators
|
||||||
(def gen (generate [x :range [0 100] :when (pos? (% x 4))] x))
|
(def gen (generate [x :range [0 100] :when (pos? (% x 4))] x))
|
||||||
|
Loading…
Reference in New Issue
Block a user