Commit Graph

293 Commits

Author SHA1 Message Date
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
Andrew Kelley
6769183a9d
fix implicit cast error unions with non-optional to optional pointer
and update self hosted compiler for C pointers

See #1059
2019-02-14 15:48:28 -05:00
Andrew Kelley
90b8cd4a45
add C pointer type to @typeInfo
See #1059
2019-02-11 16:07:40 -05:00
Andrew Kelley
1864acd326
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-09 18:57:39 -05:00
Andrew Kelley
c2db077574
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.

This makes release mode test builds more accurately test
the actual code that will be run.

However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.

Here is the explanation of when to use either one, copied from
the assert doc comments:

Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.

closes #1304
2019-02-08 18:23:38 -05:00
Andrew Kelley
a94304d3e4
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-07 12:21:20 -05:00
Andrew Kelley
36bade5c56
fixups, and modify std.mem.join and std.os.path.resolve API
* zig fmt
 * std.mem.join takes a slice of slices instead of var args
 * std.mem.join takes a separator slice rather than byte,
   and always inserts it. Previously it would not insert the separator
   if there already was one, violating the documented behavior.
 * std.mem.join calculates exactly the correct amount to allocate
   and has no call to allocator.shrink()
 * bring back joinWindows and joinPosix and the corresponding tests.
   it is intended to be able to call these functions from any OS.
 * rename std.os.path.resolveSlice to resolve (now resolve takes
   a slice of slices instead of var args)
2019-02-07 00:42:41 -05:00
Andrew Kelley
c804ae2d6b
Merge branch 'zig-backport-std.os.path' of https://github.com/kristate/zig into kristate-zig-backport-std.os.path 2019-02-06 22:53:34 -05:00
Andrew Kelley
f32f7a937f
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-04 21:26:50 -05:00
Andrew Kelley
67bd45f0cf
adjustments to std.mem split / separate
* rename std.mem.split to std.mem.tokenize
 * add future deprecation notice to docs
 * (unrelated) add note to std.os.path.resolve docs
 * std.mem.separate - assert delimiter.len not zero
 * fix implementation of std.mem.separate to respect the delimiter
 * separate the two iterators to different structs
2019-02-04 15:24:06 -05:00
Andrew Kelley
dfbc063f79
std.mem.Allocator.create replaced with better API
`std.mem.Allocator.createOne` is renamed to `std.mem.Allocator.create`.

The problem with the previous API is that even after copy elision,
the initalization value passed as a parameter would always be a copy.
With the new API, once copy elision is done, initialization
functions can directly initialize allocated memory in place.

Related:
 * #1872
 * #1873
2019-02-03 16:13:28 -05:00
Andrew Kelley
545064c1d9
introduce vector type for SIMD
See #903

 * create with `@Vector(len, ElemType)`
 * only wrapping addition is implemented

This feature is far from complete; this is only the beginning.
2019-01-30 23:39:25 -05:00
Andrew Kelley
1411df4e27 update to llvm8 trunk. all tests passing 2019-01-24 09:31:00 -05:00
Andrew Kelley
036a49e97d Merge remote-tracking branch 'origin/master' into llvm8 2019-01-01 18:36:12 -05:00
nebulaeonline
fdea12b2d9 msvc subsystem option handling; added uefi os type 2018-12-23 22:44:02 -05:00
Andrew Kelley
c0e391e94a self-hosted: add hurd os to switch 2018-12-23 18:30:13 -05:00
Andrew Kelley
c00216701c Merge remote-tracking branch 'origin/master' into llvm8 2018-12-23 17:04:26 -05:00
Andrew Kelley
f301474531
self-hosted: add DeviceBusy as a BuildError 2018-12-21 23:01:21 -05:00
Andrew Kelley
b883bc873d
breaking API changes to all readInt/writeInt functions & more
* add `@bswap` builtin function. See #767
 * comptime evaluation facilities are improved to be able to
   handle a `@ptrCast` with a backing array.
 * `@truncate` allows "truncating" a u0 value to any integer
   type, and the result is always comptime known to be `0`.
 * when specifying pointer alignment in a type expression,
   the alignment value of pointers which do not have addresses
   at runtime is ignored, and always has the default/ABI alignment
 * threw in a fix to freebsd/x86_64.zig to update syntax from
   language changes
 * some improvements are pending #863

