CE allocate tokens with arena
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m10s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m10s
This commit is contained in:
@@ -3,6 +3,7 @@ include ../make/ufuncs.mk
|
||||
$(eval $(call add_lib,libstring))
|
||||
$(eval $(call add_lib,libprocess))
|
||||
$(eval $(call add_lib,libaux))
|
||||
$(eval $(call add_lib,libarena))
|
||||
$(eval $(call add_include,libterminal))
|
||||
|
||||
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
||||
|
||||
18
ce/ce.c
18
ce/ce.c
@@ -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);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _LIBARENA_ARENA_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define ARENA_CHUNK_CAPACITY (8 * 1024)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user