mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 07:50:27 +00:00
Improve lazy2iter and fix a typo in specials.c
This commit is contained in:
parent
41d5b5cb90
commit
0ebc95aa2b
@ -109,15 +109,14 @@ body once, and then memoizes the result."
|
||||
#Iterators is a conscept that looks a lot like lazy seq
|
||||
#The following functions turn iterators to lazy seq and vice versa
|
||||
|
||||
(defn- iter-self
|
||||
[next]
|
||||
(delay (tuple (next) (iter-self next))))
|
||||
|
||||
(defn iter2lazy
|
||||
"Create a lazy sequence froma an iterator"
|
||||
"Create a lazy sequence from an iterator"
|
||||
[iter]
|
||||
(def {:more more :next next} iter)
|
||||
(iter-self next))
|
||||
(if (more)
|
||||
(delay (tuple (next) (iter2lazy iter)))
|
||||
empty-seq))
|
||||
|
||||
(defn lazy2iter
|
||||
"turn a lazy-seq to an iterator"
|
||||
@ -138,8 +137,7 @@ body once, and then memoizes the result."
|
||||
#data structures as their values are references to this
|
||||
#data structures. Same is true for iterators
|
||||
|
||||
(defn filter2 [pred coll]
|
||||
(tail (iter2lazy (filter pred coll))))
|
||||
(defn filter2 [pred coll] (iter2lazy (filter pred coll)))
|
||||
|
||||
(def arr [0 -1 -2 33 -3 0 302 -3 2 8 54 3 -2 0])
|
||||
|
||||
|
@ -45,7 +45,7 @@ DstSlot dstc_astquote(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv)
|
||||
}
|
||||
|
||||
static void destructure(DstCompiler *c, Dst left, DstSlot right,
|
||||
void (*leaf)(DstCompiler *c,
|
||||
void (*leaf)(DstCompiler *c,
|
||||
DstAst *ast,
|
||||
const uint8_t *sym,
|
||||
DstSlot s,
|
||||
@ -72,7 +72,7 @@ static void destructure(DstCompiler *c, Dst left, DstSlot right,
|
||||
localright = dstc_preread(c, ast, 0xFF, 1, right);
|
||||
localsub = dstc_lslotn(c, 0xFF, 3);
|
||||
if (i < 0x100) {
|
||||
dstc_emit(c, ast,
|
||||
dstc_emit(c, ast,
|
||||
(i << 24) |
|
||||
(localright << 16) |
|
||||
(localsub << 8) |
|
||||
@ -80,7 +80,7 @@ static void destructure(DstCompiler *c, Dst left, DstSlot right,
|
||||
} else {
|
||||
DstSlot islot = dstc_cslot(dst_wrap_integer(i));
|
||||
int32_t locali = dstc_preread(c, ast, 0xFF, 2, islot);
|
||||
dstc_emit(c, ast,
|
||||
dstc_emit(c, ast,
|
||||
(locali << 24) |
|
||||
(localright << 16) |
|
||||
(localsub << 8) |
|
||||
@ -111,7 +111,7 @@ static void destructure(DstCompiler *c, Dst left, DstSlot right,
|
||||
localright = dstc_preread(c, ast, 0xFF, 1, right);
|
||||
localsub = dstc_lslotn(c, 0xFF, 3);
|
||||
int32_t localk = dstc_preread(c, ast, 0xFF, 2, kslot);
|
||||
dstc_emit(c, ast,
|
||||
dstc_emit(c, ast,
|
||||
(localk << 24) |
|
||||
(localright << 16) |
|
||||
(localsub << 8) |
|
||||
@ -211,7 +211,7 @@ static DstSlot namelocal(DstCompiler *c, DstAst *ast, Dst head, int32_t flags, D
|
||||
ret = localslot;
|
||||
}
|
||||
ret.flags |= flags;
|
||||
dstc_nameslot(c, dst_unwrap_symbol(head), ret);
|
||||
dstc_nameslot(c, dst_unwrap_symbol(head), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ static void defleaf(
|
||||
tableindex = dstc_preread(c, ast, 0xFF, 1, tabslot);
|
||||
valsymindex = dstc_preread(c, ast, 0xFF, 2, valsym);
|
||||
valueindex = dstc_preread(c, ast, 0xFF, 3, s);
|
||||
dstc_emit(c, ast,
|
||||
dstc_emit(c, ast,
|
||||
(valueindex << 24) |
|
||||
(valsymindex << 16) |
|
||||
(tableindex << 8) |
|
||||
@ -352,7 +352,7 @@ DstSlot dstc_if(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
}
|
||||
|
||||
/* Set target for compilation */
|
||||
target = (drop || tail)
|
||||
target = (drop || tail)
|
||||
? dstc_cslot(dst_wrap_nil())
|
||||
: dstc_gettarget(opts);
|
||||
|
||||
@ -366,7 +366,7 @@ DstSlot dstc_if(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
/* Condition left body */
|
||||
dstc_scope(c, 0);
|
||||
left = dstc_value(bodyopts, truebody);
|
||||
if (!drop && !tail) dstc_copy(c, ast, target, left);
|
||||
if (!drop && !tail) dstc_copy(c, ast, target, left);
|
||||
dstc_popscope(c);
|
||||
|
||||
/* Compile jump to done */
|
||||
@ -377,7 +377,7 @@ DstSlot dstc_if(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
labelr = dst_v_count(c->buffer);
|
||||
dstc_scope(c, 0);
|
||||
right = dstc_value(bodyopts, falsebody);
|
||||
if (!drop && !tail) dstc_copy(c, ast, target, right);
|
||||
if (!drop && !tail) dstc_copy(c, ast, target, right);
|
||||
dstc_popscope(c);
|
||||
|
||||
/* Write jumps - only add jump lengths if jump actually emitted */
|
||||
@ -584,7 +584,7 @@ DstSlot dstc_fn(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
dstc_freeslot(c, s);
|
||||
if (dstc_iserr(&opts)) return dstc_cslot(dst_wrap_nil());
|
||||
}
|
||||
|
||||
|
||||
/* Build function */
|
||||
def = dstc_pop_funcdef(c);
|
||||
def->arity = arity;
|
||||
@ -603,9 +603,9 @@ DstSlot dstc_fn(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
(defindex << 16) |
|
||||
(localslot << 8) |
|
||||
DOP_CLOSURE);
|
||||
|
||||
|
||||
if (ret.index != localslot) {
|
||||
dstc_emit(c, ast,
|
||||
dstc_emit(c, ast,
|
||||
(ret.index << 16) |
|
||||
(localslot << 8) |
|
||||
DOP_MOVE_FAR);
|
||||
@ -614,7 +614,7 @@ DstSlot dstc_fn(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Keep in lexographic order */
|
||||
/* Keep in lexicographic order */
|
||||
static const DstSpecial dstc_specials[] = {
|
||||
{":=", dstc_varset},
|
||||
{"ast-quote", dstc_astquote},
|
||||
|
Loading…
Reference in New Issue
Block a user