Commit Graph

98 Commits (a32d3a85d21d614e5960b9eadcd85374954b910f)

Author SHA1 Message Date
Andrew Kelley a32d3a85d2 rework self-hosted compiler for incremental builds
* introduce std.ArrayListUnmanaged for when you have the allocator
   stored elsewhere
 * move std.heap.ArenaAllocator implementation to its own file. extract
   the main state into std.heap.ArenaAllocator.State, which can be
   stored as an alternative to storing the entire ArenaAllocator, saving
   24 bytes per ArenaAllocator on 64 bit targets.
 * std.LinkedList.Node pointer field now defaults to being null
   initialized.
 * Rework self-hosted compiler Package API
 * Delete almost all the bitrotted self-hosted compiler code. The only bit
   rotted code left is in main.zig and compilation.zig
 * Add call instruction to ZIR
 * self-hosted compiler ir API and link API are reworked to support
   a long-running compiler that incrementally updates declarations
 * Introduce the concept of scopes to ZIR semantic analysis
 * ZIR text format supports referencing named decls that are declared
   later in the file
 * Figure out how memory management works for the long-running compiler
   and incremental compilation. The main roots are top level
   declarations. There is a table of decls. The key is a cryptographic
   hash of the fully qualified decl name. Each decl has an arena
   allocator where all of the memory related to that decl is stored.
   Each code block has its own arena allocator for the lifetime of
   the block. Values that want to survive when going out of scope in
   a block must get copied into the outer block. Finally, values must
   get copied into the Decl arena to be long-lived.
 * Delete the unused MemoryCell struct. Instead, comptime pointers are
   based on references to Decl structs.
 * Figure out how caching works. Each Decl will store a set of other
   Decls which must be recompiled when it changes.

This branch is still work-in-progress; this commit breaks the build.
2020-05-10 02:05:54 -04:00
Andrew Kelley 8766821157 rework std.math.big.Int
Now there are 3 types:
 * std.math.big.int.Const
   - the memory is immutable, only stores limbs and is_positive
   - all methods operating on constant data go here
 * std.math.big.int.Mutable
   - the memory is mutable, stores capacity in addition to limbs and
     is_positive
   - methods here have some Mutable parameters and some Const
     parameters. These methods expect callers to pre-calculate the
     amount of resources required, and asserts that the resources are
     available.
 * std.math.big.int.Managed
   - the memory is mutable and additionally stores an allocator.
   - methods here perform the resource calculations for the programmer.
   - this is the high level abstraction from before

Each of these 3 types can be converted to the other ones.

You can see the use case for this in the self-hosted compiler, where we
only store limbs, and construct the big ints as needed.

