Commit 10a8b6fd3a0c8bc37fa0b0b70efffa0fc78d9abf

Thomas de Grivel 2024-02-09T20:29:24

wip block

diff --git a/.ic3_history b/.ic3_history
index 0c2d49b..97e3930 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,12 +1,3 @@
-1234567.0f
-1.234f
-%GL.Point2D{}
-GL.Point2D
-type(GL.Point2D)
-quote %GL.Point2D{}
-GL.Point2D{
-GL.Point2D{}
-GL.Point2D{}}
 GL.Point2D{}
 GL.Point2D
 {}
@@ -97,3 +88,12 @@ dlopen("../libc3/window/.libs/libc3_window_debug.so.0.0")
 dlopen("libc3/window/.libs/libc3_window_debug.dylib")
 dlopen("libc3/window/sdl2/.libs/libc3_window_sdl2_debug.dylib")
 quote %GL.Sphere{}
+do
+123
+456
+789
+end
+123/
+234
+123/123
+123/ 123
diff --git a/libc3/buf.c b/libc3/buf.c
index 96527d5..d0906cc 100644
--- a/libc3/buf.c
+++ b/libc3/buf.c
@@ -709,6 +709,26 @@ sw buf_read_str (s_buf *buf, const s_str *src)
   return r;
 }
 
+sw buf_read_sym (s_buf *buf, const s_sym *src)
+{
+  character c;
+  sw r;
+  s_buf_save save;
+  buf_save_init(buf, &save);
+  r = buf_read_str(buf, &src->str);
+  if (r > 0 &&
+      buf_peek_character_utf8(buf, &c) > 0 &&
+      ! sym_character_is_reserved(c))
+    goto restore;
+  goto clean;
+ restore:
+  r = 0;
+  buf_save_restore_rpos(buf, &save);
+ clean:
+  buf_save_clean(buf, &save);
+  return r;
+}
+
 sw buf_read_to_str (s_buf *buf, s_str *dest)
 {
   sw size;
diff --git a/libc3/buf.h b/libc3/buf.h
index 571efea..517c47d 100644
--- a/libc3/buf.h
+++ b/libc3/buf.h
@@ -73,6 +73,7 @@ sw      buf_read_s16 (s_buf *buf, s16 *p);
 sw      buf_read_s32 (s_buf *buf, s32 *p);
 sw      buf_read_s64 (s_buf *buf, s64 *p);
 sw      buf_read_str (s_buf *buf, const s_str *src);
+sw      buf_read_sym (s_buf *buf, const s_sym *src);
 sw      buf_read_to_str (s_buf *buf, s_str *dest);
 sw      buf_read_u8 (s_buf *buf, u8 *p);
 sw      buf_read_u16 (s_buf *buf, u16 *p);
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 2ef1ee2..c6b7094 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -257,6 +257,8 @@ sw buf_inspect_block_size (const s_block *block)
   u64 i = 0;
   sw r;
   sw result;
+  if (! block->count)
+    result = strlen("do end");
   result = strlen("do\n  ");
   if (block->count) {
     while (i < block->count - 1) {
@@ -270,7 +272,7 @@ sw buf_inspect_block_size (const s_block *block)
       return r;
     result += r;
   }
-  result += strlen("end");
+  result += strlen("\nend");
   return result;
 }
 
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 7c3f7c8..39d109e 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -411,7 +411,7 @@ sw buf_parse_block (s_buf *buf, s_block *block)
   assert(buf);
   assert(block);
   buf_save_init(buf, &save);
-  if ((r = buf_read_1(buf, "do")) <= 0)
+  if ((r = buf_read_sym(buf, &g_sym_do)) <= 0)
     goto clean;
   result += r;
   i = &list;
diff --git a/libc3/sym.c b/libc3/sym.c
index a1525ad..1f04492 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -60,6 +60,7 @@ const s_sym g_sym_Uw_brackets = {{{NULL},  4, {"Uw[]"}}};
 const s_sym g_sym_Var         = {{{NULL},  3, {"Var"}}};
 const s_sym g_sym_Void        = {{{NULL},  4, {"Void"}}};
 const s_sym g_sym_defstruct   = {{{NULL},  9, {"defstruct"}}};
+const s_sym g_sym_do          = {{{NULL},  2, {"do"}}};
 const s_sym g_sym_cast        = {{{NULL},  4, {"cast"}}};
 const s_sym g_sym_load_time   = {{{NULL},  9, {"load_time"}}};
 const s_sym g_sym_r           = {{{NULL},  1, {"r"}}};
@@ -295,6 +296,7 @@ void sym_init_g_sym (void)
   sym_intern(&g_sym_Void, NULL);
   sym_intern(&g_sym_cast, NULL);
   sym_intern(&g_sym_defstruct, NULL);
+  sym_intern(&g_sym_do, NULL);
   sym_intern(&g_sym_load_time, NULL);
   sym_intern(&g_sym_r, NULL);
   sym_intern(&g_sym_rw, NULL);
diff --git a/libc3/sym.h b/libc3/sym.h
index dadc02b..80684d6 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -73,6 +73,7 @@ extern const s_sym g_sym_Var;
 extern const s_sym g_sym_Void;
 extern const s_sym g_sym_cast;
 extern const s_sym g_sym_defstruct;
+extern const s_sym g_sym_do;
 extern const s_sym g_sym_load_time;
 extern const s_sym g_sym_r;
 extern const s_sym g_sym_rw;
diff --git a/test/ic3/block.in b/test/ic3/block.in
new file mode 100644
index 0000000..6ed5406
--- /dev/null
+++ b/test/ic3/block.in
@@ -0,0 +1,30 @@
+quote do
+  1
+end
+do
+  1
+end
+quote do
+  1
+  2
+end
+do
+  1
+  2
+end
+quote do
+  1
+  2
+  3
+end
+do
+  1
+  2
+  3
+end
+quote do 1; end
+do 1; end
+quote do 1; 2; end
+do 1; 2; end
+quote do 1; 2; 3; end
+do 1; 2; 3; end
diff --git a/test/ic3/block.out.expected b/test/ic3/block.out.expected
new file mode 100644
index 0000000..fc87f5e
--- /dev/null
+++ b/test/ic3/block.out.expected
@@ -0,0 +1,30 @@
+do
+  1
+end
+1
+do
+  1
+  2
+end
+2
+do
+  1
+  2
+  3
+end
+3
+do
+  1
+end
+1
+do
+  1
+  2
+end
+2
+do
+  1
+  2
+  3
+end
+3
diff --git a/test/ic3/block.ret.expected b/test/ic3/block.ret.expected
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/ic3/block.ret.expected
@@ -0,0 +1 @@
+0