Commit Graph

282 Commits (cbfe4b4bae61682e367a477283e4d64a518203a8)

Author SHA1 Message Date
Andrew Kelley 8fd0fddce5 zig build system progress
* In-progress os.ChildProcess.spawn implementation. See #204
 * Add explicit cast from integer to error. Closes #294
 * fix casting from error to integer
 * fix compiler crash when initializing variable to undefined
   with no type
2017-04-02 18:19:59 -04:00
Andrew Kelley f8e63c4584 change `@bitcast` to `@ptrcast`
See #290
2017-03-31 06:18:20 -04:00
Andrew Kelley 3ca027ca82 first pass at zig build system
* `zig build --export [obj|lib|exe]` changed to `zig build_obj`,
   `zig build_lib` and `zig build_exe` respectively.
 * `--name` parameter is optional when it can be inferred from the
   root source filename. closes #207
 * `zig build` now looks for `build.zig` which interacts with
   `std.build.Builder` to describe the targets, and then the zig
   build system prints TODO: build these targets. See #204
 * add `@bitcast` which is mainly used for pointer reinterpret
   casting and make explicit casting not do pointer reinterpretation.
   Closes #290
 * fix debug info for byval parameters
 * sort command line help options
 * `std.debug.panic` supports format string printing
 * add `std.mem.IncrementingAllocator`
 * fix const ptr to a variable with data changing at runtime.
   closes #289
2017-03-31 05:55:41 -04:00
Andrew Kelley f48f7f43fe std/mem: take advantage of new printf 2017-03-28 18:05:01 -04:00
Andrew Kelley a32b5929cc add stack protector safety when linking libc
* introduce zigrt file. it contains only weak symbols so that
   multiple instances can be merged. it contains __zig_panic
   so that multiple .o files can call the same panic function.
 * remove `@setFnVisible` builtin and add @setGlobalLinkage builtin
   which is more powerful
 * add `@panic` builtin function.
 * fix collision of symbols with extern prototypes and internal
   function names
 * add stack protector safety when linking against libc. To add
   the safety mechanism without libc requires implementing
   Thread Local Storage. See #276
2017-03-26 21:07:07 -04:00
Andrew Kelley 5bc9feb5cb organize std and make import relative to current file
closes #216
2017-03-26 06:39:28 -04:00
Andrew Kelley 7ce753a16b replace "&&" and "||" with "and" and "or"
closes #272
2017-03-26 05:21:28 -04:00
Andrew Kelley 451ce09067 new unreachable syntax
* `noreturn` is the primitive type.
 * `unreachable` is a control flow keyword.
 * `@unreachable()` builtin function is deleted.

closes #214
2017-03-26 04:58:48 -04:00
Andrew Kelley 7c53230a61 introduce copyable concept
closes #103
2017-03-26 03:39:18 -04:00
Andrew Kelley 5c04730534 use intel dialect for inline assembly
closes #242
2017-03-23 18:59:43 -04:00
Andrew Kelley d6856859d3 improvements for windows and libc integration
* standard library knows if it is linking against libc and will
   sometimes call libc functions in that case instead of providing
   redundant definitions
 * fix infinite loop bug when resolving use declarations
 * allow calling the same C function from different C imports.
   closes #277
 * push more logic from compiler to std/bootstrap.zig
 * standard library provides way to access errno
   closes #274
 * fix compile error in standard library for windows
 * add implementation of getRandomBytes for windows
2017-03-23 02:59:58 -04:00
Andrew Kelley 87bc97daef unify main entry point regardless of whether linking libc
closes #248
2017-03-22 11:26:30 -04:00
Andrew Kelley af536ac343 introduce new test syntax
* remove setFnTest builtin
 * add test "name" { ... } syntax
 * remove --check-unused argument. functions are always lazy now.
2017-03-16 16:02:35 -04:00
Andrew Kelley 47f267d25f break off some of std.io into std.fmt, generalize printf
closes #250
2017-03-09 19:12:15 -05:00
Jackie Meggesto 5bbde1dc91 Fix unused return value in darwin.zig 2017-03-02 19:21:02 -05:00
Andrew Kelley 6d0afc2bd2 add compile error for assigning number literal to non-comptime var 2017-03-02 18:51:19 -05:00
Andrew Kelley 9eb29e81f9 rename CBuf to Buffer0 and some minor std API changes 2017-02-28 03:07:11 -05:00
Andrew Kelley a665872e88 add compile error for ignoring return value
also introduce the _ identifier which you can assign to
to discard a return value