This gets rid of the hack where the allocator was optional and the
notion of "fixed" versions of the struct. Such things are now modeled
with the `big.int.Const` type.
2020-05-01 06:47:56 -04:00
Andrew Kelley 751903ba8f zir: add breakpoint() instruction and object file ability 2020-05-01 06:47:20 -04:00
Andrew Kelley f89dbe6c4e link: introduce the concept of output mode and link mode 2020-05-01 06:47:20 -04:00
Andrew Kelley 28729efe29 ZIR: implement return instruction 2020-05-01 06:47:20 -04:00
Andrew Kelley 6b0f7de247 ZIR: add cmp and condbr instructions 2020-05-01 06:47:20 -04:00
Andrew Kelley 2bae942800 add ZIR compare output test case to test suite 2020-05-01 06:47:20 -04:00
Andrew Kelley d44c9bdbd9 ir: elemptr and add instructions 2020-04-26 01:20:58 -04:00
Andrew Kelley 757d13d784 codegen supports embedded-in-code constants
also coerce no longer requires a bitcast
2020-04-23 20:23:16 -04:00
Andrew Kelley 24a01eed90 basics of writing ELF and machine code generation 2020-04-23 16:41:20 -04:00
Andrew Kelley a3dfe36ca1 zir-to-elf skeleton 2020-04-22 23:42:58 -04:00
Andrew Kelley 1eda2ada9a std.math.big.Int: don't rely on the allocator when printing 2020-04-22 03:49:50 -04:00
Andrew Kelley d58233b361 ir: improve ZIR emission enough to emit hello world 2020-04-22 03:08:50 -04:00
Andrew Kelley 993e654554 emit zir skeleton 2020-04-22 00:04:52 -04:00
Andrew Kelley 2e6ccec100 ir: analyze asm instruction 2020-04-21 22:19:32 -04:00
Andrew Kelley 8d3e4147d5 ir: analyze deref instruction 2020-04-21 21:33:55 -04:00
Andrew Kelley 2c11acf807 ir: analyze fieldptr instruction 2020-04-21 21:14:56 -04:00
Andrew Kelley c12bc8652e ir: analyze ptrtoint 2020-04-21 20:34:40 -04:00
Andrew Kelley 2cdbb5f472 ir: analyze int casting 2020-04-21 19:48:59 -04:00
Andrew Kelley 0746028a2a ir: analyze int instruction 2020-04-21 17:54:00 -04:00
Andrew Kelley 69878207e7 ir: analyze `as` instruction 2020-04-21 17:33:41 -04:00
Andrew Kelley 25679b63eb ir: analyze primitive instruction 2020-04-21 17:11:42 -04:00
Andrew Kelley 8671e8d6d4 ir: analyze fntype instruction 2020-04-21 17:06:09 -04:00
Andrew Kelley 22e7ca5613 ir: analysis of fn instruction 2020-04-21 16:06:15 -04:00
Andrew Kelley 9a2ea5ca42 ir: comptime coerceArrayPtrToSlice 2020-04-21 13:50:04 -04:00
Andrew Kelley fb63ba2577 ir: type coercion skeleton 2020-04-21 13:24:25 -04:00
Andrew Kelley 8e0bcaca9b ir: analyze str instruction 2020-04-21 01:20:01 -04:00
Andrew Kelley 4c7507cceb ir: semantic analysis skeleton 2020-04-21 00:56:30 -04:00
Andrew Kelley cc1c2bd568 simplify ZIR spec; separate parsing/rendering from analysis 2020-04-20 19:21:03 -04:00
Andrew Kelley af4ccf34c1 ir: render keyword parameters 2020-04-19 23:59:00 -04:00
Andrew Kelley f7786d0ca8 ir: render function body 2020-04-19 23:39:34 -04:00
Andrew Kelley e74c5a7c24 ir: nice rendering of string literal constants 2020-04-19 20:44:18 -04:00
Andrew Kelley ded6e0326d ir: rendering skeleton 2020-04-19 20:04:11 -04:00
Andrew Kelley 1f3eeb5443 ir: parse type noreturn 2020-04-19 19:31:50 -04:00
Andrew Kelley 104ae419e4 ir: parse export instruction 2020-04-19 19:31:50 -04:00
Andrew Kelley f020999ca3 ir: parse asm instructions 2020-04-19 19:31:50 -04:00
Andrew Kelley 82e294cf09 ir: parse deref instruction 2020-04-19 19:31:50 -04:00
Andrew Kelley 730dd887e4 ir: parse string literals as parameters 2020-04-19 19:31:50 -04:00
Andrew Kelley bd37c8d8ed ir: parse ptrtoint 2020-04-19 19:31:50 -04:00
Andrew Kelley 49e2f3ca36 ir: more foolproof way to organize instruction parsing 2020-04-19 19:31:50 -04:00
Andrew Kelley 4cb203db92 ir: parsing integer literals 2020-04-19 19:31:50 -04:00
Andrew Kelley 7127c07f68 ir: parse types 2020-04-19 19:31:50 -04:00
Andrew Kelley 59154a1c51 ir: parse fn body 2020-04-19 19:31:50 -04:00
Andrew Kelley 018daa028e rework types and values data layout 2020-04-19 19:31:50 -04:00
Andrew Kelley f92ccf365b generic ir parsing framework 2020-04-19 19:31:50 -04:00
Andrew Kelley bd4280decf beginnings of zig ir parser 2020-04-19 19:31:50 -04:00
Andrew Kelley 9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Andrew Kelley 13d04f9963
Merge pull request #4741 from momumi/master
allow `_` separators in number literals (stage 1)
2020-03-23 00:54:54 -04:00
momumi 2d18178c27 minor fixes and more tests for _ separators
* Make the tokenizer spit out an Invalid token on the first invalid
  character found in the number literal.
* More parsing and tokenizer tests for number literals
* fix invalid switch statement in ir.zig
2020-03-23 09:21:34 +10:00
momumi 8de45e5143 update parsing of int literals in self-hosted
* update std.math.big.Int.setString() to ignore underscores and make it
  case insensitive
* fix issue in ir.zig with leading zeroes in integer literals
2020-03-22 13:59:14 +10:00