1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

Small changes to boot.dst.

This commit is contained in:
Calvin Rose 2018-07-01 12:44:41 -04:00
parent f4fc4a0bcc
commit 0bbf7d57b0
3 changed files with 25 additions and 27 deletions

View File

@ -561,32 +561,29 @@ which (pred element) is truthy. Returns the same type as the input sequence."
(defn take-until
"Given a predicate, take only elements from an indexed type that satisfy
the predicate, and abort on first failure. Returns a new indexed type that is
the same type as the input."
[pred ind t]
the predicate, and abort on first failure. Returns a new tuple."
[pred ind]
(def i (find-index pred ind))
(if (= :tuple (type (or t ind)))
(tuple.slice ind 0 i)
(array.slice ind 0 i)))
(if i
(tuple.slice ind 0 i)
ind))
(defn take-while
"Same as (take-until (complement pred) ind t)."
[pred ind t]
(take-until (complement pred) ind t))
"Same as (take-until (complement pred) ind)."
[pred ind]
(take-until (complement pred) ind))
(defn drop-until
"Given a predicate, remove elements from an indexed type that satisfy
the predicate, and abort on first failure."
[pred ind t]
the predicate, and abort on first failure. Returns a new tuple."
[pred ind]
(def i (find-index pred ind))
(if (= :tuple (type (or t ind)))
(tuple.slice ind i -1)
(array.slice ind i -1)))
(tuple.slice ind i -1))
(defn drop-while
"Same as (drop-until (complement pred) ind t)."
[pred ind t]
(drop-until (complement pred) ind t))
"Same as (drop-until (complement pred) ind)."
[pred ind]
(drop-until (complement pred) ind))
(defn juxt*
[& funs]

View File

@ -397,21 +397,19 @@ static DstSlot dstc_call(DstFopts opts, DstSlot *slots, DstSlot fun) {
}
if (!specialized) {
dstc_pushslots(c, slots);
int32_t fun_register;
if (opts.flags & DST_FOPTS_TAIL) {
fun_register = dstc_to_reg(c, fun);
dstc_emit(c, DOP_TAILCALL | (fun_register << 8));
dstc_emit_s(c, DOP_TAILCALL, fun);
retslot = dstc_cslot(dst_wrap_nil());
retslot.flags = DST_SLOT_RETURNED;
} else {
retslot = dstc_gettarget(opts);
fun_register = dstc_to_tempreg(c, fun, DSTC_REGTEMP_0);
int32_t fun_register = dstc_to_tempreg(c, fun, DSTC_REGTEMP_0);
dstc_emit(c, DOP_CALL |
(retslot.index << 8) |
(fun_register << 16));
/* Don't free ret register */
dstc_free_reg(c, fun, fun_register);
}
dstc_free_reg(c, fun, fun_register);
}
dstc_freeslots(c, slots);
return retslot;
@ -677,7 +675,7 @@ DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where) {
}
/* C Function for compiling */
int dst_compile_cfun(DstArgs args) {
static int cfun(DstArgs args) {
DstCompileResult res;
DstTable *t;
DstTable *env;
@ -700,8 +698,13 @@ int dst_compile_cfun(DstArgs args) {
}
}
static const DstReg cfuns[] = {
{"compile", cfun},
{NULL, NULL}
};
int dst_lib_compile(DstArgs args) {
DstTable *env = dst_env_arg(args);
dst_env_def(env, "compile", dst_wrap_cfunction(dst_compile_cfun));
dst_env_cfuns(env, cfuns);
return 0;
}

View File

@ -211,10 +211,8 @@ static struct DstScanRes dst_scan_impl(
res.mant = 0;
seenadigit = 0;
gotradix = 1;
} else if (*str == '_') {
;
} else if (*str != '_') {
/* underscores are ignored - can be used for separator */
} else {
int digit = digit_lookup[*str & 0x7F];
if (*str > 127 || digit >= res.base) goto error;
if (res.seenpoint) res.ex--;