Commit Graph

9745 Commits

Author SHA1 Message Date
Vexu
5e88a7a427
add behavior tests fro macro translations 2020-07-16 17:10:52 +03:00
Vexu
06c08e5219
std.mem.zeroes use std.mem.set instead of @memset
stage1 comptime is not smart enough to remeber the size of the casted
item which leads to out of bounds errors.
2020-07-16 17:05:14 +03:00
Vexu
37647375dc
translate-c: support initializer list expr macros 2020-07-16 16:20:47 +03:00
Vexu
8fe076daaf
std.mem.zeroInit support initiating with tuples 2020-07-16 16:00:42 +03:00
pfg
01ab167ce3 stage2: change large switch → inline for loop 2020-07-16 10:32:24 +00:00
Andrew Kelley
e079fdeee7
Merge pull request #5885 from ziglang/stage2-locals
self-hosted compiler local consts
2020-07-16 05:57:32 +00:00
Andrew Kelley
d29dd5834b stage2: local consts
These are now supported enough that this example code hits the
limitations of the register allocator:

fn add(a: u32, b: u32) void {
    const c = a + b; // 7
    const d = a + c; // 10
    const e = d + b; // 14
    assert(e == 14);
}
// error: TODO implement copyToNewRegister

So now the next step is to implement register allocation as planned.
2020-07-15 22:36:35 -07:00
Andrew Kelley
af12596e8d stage2: breaking AST memory layout modifications
InfixOp is flattened out so that each operator is an independent AST
node tag. The two kinds of structs are now Catch and SimpleInfixOp.