closes #638
closes #1733

std lib API changes
 * io.InStream().readIntNe renamed to readIntNative
 * io.InStream().readIntLe renamed to readIntLittle
 * io.InStream().readIntBe renamed to readIntBig
 * introduced io.InStream().readIntForeign
 * io.InStream().readInt has parameter order changed
 * io.InStream().readVarInt has parameter order changed
 * io.InStream().writeIntNe renamed to writeIntNative
 * introduced io.InStream().writeIntForeign
 * io.InStream().writeIntLe renamed to writeIntLittle
 * io.InStream().writeIntBe renamed to writeIntBig
 * io.InStream().writeInt has parameter order changed
 * mem.readInt has different parameters and semantics
 * introduced mem.readIntNative
 * introduced mem.readIntForeign
 * mem.readIntBE renamed to mem.readIntBig and different API
 * mem.readIntLE renamed to mem.readIntLittle and different API
 * introduced mem.readIntSliceNative
 * introduced mem.readIntSliceForeign
 * introduced mem.readIntSliceLittle
 * introduced mem.readIntSliceBig
 * introduced mem.readIntSlice
 * mem.writeInt has different parameters and semantics
 * introduced mem.writeIntNative
 * introduced mem.writeIntForeign
 * mem.writeIntBE renamed to mem.readIntBig and different semantics
 * mem.writeIntLE renamed to mem.readIntLittle and different semantics
 * introduced mem.writeIntSliceForeign
 * introduced mem.writeIntSliceNative
 * introduced mem.writeIntSliceBig
 * introduced mem.writeIntSliceLittle
 * introduced mem.writeIntSlice
 * removed mem.endianSwapIfLe
 * removed mem.endianSwapIfBe
 * removed mem.endianSwapIf
 * added mem.littleToNative
 * added mem.bigToNative
 * added mem.toNative
 * added mem.nativeTo
 * added mem.nativeToLittle
 * added mem.nativeToBig
