From 0bbf7d57b0e5950c073bd579b016d7525581d038 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 1 Jul 2018 12:44:41 -0400 Subject: [PATCH] Small changes to boot.dst. --- src/compiler/boot.dst | 31 ++++++++++++++----------------- src/compiler/compile.c | 17 ++++++++++------- src/core/strtod.c | 4 +--- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/compiler/boot.dst b/src/compiler/boot.dst index 44a1423c..2b9f814f 100644 --- a/src/compiler/boot.dst +++ b/src/compiler/boot.dst @@ -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] diff --git a/src/compiler/compile.c b/src/compiler/compile.c index 27f8aed9..468194c7 100644 --- a/src/compiler/compile.c +++ b/src/compiler/compile.c @@ -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; } diff --git a/src/core/strtod.c b/src/core/strtod.c index 4bfdf4eb..1d0a68bd 100644 --- a/src/core/strtod.c +++ b/src/core/strtod.c @@ -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--;