Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types from beginning to end #37

Merged
merged 98 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
0d41365
Initial Mess
LensPlaysGames Jan 21, 2023
fe4610d
Make it work more betterer
LensPlaysGames Jan 22, 2023
2f4d462
[Bugfix] Zero extending loads fixes *a lot*
LensPlaysGames Jan 22, 2023
9a013f3
[Bug] Identify bug with binary operator type
LensPlaysGames Jan 22, 2023
5831094
[Bugfix] Fix error in format string
LensPlaysGames Jan 23, 2023
055931c
[Codegen] Handle size of type when calculating address offset
LensPlaysGames Jan 27, 2023
08f8d36
[Codegen] Make IR_LOAD great again (arrays! (again))
LensPlaysGames Jan 27, 2023
2578acc
[x86_64/Bugfix] Missing register size parameter in femit
LensPlaysGames Jan 27, 2023
89337ae
[MSWIN/Bugfix] Handle error of `SymFromAddr()`
LensPlaysGames Jan 27, 2023
9fa9485
[Sema] Handle some basic type casting cases in typechecker
LensPlaysGames Jan 27, 2023
3457d53
[Typo] Forgetting a newline is bad, mmkay?
LensPlaysGames Jan 27, 2023
b5b3183
[Minor] Fix horribly phrased comment
LensPlaysGames Jan 29, 2023
8a94037
[Docs] Better comments regarding type helpers in `ast.h`
LensPlaysGames Jan 29, 2023
61f28a8
[Minor] Add signedness reminder to casting codegen todo
LensPlaysGames Jan 29, 2023
98ae71e
[Bugfix] Copy and paste strikes again :I
LensPlaysGames Jan 29, 2023
f06972a
[Codegen] Handle subscript operator all at once, instead of split
LensPlaysGames Jan 29, 2023
aa23eae
[Minor] Add commentary on array pointer decay codegen
LensPlaysGames Jan 29, 2023
c9be95c
[Minor] Remove unnecessary `t_void` assignments from IR helpers
LensPlaysGames Jan 29, 2023
61d343d
[Bugfix] IR type of bitwise not was incorrectly always `t_integer`
LensPlaysGames Jan 29, 2023
1ad6dbf
[Codegen/x86_64] Remove useless `r128` RegSize
LensPlaysGames Jan 29, 2023
d82cd3d
[Codegen/x86_64] Don't emit xor + mov when a 32-bit mov is usable
LensPlaysGames Jan 29, 2023
9b30942
[Codegen/IR] Make variable allocation instructions pointers to type
LensPlaysGames Jan 29, 2023
20e42a0
[Sema/Minor] Some updates to typecasting
LensPlaysGames Jan 29, 2023
3ad2392
[TODO] `as void` discard cast
LensPlaysGames Jan 29, 2023
e7d77a7
[Tests] Lines with trailing whitespace keep me up at night
LensPlaysGames Jan 29, 2023
b4af7c9
[Codegen/x86_64] Update incorrect comments regarding var. args
LensPlaysGames Jan 30, 2023
8013c43
[Codegen/x86_64] Mention `movzx` instruction where applicable
LensPlaysGames Jan 30, 2023
a836f0b
[Codegen/x86_64] Add `t_pointer` primitive type
LensPlaysGames Jan 30, 2023
9d23bd2
[Sema] Fix `t_pointer` definition
LensPlaysGames Jan 30, 2023
55e1ec0
[Sema] Disallow typecasting between arrays
LensPlaysGames Jan 31, 2023
e339100
[Minor] TODO comment in Sema
LensPlaysGames Jan 31, 2023
6c4570d
[Examples] Using a byte array as a C string
LensPlaysGames Jan 31, 2023
a94f836
[Bugfix] Lexer no longer relies on null terminator
LensPlaysGames Feb 1, 2023
933ed59
[Frontend] Basic string literal support :O
LensPlaysGames Feb 1, 2023
312d4e7
[Codegen] Very basic codegen of string literals
LensPlaysGames Feb 1, 2023
ac386a8
[Examples] Basic string literal example
LensPlaysGames Feb 1, 2023
ab4eac2
[TODO] Arrays have two kinds of loading we need to be able to emit
LensPlaysGames Feb 1, 2023
4423fee
[AST] Make `ast_print_node` publicly available
LensPlaysGames Feb 2, 2023
c57b388
[Minor] Formatting
LensPlaysGames Feb 2, 2023
ab7dcf8
[Sema] Emit error over previous todo as we now handle (some) casting
LensPlaysGames Feb 2, 2023
db2d432
[Sema] Disallow non-equal incomplete types entirely
LensPlaysGames Feb 2, 2023
1bd10b3
[Minor/AST] Add meaningful docstring to `type_is_incomplete_canon`
LensPlaysGames Feb 2, 2023
66f7289
[Minor/AST] Better formatting of docstring for `type_canonical`
LensPlaysGames Feb 2, 2023
b125c17
[Minor/TODO] Update unnecessarily narrowing statement :P
LensPlaysGames Feb 2, 2023
bee8136
[AST] Remove `id` system entirely
LensPlaysGames Feb 2, 2023
afebae2
[Tests] Two tests---one passes, one fails
LensPlaysGames Feb 2, 2023
e669db3
[Codegen/IR] Remove `cached_*` members from `IRStaticVariable`
LensPlaysGames Feb 2, 2023
c9ccbb2
[Minor/AST] Stub implementation of `type_alignof`
LensPlaysGames Feb 2, 2023
6615957
[Codegen/x86_64] Use `type_sizeof(t_pointer)` where applicable
LensPlaysGames Feb 2, 2023
9b71982
[Codegen/IR] Fix overwrite of `rhs` of subscript operator
LensPlaysGames Feb 2, 2023
dc49514
[Minor/Codegen] Update diagnostic message
LensPlaysGames Feb 2, 2023
4e3e0f8
[Tests] Add `negative-numbers.un`
LensPlaysGames Feb 2, 2023
ec7b772
[Minor] Be slightly more explicit about primitive type defined name
LensPlaysGames Feb 2, 2023
974bdff
[Minor/Codegen] Fix scuffed diagnostic message
LensPlaysGames Feb 2, 2023
32f6a44
[IR] Create `ir_static_reference()` to reference an existing static
LensPlaysGames Feb 3, 2023
b2d090d
[Codegen] Use `ir_static_reference()` to create many references
LensPlaysGames Feb 3, 2023
b14fa1c
[Bugfix/x86_64] Add missing parameter...
LensPlaysGames Feb 3, 2023
8281a44
[Minor/Codegen] Add TODO comment
LensPlaysGames Feb 3, 2023
ec35e50
[Codegen/x86_64] Begin move away from `va_list` towards typed params
LensPlaysGames Feb 3, 2023
6574a1d
[Codegen/x86_64] Move further away from variable args...
LensPlaysGames Feb 3, 2023
e830a9f
[Codegen/x86_64] Moving even further away from variable args...
LensPlaysGames Feb 3, 2023
339e07c
[Codegen/x86_64] `femit_name_to_reg()` typed parameters
LensPlaysGames Feb 3, 2023
84f1e10
[Codegen/x86_64] `femit_reg_to_mem()` typed parameters
LensPlaysGames Feb 3, 2023
80749cf
[Codegen/x86_64] Nearly completely moved away from variable args...
LensPlaysGames Feb 3, 2023
81aaf8e
[Codegen/x86_64] More comprehensive ICE error message in `femit()`
LensPlaysGames Feb 3, 2023
a400f57
[Minor/x86_64] Comments, error message
LensPlaysGames Feb 3, 2023
4a70c4c
Merge branch 'main' into ir_types_bb
LensPlaysGames Feb 3, 2023
cd2381a
[Minor/Codegen] Outline places where string literals need handled
LensPlaysGames Feb 3, 2023
f922e21
[Minor/Codegen] Yet still always more to do due soon
LensPlaysGames Feb 3, 2023
13b8210
[Bugfix] Add missing zero initialiser (needed by MSVC)
LensPlaysGames Feb 4, 2023
33c195c
[Minor] Remove accidentally tracked file
LensPlaysGames Feb 4, 2023
49c9970
[Sema] Fix copy-and-paste error
LensPlaysGames Feb 6, 2023
e594ee5
[UX] Allow `colors` as well as `colours` in CLI
LensPlaysGames Feb 7, 2023
b95d879
[TODO] String literals are parsed, now
LensPlaysGames Feb 7, 2023
b7be438
Disable IR intake as it is severely lacking in development right now
LensPlaysGames Feb 7, 2023
49f6762
[Bugfix] Fix types in wrong order in error message
LensPlaysGames Feb 7, 2023
6c49cac
[Sema] Move some `type_is_*` functions up to `ast.h` from `typechecke…
LensPlaysGames Feb 7, 2023
7253339
[Minor/Sema] Use `vector_back` instead of manual calculation
LensPlaysGames Feb 7, 2023
7b84f66
[Minor/Sema] Actually use `vector_back_or` in case of no children
LensPlaysGames Feb 7, 2023
771b9b4
[Minor/Sema] This should now work pretty much as expected
LensPlaysGames Feb 7, 2023
df8ffb0
[Minor/Sema] Very minor formatting
LensPlaysGames Feb 7, 2023
5a60f48
[Bugfix] Source spans of assignments were off; this fixes them
LensPlaysGames Feb 7, 2023
cc09b8b
[Sema] Use `type_is_*` instead of direct comparisons
LensPlaysGames Feb 7, 2023
836f99b
[Codegen] Improve codegen of subscript variable reference
LensPlaysGames Feb 7, 2023
acd725c
[AST] Update `ast_print_node` with easier to use signature
LensPlaysGames Feb 7, 2023
f3fab2d
[Codegen] Remove now-unnecessary array bodge in var. ref. codegen
LensPlaysGames Feb 7, 2023
a8241fa
[Codegen] ¡Subscript of local variable!
LensPlaysGames Feb 7, 2023
6c027c7
[Codegen] Apparently better ¡Codegen of Subscript of local variable!
LensPlaysGames Feb 7, 2023
c7f87aa
[Codegen/x86_64] Fix clobber values of `does_clobber` for shift instr…
LensPlaysGames Feb 7, 2023
88715b4
[Tests] Add bit-shifting left and right tests
LensPlaysGames Feb 7, 2023
1104d93
[AST] Rename `t_pointer` to `t_void_ptr`
LensPlaysGames Feb 7, 2023
b222c7f
[Codegen/IR] Remove use of `ir_static_reference`
LensPlaysGames Feb 7, 2023
6411d36
[Minor/IR] Simplify wording of comment
LensPlaysGames Feb 7, 2023
40b4430
[Minor/Codegen] Comments; fixed a typo
LensPlaysGames Feb 7, 2023
f1f876c
[Codegen] Rename `var` to the more correct `var_decl`
LensPlaysGames Feb 7, 2023
8282edc
[Sema] Get rid of `is_*` wrappers, where possible
LensPlaysGames Feb 7, 2023
3a9c115
[Codegen/IR] Fix assigned type of `IR_LOAD` instructions
LensPlaysGames Feb 7, 2023
79c22b1
[TODO] NODISCARD should be default for non-void return types
LensPlaysGames Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions .clang-format

This file was deleted.

17 changes: 13 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
- [ ] Function bodies must be blocks or preceded by `=`.
- [ ] `ext` functions may have a body.
- [ ] Implicit cast sema pass: `a + b` where `a` is a `byte` and `b` an `integer` -> `(a as integer) + b`
- [ ] Testing Framework: Add ability to only show failing tests
- [ ] `x as void` used to discard `x`
- [ ] Resolve the two different kinds of array-type loading: entire copy vs pointer decay. Basically, `foo[2]` needs `foo` to be loaded as a pointer. `a : foo[2] = b` requires loading entire copy of `b` into `a`.
- [ ] Optimisation
- [ ] Zero subscript still does add/multiply when it doesn't need to
- [ ] Eliminate unused parameters (they are currently allocated registers)
- [ ] Attributes
- [ ] Parsing
- [ ] `[[noreturn]]`
Expand All @@ -36,12 +42,14 @@
- [ ] Disallow overloading on the return value.
- [ ] Proper checking for incomplete types in the parser.
- [ ] Types in the IR
- [ ] Byte type
- [ ] Type info in codegen/IR.
- [x] Byte type
- [x] Type info in codegen/IR.
- [ ] Backend: Handle size/alignment requirements
- [ ] Use eax, ax, al, etc.
- [x] Use eax, ax, al, etc.
- [ ] Actually implementing casts.
- [ ] During codegen, we should actually output `zext`/`sext` if needed. Otherwise truncation is automatic.
- [ ] Update IR parser
- [ ] Operators (unary and binary) need to pick return type instead of strictly returning `integer`
- [ ] Arrays
- [ ] Semantic analysis for static arrays.
- [ ] Codegen
Expand All @@ -57,7 +65,7 @@
- [ ] Length operator: `#`
- [ ] Subscripting
- [ ] Strings
- [ ] Parsing string literals.
- [x] Parsing string literals.
- [ ] Codegen.
- [ ] Backend.
- [ ] Structs
Expand All @@ -69,6 +77,7 @@
- [ ] `type` keyword in the parser/grammar.
- [ ] Make sure nested structs work.
- [ ] Arbitrary compile-time struct literals.
- [ ] Syntax?
- [ ] Structs as parameters.
- [ ] Structs as return values.
- [ ] Modules.
Expand Down
4 changes: 4 additions & 0 deletions examples/byte.un
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a : byte = 34
b : byte = 35
c : byte = a + b
c
15 changes: 15 additions & 0 deletions examples/bytearray.un
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 0
; Eyyy

