Commit 06ef8e3671800d584e62ab1ffd80180455a38302

Baptiste 2024-07-22T16:02:42

rework of frame_binding_new

diff --git a/libkc3/env.c b/libkc3/env.c
index e16b1f3..556a509 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -2037,20 +2037,18 @@ s_env * env_init_args (s_env *env, int *argc, char ***argv)
 
 s_env * env_init_globals (s_env *env)
 {
-  s_tag file_dir;
-  s_tag file_path;
+  s_tag *file_dir;
+  s_tag *file_path;
   if (! frame_init(&env->global_frame, NULL))
     return NULL;
-  file_dir.type = TAG_STR;
-  if (! file_pwd(&file_dir.data.str))
+  if (! (file_dir = frame_binding_new(&env->global_frame, &g_sym___DIR__)))
     return NULL;
-  if (! frame_binding_new(&env->global_frame, &g_sym___DIR__,
-                          &file_dir))
+  if (! (file_path = frame_binding_new(&env->global_frame, &g_sym___FILE__)))
     return NULL;
-  if (! tag_init_str_1(&file_path, NULL, "stdin"))
+  file_dir->type = TAG_STR;
+  if (! file_pwd(&file_dir->data.str))
     return NULL;
-  if (! frame_binding_new(&env->global_frame, &g_sym___FILE__,
-                          &file_path))
+  if (! tag_init_str_1(file_path, NULL, "stdin"))
     return NULL;
   return env;
 }
@@ -2100,7 +2098,7 @@ s_tag * env_let (s_env *env, const s_tag *tag, const s_block *block,
       assert(! "env_let: binding key is not a symbol");
       return NULL;
     }
-    if (! frame_binding_new(env->frame, map->key[i].data.sym,
+    if (! frame_binding_new_copy(env->frame, map->key[i].data.sym,
                             map->value + i)) {
       tag_clean(&tmp);
       return NULL;
diff --git a/libkc3/frame.c b/libkc3/frame.c
index 5703611..7da3b5f 100644
--- a/libkc3/frame.c
+++ b/libkc3/frame.c
@@ -17,14 +17,14 @@
 #include "list.h"
 #include "tag.h"
 
-s_frame * frame_binding_new (s_frame *frame, const s_sym *name)
+s_tag * frame_binding_new (s_frame *frame, const s_sym *name)
 {
   s_binding *b;
   b = binding_new(name, frame->bindings);
   if (! b)
     return NULL;
   frame->bindings = b;
-  return frame;
+  return &b->value;
 }
 
 s_frame * frame_binding_new_copy (s_frame *frame, const s_sym *name, const s_tag *value)
diff --git a/libkc3/frame.h b/libkc3/frame.h
index e652ac4..9702c0f 100644
--- a/libkc3/frame.h
+++ b/libkc3/frame.h
@@ -27,7 +27,7 @@ s_frame * frame_delete (s_frame *frame);
 void      frame_delete_all (s_frame *frame);
 
 /* Operators. */
-s_frame * frame_binding_new (s_frame *frame, const s_sym *name);
+s_tag *   frame_binding_new (s_frame *frame, const s_sym *name);
 s_frame * frame_binding_new_copy (s_frame *frame, const s_sym *name, const s_tag *value);
 s_frame * frame_binding_delete (s_frame *frame, const s_sym *name);
 s_tag *   frame_get_w (s_frame *frame, const s_sym *sym);