941 Commits

Author SHA1 Message Date
Noam Preil
2f28ecf946
CBE: Get test more useful 2020-07-07 17:06:07 -04:00
Noam Preil
aaaebfe97f
Detect unexpected compilation errors in tests 2020-07-07 16:47:39 -04:00
Noam Preil
a17200dab1
CBE skeleton 2020-07-07 16:40:14 -04:00
Noam Preil
b4c571301b
Stage2: Refactor in preparation for C backend 2020-07-07 14:55:44 -04:00
Noam Preil
0db0258fb2
Remove old comment 2020-07-06 17:54:06 -04:00
Andrew Kelley
abcd4ea5d8
Merge pull request #5793 from pfgithub/stage-2-testing
stage2 + operator and @as builtin
2020-07-05 22:58:05 +00:00
emekoi
68be229917 added custom format method for WindowsVersion 2020-07-05 22:43:10 +00:00
Andrew Kelley
3a89f214aa update more HashMap API usage 2020-07-05 21:11:42 +00:00
Andrew Kelley
632acffcbd update std lib to new hash map API 2020-07-05 21:11:42 +00:00
pfg
d4456d92f5 stage2: builtin @as 2020-07-04 15:16:46 -07:00
pfg
1d52438bd5 stage2: InfixOp add 2020-07-04 15:16:46 -07:00
Ian Simonson
70cc1751ca Translate-c fix rhs not cast on array access
Closes #5671. Checks if the rhs is integral and of
differing or the same signedness. If they are different
does an @intCast to the lhs type
2020-07-02 14:05:12 +00:00
Andrew Kelley
1eed0cf0f3 zig fmt and delete unused type 2020-06-28 19:45:10 -04:00
Andrew Kelley
aa92446365 stage2: implement function parameters
In codegen.zig, the std.Target.Cpu.Arch is now generally available as a
comptime value where needed. This is a tradeoff that causes the compiler
binary to be more bloated, but gives us higher performance, since the
optimizer can optimize per architecture (which is usually how compilers
are designed anyway, with different code per-architecture), and it also
allows us to use per-architecture types, such as a Register enum that is
specific to the comptime-known architecture.