closes #219
2017-02-24 15:01:19 -05:00
Andrew Kelley 4b99f5978f add character format specifier to std.io.OutStream.printf 2017-02-23 18:56:10 -05:00
Andrew Kelley fe3063e58c update std code for MacOS
closes #264
2017-02-23 16:13:57 -05:00
Andrew Kelley b6e7a0dadd support arithmetic for non byte aligned integer types
see #261
2017-02-16 17:08:55 -05:00
Andrew Kelley b61f1a9f7d printf: only include + sign on signed ints if width specified
see #258
2017-02-12 17:46:28 -05:00
Andrew Kelley 6dba1f1c8e slice and array re-work plus some misc. changes
* `@truncate` builtin allows casting to the same size integer.
   It also performs two's complement casting between signed and
   unsigned integers.
 * The idiomatic way to convert between bytes and numbers is now
   `mem.readInt` and `mem.writeInt` instead of an unsafe cast.
   It works at compile time, is safer, and looks cleaner.
 * Implicitly casting an array to a slice is allowed only if the
   slice is const.
 * Constant pointer values know if their memory is from a compile-
   time constant value or a compile-time variable.
 * Cast from [N]u8 to []T no longer allowed, but [N]u8 to []const T
   still allowed.
 * Fix inability to pass a mutable pointer to comptime variable at
   compile-time to a function and have the function modify the
   memory pointed to by the pointer.
 * Add the `comptime T: type` parameter back to mem.eql. Prevents
   accidentally creating instantiations for arrays.
2017-02-12 17:35:51 -05:00
Andrew Kelley ca180d3f02 std.io.parseUnsigned buf parameter is const
fixes padding in printf

See #258
2017-02-11 15:06:20 -05:00
Andrew Kelley f7173f4f08 fix crash on string literal with character code >= 128
See #258
2017-02-11 14:01:11 -05:00
Andrew Kelley fc100d7b3b lots of miscellaneous things all in one big commit
* add `@compileLog(...)` builtin function
   - Helps debug code running at compile time
   - See #240
 * fix crash when there is an error on the start value of a slice
 * add implicit cast from int and float types to int and float
   literals if the value is known at compile time
 * make array concatenation work with slices in addition to
   arrays and c string literals
 * fix compile error message for something not having field access
 * fix crash when `@setDebugSafety()` was called from a
   function being evaluated at compile-time
 * fix compile-time evaluation of overflow math builtins.
 * avoid debug safety panic handler in builtin.o and compiler_rt.o
   since we use no debug safety in these modules anyway
 * add compiler_rt functions for division on ARM
   - Closes #254
 * move default panic handler to std.debug so users can
   call it manually
 * std.io.printf supports a width in the format specifier
2017-02-09 03:09:25 -05:00
Andrew Kelley 8a859afd58 std.io supports printing integers as hex values
remove "unnecessary if statement" error
this "depends on compile variable" code is too hard to validate,
and has false negatives. not worth it right now.

std.str removed, instead use std.mem.

std.mem.eql and std.mem.sliceEql merged and do not require explicit
type argument.
2017-02-07 17:23:50 -05:00
Andrew Kelley 07a71fc322 improved behavior on debug safety crash
* instead of emitting a breakpoint for a debug safety crash,
   zig calls a panic function which prints an error message
   and a stack trace and then calls abort.
 * on freestanding OS, this panic function has a default
   implementation of a simple infinite loop.
 * users can override the panic implementation by providing
   `pub fn panic(message: []const u8) -> unreachable { }`
 * workaround for LLVM segfaulting when you try to use cold
   calling convention on ARM.

closes #245
2017-02-06 03:10:32 -05:00
Andrew Kelley 0c88b1ce73 use printf in test runner code 2017-02-05 16:09:33 -05:00
Andrew Kelley e56f903522 memset and memcpy implementations need not return dest 2017-02-04 23:04:07 -05:00
Andrew Kelley c0b37e8514 add try expression
See #83
2017-02-02 17:09:27 -05:00
Andrew Kelley b78c91951a remove ability to mark if and switch as inline
if and switch are implicitly inline if the condition/target
expression is known at compile time.

instead of:

```
inline if (condition) ...
inline switch (target) ...
```

one can use:

```
if (comptime condition) ...
switch (comptime target) ...
```
2017-02-02 13:23:18 -05:00
Andrew Kelley 88a253c64d fix crash when passing void to var args function
closes #235
2017-01-31 15:50:38 -05:00
Andrew Kelley 4b3f18de3c printf var args proof of concept
See #167

Need to troubleshoot when we send 2 slices to printf. It goes
into an infinite loop.

This commit introduces 4 builtin functions:

 * `@isInteger`
 * `@isFloat`
 * `@canImplictCast`
 * `@typeName`
