199 Commits

Author SHA1 Message Date
Lachlan Easton
bb848dbeee zig fmt: Patch rename stream to ais (auto indenting stream) & other small refactors 2020-09-02 20:16:28 +10:00
Lachlan Easton
671b3abe5d Merge remote-tracking branch 'ziglang/master' into fmt_indentation 2020-09-01 18:41:23 +10:00
Andrew Kelley
212fe21d68 zen of zig: reword the last one a little bit 2020-08-31 14:40:08 -07:00
Lachlan Easton
a72b9d403d Refactor zig fmt indentation. Remove indent from rendering code and have a stream handle automatic indentation 2020-08-29 13:35:00 +10:00
Andrew Kelley
b1c7334355
Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
2020-08-19 23:46:22 -04: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
Andrew Kelley
502d413621 simplify zig info and rename it to zig env
also add version to it
2020-08-17 17:06:43 -07:00
Sergey Poznyak
80e70735fb add zig info command 2020-08-17 16:35:32 -07:00
Isaac Freund
3370b5f109
stage2/wasm: implement basic container generation
Thus far, we only generate the type, function, export, and code
sections. These are sufficient to generate and export simple functions.

Codegen is currently hardcoded to `i32.const 42`, the main goal of this
commit is to create infrastructure for the container format which will
work with incremental compilation.
2020-08-18 00:32:58 +02:00
Andrew Kelley
624e643872
Merge pull request #6046 from heidezomp/std-log-scoped-part2
std.log: (breaking) remove scope parameter from logging functions
2020-08-17 16:59:27 -04:00
Andrew Kelley
8d8d568854 stage2: implement zig version 2020-08-15 20:04:08 -04:00
heidezomp
16d118a8d9 update std and src-self-hosted for std.log breaking change 2020-08-13 17:14:15 +02:00
Andrew Kelley
a2a5cea286 stage2: emit DW_TAG_subprogram for function Decls
these have the virtual address range, return type, and name.
2020-08-11 19:02:21 -07:00
Andrew Kelley
20510d209b GeneralPurposeAllocator: use std.log instead of std.debug.print
`std.builtin.StackTrace` gains a `format` function.

GeneralPurposeAllocator uses `std.log.err` instead of directly printing
to stderr. Some errors are recoverable.

The test runner is modified to fail the test run if any log messages of
"err" or worse severity are encountered.

self-hosted is modified to always print log messages of "err" severity
or worse even if they have not been explicitly enabled.

This makes GeneralPurposeAllocator available on the freestanding target.
2020-08-11 02:01:32 -04:00
Andrew Kelley
fd47839064 stage2: fix crash on empty source file 2020-08-08 18:19:48 -07:00
Andrew Kelley
0347df82e8 improvements & fixes for general purpose allocator integration
* std.Mutex API is improved to not have init() deinit(). This API is
   designed to support static initialization and does not require any
   resource cleanup. This also happens to work around some kind of
   stage1 behavior that wasn't letting the new allocator mutex code
   get compiled.
 * the general purpose allocator now returns a bool from deinit()
   which tells if there were any leaks. This value is used by the test
   runner to fail the tests if there are any.
 * self-hosted compiler is updated to use the general purpose allocator
   when not linking against libc.
2020-08-07 23:26:58 -07:00
Andrew Kelley
8824491fc7 stage2: add missing newlines to cli error messages 2020-08-04 18:38:42 -07:00
Andrew Kelley
edfede575c self-hosted: add build option for log scopes
Now you can enable a set of log scopes by passing -Dlog=<scope>
2020-08-03 21:56:21 -07:00
Andrew Kelley
f1c1b8c02d stage2: add DWARF info for the main compilation unit 2020-07-31 06:48:17 +00:00
Andrew Kelley
aac6e8c418 self-hosted: AST flattening, astgen improvements, result locations, and more
* AST: flatten ControlFlowExpression into Continue, Break, and Return.
 * AST: unify identifiers and literals into the same AST type: OneToken
 * AST: ControlFlowExpression uses TrailerFlags to optimize storage
   space.
 * astgen: support `var` as well as `const` locals, and support
   explicitly typed locals. Corresponding Module and codegen code is not
   implemented yet.
 * astgen: support result locations.
 * ZIR: add the following instructions (see the corresponding doc
   comments for explanations of semantics):
   - alloc
   - alloc_inferred
   - bitcast_result_ptr
   - coerce_result_block_ptr
   - coerce_result_ptr
   - coerce_to_ptr_elem
   - ensure_result_used
   - ensure_result_non_error
   - ret_ptr
   - ret_type
   - store
   - param_type
 * the skeleton structure for result locations is set up. It's looking
   pretty clean so far.
 * add compile error for unused result and compile error for discarding
   errors.
 * astgen: split builtin calls up to implemented manually, and implement
   `@as`, `@bitCast` (and others) with respect to result locations.
 * add CLI support for hex and raw object formats. They are not
   supported by the self-hosted compiler yet, and emit errors.
 * rename `--c` CLI to `-ofmt=[objectformat]` which can be any of the
   object formats. Only ELF and C are supported so far. Also added missing
   help to the help text.
 * Remove hard tabs from C backend test cases. Shame on you Noam, you
   are grounded, you should know better, etc. Bad boy.
 * Delete C backend code and test case that relied on comptime_int
   incorrectly making it all the way to codegen.