2018-12-12 20:35:04 -05:00
kristopher tate
1e60ca4b75
stage2: update std.os.path.join method signature;
stage2: take 2;
2018-11-30 03:52:28 +09:00
Andrew Kelley
dd2450b1b2
tier 2 support for freebsd 2018-11-27 20:56:43 -05:00
Andrew Kelley
9493738e54
Merge branch 'freebsd-up' of https://github.com/myfreeweb/zig into freebsd2 2018-11-19 17:24:41 -05:00
Andrew Kelley
c21884e1d6 Merge remote-tracking branch 'origin/master' into llvm8 2018-11-17 02:18:56 -05:00
Jimmi Holst Christensen
2a9843de95
Added NullOutStream and CountingOutStream (#1722) 2018-11-15 09:37:39 -08:00
Andrew Kelley
0c3bd0c3d1
zig fmt: add --check flag
closes #1558
closes #1555
2018-11-15 00:26:43 -05:00
Jimmi Holst Christensen
8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00
Andrew Kelley
c19bc7ecb4 update self-hosted compiler for new targets 2018-11-05 11:32:02 -05:00
Andrew Kelley
2b395d4ede
remove @minValue,@maxValue; add std.math.minInt,maxInt
closes #1466
closes #1476
2018-10-26 15:01:51 -04:00
Greg V
831bb66895 Set up libc/rtld paths for FreeBSD 2018-10-20 15:21:35 +03:00
Andrew Kelley
d5648d2640
remove implicit cast from T to *const T
closes #1465
2018-10-15 18:23:47 -04:00
Jimmi Holst Christensen
378d3e4403
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
2018-10-15 09:51:15 -04:00
Andrew Kelley
d40c4e7c89
Merge pull request #1429 from shawnl/arm64
initial arm64 support
2018-10-06 00:11:39 -04:00
Andrew Kelley
9d4eaf1e07
update std lib API for I/O
std.io.FileInStream -> std.os.File.InStream
std.io.FileInStream.init(file) -> file.inStream()
std.io.FileOutStream -> std.os.File.OutStream
std.io.FileOutStream.init(file) -> file.outStream()

remove a lot of error code possibilities from os functions

std.event.net.socketRead -> std.event.net.read
std.event.net.socketWrite -> std.event.net.write
add std.event.net.readv
add std.event.net.writev
add std.event.net.readvPosix
add std.event.net.writevPosix
add std.event.net.OutStream
add std.event.net.InStream

add std.event.io.InStream
add std.event.io.OutStream
2018-09-30 17:28:35 -04:00
Andrew Kelley
c06a61e9bf
remove this. add @This().
closes #1283
2018-09-13 16:34:33 -04:00
Andrew Kelley
178d69191b windows: std.fs functions support concurrent ops
when reading and writing the same file descriptors
2018-09-12 13:55:35 -04:00
Shawn Landden
342cff28f5 initial arm64 support 2018-09-08 03:52:28 +00:00
Andrew Kelley
832caefc2a fix regressions 2018-09-02 18:35:32 -04:00
Andrew Kelley
ea1b21dbdb fix linux
* error.BadFd is not a valid error code. it would always be a bug to
   get this error code.
 * merge error.Io with existing error.InputOutput
 * merge error.PathNotFound with existing error.FileNotFound.
   Not all OS's support both.
 * add os.File.openReadC
 * add error.BadPathName for windows file operations with invalid
   characters
 * add os.toPosixPath to help stack allocate a null terminating byte
 * add some TODOs for other functions to investigate removing the
   allocator requirement
 * optimize some implementations to use the alternate functions when
   a null byte is already available
 * add a missing error.SkipZigTest
 * os.selfExePath uses a non-allocating API
 * os.selfExeDirPath uses a non-allocating API
 * os.path.real uses a non-allocating API
 * add os.path.realAlloc and os.path.realC
 * convert many windows syscalls to use the W versions (See #534)
2018-08-21 20:31:50 -04:00
Andrew Kelley
51852d2587 fix windows 2018-08-21 16:07:28 -04:00
Andrew Kelley
598e80957e windows: call CancelIo when canceling an fs watch 2018-08-10 13:19:07 -04:00
Andrew Kelley
0df485d4dc self-hosted: reorganize creation and destruction of Compilation 2018-08-10 12:28:20 -04:00
Andrew Kelley
b219feb3f1 initial windows implementation of std.event.fs.Watch 2018-08-09 16:48:44 -04:00
Andrew Kelley
60955feab8 std.event.fs.Watch distinguishes between Delete and CloseWrite on darwin
TODO: after 1 event emitted for a deleted file, the file is no longer
watched
2018-08-07 22:14:30 -04:00
Andrew Kelley
c5f1925bc8 when decls don't change, don't regenerate them 2018-08-03 17:59:11 -04:00
Andrew Kelley
5dfcd09e49 self-hosted: watch files and trigger a rebuild 2018-08-03 17:22:17 -04:00
Andrew Kelley
7f6e97cb26 fixups from the merge 2018-08-02 17:36:08 -04:00
Andrew Kelley
951124e177 evented I/O zig fmt 2018-08-02 17:24:15 -04:00
Andrew Kelley
821805aa92 WIP: Channel.getOrNull 2018-08-02 17:04:17 -04:00
Andrew Kelley
a870228ab4 self-hosted: use std.event.fs.readFile 2018-07-30 13:44:36 -04:00
Andrew Kelley
02713e8d8a fix race conditions in self-hosted compiler; add test
* fix race condition in std.event.Channel deinit
 * add support to zig build for --no-rosegment
 * add passing self-hosted compare-output test for calling a function
 * put a global lock on LLD linking because it's not thread safe
2018-07-24 21:28:54 -04:00
Andrew Kelley
adefd1a52b self-hosted: function calling another function 2018-07-24 20:24:05 -04:00
Andrew Kelley
2ea08561cf self-hosted: function types use table lookup 2018-07-24 14:20:49 -04:00
Andrew Kelley
72599d420b self-hosted: find all libc paths; windows linker code 2018-07-24 00:06:34 -04:00
Andrew Kelley
2614ef056a self-hosted: basic linker code for macos 2018-07-23 17:38:03 -04:00
Andrew Kelley
5a919dd82d Merge remote-tracking branch 'origin/master' into self-hosted-libc-hello-world 2018-07-23 14:32:13 -04:00
Andrew Kelley
10d2f08d37 self-hosted: fix error messages not cleaning up correctly 2018-07-23 14:28:14 -04:00
Andrew Kelley
d767fae47e self-hosted: add first compare-output test 2018-07-23 00:35:53 -04:00
Andrew Kelley
93e78ee722 self-hosted can compile libc hello world 2018-07-22 23:28:53 -04:00
Andrew Kelley
58c5f94a99 self-hosted: share C++ code for finding libc on windows 2018-07-20 23:38:13 -04:00
Andrew Kelley
f5a67dba08 self-hosted: implicit cast comptime ints to other ints
we now have successful exit codes from main linking
against libc
2018-07-20 01:46:49 -04:00
Andrew Kelley
33fbd8c1d3 self-hosted: convert some stuff to async/await 2018-07-20 00:13:48 -04:00
Andrew Kelley
d9fc149752 relative path to cwd in compile errors 2018-07-19 23:52:44 -04:00
Andrew Kelley
3908b4fdee self-hosted: refactor ParsedFile out of existence
also we are successfully analyzing the return type of main
2018-07-19 15:11:39 -04:00
Andrew Kelley
1d85b588ea self-hosted: progress on IR for supporting libc hello world
* add c int types
 * some more ir stubs
2018-07-19 00:08:47 -04:00
Andrew Kelley
bd1c55d2c2 self-hosted: compile errors for return in wrong place
* outside fn definition
 * inside defer expression
2018-07-18 17:43:36 -04:00
Andrew Kelley
aa3b41247f self-hosted: linking against libc
also introduce `zig libc` command to display paths
`zig libc file.txt` will parse equivalent text and use that for libc
paths.
2018-07-18 17:43:36 -04:00
Andrew Kelley
3e4a3fa5b7 self-hosted: find libc on linux 2018-07-18 17:43:36 -04:00
Andrew Kelley
a8a1b5af07 fix build on windows
* move getAppDataDir and utf16leToUtf8 from self-hosted to std lib
 * fix std.event.Loop on windows
2018-07-18 10:07:22 -04:00
Josh Wolfe
843529d234 implement proper utf16leToUtf8 2018-07-18 03:01:01 -04:00
Andrew Kelley
ecf8da00c5 self-hosted: linking 2018-07-17 13:18:13 -04:00
Andrew Kelley
1a7cf4cbce port 69e3b4e to self-hosted compiler
See #1249
2018-07-17 10:42:44 -04:00
Andrew Kelley
3bb00eac37 self-hosted: implement getAppDataDir for windows 2018-07-17 00:01:36 -04:00
Andrew Kelley
97bfeac13f self-hosted: create tmp dir for .o files and emit .o file for fn 2018-07-16 20:52:50 -04:00
Andrew Kelley
363f4facea self-hosted: generate LLVM IR for simple function 2018-07-15 00:07:33 -04:00
Andrew Kelley
28c3d4809b rename Module to Compilation
and CompilationUnit to ObjectFile
2018-07-14 16:31:17 -04:00
Andrew Kelley
278829fc2c self-hosted: adding a fn to an llvm module 2018-07-14 16:03:22 -04:00
Marc Tiehuis
bf441ed244 Add --stdin option to zig fmt 2018-07-14 11:43:35 -04:00
Andrew Kelley
e78b1b810f self-hosted: basic IR pass2 2018-07-13 21:56:38 -04:00
Andrew Kelley
69e60e351b self-hosted: better IR for empty fn
avoids a void
2018-07-12 15:22:23 -04:00
Andrew Kelley
687bd92f9c self-hosted: generate zig IR for simple function
no tests for this yet. I think the quickest path to testing will be
creating the .o files and linking with libc, executing, and then
comparing output.
2018-07-12 15:12:44 -04:00
Andrew Kelley
9bdcd2a495 add std.event.Future
This is like a promise, but it's for multiple getters, and
uses an event loop.
2018-07-11 16:00:06 -04:00
Andrew Kelley
c6c49389eb self-hosted: add compile error test for missing fn name 2018-07-11 01:26:46 -04:00
Andrew Kelley
8197a14ceb self-hosted test: use C allocator since we depend on libc 2018-07-10 20:27:15 -04:00
Andrew Kelley
574e31f0a0 self-hosted: first passing test
* introduce std.atomic.Int
 * add src-self-hosted/test.zig which is tested by the main test suite
   - it fully utilizes the multithreaded async/await event loop so the
     tests should Go Fast
 * `stage2/bin/zig build-obj test.zig` is able to spit out an error if 2 exported
   functions collide
 * ability for `zig test` to accept `--object` and `--assembly`
   arguments
 * std.build: TestStep supports addLibPath and addObjectFile
2018-07-10 20:18:43 -04:00
Andrew Kelley
8fba0a6ae8 introduce std.event.Group for making parallel async calls 2018-07-10 15:17:01 -04:00
Andrew Kelley
ccef60a640
Merge pull request #1198 from ziglang/m-n-threading
M:N threading
2018-07-09 22:06:47 -04:00
Andrew Kelley
10cc49db1c define c macros before importing llvm h files
Seems to matter on Ubuntu 16.04.

closes #1196
2018-07-09 22:05:22 -04:00
Andrew Kelley
eb326e1553 M:N threading
* add std.atomic.QueueMpsc.isEmpty
 * make std.debug.global_allocator thread-safe
 * std.event.Loop: now you have to choose between
   - initSingleThreaded
   - initMultiThreaded
 * std.event.Loop multiplexes coroutines onto kernel threads
 * Remove std.event.Loop.stop. Instead the event loop run() function
   returns once there are no pending coroutines.
 * fix crash in ir.cpp for calling methods under some conditions
 * small progress self-hosted compiler, analyzing top level declarations
 * Introduce std.event.Lock for synchronizing coroutines
 * introduce std.event.Locked(T) for data that only 1 coroutine should
   modify at once.
 * make the self hosted compiler use multi threaded event loop
 * make std.heap.DirectAllocator thread-safe

See #174

TODO:
 * call sched_getaffinity instead of hard coding thread pool size 4
 * support for Windows and MacOS
 * #1194
 * #1197
2018-07-07 00:32:19 -04:00
Andrew Kelley
06e8c2e519 fix stage2 macos build
See #1173
2018-07-02 17:55:59 -04:00
Andrew Kelley
2da999372a add another BuildError code 2018-07-02 15:25:23 -04:00
Andrew Kelley
a3f55aaf34 add event loop Channel abstraction
This is akin to channels in Go, except:
 * implemented in userland
 * they are lock-free and thread-safe
 * they integrate with the userland event loop

The self hosted compiler is changed to use a channel for events,
and made to stay alive, watching files and performing builds when
things change, however the main.zig file exits after 1 build.

Note that nothing is actually built yet, it just parses the input
and then declares that the build succeeded.

Next items to do:
 * add windows and macos support for std.event.Loop
 * improve the event loop stop() operation
 * make the event loop multiplex coroutines onto kernel threads
 * watch source file for updates, and provide AST diffs
   (at least list the top level declaration changes)
 * top level declaration analysis
2018-07-02 14:38:11 -04:00
Andrew Kelley
8866bef92c clean up self hosted main. delete unsupported commands 2018-06-22 01:54:38 -04:00
Andrew Kelley
85f928f8bf remove std.mem.Allocator.construct and other fixups 2018-06-20 17:33:29 -04:00
kristopher tate
71db8df548 std: update stdlib to match updated allocator create signature; ref #733 2018-06-21 00:40:21 +09:00
Andrew Kelley
1ca90b5856 zig fmt: support directories
zig fmt accepts any number of file paths. For each one, if it
is a file, then it formats the file. If it is a directory, then
zig recursively scans the directory, formatting all files that
end in `.zig`.

it maintains a map of paths that have been seen already, to avoid
softlink loops.

closes #1068
2018-06-18 13:58:08 -04:00
Andrew Kelley
6943cefebf std.os.path.dirname: return null instead of empty slice
for when there is no directory component. Makes it harder
to write bugs.

closes #1017
2018-06-14 16:15:32 -04:00
Andrew Kelley
77678b2cbc
breaking syntax change: orelse keyword instead of ?? (#1096)
use the `zig-fmt-optional-default` branch to have zig fmt
automatically do the changes.

closes #1023
2018-06-10 01:13:51 -04:00
Andrew Kelley
ec1b6f6673
breaking syntax change: ??x to x.? (#1095)
See #1023

This also renames Nullable/Maybe to Optional
2018-06-09 23:42:14 -04:00
Braedon
f389e53735 Add newline to zig fmt error (#1064) 2018-06-06 10:45:19 -04:00
Marc Tiehuis
e514454c0e Make zig fmt exit with error on any parse errors
This is required for proper detection in editor plugins. Other files may
have been formatted correctly, this only indicates that some failed.
2018-06-02 20:49:35 +12:00
Andrew Kelley
fcbb7426fa use * for pointer type instead of &
See #770

To help automatically translate code, see the
zig-fmt-pointer-reform-2 branch.

This will convert all & into *. Due to the syntax
ambiguity (which is why we are making this change),
even address-of & will turn into *, so you'll have
to manually fix thes instances. You will be guaranteed
to get compile errors for them - expected 'type', found 'foo'
2018-05-31 17:28:07 -04:00
Andrew Kelley
717ac85a5a zig fmt: add --color option to CLI help text 2018-05-30 18:37:12 -04:00
Andrew Kelley
a05acaf9fd Add --color CLI option to zig fmt
It doesn't actually do terminal color yet because we need to add
cross platform terminal color abstractions. But it toggles between
the single line error reporting and the multiline error reporting.

See #1026
2018-05-30 18:26:09 -04:00
Andrew Kelley
d8699ae57e zig fmt: don't compute a sha-256 for no reason
I forgot to delete this code before pushing 2c96f19fd3
2018-05-30 16:45:32 -04:00
Andrew Kelley
ea58f4a5a9 run zig fmt on the codebase 2018-05-30 16:09:11 -04:00
Andrew Kelley
2c96f19fd3 std.zig.render returns bool of whether anything changed
zig fmt only renames files and prints to stdout for files which changed
2018-05-30 14:58:27 -04:00
Andrew Kelley
b184ae5ca5 run zig fmt on some of the codebase
See #1003
2018-05-26 23:00:29 -04:00
Andrew Kelley
c38b165db4 all tests passing with postfix deref syntax 2018-05-17 23:21:44 -04:00
Andrew Kelley
4c3aa09f2a self hosted compiler: remove unused flag 2018-05-13 01:06:52 -04:00
Andrew Kelley
c3ddf5069e zig fmt: fix not writing results 2018-05-10 00:40:07 -04:00
Andrew Kelley
bbae6267fe fix self hosted compiler 2018-05-09 21:45:29 -04:00
Marc Tiehuis
03bec631bd Replace File.exists with File.access 2018-04-13 21:27:09 +12:00
Marc Tiehuis
b946982e90 Use builtin Arch/Os/Environ 2018-04-13 20:12:30 +12:00
Marc Tiehuis
7fe1c7c04f Remove cc command 2018-04-13 19:43:18 +12:00
Andrew Kelley
7b2cb7e679 remove --zig-install-prefix arg now that we find std at runtime 2018-04-12 11:00:11 -04:00
Marc Tiehuis
803f0a295b Revise self-hosted command line interface
Commands are now separated more precisely from one another. Arguments
are parsed mostly using a custom argument parser instead of manually.
This should be on parity feature-wise with the previous main.zig but
adds a few extra code-paths as well that were not yet implemented.

Subcommands are much more prominent and consistent. The first argument
is always a sub-command and then all following arguments refer to that
command. Different commands display there own usage messages and options
based on what they can do instead of a one-for-all usage message that
was only applicable for the build commands previously.

The `cc` command is added and is intended for driving a c compiler. See #490.
This is currently a wrapper over the system cc and assumes that it
exists, but it should suffice as a starting point.
2018-04-12 22:28:47 +12:00
Andrew Kelley
477ded9042 add missing call in zig fmt to commit results to disk 2018-04-10 11:00:57 -04:00
Ben Noordhuis
b60b01ce97 skeleton stage 2 support for 'zig build'
Initial port of the 'zig build' logic from the stage 1 compiler to the
stage 2 compiler sans code generation and BUILD_INFO support.
2018-03-28 18:30:41 +02:00
Andrew Kelley
445b03384a introduce std.heap.ArenaAllocator and std.heap.DirectAllocator
* DirectAllocator does the underlying syscall for every allocation.
 * ArenaAllocator takes another allocator as an argument and
   allocates bytes up front, falling back to DirectAllocator with
   increasingly large allocation sizes, to avoid calling it too often.
   Then the entire arena can be freed at once.

The self hosted parser is updated to take advantage of ArenaAllocator
for the AST that it returns. This significantly reduces the complexity
of cleanup code.

docgen and build runner are updated to use the combination of
ArenaAllocator and DirectAllocator instead of IncrementingAllocator,
which is now deprecated in favor of FixedBufferAllocator combined
with DirectAllocator.

The C allocator calls aligned_alloc instead of malloc, in order to
respect the alignment parameter.

Added asserts in Allocator to ensure that implementors of the
interface return slices of the correct size.

Fixed a bug in Allocator when you call realloc to grow the allocation.
2018-02-12 02:14:44 -05:00
Andrew Kelley
46aa416c48 std.os and std.io API update
* move std.io.File to std.os.File
 * add `zig fmt` to self hosted compiler
 * introduce std.io.BufferedAtomicFile API
 * introduce std.os.AtomicFile API
 * add `std.os.default_file_mode`
 * change FileMode on posix from being a usize to a u32
 * add std.os.File.mode to return mode of an open file
 * std.os.copyFile copies the mode from the source file instead of
   using the default file mode for the dest file
 * move `std.os.line_sep` to `std.cstr.line_sep`
2018-02-10 21:02:24 -05:00
Andrew Kelley
8c31eaf2a8 std zig tokenizer: don't require 3 newlines at the end of the source 2018-02-10 14:52:39 -05:00
Andrew Kelley
a2bd9f8912 std lib: modify allocator idiom
Before we accepted a nullable allocator for some stuff like
opening files. Now we require an allocator.

Use the mem.FixedBufferAllocator pattern if a bound on the amount
to allocate is known.

This also establishes the pattern that usually an allocator is the
first argument to a function (possibly after "self").

fix docs for std.cstr.addNullByte

self hosted compiler:
 * only build docs when explicitly asked to
 * clean up main
 * stub out zig fmt
2018-02-09 18:27:50 -05:00
Andrew Kelley
1fb308ceee self hosted compiler: move tokenization and parsing to std lib 2018-02-09 13:08:02 -05:00
Andrew Kelley
0d5ff6f462 error sets - most tests passing 2018-02-08 02:08:45 -05:00
Andrew Kelley
5f518dbeb9 *WIP* error sets converting std lib 2018-01-31 22:48:40 -05:00
Andrew Kelley
3671582c15 syntax: functions require return type. remove ->
The purpose of this is:

 * Only one way to do things
 * Changing a function with void return type to return a possible
   error becomes a 1 character change, subtly encouraging
   people to use errors.

See #632

Here are some imperfect sed commands for performing this update:

remove arrow:

```
sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig")
```

add void:

```
sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig")
```

Some cleanup may be necessary, but this should do the bulk of the work.
2018-01-25 04:10:11 -05:00
Andrew Kelley
e5bc5873d7 rename "debug safety" to "runtime safety"
closes #437
2018-01-25 01:46:12 -05:00
Andrew Kelley
b3a6faf13e replace %defer with errdefer
See #632

now we have 1 less sigil
2018-01-23 23:08:09 -05:00
Andrew Kelley
cf39819478 add new kind of test: generating .h files. and more
* docgen supports obj_err code kind for demonstrating
   errors without explicit test cases
 * add documentation for `extern enum`. See #367
 * remove coldcc keyword and add @setIsCold. See #661
 * add compile errors for non-extern struct, enum, unions
   in function signatures
 * add .h file generation for extern struct, enum, unions
2018-01-22 22:24:07 -05:00
Andrew Kelley
793f031c4c remove 32-bit windows from supported targets list
we still want to support it, but there are too many bugs
to claim that we support it right now.

See #537
2018-01-14 15:17:07 -05:00
Andrew Kelley
632d143bff replace a %% b with a catch b
See #632

better fits the convention of using keywords for control flow
2018-01-07 17:28:20 -05:00
Andrew Kelley
66717db735 replace %return with try
See #632

better fits the convention of using keywords for control flow
2018-01-07 16:53:13 -05:00
Andrea Orru
e932919e68 Darwin -> MacOSX, added Zen. See #438 2018-01-06 23:10:53 -05:00
Andrew Kelley
e1c03d9e8e self-hosted compiler works on windows
* better error message for realpath failing
 * fix bug in std.io.readFileAllocExtra incorrectly returning
   error.EndOfStream
 * implement std.os.selfExePath and std.os.selfExeDirPath for windows
2018-01-04 13:48:45 -05:00
Andrew Kelley
a45db7e853 add building the self hosted compiler to the main test suite 2018-01-03 18:25:17 -05:00