2633 Commits

Author SHA1 Message Date
Andrew Kelley
c86108dd63
Merge pull request #6229 from LemonBoy/fix-6054
ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts
2020-09-02 19:13:21 -04:00
Andrew Kelley
12ce6eb8f6 stage2: support dbg_stmt at comptime 2020-09-02 00:09:24 -07:00
Tadeo Kondrak
1b2154dfe2 builtin: Add TypeInfo.StructField.is_comptime 2020-09-02 00:17:59 -04:00
Andrew Kelley
4c13d020db stage2: proper split of requireRuntimeBlock and requireFunctionBlock
* improve the ZIR generated of variable decls
   - utilize the same ZIR for the type and init value when possible
   - init value gets a result location with the variable type.
     no manual coercion is required.
 * no longer use return instructions to extract values out of comptime
   blocks. Instead run the analysis and then look at the corresponding
   analyzed instruction, relying on the comptime mechanism to report
   errors when something could not be comptime evaluated.
2020-09-01 12:39:47 -07:00
LemonBoy
c51b871c45 ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts
Closes #6054
2020-09-01 17:29:10 +02:00
Andrew Kelley
717b0e8275 stage2: introduce the ability for Scope.Block to be comptime
This gives zir_sema analysis the ability to check if the current scope
is expected to be comptime.
2020-08-31 23:34:58 -07:00
Andrew Kelley
8dc58a4e94
Merge pull request #6208 from tadeokondrak/remove-@OpaqueType
Remove @OpaqueType
2020-08-31 17:44:03 -04:00
Tadeo Kondrak
82273f1a2a translate_c: fix shadowing on nested blocks 2020-08-31 20:29:57 +03:00
Tadeo Kondrak
a2c47d2b0b
Remove @OpaqueType 2020-08-30 19:02:23 -06:00
Vexu
cc26cb9b23 stage2: codegen needed for basic for loop 2020-08-26 19:50:56 -07:00
Vexu
bf014d529a stage2: array access astgen 2020-08-26 19:50:56 -07:00
Andrew Kelley
0c5faa61ae stage2: codegen: fix reuseOperand not doing death bookkeeping 2020-08-26 01:00:04 -07:00
Vexu
c1ee9efb7c
fix error note using invalid source node
Closes #6153
2020-08-24 15:24:00 +03:00
Vexu
9589dc4c95 add error checks to @Type 2020-08-24 11:13:43 +03:00
joachimschmidt557
4f2618e75b stage2: Add Hello World test for ARM backend 2020-08-23 23:13:41 +02:00
Andrew Kelley
54f3b0a560 stage2: clean up SPU Mk II code
* move SPU code from std to self hosted compiler
 * change std lib comments to be descriptive rather than prescriptive
 * avoid usingnamespace
 * fix case style of error codes
 * remove duplication of producer_string
 * generalize handling of less than 64 bit arch pointers
 * clean up SPU II related test harness code
2020-08-22 13:36:08 -07:00
Noam Preil
f2fef240a1 SPU-II: Test harness skeleton 2020-08-22 12:45:29 -07:00
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 56c81c713f749f858089e5bcdf9e6fac588bcf86
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