diff --git a/doc/lbmref.dox b/doc/lbmref.dox
index 607209ad..b3f49027 100644
--- a/doc/lbmref.dox
+++ b/doc/lbmref.dox
@@ -825,12 +825,12 @@ Example that combines to lists.
ix
Index into a list using the ix
. the form of an ix
expression
-is (ix index-expr list-expr)
. Indexing starts from 0 and if you index out of bounds the result is nil.
+is (ix list-expr index-expr)
. Indexing starts from 0 and if you index out of bounds the result is nil.
\note
Example that evaluates to 2.
\code
-(ix 1 (list 1 2 3))
+(ix (list 1 2 3) 1)
\endcode
diff --git a/include/lbm_llama_ascii.h b/include/lbm_llama_ascii.h
new file mode 100644
index 00000000..41a97740
--- /dev/null
+++ b/include/lbm_llama_ascii.h
@@ -0,0 +1,110 @@
+unsigned char llama_ascii[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x27, 0x2c, 0x2c, 0x5e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x5e, 0x5f, 0x5f, 0x5f, 0x5f, 0x2b, 0x6c, 0x60,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x49, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0x5f, 0x5f, 0x49, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x5f,
+ 0x2d, 0x5f, 0x2b, 0x2b, 0x7e, 0x2d, 0x5f, 0x2c, 0x60, 0x60, 0x2e, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x60, 0x2c, 0x69, 0x5f, 0x5f, 0x2b, 0x2b, 0x7e, 0x7e, 0x3e, 0x5e,
+ 0x2e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x21, 0x21, 0x3c, 0x2b, 0x69, 0x3c,
+ 0x2b, 0x7e, 0x22, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x5f, 0x2d, 0x2b, 0x2b,
+ 0x5f, 0x5f, 0x2d, 0x5f, 0x7e, 0x2b, 0x3a, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x21,
+ 0x2b, 0x5f, 0x2b, 0x2b, 0x7e, 0x7e, 0x2b, 0x7e, 0x5f, 0x5f, 0x49, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x21, 0x5f, 0x2b, 0x7e, 0x2b, 0x7e, 0x5f, 0x2b, 0x2b, 0x2b, 0x5f,
+ 0x5f, 0x5f, 0x49, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0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0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x3a, 0x7e, 0x7e, 0x2b, 0x2b, 0x69, 0x2d, 0x5f, 0x5f,
+ 0x5f, 0x6c, 0x3e, 0x2b, 0x5f, 0x2b, 0x5f, 0x5f, 0x5f, 0x3c, 0x49, 0x5e,
+ 0x2e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2e, 0x3a, 0x22, 0x2e, 0x2c,
+ 0x6c, 0x49, 0x49, 0x22, 0x20, 0x20, 0x3a, 0x5e, 0x2c, 0x21, 0x3a, 0x60,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x27,
+ 0x27, 0x20, 0x60, 0x2e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x20, 0x2e,
+ 0x2e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x0a
+};
+unsigned int llama_ascii_len = 1275;
diff --git a/src/eval_cps.c b/src/eval_cps.c
index fbc0c733..39b578fa 100644
--- a/src/eval_cps.c
+++ b/src/eval_cps.c
@@ -1256,9 +1256,10 @@ static inline void eval_lambda(eval_context_t *ctx) {
static inline void eval_if(eval_context_t *ctx) {
- CHECK_STACK(lbm_push_u32_3(&ctx->K,
+ CHECK_STACK(lbm_push_u32_4(&ctx->K,
lbm_car(lbm_cdr(lbm_cdr(lbm_cdr(ctx->curr_exp)))), // Else branch
lbm_car(lbm_cdr(lbm_cdr(ctx->curr_exp))), // Then branch
+ ctx->curr_env,
lbm_enc_u(IF)));
ctx->curr_exp = lbm_car(lbm_cdr(ctx->curr_exp));
}
@@ -1859,15 +1860,19 @@ static inline void cont_bind_to_key_rest(eval_context_t *ctx) {
}
static inline void cont_if(eval_context_t *ctx) {
+
lbm_value then_branch;
lbm_value else_branch;
+ lbm_value env;
lbm_value arg = ctx->r;
- lbm_pop_u32_2(&ctx->K, &then_branch, &else_branch);
+ lbm_pop_u32_3(&ctx->K, &env, &then_branch, &else_branch);
if (lbm_type_of(arg) == LBM_VAL_TYPE_SYMBOL && lbm_dec_sym(arg) == SYM_TRUE) {
+ ctx->curr_env = env;
ctx->curr_exp = then_branch;
} else {
+ ctx->curr_env = env;
ctx->curr_exp = else_branch;
}
}
diff --git a/src/extensions/array_extensions.c b/src/extensions/array_extensions.c
index 1901ea95..41984d7f 100644
--- a/src/extensions/array_extensions.c
+++ b/src/extensions/array_extensions.c
@@ -774,14 +774,14 @@ lbm_value array_extension_buffer_length(lbm_value *args, lbm_uint argn) {
lbm_array_header_t *array = (lbm_array_header_t *)lbm_car(args[0]);
switch(array->elt_type) {
case LBM_VAL_TYPE_CHAR: /* Same as byte */
- res = lbm_enc_i(array->size);
+ res = lbm_enc_i((lbm_int)array->size);
break;
case LBM_VAL_TYPE_I: /* fall through */
case LBM_VAL_TYPE_U:
case LBM_PTR_TYPE_BOXED_I:
case LBM_PTR_TYPE_BOXED_U:
case LBM_PTR_TYPE_BOXED_F:
- res = lbm_enc_i(array->size * 4);
+ res = lbm_enc_i((lbm_int)array->size * 4);
break;
}
}
diff --git a/tests/test_heap_alloc.c b/tests/test_heap_alloc.c
index f57841f2..3d7a7ac1 100644
--- a/tests/test_heap_alloc.c
+++ b/tests/test_heap_alloc.c
@@ -40,7 +40,7 @@ int main(int argc, char **argv) {
printf("Initialized heap: OK\n");
- for (int i = 0; i < heap_size; i ++) {
+ for (unsigned int i = 0; i < heap_size; i ++) {
cell = lbm_heap_allocate_cell(LBM_PTR_TYPE_CONS);
if (!lbm_is_ptr(cell)) {
printf("Error allocating cell %d\n", i);
diff --git a/tests/test_if_2.lisp b/tests/test_if_2.lisp
new file mode 100644
index 00000000..1d9686e5
--- /dev/null
+++ b/tests/test_if_2.lisp
@@ -0,0 +1,7 @@
+
+(define test (lambda (f x)
+ (if (f x)
+ x
+ (test f (- x 1)))))
+
+(= (test (lambda (x) (< x 0)) 2) -1)