summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2025-04-10 05:21:21 +0000
committerLinnnus <[email protected]>2025-04-15 00:55:08 +0000
commitbdbb94b63785d03d12b2225222ee34108d896668 (patch)
treef4e7d779db6264ddcc15b9ef9cb0995f15dfadae /src/core
parent7bd2461c849b4626653a4744427c904b87354bd7 (diff)
feat(cli): More CLI stuff, idk
Diffstat (limited to 'src/core')
-rw-r--r--src/core/interpret.c19
-rw-r--r--src/core/interpret.h20
-rw-r--r--src/core/state.c11
-rw-r--r--src/core/state.h25
4 files changed, 75 insertions, 0 deletions
diff --git a/src/core/interpret.c b/src/core/interpret.c
new file mode 100644
index 0000000..bbb238c
--- /dev/null
+++ b/src/core/interpret.c
@@ -0,0 +1,19 @@
+#include "interpret.h"
+#include "tokenizer.h"
+
+#include <stdbool.h>
+
+SandInterpretResult sand_interpret(SandState *S, const char *filename, const char *source, size_t source_length) {
+ SandTokenizer tokenizer = sand_create_tokenizer(source, source_length, filename);
+
+ while (true) {
+ SandToken token = sand_get_next_token(&tokenizer);
+ sand_print_location(stdout, &token.location);
+ printf(": %s \"%.*s\"\n", sand_token_kind_to_string(token.kind), (int)token.content_length, token.content);
+ if (token.kind == SAND_TOKEN_EOF) {
+ break;
+ }
+ }
+
+ return SAND_INTERPRET_OK;
+}
diff --git a/src/core/interpret.h b/src/core/interpret.h
new file mode 100644
index 0000000..8bdc92f
--- /dev/null
+++ b/src/core/interpret.h
@@ -0,0 +1,20 @@
+#ifndef SAND_INTERPRET_H
+#define SAND_INTERPRET_H
+
+// This module defines a single function which composes all the stuff the
+// interpreter does. It should be bascially the only function that an embedder
+// needs to know.
+
+#include "state.h"
+
+#include <stddef.h>
+
+typedef enum {
+ SAND_INTERPRET_OK,
+ SAND_INTERPRET_COMPILE_ERROR,
+ SAND_INTERPRET_RUNTIME_ERROR,
+} SandInterpretResult;
+
+SandInterpretResult sand_interpret(SandState *, const char *filename, const char *source, size_t source_length);
+
+#endif
diff --git a/src/core/state.c b/src/core/state.c
new file mode 100644
index 0000000..91bd9e4
--- /dev/null
+++ b/src/core/state.c
@@ -0,0 +1,11 @@
+#include "state.h"
+
+SandState sand_create_state(SandConfig config) {
+ return (SandState) {
+ .config = config,
+ };
+}
+
+void sand_destroy_state(SandState *S) {
+ (void) S;
+}
diff --git a/src/core/state.h b/src/core/state.h
new file mode 100644
index 0000000..406a79c
--- /dev/null
+++ b/src/core/state.h
@@ -0,0 +1,25 @@
+#ifndef SAND_STATE_H
+#define SAND_STATE_H
+
+// This module defines the evaluator state. This is the "world" in Sand.
+// Multiple evaluator states can coexist as they are totally separate.
+
+#include <stddef.h>
+
+typedef void (* SandPrintHandler)(const char *message, size_t length);
+
+typedef struct {
+ SandPrintHandler print_handler;
+} SandConfig;
+
+// This data structure should be treated as entirely opaque by consuming code.
+typedef struct {
+ SandConfig config;
+} SandState;
+
+
+SandState sand_create_state(SandConfig config);
+
+void sand_destroy_state(SandState *);
+
+#endif