Commit Graph

2616 Commits

Author SHA1 Message Date
Andrew Kelley 55d7c399c1 Merge pull request #6119 from tadeokondrak/@Type(.Enum)
Implement @Type for Enum
2020-08-22 03:21:46 -04:00
Tadeo Kondrak a049c31f21 Remove TypeInfo.Error.value 2020-08-22 03:20:12 -04:00
Andrew Kelley f18b92ef3a stage2: implement spilling registers to the stack 2020-08-21 23:36:21 -07:00
Tadeo Kondrak c31e8701d7 Update compile-errors test for @Type(.Enum) changes 2020-08-21 15:00:23 -06:00
Tadeo Kondrak 5a5956bd20 Implement @Type for Enum 2020-08-21 14:31:24 -06:00
Jakub Konka 243b5c7a88 Add macosx end-to-end smoke test
This test case will grow as the linker gets more functionality.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-21 09:41:05 +02:00
Andrew Kelley 73d16d015e stage2: reorganize tests
The main test cases are now in `test/stage2/test.zig` which can then
call addCases on other files if it wants to organize things differently.
2020-08-20 17:25:09 -07:00
Andrew Kelley 56ea04cb6d stage2: don't test compile errors of ZIR 2020-08-20 17:19:26 -07:00
Andrew Kelley 7d6d4b1473 stage2: move all tests to compare_output.zig 2020-08-20 17:15:01 -07:00
Vexu 6a053ffcc8 stage2: comptime decl 2020-08-20 16:42:48 -07:00
Andrew Kelley 9cfcd0c296 Merge pull request #6103 from Vexu/extern
Disallow extern variables with initializers.
2020-08-20 18:35:31 -04:00
Andrew Kelley 776bfb0ee6 Merge pull request #6099 from tadeokondrak/@Type(.Struct)
Implement @Type for structs
2020-08-20 16:57:10 -04:00
Andrew Kelley 4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Vexu d25674a51e disallow extern variables with initializers 2020-08-20 11:35:33 +03:00
Vexu a553947a51 translate-c: correctly put static and extern local variables in global scope 2020-08-20 10:45:55 +03:00
Vexu adc5bce5e8 translate-c: correct translation of global variables
* externs with intializers are translated as exports
* non extern without explicit initialization are zero initalized
2020-08-20 10:08:27 +03:00
Andrew Kelley 9ec9c0f5e5 optimize the memory layout of Module.Fn and Module.Var
`is_pub` added to `Fn` would cost us an additional 8
bytes of memory per function, which is a real bummer
since it's only 1 bit of information.

If we wanted to really remove this, I suspect we could
make this a function isPub() which looks at the AST of
the corresponding Decl and finds if the FnProto AST node
has the pub token. However I saw an easier approach -

The data of whether something is pub or not is actually
a property of a Decl anyway, not a function, so we can
look at moving the field into Decl. Indeed, doing this,
we see that Decl already has deletion_flag: bool which
is hiding in the padding bytes between the enum (1 byte)
and the following u32 field (generation). So if we put
the is_pub bool there, it actually will take up no
additional space, with 1 byte of padding remaining.

This was an easy reworking of the code since any
func.is_pub could be changed simply to func.owner_decl.is_pub.