puts : ext integer(str : @byte)

foo : byte[69]
@foo[0] := 69
@foo[1] := 121
@foo[2] := 121
@foo[3] := 121
@foo[4] := 0

puts(foo[0])

0
6 changes: 6 additions & 0 deletions examples/string_literals.un
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
puts : ext void(s : @byte)

str : @byte = "Hello, LISP programmer!"[0]

puts(str)
0
84 changes: 55 additions & 29 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@
usz alignment;
span name;
bool is_signed;
/// A unique ID that is used to compare primitives.
uint8_t id;
LensPlaysGames marked this conversation as resolved.
Show resolved Hide resolved
} TypePrimitive;*/
static Type t_void_def = {
.kind = TYPE_PRIMITIVE,
.source_location = {0},
.primitive = {
.size = 0,
.alignment = 0,
.name = literal_span_raw("void"),
.id = 0,
},
.kind = TYPE_PRIMITIVE,
.source_location = {0},
.primitive = {
.size = 0,
.alignment = 0,
.name = literal_span_raw("void"),
},
};

static Type t_void_pointer_def = {
.kind = TYPE_POINTER,
.source_location = {0},
.pointer = { .to = &t_void_def },
};

static Type t_integer_literal_def = {
Expand All @@ -30,34 +36,33 @@ static Type t_integer_literal_def = {
.alignment = 8,
.name = literal_span_raw("<integer_literal>"),
.is_signed = true,
.id = 1,
},
};

