summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-30 23:45:52 +0100
committerubq323 <ubq323@ubq323.website>2024-06-30 23:45:52 +0100
commit61ff477d139e8a93b635993cd8b8725a2957ce1b (patch)
tree5ff35389d6511209648c8d6123e5f23cc5c35485
parent567f2ebc2d467b5fc6fdff36c1c7c276fb80adf1 (diff)
add doc.txt
-rw-r--r--com.c7
-rw-r--r--doc.txt47
2 files changed, 48 insertions, 6 deletions
diff --git a/com.c b/com.c
index 4b65ca3..310117a 100644
--- a/com.c
+++ b/com.c
@@ -499,10 +499,7 @@ static void compile_node(Compiler *C, AstNode a, int flags) {
} else {
// function call
// (f a b c )
- if (l.len > 255) {
- fprintf(stderr, "can't have more than 255 args in a function call\n");
- exit(1);
- }
+ CHECK(l.len < 256, "max 255 args in a function call");
for (int i = 0; i < l.len; i++) {
compile_node(C, l.vals[i], 0);
}
@@ -588,5 +585,3 @@ int main(int argc, char **argv) {
return runvm(S);
}
-#undef CHECK
-#undef ER
diff --git a/doc.txt b/doc.txt
new file mode 100644
index 0000000..a653e5f
--- /dev/null
+++ b/doc.txt
@@ -0,0 +1,47 @@
+# types
+ nil: nil. it's always nil
+ bool: true, false.
+ num: 1234. -123.56. 64bit floating point number
+ cfunc: pointer to native c function
+ func: badthing function
+ arr: [ 10 20 30 ] array of badthing values
+ array indexing is the same as function calling: (a 1) -> 20
+ string: "hii".
+ strings are interned: two strings are the same object in memory
+ iff their contents are the same
+
+# variables
+ let, def, fn introduce new locals
+ locals are lexically scoped, and scopes can be nested
+ closures and upvalues will work soon
+ if a local is not found with a given name, the name is instead
+ resolved as a global. this behaviour might change because it's not very good.
+
+# builtin forms
+ arithmetic: + - * / % (+ 1 2)
+ equality: (= (+ 2 2) 4)
+ comparison: (< 0 1). ">" omitted deliberately.
+ let: unremarkable. (let (a 100 b 200) (+ a b))
+ set: mutates values. (set x 10)
+ arrays: (set (a 1) 20) sets index 1 of a
+ setting 1 past the end of an array will append
+ if: (if cond true-expr false-expr)
+ while: (while cond body...) returns nil
+ do: (do body...) returns value of last expr in body
+ def: (def foo 123) creates new local. only allowed at top level of a body
+ fn: (fn (arg0 arg1 arg2) body...) anonymous. for now.
+
+# builtin functions
+ (clock): clock(3)
+ (say x): print representation of x, followed by newline
+ (write x): print representation of x, with no newline
+ (arr): create new empty array
+ (append a x): appends to array a
+ (len a): get length of array a
+
+# cmdline args
+ bth [-Dl] [-Dt] filenames...
+ -Dl: print bytecode listing before execution
+ -Dt: trace each executed bytecode instruction
+ filename "-" can be provided to mean stdin.
+