mirror of
https://github.com/janet-lang/janet
synced 2025-05-05 17:04:15 +00:00
Fix nil check issue.
This commit is contained in:
parent
03f99752a7
commit
5c35d24e13
@ -3689,15 +3689,6 @@
|
|||||||
|
|
||||||
(do
|
(do
|
||||||
|
|
||||||
(defn proto-flatten
|
|
||||||
"Flatten a table and its prototypes into a single table."
|
|
||||||
[into x]
|
|
||||||
(when x
|
|
||||||
(proto-flatten into (table/getproto x))
|
|
||||||
(loop [k :keys x]
|
|
||||||
(put into k (x k))))
|
|
||||||
into)
|
|
||||||
|
|
||||||
# Deprecate file/popen
|
# Deprecate file/popen
|
||||||
(when-let [v (get root-env 'file/popen)]
|
(when-let [v (get root-env 'file/popen)]
|
||||||
(put v :deprecated true))
|
(put v :deprecated true))
|
||||||
@ -3706,7 +3697,7 @@
|
|||||||
# flatten nested tables.
|
# flatten nested tables.
|
||||||
(loop [[k v] :in (pairs root-env)
|
(loop [[k v] :in (pairs root-env)
|
||||||
:when (symbol? k)]
|
:when (symbol? k)]
|
||||||
(def flat (proto-flatten @{} v))
|
(def flat (table/proto-flatten @{} v))
|
||||||
(when (boot/config :no-docstrings)
|
(when (boot/config :no-docstrings)
|
||||||
(put flat :doc nil))
|
(put flat :doc nil))
|
||||||
(when (boot/config :no-sourcemaps)
|
(when (boot/config :no-sourcemaps)
|
||||||
|
@ -167,30 +167,22 @@ Janet janet_struct_rawget(const JanetKV *st, Janet key) {
|
|||||||
|
|
||||||
/* Get an item from a struct */
|
/* Get an item from a struct */
|
||||||
Janet janet_struct_get(const JanetKV *st, Janet key) {
|
Janet janet_struct_get(const JanetKV *st, Janet key) {
|
||||||
int i = JANET_MAX_PROTO_DEPTH;
|
for (int i = JANET_MAX_PROTO_DEPTH; st && i; --i, st = janet_struct_proto(st)) {
|
||||||
for (; st && i; --i) {
|
|
||||||
const JanetKV *kv = janet_struct_find(st, key);
|
const JanetKV *kv = janet_struct_find(st, key);
|
||||||
if (NULL != kv)
|
if (NULL != kv && !janet_checktype(kv->key, JANET_NIL)) {
|
||||||
return kv->value;
|
return kv->value;
|
||||||
st = janet_struct_proto(st);
|
}
|
||||||
}
|
}
|
||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get an item from a struct, and record which prototype the item came from. */
|
/* Get an item from a struct, and record which prototype the item came from. */
|
||||||
Janet janet_struct_get_ex(const JanetKV *st, Janet key, JanetStruct *which) {
|
Janet janet_struct_get_ex(const JanetKV *st, Janet key, JanetStruct *which) {
|
||||||
const JanetKV *kv = janet_struct_find(st, key);
|
for (int i = JANET_MAX_PROTO_DEPTH; st && i; --i, st = janet_struct_proto(st)) {
|
||||||
if (NULL != kv)
|
const JanetKV *kv = janet_struct_find(st, key);
|
||||||
return kv->value;
|
if (NULL != kv && !janet_checktype(kv->key, JANET_NIL)) {
|
||||||
/* Check prototypes */
|
*which = st;
|
||||||
{
|
return kv->value;
|
||||||
int i = JANET_MAX_PROTO_DEPTH;
|
|
||||||
for (st = janet_struct_proto(st); st && i; st = janet_struct_proto(st), --i) {
|
|
||||||
kv = janet_struct_find(st, key);
|
|
||||||
if (NULL != kv) {
|
|
||||||
*which = kv;
|
|
||||||
return kv->value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
|
@ -132,37 +132,21 @@ static void janet_table_rehash(JanetTable *t, int32_t size) {
|
|||||||
|
|
||||||
/* Get a value out of the table */
|
/* Get a value out of the table */
|
||||||
Janet janet_table_get(JanetTable *t, Janet key) {
|
Janet janet_table_get(JanetTable *t, Janet key) {
|
||||||
JanetKV *bucket = janet_table_find(t, key);
|
for (int i = JANET_MAX_PROTO_DEPTH; t && i; t = t->proto, --i) {
|
||||||
if (NULL != bucket && !janet_checktype(bucket->key, JANET_NIL))
|
JanetKV *bucket = janet_table_find(t, key);
|
||||||
return bucket->value;
|
if (NULL != bucket && !janet_checktype(bucket->key, JANET_NIL))
|
||||||
/* Check prototypes */
|
return bucket->value;
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = JANET_MAX_PROTO_DEPTH, t = t->proto; t && i; t = t->proto, --i) {
|
|
||||||
bucket = janet_table_find(t, key);
|
|
||||||
if (NULL != bucket && !janet_checktype(bucket->key, JANET_NIL))
|
|
||||||
return bucket->value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a value out of the table, and record which prototype it was from. */
|
/* Get a value out of the table, and record which prototype it was from. */
|
||||||
Janet janet_table_get_ex(JanetTable *t, Janet key, JanetTable **which) {
|
Janet janet_table_get_ex(JanetTable *t, Janet key, JanetTable **which) {
|
||||||
JanetKV *bucket = janet_table_find(t, key);
|
for (int i = JANET_MAX_PROTO_DEPTH; t && i; t = t->proto, --i) {
|
||||||
if (NULL != bucket && !janet_checktype(bucket->key, JANET_NIL)) {
|
JanetKV *bucket = janet_table_find(t, key);
|
||||||
*which = t;
|
if (NULL != bucket && !janet_checktype(bucket->key, JANET_NIL)) {
|
||||||
return bucket->value;
|
*which = t;
|
||||||
}
|
return bucket->value;
|
||||||
/* Check prototypes */
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = JANET_MAX_PROTO_DEPTH, t = t->proto; t && i; t = t->proto, --i) {
|
|
||||||
bucket = janet_table_find(t, key);
|
|
||||||
if (NULL != bucket && !janet_checktype(bucket->key, JANET_NIL)) {
|
|
||||||
*which = t;
|
|
||||||
return bucket->value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user