2017-01-24 02:02:48 -05:00
Andrew Kelley 1826a96160 update charToDigit to take advantage of switch syntax 2017-01-23 01:19:03 -05:00
Andrew Kelley 0b34439c1f mem.free no longer requires explicit type argument 2017-01-23 00:11:21 -05:00
Andrew Kelley 47cf8520ad use comptime instead of inline for var and params
See #221
2017-01-22 19:51:37 -05:00
Andrew Kelley fdbc2d8da1 implement error when assigning to field of const struct
closes #48
2017-01-16 15:24:03 -05:00
Andrew Kelley c715309bc5 Merge branch 'master' into ir-merge 2017-01-16 14:23:32 -05:00
Andrew Kelley e621ad014e pass cannot assign to constant test 2017-01-05 18:50:36 -05:00
Andrew Kelley 97e1054890 fix compiler rt 2017-01-05 04:20:07 -05:00
Andrew Kelley ee09eb7f54 fix hash map implementation
standard library passes all tests now
2017-01-05 03:40:12 -05:00
Andrew Kelley 27a633b32a fix mem.sliceAsInt regression 2017-01-05 01:23:59 -05:00
Andrew Kelley ff5120c584 IR: std makes it to codegen 2016-12-31 18:25:10 -05:00
Andrew Kelley 69132bdeda IR: progress toward compiling standard library
* comptime fn call
 * is_comptime doesn't count as an instruction dependency
 * update more std code to latest zig
2016-12-31 17:10:29 -05:00
Andrew Kelley 76fa6cdce3 eradicate use of zeroes in std 2016-12-31 01:31:23 -05:00
Andrew Kelley b55efe5fab update more std library to new zig 2016-12-21 23:34:14 -05:00
Andrew Kelley 132e2fa5d9 errors from inline fn calls include stack trace 2016-12-18 20:52:40 -05:00
Andrew Kelley 82101198f1 workaround for Arch being a primitive type 2016-12-18 20:09:34 -05:00
Andrew Kelley a71fbe49cb IR: add FnProto instruction 2016-12-18 19:40:26 -05:00
Andrew Kelley 37b13bf151 hello.zig working with all structs anonymous 2016-12-18 17:24:52 -05:00
Andrew Kelley 0d2f2b79ea IR: basic support for implicit casting to const pointer 2016-12-18 01:54:27 -05:00
Andrew Kelley 05b3b6a45e IR: update some std code to newest zig 2016-12-18 00:25:26 -05:00
Andrew Kelley 0f047337ac IR: fix `this` expression
Previously it returned a block instead of a function when
a function had any arguments.
2016-12-17 20:47:35 -05:00
Andrew Kelley a07d7ee53d IR: fix compile time switch eval for enums 2016-12-17 17:57:26 -05:00
Andrew Kelley c64f9991d5 IR: fix switching on enum 2016-12-17 17:48:07 -05:00
Andrew Kelley ef63bc9cca IR: implement memcpy, memset, and slice expression 2016-12-12 00:31:35 -05:00
Andrew Kelley a2257e4b81 IR: implement setFnVisible builtin 2016-11-21 15:36:25 -05:00
Andrew Kelley 19037014e5 IR: more maybe type support 2016-11-18 23:52:42 -05:00
Andrew Kelley d94cb0566b IR: correctly codegening memset and memcpy 2016-11-18 22:24:41 -05:00
Steve Perkins 4b55966a16 add sort to CMakeLists + std/index 2016-11-03 07:01:40 +00:00
Steve Perkins cf00245bf9 sort requires compare function.
Provide some handy functions for builtin comparable types.
2016-11-03 04:10:33 +00:00
Steve Perkins e761aa2d2f sortCmp allows for a custom cmp function 2016-11-02 18:52:00 -04:00
Steve Perkins c5b2bdae11 quicksort 2016-11-02 18:10:44 -04:00
Andrew Kelley b581da41f8 remove compiler directives
* add `setFnTest`, `setFnVisible`, `setFnStaticEval`,
   `setFnNoInline` builtin functions to replace previous
   directive functionality
 * add `coldcc` and `nakedcc` as keywords which can be used as part
   of a function prototype.
 * `setDebugSafety` builtin can be used to set debug safety features
   at a per block scope level.
 * closes #169
2016-09-28 02:33:32 -04:00
Andrew Kelley 183976b242 add this keyword refers to thing in immediate scope
See #169
2016-09-26 23:47:30 -04:00
Andrew Kelley f4d7c91363 std/rand: remove unneeded TODO 2016-09-26 22:42:25 -04:00
Andrew Kelley 87b7c28c9a cstr.len and cstr.cmp can run at compile time
closes #140
2016-09-26 22:33:33 -04:00
Andrew Kelley 7ce7e2c9d1 emit error for extern function
with byvalue return value or parameter.

currently we don't codegen byvalue parameters or return values
correctly for C compatibilty functions so instead of generating
incorrect code, we emit a compile error.

eventually we'll support this feature and remove the compile error.

See #180
2016-09-26 20:01:42 -04:00
Andrew Kelley 46eb77dbb2 stack trace is able to figure out compilation unit
each address is contained within

