Commit Graph

527 Commits (9a0a378e2f957f6acf5fbb37818d1cc0e3a38d33)

Author SHA1 Message Date
Vexu 75218d4765
translate-c-2 macros 2019-12-15 14:44:11 +02:00
Vexu c3724a6e72
translate-c-2 c tokenizer 2019-12-15 10:30:38 +02:00
Vexu e57e3602e7
translate-c-2 implement enums 2019-12-14 23:24:47 +02:00
Vexu 1a967db083
add default initializers to all ast.Node base values 2019-12-14 20:40:56 +02:00
Vexu 1f84586836
translate-c-2 avoid collisions with zig keywords 2019-12-14 17:00:10 +02:00
Vexu 4dae70e702
translate-c-2 container aliases 2019-12-14 13:40:33 +02:00
Vexu a4ac6d15c4
translate-c-2 array initializer expr 2019-12-14 10:49:25 +02:00
Vexu e4ca1f441b
translate-c-2 record type 2019-12-14 02:00:01 +02:00
Vexu 41a67126a5
translate-c-2 typedef 2019-12-13 17:40:37 +02:00
Vexu eb057ef41c
translate-c-2 dont eval init expr 2019-12-13 15:07:10 +02:00
Vexu 0795f17db2
translate-c-2 incompleteArray 2019-12-12 21:39:04 +02:00
Vexu 48ac84db1b
translate-c-2 translate apvalue 2019-12-12 20:35:40 +02:00
Vexu 3bca025091
update tests 2019-12-12 18:18:43 +02:00
Vexu ef361161e2
translate-c-2 add var decl 2019-12-12 16:12:19 +02:00
Vexu 69dee57d95
remove concept of translate mode 2019-12-12 14:26:24 +02:00
Merlyn Morgan-Graham 12171dba92 Add function parameters to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham fe415dae04 Add paren expression statements to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham 3e4f5de33c Add rem binary operator to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham 79fe7e6515 Add mul and div binary operators to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Andrew Kelley 7c1dbfab72
self-hosted: manually parse args 2019-12-11 02:08:33 -05:00
Robin Voetter 4b4fbe3887
Replace @typeOf with @TypeOf in all zig source
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-10 11:09:41 -05:00
Robin Voetter c519bb02df
Fix usage of freed memory in zig fmt 2019-12-10 11:09:29 -05:00
Andrew Kelley a3f6a58c77
remove var args from the language
closes #208
2019-12-09 15:27:27 -05:00
Andrew Kelley f205d23e65
implement async function call with `@call`
this removes the last usage of var args in zig std lib
2019-12-09 15:27:26 -05:00
Andrew Kelley 03396b3caa
update docs to new fmt API 2019-12-08 23:46:50 -05:00
Andrew Kelley fe4963412f
update self-hosted compiler to new format API 2019-12-08 23:17:03 -05:00
Andrew Kelley 8b2622cdd5
std.fmt.format: tuple parameter instead of var args 2019-12-08 22:53:51 -05:00
Andrew Kelley 525b1e8fb4
Merge pull request #3856 from ziglang/builtin-call
introduce `@call` and remove other builtin calls
2019-12-06 15:49:47 -05:00
Andrew Kelley 71b7f4b47f
remove `@newStackCall` from zig 2019-12-06 14:52:09 -05:00
Andrew Kelley 1f602fe8c5
implement `@call`
closes #3732
2019-12-05 17:07:15 -05:00
Andrew Kelley 10e172b1d7
add `other` OS and fix regression in build-exe for freestanding 2019-12-04 14:42:40 -05:00
Andrew Kelley dcbd5ad155
remove upstream support for Zen hobby OS
The new plan to support hobby operating systems is #3784.