2020-07-23 23:05:26 -07:00
pixelherodev
2c882b2e65
CBE: Make C an ObjectFormat instead of a special bool (#5849) 2020-07-12 22:56:31 -04:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Andrew Kelley
7bd0500589 Merge remote-tracking branch 'origin/master' into register-allocation 2020-07-08 20:46:06 -07:00
Noam Preil
e2aad33d4e
Stage2: facepalm. 2020-07-08 00:11:41 -04:00
Noam Preil
173e671241
CBE: Some cleanup 2020-07-07 23:11:17 -04:00
Noam Preil
b91cf15972
CBE: Move standards determination to generated code 2020-07-07 22:57:34 -04:00
Noam Preil
5461c482d0
CBE: Integrate into stage2 via --c-standard 2020-07-07 21:54:34 -04:00
Andrew Kelley
4d01385e14 fix liveness analysis and not correctly propagating link errors
We still flush the ELF file even when there are compile errors.
2020-07-07 03:48:20 +00:00
Andrew Kelley
8be8ebd698 stage2: skeleton codegen for x64 ADD
also rework Module to take advantage of the new hash map implementation.
2020-07-06 06:10:44 +00:00
Andrew Kelley
632acffcbd update std lib to new hash map API 2020-07-05 21:11:42 +00:00
Luna
f47c6d3c6b std.os: make EBADF return error for read and write 2020-06-28 18:40:43 -03:00
Andrew Kelley
20b4a2cf2c self-hosted: add compare output test for new AST->ZIR code 2020-06-24 21:28:42 -04:00
Andrew Kelley
5aa3f56773 self-hosted: fix test regressions
I'm allowing incremental compilation of ZIR modules to be broken. This
is not a real use case of ZIR, and the feature requires a lot of code
duplication with incremental compilation of Zig AST (which works great).
2020-06-24 20:28:52 -04:00
Andrew Kelley
14aa08fcd3 self-hosted: restore ZIR functionality 2020-06-24 03:46:32 -04:00
Andrew Kelley
b1b7708cc8 self-hosted: hook up incremental compilation to .zig source code 2020-06-23 23:29:51 -04:00
Andrew Kelley
6938245fcc Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-22 23:22:17 -04:00
Alexandros Naskos
b70c38c33c Close source file after reading it in zig fmt 2020-06-21 12:22:16 -04:00
Andrew Kelley
64dfd1883e zig fmt: avoid unnecessary file system access
zig fmt previously would write a temp file, and then either rename it
into place if necessary, or unlink it if nothing was changed. Now zig
fmt renders into a memory buffer, and only writes the temp file and
renames it into place if anything changed.

Based on the performance testing I did this actually did not have much
of an impact, however it's likely that on other operating systems and
other hard drives this could make a big difference.
2020-06-20 20:14:33 -04:00
Andrew Kelley
0a9672fb86 rework zig fmt to avoid unnecessary realpath() calls
* add `std.fs.Dir.stat`
 * zig fmt checks for sym link loops using inodes instead of using
   realpath
2020-06-20 19:46:14 -04:00
Andrew Kelley
d87cd06296 rework zig fmt to use less syscalls and open fds
* `std.fs.Dir.Entry.Kind` is moved to `std.fs.File.Kind`
 * `std.fs.File.Stat` gains the `kind` field, so performing a stat() on
   a File now tells what kind of file it is. On Windows this only will
   distinguish between directories and files.
 * rework zig fmt logic so that in the case of opening a file and
   discovering it to be a directory, it closes the file descriptor
   before re-opening it with O_DIRECTORY, using fewer simultaneous open
   file descriptors when walking a directory tree.
 * rework zig fmt logic so that it pays attention to the kind of
   directory entries, and when it sees a sub-directory it attempts to
   open it as a directory rather than a file, reducing the number of
   open() syscalls when walking a directory tree.
2020-06-20 18:27:37 -04:00
DrDeano
bc0ca73887 Moved the check for formatting a directory
The original check for a directory was for the `readAllAlloc` so move the check from open to read. This in turn fixes the fmt step in the build script for directories.
2020-06-20 17:25:12 -04:00
Andrew Kelley
f7bcc8e040 rework zig fmt to only make one allocation
taking advantage of the fstat size
2020-06-18 21:08:30 -04:00
Cassidy Dingenskirchen
b30642a86a Fix zig fmt clobbering a file's mode 2020-06-18 20:41:40 -04:00
Andrew Kelley
b4eac0414a stage2: hook up Zig AST to ZIR
* Introduce the concept of anonymous Decls
 * Primitive Hello, World with inline asm works
 * There is still an unsolved problem of how to manage ZIR instructions
   memory when generating from AST. Currently it leaks.
2020-06-18 17:12:56 -04:00
Andrew Kelley
91930a4ff0 stage2: fix not re-loading source file for updates after errors 2020-06-08 15:16:40 -04:00
Andrew Kelley
1a90a5e63a translate-c is building again, but I have 1 @panic in there 2020-05-23 16:24:03 -04:00
Andrew Kelley
8c10178a1e golly jeepers it's taking a long time to update translate-c 2020-05-20 13:53:53 -04:00
Andrew Kelley
017ecc5148 self hosted repl: close executables between updates
This allows the executable to be executed
2020-05-16 15:44:20 -04:00
Andrew Kelley
b0375978ba self-hosted: remove zig libc command for now
Since it depends on the C++ Windows SDK code. For now, self-hosted is
staying pure self hosted, no C/C++ components.
2020-05-16 13:25:39 -04:00
Andrew Kelley
294bfb3321 stage2 zir tests passing 2020-05-15 23:54:13 -04:00