also fix a bug having to do with codegen for enum value
initialization expressions
2016-09-23 02:00:23 -04:00
Andrew Kelley 7aeca9bfed fix incorrect linking from previous commit 2016-09-21 17:40:50 -04:00
Andrew Kelley b97bfc3ecb fix error when switch prong has implicit cast
closes #194
2016-09-20 16:10:34 -04:00
Andrew Kelley 3239b3cb69 use size_t for indexes
protect against incorrect copies in debug mode
2016-09-19 11:54:01 -04:00
Andrew Kelley f1761632da darwin compat fixups
- delete commented out code
 - delete redundant check for missing
   mmacosx-version-min/maxdir
 - add TODO comment in std library
 - rename 'os' to 'self' in io.zig
 - `openSelfExe` aborts on darwin instead of compile error
 - only allow warnings on the one parseh test that has
   `#include <stdint.h>`.
2016-09-14 02:47:16 -04:00
alter cf9b21c09f MacOSX compatibility
- Implemented some syscall for MacOSX
- tested on : El Capitan 10.11 x86_64
- make self hosted test run on macosx
- modified run_test so it does not fail when parseh throws
  warnings (most of them are related to buildin types from
  gcc that arent defined in header files and unions)
- making -mmacosx-version-min and -mios-version-min works like
  gcc (command line paramers have precedence over enviroment variables)
2016-09-14 02:46:02 -04:00
Andrew Kelley 06f2f4d64b change `unreachable{}` to `@unreachable()`
instead of a container init expression, it's a builtin
function call.
2016-09-13 16:46:27 -04:00
Andrew Kelley ea2f6594ce std: fix compile error for unsupported os 2016-09-13 15:36:30 -04:00
Andrew Kelley 9e92dbdd08 std: use parameter type inference on min and max functions 2016-09-10 20:53:57 -04:00
Andrew Kelley fc9ff13fb6 std: avoid calling close twice in InStream
thanks ofelas for pointing this out
2016-09-08 14:21:42 -04:00
Andrew Kelley d324b1befa ability to infer parameter types 2016-09-08 00:24:48 -04:00
Andrew Kelley cfaced3f73 rename errName builtin to errorName 2016-09-05 17:03:11 -04:00
Andrew Kelley 768a9780ca rename compileErr builtin to compileError 2016-09-05 17:01:54 -04:00
Andrew Kelley 320e26590a fix std io input to work for non seekable fds 2016-08-31 20:23:47 -07:00
Andrew Kelley 651dc31247 implement null as a literal type 2016-08-29 22:14:09 -07:00
Andrew Kelley 6149f73189 std: more progress toward stack printing 2016-08-29 22:13:59 -07:00
Andrew Kelley ed50bd1b65 progress toward stack trace printing 2016-08-17 20:11:04 -07:00
Andrew Kelley a2ac06dcd5 std: replace print_u64/i64 with printInt 2016-08-16 22:59:32 -07:00
Andrew Kelley 37d167f6e0 std: conform to style guidelines 2016-08-16 22:42:50 -07:00
Andrew Kelley 0ae9023832 add CBuf to standard library
and fix ability to take address of variables
from other namespaces
2016-08-11 22:25:13 -07:00
Andrew Kelley 0d5ecc4312 ability to have a return type of 'type' 2016-08-07 20:08:37 -07:00
Andrew Kelley 0450b73e3e std: add tests for mt32 and mt64 2016-07-28 20:14:57 -07:00
Andrew Kelley 711e3d71b9 std: add vaporware plans for floating point builtins 2016-07-27 23:46:20 -07:00
Andrew Kelley 1fa0cabf9d remove multiline comments
closes #161
2016-07-27 23:26:12 -07:00
Andrew Kelley 8552d7fd19 explicit wrapping integer operations
instead of wrapping integer types

closes #159
2016-07-27 23:08:27 -07:00
Andrew Kelley 3eb5afd245 std: cleanup of rand 2016-07-27 19:52:38 -07:00
Andrew Kelley 06c4b35eb1 std: improve rand implementation and API 2016-07-26 23:51:58 -07:00
Andrew Kelley bc81ddfea6 unsigned integers for sizes of things
Closes #62.
2016-07-26 20:40:11 -07:00
Andrew Kelley 76f87cdd96 std: add OutStream.write_byte 2016-07-26 18:13:22 -07:00
Andrew Kelley 78d4fb20c4 inline parameters
This replaces the current generic syntax for functions and replaces
it with the concept of inline parameters.

This paves the way for the "all structs anonymous" proposal.

Closes #151.
2016-07-25 22:55:15 -07:00
Andrew Kelley b08bc84a36 don't add no-frame-pointer-elim for inline functions
and make syscall functions inline
this gets the tests all passing on i386
2016-05-18 18:30:03 -07:00