And what kind of name is "Zen" anyway? There's already a
[Zen programming language](http://zenlang.sourceforge.net/)
and that's just confusing.
2019-12-02 12:01:49 -05:00
Andrew Kelley 4af5c38674
fixes for self-hosted compiler 2019-12-01 19:22:03 -05:00
Andrew Kelley b36c07a95a
Merge remote-tracking branch 'origin/master' into remove-array-type-coercion 2019-12-01 09:56:01 -05:00
Andrew Kelley 413f9a5cfc
move `std.fs.Dir.cwd` to `std.fs.cwd`
update to non-deprecated std.fs APIs throughout the codebase

Related: #3811
2019-11-30 15:35:27 -05:00
Andrew Kelley 85e1e3b95f
Merge pull request #3284 from Sahnvour/export_variables
Improved support for exporting variables
2019-11-30 00:25:52 -05:00
Andrew Kelley 6936243ee1
fix self-hosted compiler regressions 2019-11-29 21:49:08 -05:00
Andrew Kelley bf3ac66150
remove type coercion from array values to references
* Implements #3768. This is a sweeping breaking change that requires
   many (trivial) edits to Zig source code. Array values no longer
   coerced to slices; however one may use `&` to obtain a reference to
   an array value, which may then be coerced to a slice.

 * Adds `IrInstruction::dump`, for debugging purposes. It's useful to
   call to inspect the instruction when debugging Zig IR.

 * Fixes bugs with result location semantics. See the new behavior test
   cases, and compile error test cases.

 * Fixes bugs with `@typeInfo` not properly resolving const values.

 * Behavior tests are passing but std lib tests are not yet. There
   is more work to do before merging this branch.
2019-11-27 03:37:50 -05:00
Vexu 4d8a8e65df
add more workarounds 2019-11-27 10:17:37 +02:00
Vexu 0d55075de4
fix command functions not being async pointers 2019-11-26 22:38:05 +02:00
Vexu 798d05dd02
add workaround for #3190 2019-11-26 22:11:04 +02:00
Vexu 128034481a
solve recursion in self hosted 2019-11-26 18:25:29 +02:00
Vexu 36849d8a7b
fixes and cleanup in self hosted 2019-11-26 11:52:12 +02:00
Jonathan S 4014a8e4b4 Avoid deprecated cwd-based functions for opening directories, preferring to open explicitly relative to `Dir.cwd()`. 2019-11-25 23:46:48 -05:00
Andrew Kelley cb38bd0a14
rename std.heap.direct_allocator to std.heap.page_allocator
std.heap.direct_allocator is still available for now but it is marked
deprecated.
2019-11-25 17:25:06 -05:00
Andrew Kelley 15d415e10b
make std.mem.toSlice use null terminated pointers
and fix the fallout
2019-11-24 21:21:05 -05:00
Andrew Kelley 34b1ebefaa
Merge remote-tracking branch 'origin/master' into null-terminated-pointers 2019-11-24 20:28:46 -05:00
Sahnvour 696567d9d7 export: check variable type
also fixed existing occurrences
2019-11-24 21:33:58 +01:00
Vexu 0cbf00a3ec
self hosted compiler: final small fixes to get it compiling 2019-11-24 10:24:47 +02:00
Andrew Kelley 00878a15d7
zig fmt: support sentinel-terminated pointer syntax 2019-11-23 22:21:25 -05:00
Vexu 010494d8af
only test stage2 on linux 2019-11-23 23:45:54 +02:00
Vexu b9ef36094c
re-enable stage2 tests 2019-11-23 22:57:34 +02:00
Vexu d40f204ec0
self hosted compiler: small miscellaneous fixes 2019-11-23 21:57:24 +02:00
Vexu 133579d7c0
fix casts 2019-11-23 19:36:26 +02:00
Vexu 03cc81665b
Merge branch 'master' into modernize-stage2 2019-11-23 19:13:48 +02:00
Andrew Kelley fd6020c4e2
update tests, better error messages, update self-hosted tokenizer 2019-11-21 20:43:41 -05:00
Andrew Kelley 47f06be369
string literals are now null terminated
this also deletes C string literals from the language, and then makes
the std lib changes and compiler changes necessary to get the behavior
tests and std lib tests passing again.
2019-11-21 20:43:41 -05:00
Andrew Kelley 21f344b3b9
add null terminated pointers and arrays to self-hosted
as well as `@typeInfo` and `@Type`
2019-11-21 20:43:41 -05:00
daurnimator ed956b5812 translate-c: add support for MacroQualified definitions 2019-11-19 01:05:17 +00:00
Vexu b92f42d1f4
implemented container doc comments in stage 2 2019-11-14 16:25:06 +02:00
Andrew Kelley 0237e7a701 std.io.getStdOut and related fns no longer can error
Thanks to the Windows Process Environment Block, it is possible to
obtain handles to the standard input, output, and error streams without
possibility of failure.
2019-11-13 04:01:40 +00:00
Andrew Kelley 3cf5c2c62b
fix regressed tests and update docs to use "type coercion" 2019-11-08 15:57:25 -05:00
Andrew Kelley aa0daea541
update more of the std lib to use `@as` 2019-11-08 15:57:25 -05:00
Vexu 86d9563d15
self hosted compiler: various small fixes 2019-11-08 00:18:14 +02:00
Vexu bca672372a
self hosted compiler: move functions to util.zigto avoid defining llvm instricts. 2019-11-07 23:03:57 +02:00
Vexu 56ea07f4fc
self hosted compiler: comment out event.fs stuff 2019-11-07 10:30:56 +02:00
Vexu 7a24334199
self hosted compiler: small fixes to imports and declarations 2019-11-07 10:30:56 +02:00
Vexu c6076a1360
self hosted compiler: use enum literals 2019-11-07 10:30:56 +02:00
Vexu 7000316113
self hosted compiler: fix calling convention in type.zig 2019-11-07 10:30:47 +02:00
Vexu 9394d14815
self hosted compiler: unify Target and std.Target 2019-11-07 10:30:47 +02:00
Vexu 6dd4a276de
self hosted compiler: update to new std.event 2019-11-07 10:30:37 +02:00
Vexu 110e575497
self hosted compiler: replace Promise with Frame and AnyFrame 2019-11-07 10:30:21 +02:00
Vexu cb20093614
self hosted compiler: remove await async pattern 2019-11-07 10:30:11 +02:00
Vexu b06e5b8c68
self hosted compiler: fix internal build info 2019-11-07 10:29:58 +02:00
Andrew Kelley c3d816a98e
std lib networking improvements, especially non-blocking I/O
* delete the std/event/net directory
 * `std.event.Loop.waitUntilFdReadable` and related functions
   no longer have possibility of failure. On Linux, they fall
   back to poll() and then fall back to sleep().
 * add some missing `noasync` decorations in `std.event.Loop`
 * redo the `std.net.Server` API. it's quite nice now, but
   shutdown does not work cleanly. There is a race condition with
   close() that I am actively working on.
 * move `std.io.OutStream` to its own file to match `std.io.InStream`.
   I started working on making `write` integrated with evented I/O,
   but it got tricky so I backed off and filed #3557. However
   I did integrate `std.os.writev` and `std.os.pwritev` with evented I/O.
 * add `std.Target.stack_align`
 * move networking tests to `lib/std/net/test.zig`
 * add `std.net.tcpConnectToHost` and `std.net.tcpConnectToAddress`.
 * rename `error.UnknownName` to `error.UnknownHostName` within the
   context of DNS resolution.
 * add `std.os.readv`, which is integrated with evented I/O.
 * `std.os.preadv`, is now integrated with evented I/O.
 * `std.os.accept4` now asserts that ENOTSOCK and EOPNOTSUPP never
    occur (misuse of API), instead of returning errors.
 * `std.os.connect` is now integrated with evented I/O.
   `std.os.connect_async` is gone. Just use `std.os.connect`.
 * fix false positive dependency loop regarding async function frames
 * add more compile notes to help when dependency loops occur
   in determining whether a function is async.
 * ir: change an assert to ir_assert to make it easier to find
   workarounds for when such an assert is triggered. In this case
   it was trying to parse an IPv4 address at comptime.
2019-10-29 22:59:30 -04:00
Andrew Kelley 845be4ea3e
fix regression in translate-c 2019-10-28 15:29:50 -04:00
Andrew Kelley 4b80e376e3
std.net.getAddressList 2019-10-28 15:29:50 -04:00
Andrew Kelley 79cb383f7d
fix 32-bit build of translate_c.zig 2019-10-24 19:46:11 -04:00
Andrew Kelley 17eb24a7e4
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
  `@import("std").builtin`. The target-related types are moved
  to `std.Target`. This allows the data types to have methods, such as
  `std.Target.current.isDarwin()`.
 * `std.os.windows.subsystem` is moved to
   `std.Target.current.subsystem`.
 * Remove the concept of the panic package from the compiler
   implementation. Instead, `std.builtin.panic` is always the panic
   function. It checks for `@hasDecl(@import("root"), "panic")`,
   or else provides a default implementation.

This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 19:09:49 -04:00
Andrew Kelley f65b1d4680
integrate stage1 progress display with semantic analysis 2019-10-22 17:52:12 -04:00
Andrew Kelley 5b1a492012
breaking: improve std.fs directory handling API
* Added `std.c.unlinkat` and `std.os.unlinkat`.
 * Removed `std.fs.MAX_BUF_BYTES` (this declaration never made it to
   master branch)
 * Added `std.fs.Dir.deleteTree` to be used on an open directory handle.
 * `std.fs.deleteTree` has better behavior for both relative and
   absolute paths. For absolute paths, it opens the base directory
   and uses that handle for subsequent operations. For relative paths,
   it does a similar strategy, using the cwd handle.
 * The error set of `std.fs.deleteTree` is improved to no longer have
   these possible errors:
   - OutOfMemory
   - FileTooBig
   - IsDir
   - DirNotEmpty
   - PathAlreadyExists
   - NoSpaceLeft
 * Added `std.fs.Dir.posix_cwd` which is a statically initialized
   directory representing the current working directory.
 * The error set of `std.Dir.open` is improved to no longer have these
   possible errors:
   - FileTooBig
   - IsDir
   - NoSpaceLeft
   - PathAlreadyExists
   - OutOfMemory
 * Added more alternative functions to `std.fs` for when the path
   parameter is a null terminated string. This can sometimes be more
   effecient on systems which have an ABI based on  null terminated
   strings.
 * Added `std.fs.Dir.openDir`, `std.fs.Dir.deleteFile`, and
   `std.fs.Dir.deleteDir` which all operate on an open directory handle.
 * `std.fs.Walker.Entry` now has a `dir` field, which can be used to do
   operations directly on `std.fs.Walker.Entry.basename`, avoiding
   `error.NameTooLong` for deeply nested paths.
 * Added more docs to `std.os.OpenError`

This commit does the POSIX components for these changes. I plan to
follow up shortly with a commit for Windows.
2019-10-20 21:48:23 -04:00
stratact e78d3750c5
Use 8192 sized buffers and remove allocator parameters 2019-10-19 14:04:51 -04:00
Andrew Kelley 2d5b2bf1c9
improve progress reporting
* use erase rest of line escape code.
 * use `stderr.supportsAnsiEscapeCodes` rather than `isTty`.
 * respect `--color off`
 * avoid unnecessary recursion
 * add `Progress.log`
 * disable the progress std lib test since it's noisy and uses
   `time.sleep()`.
 * enable/integrate progress printing with the default test runner
2019-10-17 21:55:49 -04:00
Andrew Kelley 299991019d
rework the progress module and integrate with stage1 2019-10-17 20:20:22 -04:00
Andrew Kelley 185cb13278
Merge remote-tracking branch 'origin/master' into llvm9 2019-09-10 13:00:35 -04:00
Sahnvour f08c6e4fe6 changing occurrences of HashMap with []const u8 as keys for StringHashMap 2019-09-03 23:53:05 +02:00
Andrew Kelley 6529658ad8
Merge remote-tracking branch 'origin/master' into llvm9 2019-08-16 16:43:56 -04:00
Vexu 2151f84d59 implement new async syntax in self-hosted compiler 2019-08-16 06:17:28 -07:00
Andrew Kelley 13b5a4bf8c
remove `cancel` 2019-08-15 14:05:12 -04:00
Andrew Kelley 5092634103
avoid the word "coroutine", they're "async functions" 2019-08-13 14:14:19 -04:00
Andrew Kelley 54e716afdc
remove coroutines implementation and promise type 2019-07-19 18:18:44 -04:00
Andrew Kelley e816d592e8
update zig codebase to llvm 9 2019-07-17 17:47:39 -04:00
emekoi 0435026474 fixed size of ZigClangAPValue on mingw-w64 2019-07-16 09:34:02 -04:00
Andrew Kelley 6fe3b20962
Merge branch 'translate-c-userland' of https://github.com/hryx/zig into hryx-translate-c-userland 2019-07-15 22:19:54 -04:00
Andrew Kelley 4f43a4b30f
zig fmt: fix whitespace
closes #2819
closes #2825
2019-07-05 14:46:21 -04:00
Andrew Kelley 2f4faf306d
Merge branch 'function-sections' of https://github.com/timonkruiper/zig into timonkruiper-function-sections 2019-07-03 14:43:33 -04:00
Timon Kruiper bbc0d440b8 Added ZigLLVMCreateTargetMachine and pass function-sections flag
Also added extra cache line

Added the ZigLVVMCreateTargetMachine to self hosted zig code
2019-07-02 19:54:29 +02:00
Andrew Kelley 7d4a0cfed0
enable segfault stack traces in stage1 compiler 2019-07-02 13:41:17 -04:00
Timon Kruiper 7586f613d5 Added function-section functionality 2019-07-01 17:49:08 +02:00
hryx 0e38f7215b
Define different struct size for APValue on Windows (thanks @Sahnvour) 2019-06-29 14:34:00 -07:00
hryx 247e567422
Don't return a slice pointing to a deceased stack address 2019-06-28 18:01:41 -07:00
hryx 102bf5200c
Fix string literal: not null-terminated (thanks @mikdusan) 2019-06-28 17:40:20 -07:00
hryx cc74bf5136
Translate IntegralCast; add stage2 test coverage 2019-06-27 23:12:33 -07:00
hryx 646268875e
Use new width format option 2019-06-27 22:16:31 -07:00
hryx 2060c7c39b
Merge branch 'master' into translate-c-userland 2019-06-27 22:12:34 -07:00
hryx 3e0ff32bd8
Separate with space instead of LF to prevent rendering excessive indentation 2019-06-27 21:17:27 -07:00
hryx b4bd52cc51
Create and render big.Int from IntegerLiteral; group BinaryOperator 2019-06-27 21:02:48 -07:00
Marc Tiehuis f5af349bd6
Merge pull request #2714 from ziglang/fmt-overhaul
Add positional, precision and width support to std.fmt
2019-06-25 20:15:33 +12:00
hryx 8435351581
Escape C string literals 2019-06-24 22:37:19 -07:00
hryx f845994839
transBinaryOperator: Add, Sub 2019-06-23 17:17:21 -07:00
hryx 69b90e0681
transStringLiteral 2019-06-23 15:06:16 -07:00
hryx b2e06c3bf4
Observe translate mode in stage2 2019-06-23 14:32:45 -07:00
hryx c423697c78
Merge branch 'master' into translate-c-userland 2019-06-23 12:31:22 -07:00
hryx 1c86a191da
Fix order of tokens; omit 'pub' for fn types 2019-06-23 01:03:28 -07:00
hryx 4c8b460fec
Fix recursive self-referential block 2019-06-22 22:30:15 -07:00
hryx 4ae95d7ffc
Translate assignment BinaryOperator statements 2019-06-22 17:29:36 -07:00
hryx 6325ffc3f1
Assign undefined literal (instead of null) when no init value 2019-06-22 17:29:10 -07:00
Sahnvour 987c209b40 heap: make one global instance of DirectAllocator
it is now stateless, so the de/init are not necessary anymore
2019-06-22 14:10:53 -04:00
Marc Tiehuis 11526b6e9d breaking: Add positional, precision and width support to std.fmt
This removes the odd width and precision specifiers found and replacing
them with the more consistent api described in #1358.

Take the following example:

    {1:5.9}

This refers to the first argument (0-indexed) in the argument list. It
will be printed with a minimum width of 5 and will have a precision of 9
(if applicable).

Not all types correctly use these parameters just yet. There are still
some missing gaps to fill in. Fill characters and alignment have yet to
be implemented.
2019-06-21 20:11:15 +12:00
hryx 0f545e5a2b
transReturnStmt 2019-06-10 23:06:54 -07:00
hryx 84e479d94f
(broken) local var decls, integer literals (part) 2019-06-09 23:35:48 -07:00
daurnimator ed41d10a06
std: existing LinkedList is actually a TailQueue 2019-06-10 15:41:40 +10:00
Andrew Kelley b735764898
different array literal syntax when inferring the size
old syntax:  []i32{1, 2, 3}
new syntax: [_]i32{1, 2, 3}

closes #1797
2019-06-09 19:26:32 -04:00
hryx 586c36dd1d
Restore fn decls removed during conflict 2019-06-08 17:02:00 -07:00
hryx ad0f0562d8
Merge branch 'master' into translate-c-userland 2019-06-08 16:23:27 -07:00
hryx ed5b8335b5
(broken) translate Paren type 2019-06-08 16:09:25 -07:00
hryx 1692a76d28
transImplictCastExpr: LValueToRValue 2019-06-08 15:57:43 -07:00
hryx 1f82c7ba22
transCStyleCastExpr 2019-06-08 15:54:15 -07:00
Andrew Kelley 5784631fab
update the default macos version min to 10.14 2019-06-07 12:20:02 -04:00
Andrew Kelley 7878f9660f
dep tokenizer: run zig fmt and move exports to canonical location 2019-05-30 12:07:55 -04:00
Andrew Kelley 5954d5235f
Merge pull request #2182 from mikdusan/issue.2046
new .d file parser for stage1 compiler
2019-05-30 11:53:08 -04:00
Andrew Kelley bfc86776d5
run zig fmt to update `use` to `usingnamespace` 2019-05-29 19:09:58 -04:00
hryx 3e14f86f9e
Implement missing clang functions from last commit 2019-05-29 15:33:44 -07:00
Michael Dusan 2975bdc684
add review changes
- use std.heap.c_allocator
- use @panic instead of unreachable
- use extern enum for tokenizer result type
2019-05-29 14:39:13 -04:00
Gonzalo Diethelm 6547468af6 clang.zig cleanup #9: rename arg0 to self 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm 8d50d4f3fc clang.zig cleanup #8: add missing consts 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm b639447263 clang.zig cleanup #7: add missing struct 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm f4b4ea402e clang.zig cleanup #6: move block around 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm fd9e63da53 clang.zig cleanup #5: add missing enums 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm 7f1dd05fa7 clang.zig cleanup #4: move block around 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm 5df2e791c2 clang.zig cleanup #3: move block around 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm abf97cc232 clang.zig cleanup #2: move block around 2019-05-28 18:05:08 +02:00
Gonzalo Diethelm 333c050a1d clang.zig cleanup #1: move block around 2019-05-28 18:05:07 +02:00
Gonzalo Diethelm 775a25b7fd Add declarations missing from clang.zig 2019-05-28 18:05:07 +02:00
hryx e632c2ade3
(broken) port a bunch of stuff from stage1 translate-c 2019-05-27 23:55:48 -07:00
hryx b558d0996a
expr: DeclRefExpr 2019-05-27 19:20:23 -07:00
hryx e07888e54c
expr: FunctionToPointerDecay & ArrayToPointerDecay for ImplicitCastExpr 2019-05-27 18:18:27 -07:00
hryx 22299869ba
Prevent infinite recursion 2019-05-27 17:54:40 -07:00
hryx e1f3eec9cc
Merge branch 'master' into translate-c-userland 2019-05-27 17:24:21 -07:00
Andrew Kelley 3fccc07479
self-hosted translate-c: fix bad memory arena references 2019-05-27 20:22:15 -04:00
Michael Dusan d4b241c14e
new .d file parser for C compilation
- wip for #2046
- clang .d output must be created with `clang -MV` switch
- implemented in Zig
- hybridized for zig stage0 and stage1
- zig test src-self-hosted/dep_tokenizer.zig
2019-05-27 19:47:10 -04:00
hryx 2aa1c5da5d
Remove unused local struct type 2019-05-27 15:58:21 -07:00
hryx 3bbee1ba2e
expr: BitCast for ImplicitCastExpr 2019-05-27 14:38:09 -07:00
Andrew Kelley 0c6ab61b22
tests passing on linux 2019-05-26 23:35:26 -04:00
hryx 9c437f9032
var decl: ImplicitCastExpr 2019-05-26 19:14:50 -07:00
hryx 1a8f8c6262
var decl: init node 2019-05-26 17:36:47 -07:00
hryx c79b8aeaef
var decl: threadlocal 2019-05-26 17:05:49 -07:00
hryx 99f0b28d39
var decl: mut_token, create child scope 2019-05-26 16:51:25 -07:00
hryx fceedada5c
WIP translate var decl 2019-05-26 15:43:13 -07:00
Andrew Kelley 2f040a23c8
clean up references to os 2019-05-26 18:32:44 -04:00
Andrew Kelley 5a57610039
clean up code now that #769 is implemented 2019-05-14 19:23:31 -04:00
hryx 3a3a738478
Recursive rewrite of stage2 parser, part 3 2019-05-12 02:01:45 -07:00
Andrew Kelley 10e9d47b49
stage2 translate-c: implement functions with no prototype
stage1 translate-c actually has this wrong. When exporting a function,
it's ok to use empty parameters. But for prototypes, "no prototype"
means that it has to be emitted as a function that accepts anything,
e.g. extern fn foo(...) void;

See #1964
2019-05-11 12:09:11 -04:00
Andrew Kelley 5f4c3e6557
stage2 translate-c: simple function definitions
See #1964
2019-05-10 23:35:46 -04:00
Andrew Kelley dbb5da14f4
stage2 translate-c: builtin types and pub
See #1964
2019-05-10 17:56:00 -04:00
Andrew Kelley 82219b1fd5
translate-c: better handling of restore points 2019-05-10 17:44:47 -04:00
Andrew Kelley a6f7a9ce2b
translate-c: we have our first test of self-hosted
See #1964
2019-05-10 16:03:54 -04:00
Andrew Kelley 1c0223899c
translate-c: progress on self-hosted function prototypes
See #1964
2019-05-10 01:24:00 -04:00
Andrew Kelley eea2de108d
translate-c: progress on self-hosted function prototypes
See #1964
2019-05-09 16:52:30 -04:00
Andrew Kelley 46e1c34fcf
self-hosted translate-c progress on function decls
See #1964
2019-05-08 22:05:59 -04:00
Andrew Kelley 9bbd71c9ab
add --bundle-compiler-rt function to link options
and use it when building libuserland.a

The self-hosted part of stage1 relies on zig's compiler-rt, and so we
include it in libuserland.a.

This should potentially be the default, but for now it's behind a linker
option.

self-hosted translate-c: small progress on translating functions.
2019-05-08 20:51:49 -04:00
Andrew Kelley a7f99c8ee9
self-hosted translate-c: iterate over top level decls
See #1964
2019-04-30 00:21:45 -04:00
Shritesh Bhattarai d02489fd9a fix missing semicolon 2019-04-26 21:01:20 -04:00
Andrew Kelley 2d6520d5d4
zig fmt is built directly into stage1 rather than child process
Previously, `zig fmt` on the stage1 compiler (which is what we currently
ship) would perform what equates to `zig run std/special/fmt_runner.zig`

Now, `zig fmt` is implemented with the hybrid zig/C++ strategy outlined
by #1964.

This means Zig no longer has to ship some of the stage2 .zig files, and
there is no longer a delay when running `zig fmt` for the first time.
2019-04-26 20:46:28 -04:00
Andrew Kelley 28071ac637
self-hosted translate-c emits a hello world AST
Also breaking std lib API change: the return value of
std.zig.parse returns `*ast.Tree` rather than `ast.Tree`.

See #1964
2019-04-26 15:43:36 -04:00
Andrew Kelley 535d419590
translate-c: self-hosted implementation can detect C errors
See #1964
2019-04-25 00:06:58 -04:00
Andrew Kelley 712274997e
translate-c: unify API for self-hosted and C++ translate-c
See #1964
2019-04-25 00:06:57 -04:00
Andrew Kelley 976080462c
translate-c: a little closer to self-hosted implementation 2019-04-25 00:06:54 -04:00
Andrew Kelley ff3cdbc3a0
stage1 assertions always on, and have stack traces 2019-04-17 15:58:20 -04:00
Andrew Kelley 89763c9a0d
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.

Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.

Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.

Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.

As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).

