1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-16 13:44:48 +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 (defn take-until
"Given a predicate, take only elements from an indexed type that satisfy "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 predicate, and abort on first failure. Returns a new tuple."
the same type as the input." [pred ind]
[pred ind t]
(def i (find-index pred ind)) (def i (find-index pred ind))
(if (= :tuple (type (or t ind))) (if i
(tuple.slice ind 0 i) (tuple.slice ind 0 i)
(array.slice ind 0 i))) ind))
(defn take-while (defn take-while
"Same as (take-until (complement pred) ind t)." "Same as (take-until (complement pred) ind)."
[pred ind t] [pred ind]
(take-until (complement pred) ind t)) (take-until (complement pred) ind))
(defn drop-until (defn drop-until
"Given a predicate, remove elements from an indexed type that satisfy "Given a predicate, remove elements from an indexed type that satisfy
the predicate, and abort on first failure." the predicate, and abort on first failure. Returns a new tuple."
[pred ind t] [pred ind]
(def i (find-index pred ind)) (def i (find-index pred ind))
(if (= :tuple (type (or t ind))) (tuple.slice ind i -1))
(tuple.slice ind i -1)
(array.slice ind i -1)))
(defn drop-while (defn drop-while
"Same as (drop-until (complement pred) ind t)." "Same as (drop-until (complement pred) ind)."
[pred ind t] [pred ind]
(drop-until (complement pred) ind t)) (drop-until (complement pred) ind))
(defn juxt* (defn juxt*
[& funs] [& funs]

View File

@ -397,22 +397,20 @@ static DstSlot dstc_call(DstFopts opts, DstSlot *slots, DstSlot fun) {
} }
if (!specialized) { if (!specialized) {
dstc_pushslots(c, slots); dstc_pushslots(c, slots);
int32_t fun_register;
if (opts.flags & DST_FOPTS_TAIL) { if (opts.flags & DST_FOPTS_TAIL) {
fun_register = dstc_to_reg(c, fun); dstc_emit_s(c, DOP_TAILCALL, fun);
dstc_emit(c, DOP_TAILCALL | (fun_register << 8));
retslot = dstc_cslot(dst_wrap_nil()); retslot = dstc_cslot(dst_wrap_nil());
retslot.flags = DST_SLOT_RETURNED; retslot.flags = DST_SLOT_RETURNED;
} else { } else {
retslot = dstc_gettarget(opts); 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 | dstc_emit(c, DOP_CALL |
(retslot.index << 8) | (retslot.index << 8) |
(fun_register << 16)); (fun_register << 16));
/* Don't free ret register */ /* Don't free ret register */
}
dstc_free_reg(c, fun, fun_register); dstc_free_reg(c, fun, fun_register);
} }
}
dstc_freeslots(c, slots); dstc_freeslots(c, slots);
return retslot; return retslot;
} }
@ -677,7 +675,7 @@ DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where) {
} }
/* C Function for compiling */ /* C Function for compiling */
int dst_compile_cfun(DstArgs args) { static int cfun(DstArgs args) {
DstCompileResult res; DstCompileResult res;
DstTable *t; DstTable *t;
DstTable *env; 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) { int dst_lib_compile(DstArgs args) {
DstTable *env = dst_env_arg(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; return 0;
} }

View File

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