}
-Sexpr* load_into_env(Sexpr* env) {
+Sexpr* load_env(Sexpr* env) {
Sexpr* newenv = load_core_env(env);
return newenv;
}
#include "builtins/core.h"
-#define _HIIIII
-
Sexpr* dispatch(Sexpr* b, Sexpr* env);
-
uint64_t u64_get_num_args(Sexpr* b);
+Sexpr* load_env(Sexpr* env);
#endif
#include "core.h"
#include <inttypes.h>
+#include <stdlib.h>
Sexpr* c_quote(Sexpr* b, Sexpr* env) {
if(CORE_QUOTE_ARGS != u64_get_num_args(b))
}
+Sexpr* c_def(Sexpr* b, Sexpr* env) {
+ if(CORE_ATOM_ARGS != u64_get_num_args(b))
+ return b;
+ Sexpr* args = b->value.b.args;
+ Sexpr* val = eval(car(cdr(args)), env);
+ append_to_dict(env, car(args), cdr(args));
+ return val;
+}
+Sexpr* c_exit(Sexpr* b, Sexpr* env) {
+ if(CORE_EXIT_ARGS != u64_get_num_args(b))
+ return b;
+ Sexpr* args = b->value.b.args;
+ uint64_t value = car(args)->value.u;
+ exit(value);
+ return NULL;
+}
+
Sexpr* x_core_dispatch(Sexpr* b, Sexpr* env) {
uint64_t code = b->value.b.opcode & 0xff;
return c_not(b, env);
case CORE_ATOM:
return c_atom(b, env);
+ case CORE_DEF:
+ return c_def(b, env);
default:
return from_nil();
}
append_to_dict(env, from_sym("not"), c_not);
Sexpr* c_atom = from_opcode(CORE_ATOM);
append_to_dict(env, from_sym("atom"), c_atom);
+ Sexpr* c_def = from_opcode(CORE_DEF);
+ append_to_dict(env, from_sym("def"), c_def);
return env;
}
#define CORE_ATOM 0x07
#define CORE_ATOM_ARGS 1
+#define CORE_DEF 0xfe // huh do i want this so close to exit?
+#define CORE_DEF_ARGS 2
+#define CORE_EXIT 0xff
+#define CORE_EXIT_ARGS 1
Sexpr* x_core_dispatch(Sexpr* s, Sexpr* env);
Sexpr* load_core_env(Sexpr* env);
#include <stdio.h>
+
+// IMMENSE WARNING: as of now this is the only place where any sort of variable is modified in place.. that may come to pass more later, but beware
+
// okay, doing an incredibly /incredibly/ naive dict implementation for now,
// proper hash tables come later
// wait, this naive method can totally just be done in sexprs that I already have
+
+// great redo: have it in a cons cell, so I can modify it without having to return anything
+
Sexpr* init_dict() {
- return from_nil();
+ return cons(from_nil(), from_nil());
}
Sexpr* append_to_dict(Sexpr* dict, Sexpr* key, Sexpr* value) {
// assumes dict well-formed, returns new dict
// puts new things on the front of the dict, makes it so looking up gets the newest stuff first
Sexpr* new = cons(key, value);
- return cons(new, dict);
+ Sexpr* head = cons(new, car(dict));
+ dict->value.c->car = head;
+ //return cons(new, dict);
+ return dict;
}
Sexpr* lookup(Sexpr* dict, Sexpr* key) {
// assumes dict well-formed
// returns nil if not found, returns (result) if it is
- Sexpr* node = dict;
+ Sexpr* node = car(dict);
while(node->type != NIL) {
if(equal(key, car(car(node)))->type == T) {
return cons(cdr(car(node)), from_nil());
#include "types.h"
-
Sexpr* tokenize(char* s);
Sexpr* cons_parse(Sexpr* tokens);
Sexpr* vals_parse(Sexpr* tokens);
#include "types.h"
#include "eval.h"
#include "dict.h"
+#include "parser.h"
+#include "builtins.h"
}
int main(int argc, char** argv) {
- printf("makefile functional\n");
+ printf("makefile functional lol\n");
+
+ Sexpr* env = init_dict();
+ load_env(env);
+ // now do the loop, right?
+ char* input = NULL;
+
return 0;
}
#include "types.h"
-
Sexpr* from_nil();
-
Sexpr* from_t();
-
Sexpr* from_sym(char* s);
-
Sexpr* from_uint(uint64_t u);
-
Sexpr* from_opcode(uint64_t u);
Sexpr* cons(Sexpr* car, Sexpr* cdr);
-
Sexpr* car(Sexpr* s);
-
Sexpr* cdr(Sexpr* s);
-
Sexpr* reverse(Sexpr* s);
-
Sexpr* equal(Sexpr* a, Sexpr* b);
-
char* sprint_sexpr(Sexpr* s);
#endif
void run_tests(){
- //test_basics();
- //test2();
- //test_parsing();
- //test_parser();
- //test_eq();
+ test_basics();
+ test2();
+ test_parsing();
+ test_parser();
+ test_eq();
test_dict();
}
// here is where i define the most relevant types for this project
-
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>