This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.

This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.

See #1964
2019-04-16 19:12:20 -04:00
Marc Tiehuis 78af62a19a Pack big.Int sign and length fields
This effectively takes one-bit from the length field and uses it as the
sign bit. It reduces the size of an Int from 40 bits to 32 bits on a
64-bit arch.

This also reduces std.Rational from 80 bits to 64 bits.
2019-04-11 19:36:35 +12:00
Andrew Kelley d0551db5cd
introduce the enum literal type
see #683
2019-03-24 00:44:18 -04:00
Andrew Kelley 64dddd7afe
add compile error for ignoring error
closes #772
2019-03-23 19:33:00 -04:00
Andrew Kelley a581f4f0e2
Merge remote-tracking branch 'origin/master' into llvm8 2019-03-18 20:03:23 -04:00
Andrew Kelley 9c13e9b7ed
breaking changes to std.mem.Allocator interface API
Before, allocator implementations had to provide `allocFn`,
`reallocFn`, and `freeFn`.

Now, they must provide only `reallocFn` and `shrinkFn`.
Reallocating from a zero length slice is allocation, and
shrinking to a zero length slice is freeing.

When the new memory size is less than or equal to the
previous allocation size, `reallocFn` now has the option
to return `error.OutOfMemory` to indicate that the allocator
would not be able to take advantage of the new size.

