diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 4c15931..2ef1ee2 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -224,6 +224,56 @@ sw buf_inspect_array_size (const s_array *array)
return r;
}
+sw buf_inspect_block (s_buf *buf, const s_block *block)
+{
+ u64 i = 0;
+ sw r;
+ sw result = 0;
+ if ((r = buf_write_1(buf, "do\n ")) < 0)
+ return r;
+ result += r;
+ if (block->count) {
+ while (i < block->count - 1) {
+ if ((r = buf_inspect_tag(buf, block->tag + i)) < 0)
+ return r;
+ result += r;
+ if ((r = buf_write_1(buf, "\n ")) < 0)
+ return r;
+ result += r;
+ i++;
+ }
+ if ((r = buf_inspect_tag(buf, block->tag + i)) < 0)
+ return r;
+ result += r;
+ }
+ if ((r = buf_write_1(buf, "end")) < 0)
+ return r;
+ result += r;
+ return result;
+}
+
+sw buf_inspect_block_size (const s_block *block)
+{
+ u64 i = 0;
+ sw r;
+ sw result;
+ result = strlen("do\n ");
+ if (block->count) {
+ while (i < block->count - 1) {
+ if ((r = buf_inspect_tag_size(block->tag + i)) < 0)
+ return r;
+ result += r;
+ result += strlen("\n ");
+ i++;
+ }
+ if ((r = buf_inspect_tag_size(block->tag + i)) < 0)
+ return r;
+ result += r;
+ }
+ result += strlen("end");
+ return result;
+}
+
sw buf_inspect_bool (s_buf *buf, const bool *b)
{
if (*b)
diff --git a/libc3/env.c b/libc3/env.c
index 7c54d4d..c08372c 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -20,6 +20,7 @@
#include <unistd.h>
#include "array.h"
#include "binding.h"
+#include "block.h"
#include "buf.h"
#include "buf_file.h"
#include "buf_inspect.h"
@@ -163,6 +164,27 @@ bool env_eval_array_tag (s_env *env, const s_array *array, s_tag *dest)
dest->data.array = tmp;
return true;
}
+bool env_eval_block (s_env *env, const s_block *block, s_tag *dest)
+{
+ uw i = 0;
+ bool r;
+ s_tag tmp;
+ assert(env);
+ assert(block);
+ assert(dest);
+ if (! block->count) {
+ tag_init_void(dest);
+ return true;
+ }
+ while (i < block->count - 1) {
+ r = env_eval_tag(env, block->tag + i, &tmp);
+ tag_clean(&tmp);
+ if (! r)
+ return false;
+ i++;
+ }
+ return env_eval_tag(env, block->tag + i, dest);
+}
bool env_eval_call (s_env *env, const s_call *call, s_tag *dest)
{
@@ -456,13 +478,10 @@ bool env_eval_equal_tag (s_env *env, const s_tag *a, const s_tag *b,
dest->type = TAG_TUPLE;
return env_eval_equal_tuple(env, &a->data.tuple, &b->data.tuple,
&dest->data.tuple);
- case TAG_BLOCK:
- dest->type = TAG_BLOCK;
- return env_eval_equal_block(env, &a->data.block, &b->data.block,
- &dest->data.block);
case TAG_CALL:
case TAG_QUOTE:
case TAG_ARRAY:
+ case TAG_BLOCK:
case TAG_BOOL:
case TAG_CFN:
case TAG_CHARACTER:
@@ -709,6 +728,27 @@ bool env_eval_quote_array (s_env *env, const s_array *array,
return false;
}
+bool env_eval_quote_block (s_env *env, const s_block *block, s_tag *dest)
+{
+ uw i = 0;
+ s_block tmp;
+ assert(env);
+ assert(block);
+ assert(dest);
+ block_init(&tmp, block->count);
+ while (i < block->count) {
+ if (! env_eval_quote_tag(env, block->tag + i, tmp.tag + i))
+ goto ko;
+ i++;
+ }
+ dest->type = TAG_BLOCK;
+ dest->data.block = tmp;
+ return true;
+ ko:
+ block_clean(&tmp);
+ return false;
+}
+
bool env_eval_quote_call (s_env *env, const s_call *call, s_tag *dest)
{
const s_list *arg;