summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-08-10 23:05:24 -0400
committerWormHeamer2025-08-10 23:05:24 -0400
commit866d14b5150c356718916fe8b7cfac45aea283ce (patch)
tree955d069c8ff671a9d0c6de5f1e8ea8ec8de591c5
parent60aadb12969755727709bf293e140ef9d8301d43 (diff)
remove some debug printfs
-rw-r--r--doc/types.txt67
-rw-r--r--main.c3
-rw-r--r--peephole.c3
-rw-r--r--test.lang23
4 files changed, 80 insertions, 16 deletions
diff --git a/doc/types.txt b/doc/types.txt
new file mode 100644
index 0000000..98ac6de
--- /dev/null
+++ b/doc/types.txt
@@ -0,0 +1,67 @@
+scalar types:
+
+* i8
+* i16
+* i32
+* i64
+* u8
+* u16
+* u32
+* u64
+* uptr
+* iptr
+* usize
+* isize
+* f32
+* f64
+
+enums, struct, union:
+
+* enum Name { A, B, C, D }
+
+ranges:
+
+* T..T
+ + range type
+ + T must be an ordinal
+
+* a..b
+ + range literal
+ + a and b must be ordinals (integer or enum) of the same type
+
+slices and arrays:
+
+* []T - slice
+* [N]T - array of N elements
+* [R]T - array of as many elements as the range constant R covers
+* [E]T - array over the enum E
+* in general, any expression X that can be used in [X]T can also be used in a
+ foreach statement (`for v in X { ... }`)
+
+* sized integers
+ + i8, i16, i32, i64
+ + u8, u16, u32, u64
+ + uptr, iptr: pointer-sized
+ + usize, isize: native machine word size
+* sized floating point
+ + f32, f64
+* bool
+
+* more modern type system than c
+ + distinction between pointers and arrays
+ + slice types (ptr, len)
+ - strings are slices, like rust &str or c++ str_view
+ + dynamic arrays (ptr, len, cap)
+ - manipulation of dynamic arrays is handled by normal functions
+ + type-safe generics
+ + parametric polymorphism (at compile time)
+ + built-in types for vector and matrix math
+ + scalar types have explicit bit sizes
+ - u8, i32, u64, f32, f64
+ + bit set support!
+ + type inference
+ - let x = y
+ - can do like .ENUM_NAME when expecting an enum value, even though
+ otherwise it's `let x = EnumType.ENUM_NAME`
+ + pascal-style postfix dereference, no need for a->b or (*a).b
+ - possibly also auto-dereference when accessing fields
diff --git a/main.c b/main.c
index 6134efa..a4d1b51 100644
--- a/main.c
+++ b/main.c
@@ -226,7 +226,6 @@ void merge_scope(Lexer *l, Proc *p, Node *region, ScopeNameList *before, ScopeNa
if (yes->node == b4->node && no->node == b4->node) continue;
phi = node_new(p, N_PHI, region, yes->node, no->node);
}
- fprintf(stderr, "phi('%.*s', %d, %d)\n", (int)b4->name.n, b4->name.s, phi->in.data[1]->id, phi->in.data[2]->id);
phi = node_peephole(phi, p, l);
NameBinding *b = scope_find(&p->scope, b4->name);
assert(b);
@@ -406,7 +405,6 @@ Node *find_return(Node *n) {
}
void proc_opt_fwd(Proc *p, Lexer *l, Node *n) {
- fprintf(stderr, "%d %s\n", n->id, node_type_name(n->op));
if (n->walked == 2) return;
n->walked = 2;
switch (n->op) {
@@ -457,7 +455,6 @@ void proc_opt_fwd(Proc *p, Lexer *l, Node *n) {
}
void proc_opt(Proc *p, Lexer *l) {
- fprintf(stderr, "%ld\n", p->stop->in.len);
if (p->stop->in.len == 0) {
if (p->ret_type.t != T_NONE) {
diff --git a/peephole.c b/peephole.c
index 9f5d51a..d994356 100644
--- a/peephole.c
+++ b/peephole.c
@@ -512,9 +512,6 @@ zero_no_effect: if (node_eql_i64(CAR(n), 0)) return CDR(n);
case N_PHI:
if (same) return CAR(n);
if (CTRL(n)->in.len == 2) {
- fprintf(stderr, "ctrl: %s\n", node_type_name(CTRL(n)->op));
- fprintf(stderr, "left: %p\n", (void*)IN(CTRL(n), 0));
- fprintf(stderr, "right: %p\n", (void*)IN(CTRL(n), 1));
if (IN(CTRL(n), 1)->type.lvl == T_XCTRL) return CAR(n);
if (IN(CTRL(n), 0)->type.lvl == T_XCTRL) return CDR(n);
}
diff --git a/test.lang b/test.lang
index 4df4f82..b409560 100644
--- a/test.lang
+++ b/test.lang
@@ -1,12 +1,15 @@
-func main(a, b i64) i64 {
- let x i64, y bool
- if true {
- let t = a
- a := b
- b := t
- x := 3
- } else {
- //x := 2
+/*func main(a, b i64) i64 {
+ let x i64 = 0, y bool = true
+ if a <> 0 {
+ x := 1
}
- return x
+ return x + a
+}*/
+
+func one i64 {
+ return 1
+}
+
+func main(a, b i64) i64 {
+ return a & a & b & a & b & b & b
}