aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-10 21:50:03 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-10 21:50:03 -0800
commit8569af05d8111654f1839f1cf50175a32b0bc547 (patch)
tree4f1aa81f60a16d0ba1d8edfb0f04e945514b54c2 /src
parent4ada155b930cb5fb96493dff3a5af8809da3b214 (diff)
add shit
Diffstat (limited to 'src')
-rw-r--r--src/builtins.c3
-rw-r--r--src/main.c12
-rw-r--r--src/stem.c4
3 files changed, 12 insertions, 7 deletions
diff --git a/src/builtins.c b/src/builtins.c
index eb4b521..5c42516 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -8,6 +8,7 @@
#include <string.h>
#include <unistd.h>
+/* macros taken from stackoverflow */
#define MAX 1000
#define JUSTDO(a) \
if (!(a)) { \
@@ -18,7 +19,6 @@
extern array_t *STACK;
extern array_t *EVAL_STACK;
extern ht_t *WORD_TABLE;
-extern char *INBUF;
extern parser_t *PARSER;
extern ht_t *FLIT;
@@ -28,6 +28,7 @@ extern ht_t *OBJ_TABLE;
* (for quotes), split (split array, string, word into two), del (deleting
* entries from quotes, strings, words) */
+/* taken from stackoverflow */
char *get_line(FILE *f) {
int len = MAX;
char buf[MAX], *e = NULL, *ret;
diff --git a/src/main.c b/src/main.c
index 3b1f53f..884a198 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,9 +7,7 @@
#include <unistd.h>
extern ht_t *WORD_TABLE;
-
extern array_t *STACK;
-extern char *INBUF;
extern parser_t *PARSER;
extern array_t *EVAL_STACK;
extern ht_t *OBJ_TABLE;
@@ -29,7 +27,9 @@ void version() {
int main(int argc, char **argv) {
value_t *v;
size_t len;
+ char *buf;
+ /* Parsing arguments */
if (argc < 2) {
usage();
}
@@ -40,16 +40,18 @@ int main(int argc, char **argv) {
version();
}
+ /* Read code from file */
FILE *FP = fopen(argv[1], "rb");
if (!FP) {
usage();
}
- ssize_t bytes_read = getdelim(&INBUF, &len, '\0', FP);
+ ssize_t bytes_read = getdelim(&buf, &len, '\0', FP);
fclose(FP);
- PARSER = parser_pp(INBUF);
+ /* Set up global variables */
+ PARSER = parser_pp(buf);
STACK = init_array(10);
WORD_TABLE = init_ht(500);
EVAL_STACK = init_array(10);
@@ -58,6 +60,7 @@ int main(int argc, char **argv) {
add_funcs();
+ /* parse and eval loop */
while (1) {
v = parser_get_next(PARSER);
if (v == NULL)
@@ -65,6 +68,7 @@ int main(int argc, char **argv) {
eval(v);
}
+ /* Free all global variables */
free(PARSER->source);
ht_free(WORD_TABLE, value_free);
ht_free(FLIT, func_free);
diff --git a/src/stem.c b/src/stem.c
index b9e0a16..1bea532 100644
--- a/src/stem.c
+++ b/src/stem.c
@@ -7,10 +7,10 @@
#include <stem.h>
#include <string.h>
+/* Global variables defined */
array_t *STACK;
array_t *EVAL_STACK;
ht_t *WORD_TABLE;
-char *INBUF;
parser_t *PARSER;
ht_t *FLIT;
@@ -165,7 +165,7 @@ parser_t *parser_pp(char *s) {
parser_t *p = init_parser(s);
string_t *rstr = init_string(NULL);
while (p->c != '\0') {
- if (p->c == '#') {
+ if (p->c == '#') { /* Comment character is # in stem */
while (p->c != '\n' && p->c != '\0') {
parser_move(p);
}