For more details see #1306. This commit closes #1306.

This commit paves the way to solving #2009.

This commit also introduces a memory leak to all coroutines.
There is an issue where a coroutine calls the function and it
frees its own stack frame, but then the return value of `shrinkFn`
is a slice, which is implemented as an sret struct. Writing to
the return pointer causes invalid memory write. We could work
around it by having a global helper function which has a void
return type and calling that instead. But instead this hack will
suffice until I rework coroutines to be non-allocating. Basically
coroutines are not supported right now until they are reworked as
in #1194.
2019-03-15 17:57:21 -04:00
Andrew Kelley 4cb55d3af6 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-10 18:07:28 -04:00
Andrew Kelley 918dbd4551
std.zig: `this` is no longer a keyword 2019-03-10 15:55:54 -04:00
Andrew Kelley 0714e19598
Merge remote-tracking branch 'origin/master' into llvm8 2019-03-04 08:24:56 -05:00
Andrew Kelley e402455704
rename std lib files to new convention 2019-03-02 16:46:04 -05:00
Andrew Kelley 582fdc2869
fix dependency loops, pub, tests, use decls, root source
* fix dependency loop detection
   - closes #679
   - closes #1500
 * fix `pub`
 * fix tests
 * fix use decls
 * main package file gets a special "" namespace path
