-#include <libc.h>
-
+#include <stdio.h>
/* Main
*****************************************************************************/
-void main(int argc, char** argv) {
+int main(int argc, char** argv) {
extern void world_init(void);
extern void exec_file(FILE* file, const char* prompt);
world_init();
exec_file(stdin, ":> ");
(void)argc;
(void)argv;
+ return 0;
}
@file parser.c
*/
//#include "parser.h"
-
-#include <libc.h>
-#include <data/slist.h>
+#include "slist.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdint.h>
#define UNKNOWN 0
#define SYMBOL 1
#define KEYWORD_MSG 107
#define SELECTOR 108
+#ifndef container_of
+#define container_of(obj, type, member) \
+ (type*)((uintptr_t)obj - offsetof(type, member))
+#endif
+
/* Table of Contents
*****************************************************************************/
// Types
buf->string[buf->index] = '\0';
}
-//static void strbuf_print(strbuf_t* buf, const char* str)
-//{
-// while(*str)
-// strbuf_putc(buf, *str++);
-//}
-
static char* strbuf_string(strbuf_t* buf)
{
char* str = buf->string;
--- /dev/null
+#include "slist.h"
+
+void slist_init(slist_t* list)
+{
+ list->head = NULL;
+}
+
+bool slist_empty(slist_t* list)
+{
+ return (list->head == NULL);
+}
+
+size_t slist_size(slist_t* list)
+{
+ size_t sz = 0;
+ slist_node_t* node = list->head;
+ while (node != NULL) {
+ sz++;
+ node = node->next;
+ }
+ return sz;
+}
+
+slist_node_t* slist_front(slist_t* list)
+{
+ return list->head;
+}
+
+void slist_push_front(slist_t* list, slist_node_t* node)
+{
+ node->next = list->head;
+ list->head = node;
+}
+
+slist_node_t* slist_pop_front(slist_t* list)
+{
+ slist_node_t* node = list->head;
+ list->head = node->next;
+ node->next = NULL;
+ return node;
+}
+
+slist_node_t* slist_back(slist_t* list)
+{
+ slist_node_t* node = list->head;
+ while (node && node->next != NULL)
+ node = node->next;
+ return (node) ? node : NULL;
+}
+
+void slist_push_back(slist_t* list, slist_node_t* node)
+{
+ slist_node_t* back = slist_back(list);
+ if (NULL != back)
+ back->next = node;
+ else
+ list->head = node;
+ node->next = NULL;
+}
+
+slist_node_t* slist_pop_back(slist_t* list)
+{
+ slist_node_t* prev = NULL;
+ slist_node_t* curr = list->head;
+ while (curr && curr->next != NULL) {
+ prev = curr;
+ curr = curr->next;
+ }
+ if (prev != NULL)
+ prev->next = NULL;
+ if (list->head == curr)
+ list->head = NULL;
+ return curr;
+}
+
+bool slist_node_has_next(slist_node_t* node)
+{
+ return (node->next != NULL);
+}
+
+slist_node_t* slist_node_next(slist_node_t* node)
+{
+ return node->next;
+}
+
--- /dev/null
+/**
+ @file slist.h
+*/
+#ifndef SLIST_H
+#define SLIST_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+typedef struct slist_node_t {
+ struct slist_node_t* next;
+} slist_node_t;
+
+typedef struct {
+ slist_node_t* head;
+} slist_t;
+
+void slist_init(slist_t* list);
+
+bool slist_empty(slist_t* list);
+
+size_t slist_size(slist_t* list);
+
+slist_node_t* slist_front(slist_t* list);
+
+void slist_push_front(slist_t* list, slist_node_t* node);
+
+slist_node_t* slist_pop_front(slist_t* list);
+
+slist_node_t* slist_back(slist_t* list);
+
+void slist_push_back(slist_t* list, slist_node_t* node);
+
+slist_node_t* slist_pop_back(slist_t* list);
+
+bool slist_node_has_next(slist_node_t* node);
+
+slist_node_t* slist_node_next(slist_node_t* node);
+
+#define slist_foreach(elem, list) \
+ for(slist_node_t* elem = slist_front(list); elem != NULL; elem = elem->next)
+
+#endif /* SLIST_H */