Commit Graph

52 Commits (d464b2532200de3778ac7362e701791a11150d55)

Author SHA1 Message Date
Andrew Kelley 31aefa6a21 fix structs that contain types which require comptime
Now, if a struct has any fields which require comptime,
such as `type`, then the struct is marked as requiring
comptime as well. Same goes for unions.

This means that a function will implicitly be called
at comptime if the return type is a struct which contains
a field of type `type`.

closes #586
2018-06-07 18:07:30 -04:00
Andrew Kelley e53b683bd3
Pointer Reform: proper slicing and indexing (#1053)
* enable slicing for single-item ptr to arrays
 * disable slicing for other single-item pointers
 * enable indexing for single-item ptr to arrays
 * disable indexing for other single-item pointers

see #770
closes #386
2018-06-04 22:11:14 -04:00
Andrew Kelley 2a7c8c5b10 add test case for pointer to type and slice of type
closes #588
2018-06-01 00:18:10 -04: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 ea58f4a5a9 run zig fmt on the codebase 2018-05-30 16:09:11 -04:00
Andrew Kelley 0c16cd2d0e run zig fmt on the codebase
See #1003
2018-05-29 04:23:38 -04:00
Andrew Kelley 86a352c45b Merge branch 'master' into pointer-reform 2018-05-13 13:38:03 -04:00
Andrew Kelley 277b9cf878 fix comptime code modification of global const
closes #1008
2018-05-11 22:41:44 -04:00
Andrew Kelley a35b366eb6 [breaking] delete ptr deref prefix op
start using zig-fmt-pointer-reform branch build of zig fmt
to fix code to use the new syntax

all of test/cases/* are processed, but there are more left
to be done - all the std lib used by the behavior tests
2018-04-30 20:35:54 -04:00
Andrew Kelley ec2a81a081 fix compiler-rt ABI for x86_64 windows 2018-04-28 22:03:07 -04:00
Andrew Kelley 89a4c373d3 fix bigint twos complement implementation
closes #948
2018-04-23 12:06:18 -04:00
Andrew Kelley 032fccf615 fix compile time array concatenation for slices
closes #866
2018-03-28 23:25:12 -04:00
Andrew Kelley 5834ff0cc5 don't memoize comptime fn calls that access comptime mutable state
closes #827
2018-03-12 08:35:41 -04:00
Andrew Kelley 1bf2810f33 fix comptime slicing not preserving comptime mutability
* fix comptime slice of slice not preserving mutatibility
   of the comptime data
 * fix comptime slice of pointer not preserving mutability
   of the comptime data

closes #826
2018-03-12 01:21:10 -04:00
Andrew Kelley 49c3922037 fix incorrect setEvalBranchQuota compile error
closes #688
2018-03-12 00:08:52 -04:00
Andrew Kelley 6db9be8900 don't memoize comptime functions if they can mutate state via parameters
closes #639
2018-03-09 14:20:44 -05:00
Andrew Kelley aaf2230ae8 fix partial inlining of binary math operator using old value
the code was abusing the internal IR API. fixed now.

closes #699
2018-03-08 17:15:55 -05:00
Andrew Kelley 72ca2b214d ability to slice an undefined pointer at compile time if the len is 0 2018-02-16 15:22:29 -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 3268276b58 the same string literal codegens to the same constant
this makes it so that you can send the same string literal
as a comptime slice and get the same type
2018-01-11 21:02:30 -05:00
Andrew Kelley d917815d81 explicitly return from blocks
instead of last statement being expression value

closes #629
2017-12-22 00:50:30 -05:00
Andrew Kelley 14cda27b64 depend on embedded SoftFloat-3d instead of __float128
See #302
See #467
2017-09-14 01:46:47 -04:00
Andrew Kelley 09bd4a9a86 compile-time f32, f64 operations are now correctly lossy
previously we used the bigfloat abstraction to do all
compile-time float math. but runtime code and comptime code
are supposed to get the same result. so now if you add a
f32 to a f32 at compile time it does it with f32 math
instead of the bigfloat. float literals still get the
bigfloat math.

closes #424
2017-08-20 01:04:51 -04:00
Andrew Kelley caaeab9882 add setEvalBranchQuota builtin function 2017-08-19 17:10:29 -04:00
Andrew Kelley 2dfb1ebee2 const global values can reference each other
Before, if you did something like:

```
const hi1 = "hi";
const hi2 = hi1;
```

This would create the "hi" data twice in the built object.
But since the value is const we don't have to duplicate the
data, now we take advantage of this fact.

closes #336
2017-05-27 00:54:14 -04:00
Andrew Kelley 68add5d828 clean up behavior test names 2017-05-23 21:38:31 -04:00
Andrew Kelley 29b488245d add setFloatMode builtin and std.math.floor
* skip installing std/rand_test.zig as it's not needed beyond running
   the std lib tests
 * add std.math.floor function
 * add setFloatMode builtin function to choose between
   builtin.FloatMode.Optimized (default) and builtin.FloatMode.Strict
   (Optimized is equivalent to -ffast-math in gcc)
2017-05-20 23:06:32 -04:00
Andrew Kelley 051ee8e626 change slicing syntax from ... to ..
See #359
2017-05-19 10:39:59 -04:00
Andrew Kelley 9851a943ed add compile error for compile-time integer cast truncating bits
closes #371
2017-05-16 17:04:35 -04:00
Andrew Kelley 698829b772 change while syntax
Old:

```
while (condition; expression) {}
```

New:

```
while (condition) : (expression) {}
```

This is in preparation to allow nullable and
error union types as the condition. See #357
2017-05-03 18:12:07 -04:00
Andrew Kelley 34eff50326 fix for loops not working at compile-time
closes #315
2017-04-10 03:00:19 -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 3103355805 add comptime eval for some uint comparisons with 0
closes #55
2017-03-26 14:41:17 -04:00
Andrew Kelley 7ce753a16b replace "&&" and "||" with "and" and "or"
closes #272
2017-03-26 05:21:28 -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 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 39287d7346 rework compile-time known pointer values
See #257
2017-02-11 13:13:45 -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 2b88441295 fix behavior when initializing struct with undefined 2017-02-02 14:55:01 -05:00
Andrew Kelley d2b94afaf2 fix compile time initialization of array with undefined 2017-01-29 23:35:34 -05:00
Andrew Kelley 3caf6bacdc fix sometimes using wrong outer scope for generating defers 2017-01-29 21:57:49 -05:00
Andrew Kelley c75e58ffe6 fix behavior for comptime and runtime basic block phi 2017-01-29 19:10:56 -05:00
Andrew Kelley e0a422ae7e fix runtime branching tricking the comptime evaluation
closes #167
2017-01-26 15:34:36 -05:00
Andrew Kelley 32d8686da8 various fixes
* comptime expression is a block expression as it should be
 * fix var args when number of args passed is 0
 * implement const value equality for structs
 * fix indent when rendering container decl AST
 * IR: prevent duplicate generation of code when it is partially
   compile-time evaluated
 * implement compile time struct field pointer evaluation
 * fix compile time evaluation of slicing
2017-01-23 23:30:20 -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 3b5e26b7f7 self hosted tests import std library 2017-01-05 03:57:48 -05:00
Andrew Kelley aee7ad3de2 IR: port all passing tests over 2016-12-26 03:44:59 -05:00
Andrew Kelley 73a751911e IR: pass staticEvalListInit test 2016-12-26 03:16:19 -05:00