I also modified `Var` to make the init value non-optional
and moved the optional bit to a has_init: bool field. This is worse from
the perspective of control flow and safety, however it makes
`@sizeOf(Var)` go from 32 bytes to 24 bytes. The more code we can fit
into memory at once, the more justified we are in using the compiler as
a long-running process that does incremental updates.
2020-08-19 17:52:22 -07:00
Vexu ab8a9a6605 stage2: fix astgen of decl ref, add test for global consts 2020-08-19 16:12:29 -07:00
Tadeo Kondrak 759485cc32 Update compile-errors test for @Type(.Struct) 2020-08-19 15:26:03 -06:00
Tadeo Kondrak b46d764fd9 Implement @Type for structs without decls support 2020-08-19 14:55:42 -06:00
Tadeo Kondrak 0f677810ea Remove offset field from TypeInfo.StructField
This isn't needed with @bitOffsetOf/@byteoffsetOf and complicates
@Type handling.
2020-08-19 14:55:40 -06:00
Andrew Kelley 083c0f1ceb stage2 codegen: proper abstraction for re-using dying operands
closes #6064
2020-08-18 23:11:56 -07:00
Andrew Kelley 771f40204e Merge pull request #6086 from Vexu/stage2
Stage2: more astgen stuff
2020-08-18 22:02:55 -04:00
Isaac Freund 6242ae35f3 stage2/wasm: implement function calls
During codegen we do not yet know the indexes that will be used for
called functions. Therefore, we store the offset into the in-memory
code where the index is needed with a pointer to the Decl and use this
data to insert the proper indexes while writing the binary in the flush
function.
2020-08-19 02:05:13 +02:00
Andrew Kelley 15bcfcd368 stage2: fix use-after-free when printing ZIR 2020-08-18 15:25:01 -07:00
Veikka Tuominen d139e44cfa Merge pull request #5495 from xackus/fix_5314
stage1: fix non-exhaustive enums with one field
2020-08-18 23:55:44 +03:00
Vexu 2b45e23477 stage2: character literals and multiline strings 2020-08-18 20:10:18 +03:00
Andrew Kelley bdb8c49418 stage1: update compile error tests
follow-up to 56c81c713f
2020-08-18 08:44:34 -07:00
Andrew Kelley 3cc1f8b624 Merge pull request #6056 from ifreund/wasm-backend
stage2: add a wasm backend
2020-08-18 00:28:05 -04:00
Ashish Shekar 27cb23cbc5 Handle singular param count word in error messages (#6073) 2020-08-17 22:18:29 -04:00
Isaac Freund 9f44284ad5 stage2/wasm: add basic test cases 2020-08-18 01:47:03 +02:00
Andrew Kelley 96a27557e2 stage2 test harness: at least build all compare output tests
This should have been removed with an earlier commit that improved the
test harness.
2020-08-17 15:27:41 -07:00
Vexu 2948f2d262 fix cast from invalid non-exhaustive enum to union 2020-08-17 20:48:22 +03:00
Vexu 1e835e0fcc disallow '_' prong when switching on non-exhaustive tagged union
A tagged union cannot legally be initiated to an invalid enumeration
2020-08-17 20:47:31 +03:00
xackus 65185016f1 stage1: fix non-exhaustive enums with one field 2020-08-17 20:45:34 +03:00
Andrew Kelley 66d76cc4f9 stage2: codegen for labeled blocks 2020-08-15 17:03:05 -07:00
Andrew Kelley 2cd19c05d0 stage1: remove buggy "unable to inline function" compile error
We still want this compile error but I'm giving up on implementing it
correctly in stage1. It's been buggy and has false positives sometimes.

I left the test cases there, but commented out, so that when we go
through the stage1 compile error cases and get coverage for them in
stage2 we can reactivate the test cases.

closes #2154
2020-08-15 09:53:39 -07:00
Andrew Kelley 7a39a038db stage2: proper semantic analysis of improper returning of implicit void 2020-08-14 13:08:55 -07:00
Andrew Kelley 28a9da8bfc stage2: implement while loops (bool condition)
* introduce a dump() function on Module.Fn which helpfully prints to
   stderr the ZIR representation of a function (can be called before
   attempting to codegen it). This is a debugging tool.
 * implement x86 codegen for loops
 * liveness: fix analysis of conditional branches. The logic was buggy
   in a couple ways:
   - it never actually saved the results into the IR instruction (fixed now)
   - it incorrectly labeled operands as dying when their true death was
     after the conditional branch ended (fixed now)
 * zir rendering is enhanced to show liveness analysis results. this
   helps when debugging liveness analysis.
 * fix bug in zir rendering not numbering instructions correctly

closes #6021
2020-08-13 20:32:32 -07:00
Veikka Tuominen f5b99abc93 Merge pull request #6045 from Vexu/block
Add error for unused/duplicate labels.
2020-08-14 01:04:05 +03:00
Vexu 13e472aa2a translate-c: add return if one is needed 2020-08-13 18:40:14 +03:00
Vexu 6b2ce9d1e9 stage2: split unwrap_optional to safe and unsafe verions 2020-08-13 08:12:17 -07:00
Vexu 4a40282391 stage2: implement unwrap optional 2020-08-13 08:12:17 -07:00
Vexu c5368ba20c translate-c: ensure generated labels are unique 2020-08-13 15:27:29 +03:00
Noam Preil 5a166cead8 CBE: fix handling of IR dependencies 2020-08-12 21:58:21 -07:00
Noam Preil dbd1e42ef2 CBE: Sorta working intcasts? 2020-08-12 21:58:21 -07:00
Noam Preil 78fe86dcd2 CBE: support unreachable on GCC 2020-08-12 21:58:21 -07:00
Noam Preil d3eec7d46b CBE: working parameters 2020-08-12 21:58:21 -07:00
Noam Preil dd1f1487e4 CBE: Use zig_noreturn instead of noreturn to avoid namespace conflict 2020-08-12 21:58:21 -07:00
Vexu 3734881577 add error for unused/duplicate block labels 2020-08-13 01:13:17 +03:00