static Type t_integer_def = {
.kind = TYPE_PRIMITIVE,
.source_location = {0},
.primitive = {
.size = 8,
.alignment = 8,
.name = literal_span_raw("integer"),
.is_signed = true,
.id = 1,
},
.kind = TYPE_PRIMITIVE,
.source_location = {0},
.primitive = {
.size = 8,
.alignment = 8,
.name = literal_span_raw("integer"),
.is_signed = true,
},
};

static Type t_byte_def = {
.kind = TYPE_PRIMITIVE,
.source_location = {0},
.primitive = {
.size = 1,
.alignment = 1,
.name = literal_span_raw("byte"),
.id = 3,
},
.kind = TYPE_PRIMITIVE,
.source_location = {0},
.primitive = {
.size = 1,
.alignment = 1,
.name = literal_span_raw("byte"),
.is_signed = false,
},
};

Type * const t_void = &t_void_def;
Type * const t_void_ptr = &t_void_pointer_def;
Type * const t_integer_literal = &t_integer_literal_def;
Type * const t_integer = &t_integer_def;
Type * const t_byte = &t_byte_def;
Expand Down Expand Up @@ -497,10 +502,25 @@ usz type_sizeof(Type *type) {
}
}

usz type_alignof(Type *type) {
TODO("Unimplemented, sorry");
return 69;
}