Beginning implementation of supporting codegen for const locals.
2020-07-15 19:39:18 -07:00
haze
82562b205f
On darwin, only add the self exe to the cache hash for compiler id (#5880)
Now that Big Sur does not have system libraries on the filesystem, zig can no longer read them and add them to the cache hash for the compiler id.
This changes it so that only the first library path returned by os_self_exe_shared_libs is added to the cache hash under Darwin. I looked into methods on getting the system version to keep parity with older versions, but @fengb reported that this works on Catalina (a version behind Big Sur)

Signed-off-by: Haze Booth <isnt@haze.cool>
2020-07-15 22:37:04 -04:00
Andrew Kelley
f119092273 stage2: breaking AST memory layout modifications
ast.Node.Id => ast.Node.Tag, matching recent style conventions.

Now multiple different AST node tags can map to the same AST node data
structures. In this commit, simple prefix operators now all map top
SimplePrefixOp.

`ast.Node.castTag` is now preferred over `ast.Node.cast`.

Upcoming: InfixOp flattened out.
2020-07-15 18:15:59 -07:00
Andrew Kelley
e70d6d19f5 stage2: extract AST=>ZIR code to separate file 2020-07-15 15:42:02 -07:00
Andrew Kelley
6b103324d2
Merge pull request #5872 from ziglang/ast-flatten-2
stage2: introduce the concept of "trailer flags" to the AST
2020-07-15 18:34:06 +00:00
Andrew Kelley
c5b7322319 TrailerFlags test: fix bad alignment assumption on 32-bit 2020-07-15 04:04:04 -07:00
Andrew Kelley
804b51b179 stage2: VarDecl and FnProto take advantage of TrailerFlags API
These AST nodes now have a flags field and then a bunch of optional
trailing objects. The end result is lower memory usage and consequently
better performance. This is part of an ongoing effort to reduce the
amount of memory parsed ASTs take up.

Running `zig fmt` on the std lib:
 * cache-misses: 2,554,321 => 2,534,745
 * instructions: 3,293,220,119 => 3,302,479,874
 * peak memory: 74.0 MiB => 73.0 MiB

Holding the entire std lib AST in memory at the same time:

  93.9 MiB => 88.5 MiB
2020-07-15 02:07:30 -07:00
Andrew Kelley
eac6280241 add std.meta.TrailerFlags API
This is useful for saving memory when allocating an object that has many
optional components. The optional objects are allocated sequentially in
memory, and a single integer is used to represent each optional object
and whether it is present based on each corresponding bit.
2020-07-14 17:19:17 -07:00
Andrew Kelley
a7c3cec65f follow up from previous commit for generic methods 2020-07-14 15:29:07 -07:00
Andrew Kelley
4696cd3e09 fix ability to call methods on enums with pointer-to-self
closes #3218
2020-07-14 14:38:40 -07:00
Andrew Kelley
67273cbe76
Merge pull request #5868 from ziglang/stage2-improvements
Stage2 improvements
2020-07-14 09:24:43 +00:00
Andrew Kelley
a92990f993 stage2: implement enough for assert() function to codegen 2020-07-14 02:24:12 -07:00
Andrew Kelley
135580c162 stage2: fix liveness analysis of Call instructions 2020-07-13 23:48:54 -07:00
Andrew Kelley
5da5ded743 stage2: detect unreferenced non-volatile asm and NOT 2020-07-13 23:48:26 -07:00
~nue
03f14c3102
Added octal formatting fo fmt functions. (#5867)
* Added octal formatting (specifier "o") to `formatIntValue` function.
* Added octal specifier test case in `fmt.zig` (under the "int.specifier" case)
2020-07-14 02:27:58 -04:00
Andrew Kelley
4f5e065d6e stage2: add ZIR support for BoolNot 2020-07-13 20:47:47 -07:00
Andrew Kelley
14cef9dd3d stage2 parser: split out PrefixOp into separate AST Nodes
This is part of a larger effort to improve the memory layout of AST
nodes of the self-hosted parser to reduce wasted memory. Reduction of
wasted memory also translates to improved performance because of fewer
memory allocations, and fewer cache misses.

Compared to master, when running `zig fmt` on the std lib:

 * cache-misses: 801,829 => 768,624
 * instructions: 3,234,877,167 => 3,232,075,022
 * peak memory: 81480 KB => 75964 KB
2020-07-13 20:13:51 -07:00
Nathan Michaels
bc900cdeaf Document top-level doc comments, per #2288. 2020-07-13 22:57:23 +00:00
Andrew Kelley
fabdef44a8
Merge pull request #5831 from paulespinosa/langref-hello-world-more
Explain Language Ref's Hello World
2020-07-13 22:45:32 +00:00
Paul Espinosa
a8d8ce9733 Use Writer for Language Reference Hello World Example
`OutStream` has been deprecated, so the "Hello, World!" example has been
updated to use `Writer`.
2020-07-13 22:41:57 +00:00
Andrew Kelley
204f61d7f5 stage2: Module: use StringHashMapUnmanaged 2020-07-13 15:34:31 -07:00
Andrew Kelley
75a720565b Merge branch 'stage2-condbr' 2020-07-13 00:32:12 -07:00
Andrew Kelley
c94652a2fd stage2: add new test case 2020-07-13 00:31:55 -07:00
Andrew Kelley
08154c0deb stage2: add retvoid support to CBE 2020-07-13 00:28:11 -07:00
Andrew Kelley
25b1c00c72 stage2: add implicit return void where applicable 2020-07-13 00:08:21 -07:00
Andrew Kelley
c306392b44 stage2: codegen: more branching support 2020-07-13 00:08:21 -07:00
Andrew Kelley
b75a51f94b stage2: implement function calling convention for calls 2020-07-13 00:08:21 -07:00
Andrew Kelley
8fe63d5042 stage2: peer type resolution with noreturn 2020-07-13 00:08:21 -07:00
Andrew Kelley
1cab40d783
Merge pull request #5864 from pixelherodev/cbe
CBE: get basic returns working
2020-07-13 07:07:27 +00:00
Noam Preil
8d6cadee16
CBE: Code cleanup 2020-07-13 01:49:04 -04:00
Noam Preil
4a46248198
CBE: Only generate (void) for calls whose return values are ignored 2020-07-13 01:49:04 -04:00
Noam Preil
a124b027b4
CBE: Use hasCodeGenBits instead of checking against void and noreturn 2020-07-13 01:49:04 -04:00
Noam Preil
3bad1c16cc
Get basic return test working 2020-07-13 01:49:04 -04:00
pixelherodev
2c882b2e65
CBE: Make C an ObjectFormat instead of a special bool (#5849) 2020-07-12 22:56:31 -04:00
Vexu
dff1ac1089 check for invalid sentinel when creating pointer with @Type 2020-07-13 00:29:53 +00:00
Isaac Freund
ef17af1270 std: add mem.joinZ
currently the only options are doing a second allocation and copying or
implementing this yourself.
2020-07-12 22:17:40 +00:00
xackus
5b570bceb5 document a few functions in std.mem 2020-07-12 21:55:49 +00:00
Andrew Kelley
7adbc11403
Merge pull request #5857 from daurnimator/use-unmanaged
Use unmanaged datastructures from std.http.headers
2020-07-12 21:46:26 +00:00
Sam Tebbs
873e187f05 Make allocator test functions public 2020-07-12 21:45:25 +00:00
Jakub Konka
eea7271c4e Fix incorrect continue condition in PreopeonList
Also, check for overflow on incremented file descriptors. Previously,
we'd trigger a panic if we exceeded the `fd_t` resolution. Now, instead,
we throw an `error.Overflow` to signal that there can be no more
file descriptors available from the runtime. This way we give the user
the ability to still be able to check if their desired preopen exists
in the list or not.
2020-07-12 21:02:33 +00:00
daurnimator
91235b9371
std: don't store allocator inside of std.http.HeaderEntry 2020-07-13 00:38:59 +10:00
daurnimator
f7e4014c82
std: use *Unmanaged data structures in http.Headers object 2020-07-13 00:34:58 +10:00
daurnimator
4b48266bb7
std: add StringHashMapUnmanaged 2020-07-13 00:34:02 +10:00