aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormryouse2023-06-07 21:42:54 -0400
committermryouse2023-06-07 21:42:54 -0400
commit730a6d777530a33fbb8df86df8b16d842b12c283 (patch)
tree1a5b7c8a200c0b2e9568feece006be6f34b0f807
parentd30e4695f7390c56e2f87dfe76fa4e681eaeb082 (diff)
initial commit of the start of the core library
-rw-r--r--core.neb21
-rw-r--r--main.d21
2 files changed, 30 insertions, 12 deletions
diff --git a/core.neb b/core.neb
new file mode 100644
index 0000000..62e1069
--- /dev/null
+++ b/core.neb
@@ -0,0 +1,21 @@
+; math
+(func ++ (num) (+ num 1))
+(func -- (num) (- num 1))
+
+; strings
+(func join (lst joiner)
+ ; TODO this doesn't handle empty lists
+ (concat
+ (reduce
+ (lambda (acc x)
+ (concat acc x joiner))
+ (most lst)
+ "")
+ (last lst)))
+
+; lists
+(func slice (lst idx)
+ ; TODO doesn't handle lengths
+ (if (eq? 1 idx)
+ lst
+ (slice (rest lst) (- idx 1))))
diff --git a/main.d b/main.d
index 7006a52..57a6dbc 100644
--- a/main.d
+++ b/main.d
@@ -24,6 +24,7 @@ import vm;
void repl() {
REPL = true;
VM vm = new VM();
+ interpret(getCore(), vm);
while(true) {
write("> ");
@@ -33,17 +34,6 @@ void repl() {
continue;
}
- /*
- Parser parser = new Parser(input);
-
- Compiler compiler = new Compiler(ObjType.SCRIPT, &parser);
- Function func = compiler.compile();
- */
-
- /*
- VM vm = new VM(func);
- vm.run();
- */
interpret(input, vm);
}
}
@@ -60,6 +50,10 @@ string readFile(string fname) {
return to!string(ret);
}
+string getCore() {
+ return readFile("core.neb");
+}
+
int main(string[] args) {
if (args.length <= 1) {
repl();
@@ -71,9 +65,12 @@ int main(string[] args) {
return 1;
}
+ VM vm = new VM();
+ interpret(getCore(), vm);
+
string data = readFile(fname);
- interpret(data, new VM());
+ interpret(data, vm);
}
return 0;
}