Commit Graph

222 Commits

Author SHA1 Message Date
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