bool type_is_void(Type *type) {
return type_canonical(type) == t_void;
}

bool type_is_pointer(Type *type) {
Type * t = type_canonical(type);
return t && t->kind == TYPE_POINTER;
}

bool type_is_array(Type *type) {
Type * t = type_canonical(type);
return t && t->kind == TYPE_ARRAY;
}

/// ===========================================================================
/// Miscellaneous AST functions.
/// ===========================================================================
Expand Down Expand Up @@ -597,7 +617,7 @@ static void ast_print_children(
);

/// Print a node.
static void ast_print_node(
void ast_print_node_internal(
FILE *file,
const Node *logical_parent,
const Node *node,
Expand Down Expand Up @@ -745,6 +765,12 @@ static void ast_print_node(
}
}

void ast_print_node(const Node *node) {
string_buffer buf = {0};
ast_print_node_internal(stdout, NULL, node, &buf);
vector_delete(buf);
}

/// Scope tree for printing scopes.
typedef struct scope_tree_node {
const Scope *scope;
Expand Down Expand Up @@ -826,7 +852,7 @@ void ast_print(FILE *file, const AST *ast) {
string_buffer buf = {0};

/// Print the root node.
ast_print_node(file, NULL, ast->root, &buf);
ast_print_node_internal(file, NULL, ast->root, &buf);
}

/// Print the children of a node.
Expand All @@ -851,7 +877,7 @@ static void ast_print_children(
format_to(buf, "%s", node == vector_back(*nodes) ? " " : "│ ");

/// Print the node.
ast_print_node(file, logical_parent, node, buf);
ast_print_node_internal(file, logical_parent, node, buf);

/// Restore the leading text.
buf->size = sz;
Expand Down
Loading