Commit 8a7abc20bed4da258ec66590ae43297c5eec2c58

Thomas de Grivel 2024-12-04T10:38:39

wip threads, httpd

diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index e1ec192..79653b1 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -118,16 +118,22 @@ defmodule HTTPd do
     end
   }
 
+  def enable_threads = true
+
   def server = fn (host, port) {
     def socket = Socket.listen(host, port)
     if socket do
       daemonize()
       puts("KC3 HTTPd: listening on #{host}:#{port}")
       load_app()
-      threads = List.map(List.count(1), fn (x) {
-        Thread.new(HTTPd.server_thread)
-      })
-      List.map(threads, Thread.delete)
+      if enable_threads do
+        threads = List.map(List.count(8), fn (x) {
+          Thread.new(HTTPd.server_thread)
+        })
+        List.map(threads, Thread.delete)
+      else
+        HTTPd.server_thread()
+      end
       0
     else
       puts("KC3 HTTPd: cannot listen on #{host}:#{port}")
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 36c08df..c74f641 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -4025,7 +4025,7 @@ sw buf_parse_tag_ident (s_buf *buf, s_tag *dest)
   r = buf_parse_ident(buf, &dest->data.ident);
   if (r > 0) {
     if (! dest->data.ident.module &&
-        (tag = frame_get_w(&g_kc3_env->read_time_frame,
+        (tag = frame_get_w(g_kc3_env->read_time_frame,
                            dest->data.ident.sym)))
       tag_init_copy(dest, tag);
     else
diff --git a/libkc3/env.c b/libkc3/env.c
index fb26ad4..a2ade3e 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -251,7 +251,7 @@ void env_clean (s_env *env)
 void env_clean_globals (s_env *env)
 {
   frame_delete(env->global_frame);
-  frame_clean(&env->read_time_frame);
+  frame_delete(env->read_time_frame);
 }
 
 void env_clean_toplevel (s_env *env)
@@ -2761,7 +2761,7 @@ s_env * env_init_copy (s_env *env, s_env *src)
   tmp.out = src->out;
   tmp.path = src->path;
   tmp.quote_level = src->quote_level;
-  if (! frame_init(&tmp.read_time_frame, NULL, NULL))
+  if (! (tmp.read_time_frame = frame_new(NULL, NULL)))
     return NULL;
   tmp.search_modules = src->search_modules_default;
   tmp.search_modules_default = src->search_modules_default;
@@ -2776,12 +2776,12 @@ s_env * env_init_globals (s_env *env)
 {
   s_tag *file_dir;
   s_tag *file_path;
-  if (! frame_init(&env->read_time_frame, NULL, NULL))
+  if (! (env->read_time_frame = frame_new(NULL, NULL)))
     return NULL;
-  if (! (file_dir = frame_binding_new(&env->read_time_frame,
+  if (! (file_dir = frame_binding_new(env->read_time_frame,
                                       &g_sym___DIR__)))
     return NULL;
-  if (! (file_path = frame_binding_new(&env->read_time_frame,
+  if (! (file_path = frame_binding_new(env->read_time_frame,
                                        &g_sym___FILE__)))
     return NULL;
   file_dir->type = TAG_STR;
@@ -2789,7 +2789,7 @@ s_env * env_init_globals (s_env *env)
     return NULL;
   if (! tag_init_str_1(file_path, NULL, "stdin"))
     return NULL;
-  if (! (env->global_frame = frame_new(&env->read_time_frame, NULL)))
+  if (! (env->global_frame = frame_new(env->read_time_frame, NULL)))
     return NULL;
   return env;
 }
diff --git a/libkc3/types.h b/libkc3/types.h
index 7ff711e..1828a78 100644
--- a/libkc3/types.h
+++ b/libkc3/types.h
@@ -758,7 +758,7 @@ struct env {
   s_buf            *out;
   s_list           *path;
   uw                quote_level;
-  s_frame           read_time_frame;
+  s_frame          *read_time_frame;
   s_list           *search_modules;
   s_list           *search_modules_default;
   bool              trace;
diff --git a/test/httpd/app/controllers/doc_controller.kc3 b/test/httpd/app/controllers/doc_controller.kc3
index 115167f..b58a201 100644
--- a/test/httpd/app/controllers/doc_controller.kc3
+++ b/test/httpd/app/controllers/doc_controller.kc3
@@ -63,9 +63,10 @@ defmodule DocController do
     index = doc_index("./doc/", path_html)
     menu = DocView.render_menu(index)
     title = "kc3-lang.org"
-    slug = Str.slice(name, 0, -9)
+    slug = Str.slice(path_html, 0, -9)
     slug = Str.subst(slug, " ", "-")
     slug = Str.subst(slug, ".", "-")
+    slug = Str.subst(slug, "/", "-")
     html = File.read_all(path_html)
     page = DocView.render_show(menu, html)
     body = LayoutView.render(slug, title, page, url)
diff --git a/test/httpd/app/controllers/fx_controller.kc3 b/test/httpd/app/controllers/fx_controller.kc3
deleted file mode 120000
index f2ff19b..0000000
--- a/test/httpd/app/controllers/fx_controller.kc3
+++ /dev/null
@@ -1 +0,0 @@
-../../../../httpd/fx/app/controllers/fx_controller.kc3
\ No newline at end of file
diff --git a/test/httpd/app/models/fx.kc3 b/test/httpd/app/models/fx.kc3
deleted file mode 120000
index 7c15dc8..0000000
--- a/test/httpd/app/models/fx.kc3
+++ /dev/null
@@ -1 +0,0 @@
-../../../../httpd/fx/app/models/fx.kc3
\ No newline at end of file
diff --git a/test/httpd/app/views/fx_view.kc3 b/test/httpd/app/views/fx_view.kc3
deleted file mode 120000
index ef77bc7..0000000
--- a/test/httpd/app/views/fx_view.kc3
+++ /dev/null
@@ -1 +0,0 @@
-../../../../httpd/fx/app/views/fx_view.kc3
\ No newline at end of file
diff --git a/test/httpd/config/routes.kc3 b/test/httpd/config/routes.kc3
index 66967be..4284363 100644
--- a/test/httpd/config/routes.kc3
+++ b/test/httpd/config/routes.kc3
@@ -9,4 +9,4 @@ def_route("/doc/", DocController.route)
 
 def_route("/", PageController.route)
 
-def_static_route("", "./static/", 0)
+HTTPd.Route.def_static_route("", "./static/", 0)