aboutsummaryrefslogtreecommitdiff
path: root/src/astgen.zig
AgeCommit message (Collapse)Author
2021-03-28stage2: rename WipZirCode => AstGen, astgen.zig => AstGen.zigIsaac Freund
2021-03-26stage2: implement bitwise expr and error literalsAndrew Kelley
2021-03-26astgen: fix continue expressionsAndrew Kelley
2021-03-26astgen: fix result location for sliced objectsIsaac Freund
2021-03-26astgen: implement float literalsIsaac Freund
2021-03-26astgen: implement more builtin functionsIsaac Freund
2021-03-26astgen: implement slicingIsaac Freund
2021-03-25stage2: improve source locations of Decl accessAndrew Kelley
* zir.Code: introduce a decls array. This is so that `decl_val` and `decl_ref` instructions can refer to a Decl with a u32 and therefore they can also store a source location. This is needed for proper compile error reporting. * astgen uses a hash map to avoid redundantly adding a Decl to the decls array. * fixed reporting "instruction illegal outside function body" instead of the desired message "unable to resolve comptime value". * astgen skips emitting dbg_stmt instructions in comptime scopes. * astgen has some logic to avoid adding unnecessary type coercion instructions for common values.
2021-03-25stage2: fix `@compileLog`.Andrew Kelley
2021-03-25astgen: fix var decl source locationsAndrew Kelley
2021-03-25astgen: fix for loop expressionsAndrew Kelley
also rename the ZIR instruction `deref_node` to `load`.
2021-03-25astgen: fix array accessAndrew Kelley
2021-03-25stage2: implement inline whileAndrew Kelley
Introduce "inline" variants of ZIR tags: * block => block_inline * repeat => repeat_inline * break => break_inline * condbr => condbr_inline The inline variants perform control flow at compile-time, and they utilize the return value of `Sema.analyzeBody`. `analyzeBody` now returns an Index, not a Ref, which is the ZIR index of a break instruction. This effectively communicates both the intended break target block as well as the operand, allowing parent blocks to find out whether they, in turn, should return the break instruction up the call stack, or accept the operand as the block's result and continue analyzing instructions in the block. Additionally: * removed the deprecated ZIR tag `block_comptime`. * removed `break_void_node` so that all break instructions use the same Data. * zir.Code: remove the `root_start` and `root_len` fields. There is now implied to be a block at index 0 for the root body. This is so that `break_inline` has something to point at and we no longer need the special instruction `break_flat`. * implement source location byteOffset() for .node_offset_if_cond .node_offset_for_cond is probably redundant and can be deleted. We don't have `comptime var` supported yet, so this commit adds a test that at least makes sure the condition is required to be comptime known for `inline while`.
2021-03-24stage2: clean up break / noreturn astgenAndrew Kelley
* Module.addBreak and addBreakVoid return zir.Inst.Index not Ref because Index is the simpler type and we never need a Ref for these. * astgen: make noreturn stuff return the unreachable_value and avoid unnecessary calls to rvalue() * breakExpr: avoid unnecessary access into the tokens array * breakExpr: fix incorrect `@intCast` (previously this unsafely casted an Index to a Ref)
2021-03-24astgen: implement breaking from a blockTimon Kruiper
2021-03-24stage2: cleanups from previous commitsAndrew Kelley
Change some ZIR instructions from un_tok to un_node. Idea here is to avoid needlessly accessing the tokens array. Go ahead and finish the catch code in orelseCatchExpr. Otherwise it would be an easy mistake to get the scopes wrong when updating that code and introduce a bug. Delete a function that is now dead code.
2021-03-24astgen: implement orelseTimon Kruiper
2021-03-24stage2: further cleanups regarding zir.Inst.RefAndrew Kelley
* Introduce helper functions on Module.WipZirCode and zir.Code * Move some logic around * re-introduce ref_start_index * prefer usize for local variables + `@intCast` at the end. Empirically this is easier to optimize. * Avoid using mem.{bytesAsSlice,sliceAsBytes} because it incurs an unnecessary multiplication/division which may cause problems for the optimizer. * Use a regular enum, not packed, for `Ref`. Memory layout is guaranteed for enums which specify their tag type. Packed enums have ABI alignment of 1 byte which is too small.
2021-03-24stage2: make zir.Inst.Ref a non-exhaustive enumIsaac Freund
This provides us greatly increased type safety and prevents the common mistake of using a zir.Inst.Ref where a zir.Inst.Index was expected or vice-versa. It also increases the ergonomics of using the typed values which can be directly referenced with a Ref over the previous zir.Const approach. The main pain point is casting between a []Ref and []u32, which could be alleviated in the future with a new std.mem function.
2021-03-23stage2: comment out failing test cases; implement more thingsAndrew Kelley
* comment out the failing stage2 test cases (so that we can uncomment the ones that are newly passing with further commits) * Sema: implement negate, negatewrap * astgen: implement field access, multiline string literals, and character literals * Module: when resolving an AST node into a byte offset, use the main_tokens array, not the firstToken function
2021-03-23stage2: fix while loopsAndrew Kelley
also start to form a plan for how inline while loops will work
2021-03-23astgen: fixups regarding var decls and rl_ptrAndrew Kelley
2021-03-23stage2: implement inttype ZIRAndrew Kelley
also add i128 and u128 to const inst list
2021-03-23astgen: finishThenElseBlock: fix putting store_to_block_ptr in wrong blockAndrew Kelley
2021-03-23stage2: fix comptimeExpr and comptime function callsAndrew Kelley
2021-03-23stage2: add helper functions to clean up astgen Ref/IndexAndrew Kelley
2021-03-23astgen: implement typeofTimon Kruiper
2021-03-23astgen: fix an issue where the alloc wasnt elidedTimon Kruiper
2021-03-23astgen: implement assign operationsTimon Kruiper
2021-03-22stage2: fix `if` expressionsAndrew Kelley
2021-03-22astgen: improve the ensure_unused_result elisionAndrew Kelley
2021-03-22stage2: Sema improvements and boolean logic astgenAndrew Kelley
* add `Module.setBlockBody` and related functions * redo astgen for `and` and `or` to use fewer ZIR instructions and require less processing for comptime known values * Sema: rework `analyzeBody` function. See the new doc comments in this commit. Divides ZIR instructions up into 3 categories: - always noreturn - never noreturn - sometimes noreturn
2021-03-23stage2: remove all async related codeIsaac Freund
The current plan is to avoid using async and related features in the stage2 compiler so that we can bootstrap before implementing them. Having this untested and incomplete code in the codebase increases friction while working on stage2, in particular when preforming larger refactors such as the current zir memory layout rework. Therefore remove all async related code, leaving only error messages in astgen.
2021-03-22astgen: implement pointer typesIsaac Freund
2021-03-22astgen: implement array typesIsaac Freund
2021-03-21cleanups from previous commitAndrew Kelley
2021-03-21zir-memory-layout: astgen: varDecljacob gw
2021-03-21Sema: implement arithmeticAndrew Kelley
2021-03-22astgen: implement bool_and/bool_orIsaac Freund
2021-03-21astgen: implement simple binary operatorsIsaac Freund
2021-03-21zir: add negate/negate_wrap, implement astgenIsaac Freund
These were previously implemented as a sub/sub_wrap instruction with a lhs of 0. Making this separate instructions however allows us to save some memory as there is no need to store a lhs.
2021-03-20astgen: fix not detecting volatile asmAndrew Kelley
if only we could have compile errors for unused locals
2021-03-20stage2: fix memory management of ZIR codeAndrew Kelley
* free Module.Fn ZIR code when destroying the owner Decl * unreachable_safe and unreachable_unsafe are collapsed into one ZIR instruction with a safety flag. * astgen: emit an unreachable instruction for unreachable literals * don't forget to call deinit on ZIR code * astgen: implement some builtin functions
2021-03-20astgen: implement string literalsAndrew Kelley
2021-03-20astgen: implement inline assemblyAndrew Kelley
2021-03-20ZIR: move some un_tok tags to un_node insteadAndrew Kelley
Idea here is to prefer un_node to un_tok in order to avoid unnecessary calls to `tree.firstToken`.
2021-03-20astgen: implement function callsAndrew Kelley
2021-03-20zir-memory-layout: remove all absolute src constsjacob gw
this is to prevent future bugs
2021-03-20zir-memory-layout: astgen: more instructionsjacob gw
2021-03-19astgen: support blocksAndrew Kelley
We are now passing this test: ```zig export fn _start() noreturn {} ``` ``` test.zig:1:30: error: expected noreturn, found void ``` I ran into an issue where we get an integer overflow trying to compute node index offsets from the containing Decl. The problem is that the parser adds the Decl node after adding the child nodes. For some things, it is easy to reserve the node index and then set it later, however, for this case, it is not a trivial code change, because depending on tokens after parsing the decl determines whether we want to add a new node or not. Possible strategies here: 1. Rework the parser code to make sure that Decl nodes are before children nodes in the AST node array. 2. Use signed integers for Decl node offsets. 3. Just flip the order of subtraction and addition. Expect Decl Node index to be greater than children Node indexes. I opted for (3) because it seems like the simplest thing to do. We'll want to unify the logic for computing the offsets though because if the logic gets repeated, it will probably get repeated wrong.