Commit d3d90b72a9257fdc7f3a59efd31a63322755be2c

Thomas de Grivel 2024-04-24T13:13:57

new tests for def

diff --git a/.ic3_history b/.ic3_history
index 5d39a23..968cc94 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,9 +1,3 @@
-defmodule Plop do end
-quote Plop
-quote_cfn Plop
-(Sym) "Abc"
-defmodule Plop do end
-defmodule Plop do def a = 1 end
 quote_cfn Plop
 defmodule Plop do def a = 1 end
 Plop.a
@@ -97,3 +91,9 @@ List.reverse
 List.reverse([1, 2])
 def a = 1
 a
+module()
+defmodule Plop do
+  def m = fn () { module() }
+end
+Plop.m()
+module()
diff --git a/libc3/env.c b/libc3/env.c
index 61618b2..4f6b658 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -1972,6 +1972,15 @@ void env_longjmp (s_env *env, jmp_buf *jmp_buf)
   longjmp(*jmp_buf, 1);
 }
 
+const s_sym ** env_module (s_env *env, const s_sym **dest)
+{
+  assert(env);
+  assert(dest);
+  assert(env->current_defmodule);
+  *dest = env->current_defmodule;
+  return dest;
+}
+
 bool env_module_is_loading (s_env *env, const s_sym *module)
 {
   s_tag tag_module;
@@ -2114,16 +2123,6 @@ bool env_module_maybe_reload (s_env *env, const s_sym *module,
   return r;
 }
 
-const s_sym ** env_module (s_env *env, const s_sym **dest)
-{
-  assert(env);
-  assert(dest);
-  assert(env->search_modules);
-  assert(env->search_modules->tag.type == TAG_SYM);
-  *dest = env->search_modules->tag.data.sym;
-  return dest;
-}
-
 s_list * env_module_search_modules (s_env *env, const s_sym *module)
 {
   assert(env);
@@ -2326,6 +2325,16 @@ void env_push_unwind_protect (s_env *env,
   env->unwind_protect = unwind_protect;
 }
 
+s_list ** env_search_modules (s_env *env, s_list **dest)
+{
+  assert(env);
+  assert(dest);
+  assert(env->search_modules);
+  assert(env->search_modules->tag.type == TAG_SYM);
+  *dest = env->search_modules;
+  return dest;
+}
+
 bool env_sym_search_modules (s_env *env, const s_sym *sym,
                              const s_sym **dest)
 {
diff --git a/libc3/hash.c b/libc3/hash.c
index 8e92390..cbc914a 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -439,6 +439,7 @@ bool hash_update_sym (t_hash *hash, const s_sym * const *sym)
   char type[] = "sym";
   assert(hash);
   assert(sym);
+  assert(*sym);
   return hash_update(hash, type, sizeof(type)) &&
     hash_update_str(hash, &(*sym)->str);
 }
diff --git a/test/ic3/def.in b/test/ic3/def.in
index 39e95b5..ec97557 100644
--- a/test/ic3/def.in
+++ b/test/ic3/def.in
@@ -44,8 +44,8 @@ def reverse = fn {
   ([], acc) { acc }
   ([a | b], acc) { reverse(b, [a | acc]) }
 }
-quote C3.reverse
-C3.reverse
+quote reverse
+reverse
 quote reverse([1, 2, 3])
 reverse([1, 2, 3])
 quote def reverse = fn {
@@ -58,8 +58,8 @@ def reverse = fn {
   ([], acc) { [:reversed | acc] }
   ([a | b], acc) { reverse(b, [a | acc]) }
 }
-quote C3.reverse
-C3.reverse
+quote reverse
+reverse
 quote reverse([1, 2, 3])
 reverse([1, 2, 3])
 quote def reverse = fn {
@@ -72,7 +72,33 @@ def reverse = fn {
   ([], acc) { acc }
   ([a | b], acc) { reverse(b, [a | acc]) }
 }
-quote C3.reverse
-C3.reverse
+quote reverse
+reverse
 quote reverse([1, 2, 3])
 reverse([1, 2, 3])
+quote def reverse = fn (x) { List.reverse(x) }
+def reverse = fn (x) { List.reverse(x) }
+quote reverse
+reverse
+quote reverse([1, 2, 3])
+reverse([1, 2, 3])
+quote module()
+module()
+quote reverse
+reverse
+quote def reverse = fn (x) { [:reversed | List.reverse(x)] }
+def reverse = fn (x) { [:reversed | List.reverse(x)] }
+quote reverse
+reverse
+quote reverse([1, 2, 3])
+reverse([1, 2, 3])
+quote reverse
+reverse
+quote def reverse = fn (x) { List.reverse(x) }
+def reverse = fn (x) { List.reverse(x) }
+quote reverse
+reverse
+quote reverse([1, 2, 3])
+reverse([1, 2, 3])
+quote reverse
+reverse
diff --git a/test/ic3/def.out.expected b/test/ic3/def.out.expected
index 6997c75..80d0f7b 100644
--- a/test/ic3/def.out.expected
+++ b/test/ic3/def.out.expected
@@ -76,3 +76,29 @@ fn {
 }
 reverse([1, 2, 3])
 [3, 2, 1]
+def reverse = fn (x) { List.reverse(x) }
+reverse
+reverse
+fn (x) { List.reverse(x) }
+reverse([1, 2, 3])
+[3, 2, 1]
+module()
+C3
+reverse
+fn (x) { List.reverse(x) }
+def reverse = fn (x) { [:reversed | List.reverse(x)] }
+reverse
+reverse
+fn (x) { [:reversed | List.reverse(x)] }
+reverse([1, 2, 3])
+[:reversed, 3, 2, 1]
+reverse
+fn (x) { [:reversed | List.reverse(x)] }
+def reverse = fn (x) { List.reverse(x) }
+reverse
+reverse
+fn (x) { List.reverse(x) }
+reverse([1, 2, 3])
+[3, 2, 1]
+reverse
+fn (x) { List.reverse(x) }