Adds abiSize method to Type.
2020-06-28 19:45:10 -04:00
Andrew Kelley
ac6bf53069
stage2: clean up test harness, implement symbol collision detection (#5708)
* Clean up test harness
* Stage2/Testing: Add convenience wrappers
* Add a `compiles` wrapper case
* fix incremental compilation after error
* exported symbol collision detection
* function redefinition detection for Zig code
* handle missing function names
* Stage2/Testing: Simplify incremental compilation tests
* Stage2/Testing: Update documentation
* Stage2/TestHarness: Improve progress reporting
* Disable test
* Improve Tranform failure output
2020-06-27 21:54:11 -04:00
Noam Preil
80b70470c0
Stage2/Module: Add symbol -> export lookup table 2020-06-27 21:50:59 -04:00
Noam Preil
ffca1569d1
Return instead of branch 2020-06-27 21:39:39 -04:00
Noam Preil
38d2c5cdf1
Rename type -> extension 2020-06-27 21:39:04 -04:00
Noam Preil
1861c25142
Improve Tranform failure output 2020-06-27 21:15:23 -04:00
Noam Preil
97c41e7152
Disable test 2020-06-27 21:10:44 -04:00
Noam Preil
54148a8c88
Stage2/TestHarness: Improve progress reporting 2020-06-27 20:01:20 -04:00
Noam Preil
ab307a22f6
Stage2: remove clearErrors, fix ZIR export collision detection 2020-06-27 07:17:20 -04:00
Noam Preil
52787f2c9b
Fix a dumb 2020-06-26 06:52:29 -04:00
Noam Preil
6d536168b0
Stage2/Testing: Update documentation 2020-06-26 06:51:35 -04:00
Noam Preil
0e952a9f3a
Stage2/Testing: Simply incremental compilation tests 2020-06-26 05:00:53 -04:00
Noam Preil
c8f60b2e2f
Stage2: handle missing function names 2020-06-26 04:36:17 -04:00
Noam Preil
6510888039
Stage2: function redefinition detection for Zig code 2020-06-26 04:05:41 -04:00
Noam Preil
4a17e008da
Stage2: exported symbol collision detection 2020-06-26 03:17:13 -04:00
Noam Preil
e5a3cb8d71
Stage2: fix incremental compilation after error 2020-06-26 03:16:36 -04:00
Noam Preil
53fead580e
Add a compiles wrapper case 2020-06-26 03:09:56 -04:00
Noam Preil
649da2df52
Stage2/Testing: Add convenience wrappers 2020-06-26 02:42:02 -04:00
Andrew Kelley
130c7fd23b self-hosted: working towards conditional branching test case
New features:
 * Functions can have parameters in semantic analysis. Codegen
   is not implemented yet.
 * Support for i8, i16, i32, i64, u8, u16, u32, u64 primitive
   identifiers.
 * New ZIR instructions: arg, block, and breakvoid

Implementation details:

 * Move Module.Body to ir.Body
 * Scope.Block gains a parent field and an optional Label field
 * Fix bug in integer type equality comparison.

Here's the test case I'm working towards:

```
@void = primitive(void)
@i32 = primitive(i32)
@fnty = fntype([@i32, @i32], @void)

@0 = str("entry")
@1 = export(@0, "entry")

@entry = fn(@fnty, {
  %0 = arg(0)
  %1 = arg(1)
  %2 = add(%0, %1)
  %3 = int(7)
  %4 = block("if", {
    %neq = cmp(%2, neq, %3)
    %5 = condbr(%neq, {
      %6 = unreachable()
    }, {
      %7 = breakvoid("if")
    })
  })
  %11 = returnvoid()
})
```

$ ./zig-cache/bin/zig build-obj test.zir
test.zir:9:12: error: TODO implement function parameters for Arch.x86_64

That's where I left off.
2020-06-26 02:30:14 -04:00
Noam Preil
c88edbc46f
OOM -> catch unreachable 2020-06-24 23:34:58 -04:00
Noam Preil
5d7e981f95
Clean up test harness 2020-06-24 22:43:18 -04: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
fd7a97b3b2 fix memory leak of anonymous decl name 2020-06-24 16:20:02 -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
d9c1d8fed3 self-hosted: improve handling of anonymous decls
* anonymous decls have automatically generated names and symbols, and
   participate in the same memory management as named decls.
 * the Ref instruction is deleted
 * the DeclRef instruction now takes a `[]const u8` and DeclRefStr takes
   an arbitrary string instruction operand.
 * introduce a `zir.Decl` type for ZIR Module decls which holds
   content_hash and name - fields that are not needed for `zir.Inst`
   which are created as part of semantic analysis. This improves the
   function signatures of Module.zig and lowers memory usage.
 * the Str instruction is now defined to create an anonymous Decl and
   reference it.
2020-06-23 19:53:32 -04:00
Andrew Kelley
6938245fcc Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-22 23:22:17 -04:00
Vexu
7b68385d7d self-hosted: astGenIntegerLiteral support other bases 2020-06-22 23:19:12 -04:00
Vexu
d98aed6eff self-hosted: generalize astGenBuiltinCall 2020-06-22 23:19:12 -04:00
Andrew Kelley
44bd0a2670
Merge pull request #5662 from shtanton/meta-cast
Adds std.meta.cast and uses it to simplify translate-c
2020-06-22 19:54:30 -04:00
Charlie Stanton
8c15cfe3da Compacts switch statements and string literal 2020-06-21 21:48:12 +01:00
Charlie Stanton
6f47513009 Adds std.meta.cast and uses it to simplify translate-c 2020-06-21 18:24:59 +01: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