2019-03-01 15:35:29 -05:00
Andrew Kelley 0fd64e6c69
stage2: update for changes regarding sub-architecture 2019-02-28 14:10:45 -05:00
Andrew Kelley 5424b4320d
remove namespace type; files are empty structs
closes #1047
2019-02-28 10:11:32 -05:00
Andrew Kelley 2dcf1a2392
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-28 09:19:18 -05:00
Andrew Kelley 33174f11ef fix regressions on Windows 2019-02-26 16:24:32 -05:00
Andrew Kelley ade10387a5
breaking changes to the way targets work in zig
* CLI: `-target [name]` instead of `--target-*` args.
   This matches clang's API.
 * `builtin.Environ` renamed to `builtin.Abi`
   - likewise `builtin.environ` renamed to `builtin.abi`
 * stop hiding the concept of sub-arch. closes #1526
 * `zig targets` only shows available targets. closes #438
 * include all targets in readme, even those that don't
   print with `zig targets` but note they are Tier 4
 * refactor target.cpp and make the naming conventions
   more consistent
 * introduce the concept of a "default C ABI" for a given
   OS/Arch combo. As a rule of thumb, if the system compiler
   is clang or gcc then the default C ABI is the gnu ABI.
2019-02-26 15:58:10 -05:00
Andrew Kelley c9fb5240d6
remove --no-rosegment workaround now that valgrind bug is fixed
See #896

Zig 0.3.0+ and Valgrind 3.14+ do not need the workaround.
2019-02-19 08:39:36 -05:00
Maya Rashish bc10382ec1 Add NetBSD support
Mostly picking the same paths as FreeBSD.
We need a little special handling for crt files, as netbsd uses its
own (and not GCC's) for those, with slightly different names.
2019-02-17 09:17:34 +02:00
Andrew Kelley ba56f365c8
bring zig fmt to stage1 2019-02-16 00:53:32 -05:00
Andrew Kelley 99b19adeb3 stage2: fix windows regressions 2019-02-14 23:46:53 -05:00
Andrew Kelley e025c70166
stage2: fix llvm.zig with opaque types back to single-item pointer 2019-02-14 23:17:11 -05:00