CE allocate tokens with arena
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m10s

This commit is contained in:
2026-02-25 18:27:51 +01:00
parent f846edf0ff
commit 961bf54ec1
3 changed files with 9 additions and 11 deletions

18
ce/ce.c
View File

@@ -1,3 +1,4 @@
#include <arena.h>
#include <desc.h>
#include <liballoc.h>
#include <list.h>
@@ -27,13 +28,15 @@ static int e_pgid;
static bool run = true;
static struct arena arena;
static void putch (char ch) { mail_send (e_pgid, &ch, 1); }
void putchar_ (char ch) { putch (ch); }
static bool tokenize_line (void* ctx, const char* start, size_t len) {
struct list_node_link** head = ctx;
struct token* token = malloc (sizeof (*token));
struct token* token = arena_malloc (&arena, sizeof (*token));
if (token == NULL)
return false;
@@ -46,15 +49,6 @@ static bool tokenize_line (void* ctx, const char* start, size_t len) {
return true;
}
static void free_tokens (struct list_node_link* tokens) {
struct list_node_link *token_link, *token_tmp_link;
list_foreach (tokens, token_link, token_tmp_link) {
struct token* token = list_entry (token_link, struct token, tokens_link);
list_remove (tokens, &token->tokens_link);
free (token);
}
}
static void cmd_echo (struct list_node_link* tokens) {
struct list_node_link *token_link, *token_tmp_link;
list_foreach (tokens, token_link, token_tmp_link) {
@@ -190,7 +184,7 @@ static void exec_line (const char* line) {
if (tokens != NULL)
exec_tokens (tokens);
free_tokens (tokens);
arena_reset (&arena);
}
void app_main (void) {
@@ -223,4 +217,6 @@ void app_main (void) {
line_cursor = 0;
memset (line_buffer, 0, sizeof (line_buffer));
}
arena_destroy (&arena);
}