Commit Graph

392 Commits (d87b13f2f7cef04058537c8bfeb1ceda1a067e73)

Author SHA1 Message Date
Andrew Kelley 52f4e934a9
fix llvm assertion and missing compile error 2018-09-10 22:44:27 -04:00
raulgrell 09a1162af5 builtin functions: @byteOffsetOf and @bitOffsetOf 2018-09-07 22:49:19 +01:00
Andrew Kelley b18af37c57
fix crash when var init has compile error
and then the var is referenced

closes #1483
2018-09-07 15:17:24 -04:00
Andrew Kelley 6632d85e5f
stage1: improve handling of generic fn proto type expr
closes #902
2018-09-05 21:21:59 -04:00
Andrew Kelley 1d8b8ad687
add compile error for using outer scoped runtime variables
from a fn defined inside it. closes #876
2018-09-05 20:32:06 -04:00
Andrew Kelley b517bea734
allow comptime_int to @floatToInt 2018-09-05 18:01:48 -04:00
hfcc 768d1fc539 Added compilation error when a non-float is given to @floatToInt() 2018-09-05 23:31:25 +02:00
Andrew Kelley c87a576cb5
stage1 compile error instead of crashing for unsupported comptime ptr cast
See #955
2018-09-05 15:53:36 -04:00
Andrew Kelley a76a72469b
stage1: fix crash when invalid type used in array type
closes #1186
2018-09-05 10:43:35 -04:00
Andrew Kelley 869167fc6d
compile error for @noInlineCall on an inline fn
closes #1133
2018-09-04 17:38:48 -04:00
Andrew Kelley 68db9d5074
add compile error for comptime control flow inside runtime block
closes #834
2018-09-04 15:28:35 -04:00
Andrew Kelley b65cca37ce
add test coverage for invalid switch expression parameter
closes #604
2018-08-28 15:48:39 -04:00
Andrew Kelley 901b5c1566
add compile error for function prototype with no body
closes #1231
2018-08-28 15:39:32 -04:00
Andrew Kelley 009e90f446
fix @typeInfo unable to distinguish compile error vs no-payload
closes #1421
closes #1426
2018-08-27 17:13:34 -04:00
kristopher tate 298abbcff8 better support for `_` identifier
* disallow variable declaration of `_`
 * prevent `_` from shadowing itself
 * prevent read access of `_`

closes #1204
closes #1320
2018-08-03 02:57:17 -04:00
Andrew Kelley 895f262a55 pull request fixups
* clean up parser code
 * fix stage2 parse and render code
 * remove redundant test
 * make stage1 compile tests leaner
2018-08-02 14:15:31 -04:00
kristopher tate 51955a5ca2 test/compile_errors.zig: update test to reflect that the promise symbol is no in scope with suspend;
Tracking Issue #1296 ;
2018-08-02 17:02:14 +09:00
kristopher tate 13ec5db234 test/compile_errors.zig: @handle() in non-async function
Tracking Issue #1296 ;
2018-08-02 16:50:08 +09:00
kristopher tate c546f750f1 test/compile_errors.zig: @handle() called outside of function definition;
Tracking Issue #1296 ;
2018-08-02 16:50:08 +09:00
Andrew Kelley 2cbad364c1 add compile error for ignoring return value of while loop bodies
closes #1049
2018-07-26 18:29:07 -04:00
Andrew Kelley fd575fe1f3 add compile error for missing parameter name of generic function 2018-07-25 18:15:55 -04:00
Andrew Kelley 84195467ad add compile error for non-inline for loop on comptime type 2018-07-25 17:08:55 -04:00
Andrew Kelley 29e19ace36 fix logic for determining whether param requires comptime
closes #778
closes #1213
2018-07-24 10:21:33 -04:00
Andrew Kelley e9a03cccf3 all integer sizes are available as primitives
* fix wrong implicit cast for `@IntType` bit_count parameter.
 * fix incorrect docs for `@IntType` bit_count parameter.

closes #1242
closes #745
closes #1240
2018-07-16 10:53:15 -04:00
Andrew Kelley 3f30897fdc add compile error for disallowed types in extern structs
closes #1218
2018-07-11 14:08:56 -04:00
Andrew Kelley 28f9230b40 fix crash when calling comptime-known undefined function ptr
closes #880
closes #1212
2018-07-10 10:12:08 -04:00
Andrew Kelley 2ee67b7642 langref: docs for invalid error set cast and incorrect pointer alignment
also add detection of incorrect pointer alignment at compile-time
of pointers that were constructed with `@intToPtr`.
2018-07-09 11:13:29 -04:00
Andrew Kelley 9eb51e20ed fix crash on @ptrToInt of a *void
closes #1192
2018-07-09 10:44:06 -04:00
Andrew Kelley d8295c1889 add @popCount intrinsic 2018-07-07 00:25:32 -04:00
Andrew Kelley 1cf7511dc9 add compile error notes for where struct definitions are
closes #1202
2018-07-06 16:20:46 -04:00
Isaac Hier 9cff23dbf9 Fix assertion crash on enum switch values 2018-07-04 13:27:10 -04:00
Andrew Kelley 4c0e280d6d
Merge pull request #1185 from ziglang/undefined-at-comptime-improvements
Operators now throw a compiler error when operating on undefined values
2018-07-01 01:33:23 -04:00
Jimmi Holst Christensen b182151de5 Fixed line numbers for tests 2018-06-30 21:59:14 +02:00
Jimmi Holst Christensen ecd5e60be9 Expanded the list of operators that catch undefined values at comptime 2018-06-30 20:50:09 +02:00
Jimmi Holst Christensen 01bd5c46e1 Revert "ir_resolve_const now checks recursivly for undef values"
This reverts commit 4c3f27ce1e.
2018-06-30 17:35:06 +02:00
isaachier f1c56f7f22 Clarify reason implicit cast does not work for large RHS (#1168)
* Clarify reason implicit cast does not work for large RHS
2018-06-29 14:52:25 -04:00
Jimmi HC 4c3f27ce1e ir_resolve_const now checks recursivly for undef values 2018-06-29 10:21:43 +02:00
Andrew Kelley 459d72f873 fix compiler crash for invalid enum
closes #1079
closes #1147
2018-06-21 17:41:49 -04:00
Andrew Kelley 42db807f37 remove redundant implicit casting code
and introduce better type mismatch errors

closes #1061
2018-06-19 18:51:46 -04:00
Andrew Kelley c7804277bf `@floatToInt` now has safety-checked undefined behavior
when the integer part does not fit in the destination integer type

 * Also fix incorrect safety triggered for integer casting an
   `i32` to a `u7`. closes #1138
 * adds compiler-rt function: `__floatuntidf`
2018-06-19 16:06:10 -04:00
Andrew Kelley a3ddd0826b remove enum to/from int casting syntax; add `@enumToInt`/`@intToEnum`
see #1061
2018-06-19 03:50:38 -04:00
Andrew Kelley 626b73e8be remove error to/from int casting syntax; add `@errorToInt`/`@intToError`
See #1061
2018-06-18 18:48:29 -04:00
Andrew Kelley 1aafbae5be remove []u8 casting syntax. add `@bytesToSlice` and `@sliceToBytes`
See #1061
2018-06-18 17:25:29 -04:00
Andrew Kelley 8fd7cc11e1 disallow opaque as a return type of fn type syntax
closes #1115
2018-06-18 11:12:15 -04:00
Andrew Kelley d49d6f0cde fix compiler crash when using @intToFloat with float literal
closes #1132
2018-06-18 11:04:18 -04:00
Andrew Kelley 3c12ba7180 update test cases 2018-06-17 04:32:57 -04:00
Andrew Kelley e311cd562b don't automatically take pointer when passing by non-copying value
this commit does not have all tests passing
2018-06-16 19:37:00 -04:00
Andrew Kelley 59b3dc8907 allow passing by non-copying value
closes #733
2018-06-16 19:36:33 -04:00
Andrew Kelley 8dd24796c4 disallow implicit casts that break rules for optionals
closes #1102
2018-06-13 11:04:09 -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
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 76c8efd56c add test for not allowing implicit cast from T to [*]const T
See #770
2018-06-05 23:54:14 -04:00
Andrew Kelley bd13e757e7 disable deref syntax for unknown length pointers
See #770
2018-06-05 23:26:43 -04:00
Andrew Kelley 0ccc186869 disable field access for unknown length pointers
See #770
2018-06-05 23:26:43 -04:00
Andrew Kelley 652f4bdf62 disallow unknown-length pointer to opaque
This also means that translate-c has to detect when a pointer to
opaque is happening, and use `*` instead of `[*]`.

See #1059
2018-06-05 18:03:21 -04:00
Andrew Kelley 7a09482536 fix crash when evaluating return type has compile error
closes #1058
2018-06-05 10:48:53 -04:00
Jimmi HC 02cb220faf Renamed "(int/float literal)" to "comptime_int/float" 2018-06-05 11:14:43 +02: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 96164ce613 disallow single-item pointer indexing
add pointer arithmetic for unknown length pointer
2018-06-04 01:39:57 -04:00
Andrew Kelley b85b68a7fd better compile error for error sets behind nullable 2018-06-02 15:20:51 -04:00
Andrew Kelley 019217d7a2 fix regressions 2018-06-01 00:17:31 -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 0c16cd2d0e run zig fmt on the codebase
See #1003
2018-05-29 04:23:38 -04:00
Andrew Kelley c38b165db4 all tests passing with postfix deref syntax 2018-05-17 23:21:44 -04:00
Alexandros Naskos 255c0ef406 Resolved merge conflict. 2018-05-01 13:09:34 +03:00
Alexandros Naskos ff1c4e1f13 Added tests. 2018-05-01 13:00:39 +03:00
Jimmi Holst Christensen fba0347ec4 .ReturnType and @ArgType now emits errors on unresolved types
related: #846
2018-04-28 17:17:48 +02:00
Andrew Kelley 8503eff8c1 add compile error for invalid deref on switch target
closes #945
2018-04-22 23:46:55 -04:00
Andrew Kelley c4840d78fb add test case for #936 2018-04-21 02:10:22 -04:00
Andrew Kelley 06909ceaab support break in suspend blocks
* you can label suspend blocks
 * labeled break supports suspend blocks

See #803
2018-04-18 22:21:54 -04:00
Andrew Kelley f1f998e071 improve cmpxchg
* remove @cmpxchg, add @cmpxchgWeak and @cmpxchgStrong
   - See explanations in the langref.
 * add operand type as first parameter
 * return type is ?T where T is the operand type

closes #461
2018-04-18 12:16:42 -04:00
Andrew Kelley 373b3586a1 inline functions must be stored in const or comptime var
closes #913
2018-04-12 16:26:23 -04:00
Andrew Kelley e48e707c32 allow integer and float literals to be passed to var params
closes #623
2018-04-11 14:47:37 -04:00
Andrew Kelley 6cb99fdac3 fix crash when compile error in analyzing @panic call 2018-03-27 15:07:45 -04:00
Andrew Kelley f885a1ab61 change async function call syntax
* instead of `async(allocator) call()`, now it is
   `async<allocator> call()`.
 * Fixes syntax ambiguity when leaving off the allocator
 * Fixes parse failure when call is a field access

This sets a precedent for using `<` to pass arguments
to a keyword. This will affect `enum`, `union`, and
`fn` (see #661)
2018-03-21 19:56:41 -04:00
Andrew Kelley efebb6d341 fix tests broken by previous commit 2018-03-14 03:37:54 -04:00
Andrea Orru c828c23f71 Tests for zero-bit field compiler error 2018-03-13 22:07:40 -07:00
Andrew Kelley 790aaeacae add compile error for using @tagName on extern union
closes #742
2018-03-07 14:35:48 -05:00
Andrew Kelley d96dd5bc32 fix missing compile error for returning error from void async function
closes #799
2018-03-06 21:44:27 -05:00
Andrew Kelley eff3530dfa var is no longer a pseudo-type, it is syntax
closes #779
2018-03-06 18:31:31 -05:00
Andrew Kelley 5d5820029d fix broken tests from previous commit 2018-03-06 16:46:45 -05:00
Andrew Kelley 07e47c058c ptrCast builtin now gives an error for removing const qualifier
closes #384
2018-03-06 16:37:03 -05:00
Ben Noordhuis 90598b4631 fix assert on self-referencing function ptr field
The construct `struct S { f: fn(S) void }` is not legal because structs
are not copyable but it should not result in an ICE.

Fixes #795.
2018-02-28 00:56:00 +01: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 9fa35adbd4 fix sometimes not type checking function parameters
closes #774

regression introduced in cfb2c67692
2018-02-14 16:24:43 -05:00
Andrew Kelley e7bf8f3f04 fix compiler crash switching on global error with no else 2018-02-09 13:49:58 -05:00
Andrew Kelley 916d24cd21 add compile error tests for error sets 2018-02-08 23:44:21 -05:00
Andrew Kelley 54c06bf715 error sets: runtime safety for int-to-err and err set cast 2018-02-08 21:54:44 -05:00
Andrew Kelley f9be970375 Merge remote-tracking branch 'origin/master' into error-sets 2018-02-08 20:45:26 -05:00
Andrew Kelley 0d5ff6f462 error sets - most tests passing 2018-02-08 02:08:45 -05:00
Andrew Kelley 44d8d654a0 fix test failure, organize code, add new compile error 2018-02-05 09:26:39 -05:00
Andrew Kelley 5f518dbeb9 *WIP* error sets converting std lib 2018-01-31 22:48:40 -05:00
Andrew Kelley 44f38b04b0 fix assertion fail when using global var number literal
closes #697
2018-01-31 11:13:39 -05:00
Andrew Kelley 40ca39d3d5 fix error message mentioning unreachable instead of noreturn 2018-01-31 01:44:52 -05:00
Andrew Kelley 3ef6a00bb8 add compile error for duplicate struct, enum, union fields
closes #730
2018-01-30 11:52:03 -05:00
Andrew Kelley 1c60f31450 add compile error for calling naked function 2018-01-29 14:01:12 -05:00
Andrew Kelley abe6c2d585 allow packed containers in extern functions 2018-01-29 10:57:09 -05:00
Andrew Kelley ad3e2a5da0 fix compiler crash on function with invalid return type
closes #722
2018-01-26 10:37:18 -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 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 5b7ae86af4 fix crash when switching on enum with 1 field and no switch prongs
closes #712
2018-01-21 14:44:24 -05:00
Andrew Kelley ea623f2d39 all doc code examples are now tested
improve color scheme of docs
make docs depend on no external files
fix broken example code in docs

closes #465
2018-01-19 03:21:47 -05:00
Andrew Kelley 4b64c777ee add compile error for shifting by negative comptime integer
closes #698
2018-01-18 17:47:21 -05:00
Andrew Kelley 0fc645ab70 emit a compile error for @panic called at compile time
closes #706
2018-01-18 17:15:36 -05:00
Andrew Kelley 7b57454cc1 clean up error return tracing
* error return tracing is disabled in release-fast mode
 * add @errorReturnTrace
 * zig build API changes build return type from `void` to `%void`
 * allow `void`, `noreturn`, and `u8` from main. closes #535
2018-01-15 00:01:02 -05:00
Andrew Kelley 3c094116aa remove %% prefix operator
See #632
closes #545
closes #510

this makes #651 higher priority
2018-01-09 00:51:51 -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
Andrew Kelley bb39e503c0 fix struct inside function referencing local const
closes #672

the crash and compile errors are fixed but structs
inside functions still get named after the functions
they're in. this will be fixed later.
2018-01-07 00:28:37 -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 8bc523219c add labeled loops, labeled break, labeled continue. remove goto
closes #346
closes #630

regression: translate-c can no longer translate switch statements.
after #629 we can ressurect and modify the code to utilize arbitrarily
returning from blocks.
2017-12-20 23:00:19 -05:00
Andrew Kelley 1cc450e6e7 fix assert when wrapping zero bit type in nullable
closes #659
2017-12-19 18:21:42 -05:00
Andrew Kelley 9d9201c3b4 bring back code that uses export and fix tests
partial revert of 1fdebc1dc4
2017-12-19 02:39:43 -05:00
Andrew Kelley 1fdebc1dc4 wip export rewrite 2017-12-18 09:59:57 -05:00
Andrew Kelley 960914a073 add implicit cast from enum to union
when the enum is the tag type of the union and is comptime known
to be of a void field of the union

See #642
2017-12-05 20:46:58 -05:00
Andrew Kelley 63a2f9a8b2 fix casting integer literal to enum 2017-12-05 18:09:22 -05:00
Andrew Kelley 05d9f07541 more tests for unions
See #618
2017-12-04 00:56:27 -05:00
Andrew Kelley fce435db26 fix abi alignment of union-enums not counting tag type
add more tests for unions

See #618
2017-12-04 00:32:12 -05:00
Andrew Kelley 0ad1239522 rework enums and unions and their relationship to each other
* @enumTagName renamed to @tagName and it works on enums and
   union-enums
 * Remove the EnumTag type. Now there is only enum and union,
   and the tag type of a union is always an enum.
 * unions support specifying the tag enum type, and they support
   inferring an enum tag type.
 * Enums no longer support field types but they do support
   setting the tag values. Likewise union-enums when inferring
   an enum tag type support setting the tag values.
 * It is now an error for enums and unions to have 0 fields.
 * switch statements support union-enums

closes #618
2017-12-03 20:43:56 -05:00
Andrew Kelley 137c8f5e8a ability to set tag values of enums
also remove support for enums with 0 values

closes #305
2017-12-02 22:32:39 -05:00
Andrew Kelley 98237f7c0b casting between integer and enum only works via tag type
See #305
2017-12-02 17:12:37 -05:00
Andrew Kelley b62e2fd870 ability to specify tag type of enums
see #305
2017-11-30 22:08:11 -05:00
Andrew Kelley a2afcae9ff fix crash when constant inside comptime function has compile error
closes #625
2017-11-25 18:16:33 -05:00
Andrew Kelley f276fd0f37 basic union support
See #144
2017-11-15 13:04:18 -05:00
Andrew Kelley 7ea669e04c fix parameter of extern var args not type checked
closes #601
2017-11-09 11:30:39 -05:00
Andrew Kelley 634e8713c3 add @memberType and @memberName builtin functions
see #383

there is a plan to unify most of the reflection into 2
builtin functions, as outlined in the above issue,
but this gives us needed features for now, and we can
iterate on the design in future commits
2017-11-06 22:07:19 -05:00
Andrew Kelley f0d755153d add compile-time reflection for function arg types
See #383
2017-11-04 16:20:02 -04:00
Marc Tiehuis 6663638195 Improve invalid character error messages (#566)
See #544
2017-10-26 10:00:23 -04:00
Andrew Kelley 300c83d893 fix crash on field access of opaque type 2017-10-25 23:18:18 -04:00
Andrew Kelley 643ab90ace add maximum value for @setAlignStack 2017-10-23 22:33:00 -04:00
Andrew Kelley e3ad13e054 fix windows argument parsing 2017-10-15 20:19:15 -04:00
Andrew Kelley b4e42042cf fix compiler crash when invalid value used
closes #527
2017-10-06 12:41:14 -04:00
Andrew Kelley f1bd02e6f4 add @setAlignStack builtin 2017-10-03 00:29:27 -04:00
Marc Tiehuis 9dfe217be3 Allow 128-bit hex float literals
Closes #499.
2017-09-28 23:33:36 +13:00
Andrew Kelley dbc202cc6a add test for struct with invalid field
see #468
2017-09-17 23:21:22 -04:00
Andrew Kelley 011df61f8a fix not verifying GlobalLinkage and AtomicOrder types
thanks to aep4Ayai on IRC
2017-09-10 14:04:19 -04:00
Andrew Kelley bc0a60c7a6 more compile errors for non-const variables of things
closes #456
2017-09-09 22:46:08 -04:00
Andrew Kelley 3ff465e288 add OpaqueType builtin
closes #326
2017-09-05 18:51:07 -04:00
Andrew Kelley c42e809f13 setEvalBranchQuota must be called from top of comptime stack 2017-08-31 16:54:20 -04:00
Andrew Kelley 67b6dd28ec allow array literals to have size and fix comptime bug 2017-08-31 16:30:46 -04:00
Andrew Kelley 052b4ae941 align syntax: align(4) instead of align 4
closes #37
2017-08-30 04:54:33 -04:00
Andrew Kelley e9280c86a1 compile error for not-aligned-enough pointer to cmpxchg
See #37
2017-08-30 02:56:42 -04:00
Andrew Kelley b35dad88b4 add tests for function alignment handling
See #37
2017-08-30 00:06:14 -04:00
Andrew Kelley 898d65baa9 more alignment improvements
* add alignment capability for fn protos
 * add @alignCast
 * fix some ast rendering code
 * fix some ir rendering code
 * add error for pointer cast increasing alignment
 * update allocators in std to correctly align

See #37
2017-08-29 23:33:25 -04:00
Andrew Kelley 910a96f046 fix tests 2017-08-29 17:10:11 -04:00
Andrew Kelley 816689a3b1 ptrCast gives compile error for increasing alignment
See #37
2017-08-29 16:52:31 -04:00
Andrew Kelley be94299666 prevent implicitly increasing pointer alignment
See #37
2017-08-29 15:19:15 -04:00
Andrew Kelley c5c9d98065 introduce align keyword
* remove `@setGlobalAlign`
 * add align keyword for setting alignment on functions and
   variables.
 * loads and stores use alignment from pointer
 * memcpy, memset use alignment from pointer
 * add syntax for pointer alignment
 * slices can have volatile
 * add u2, i2 primitives
 * ignore preferred align and use abi align everywhere
 * back to only having alignOf builtin.
   preferredAlignOf is too tricky to be useful.
   See #432. Partial revert of
   e726925e80.

See #37
2017-08-29 07:51:34 -04:00
Andrew Kelley cd2f65ff6a add compile error for globally shadowing a primitive type
closes #423
2017-08-19 02:02:25 -04:00
Andrew Kelley 987768778a bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7
 * shift operations shift amount parameter type is
   integer with log2 bit width of other param
   - This enforces not violating undefined behavior on
     shift amount >= bit width with the type system
 * clean up math.log, math.ln, math.log2, math.log10

closes #403
2017-08-19 01:43:43 -04:00
Andrew Kelley 35d3444e27 more intuitive left shift and right shift operators
Before:
 * << is left shift, not allowed to shift 1 bits out
 * <<% is left shift, allowed to shift 1 bits out
 * >> is right shift, allowed to shift 1 bits out

After:
 * << is left shift, allowed to shift 1 bits out
 * >> is right shift, allowed to shift 1 bits out
 * @shlExact is left shift, not allowed to shift 1 bits out
 * @shrExact is right shift, not allowed to shift 1 bits out

Closes #413
2017-08-09 10:09:38 -04:00
Andrew Kelley 54675b060a add ptrToInt builtin, remove usize(ptr) cast
closes #415
2017-08-08 17:38:25 -04:00
Andrew Kelley 2234788fa8 add ability to explicitly cast float to integer
closes #414
2017-08-07 15:57:41 -04:00
Marc Tiehuis 0705b711f8 Correct floating-point literal allowed ranges
The exponent range for floating-point values is [-1022, 1023].

Fixes #399.
2017-08-07 18:08:09 +12:00
Andrew Kelley ad9f48b74b fix initializing undefined and crash when casting to invalid type
closes #408
2017-08-05 16:54:50 -04:00
Andrew Kelley 6a93dda3e1 progress toward windows hello world working 2017-06-14 00:04:34 -04:00
Andrew Kelley e5b90651ba compileError builtin includes "referenced by" notes
to help track down the cause

closes #278
2017-06-03 15:09:40 -04:00
Andrew Kelley c42c91ee7c fix segfault with array of generic functions
closes #377
2017-05-26 14:39:18 -04:00
Andrew Kelley fcdd808c5c fix segfault with array of variadic functions
closes #377
2017-05-25 13:48:10 -04:00
Andrew Kelley 1c8fee41c2 add compile error for goto leaving defer expression
closes #284
2017-05-21 10:59:09 -04:00
Andrew Kelley 9f3cca8615 add error for break/continue exiting defer expression
See #284
2017-05-21 10:44:55 -04:00
Andrew Kelley 1c6f415a64 fix compiler crash when indexing types
closes #376
2017-05-21 09:50:15 -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 a7570186eb add compile error for comptime division by zero
closes #372
2017-05-14 13:07:45 -04:00
Andrew Kelley 63f6676fee add compile error for casting negative value to...
...unsigned integer at compile-time
2017-05-10 00:21:27 -04:00
Andrew Kelley 7261cd19b7 detect duplicate switch value even when else prong present
closes #43
2017-05-07 13:40:35 -04:00
Andrew Kelley 818a0a2629 switch expression - add compile errors
* for duplicate integer value
   * for missing integer values
   * for missing else prong

see #43
2017-05-07 12:07:35 -04:00
Andrew Kelley 29beb603b7 allow division and remainder operators sometimes
when the values are comptime known and the result would be the same,
allow `/` and `%` for signed integers and floats.

closes #365
2017-05-06 23:59:57 -04:00
Andrew Kelley 157af4332a builtin functions for division and remainder division
* add `@divTrunc` and `@divFloor` functions
 * add `@rem` and `@mod` functions
 * add compile error for `/` and `%` with signed integers
 * add `.bit_count` for float primitive types

closes #217
2017-05-06 23:13:12 -04:00
Andrew Kelley 866c841dd8 add compile error when unable to inline a function
See #38
2017-05-04 15:11:24 -04:00
Andrew Kelley 20b1491e6b implement while for nullables and error unions
See #357
2017-05-04 10:28:00 -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 644ea2dde9 remove test and try expressions in favor of if expressions
See #357
2017-05-03 17:23:11 -04:00
Andrew Kelley 0940d46c01 add compile error for shadowing variable
closes #360
2017-05-03 16:13:57 -04:00
Andrew Kelley 6756c27ca4 zig build: cache_root is relative to build_root 2017-05-03 16:13:57 -04:00
Andrew Kelley 17b935325e `@import("builtin")` instead of `@compileVar`
See #226
Closes #220
2017-05-01 13:12:38 -04:00
Andrew Kelley 458afb0ef9 phi instruction retains stack ptr hint 2017-04-27 23:40:43 -04:00
Andrew Kelley 2e512a0e6e add compile error for returning local variable address
closes #344
2017-04-27 19:40:35 -04:00
Josh Wolfe 08a871f625 defer requires expr to be void. closes #341 2017-04-23 22:33:06 -07:00
Josh Wolfe ac7971122d fix check-statement-is-void. add tests
see #291
2017-04-23 21:50:34 -07:00
Josh Wolfe c6605cba83 blocks check that their statements are void
closes #291

This changes the error message "return value ignored" to "expression value is ignored".
This is because this error also applies to {1;}, which has no function calls.

Also fix ignored expression values in std and test.
This caught a bug in debug.readAllocBytes where an early Eof error would have been missed.
See #219.
2017-04-23 21:15:15 -07:00
Josh Wolfe 14dfbd6ad3 remove redundant unreachable code error 2017-04-23 08:36:21 -07:00
Andrew Kelley ad9040443c new compile errors for setGlobalAlign and setGlobalSection builtins
if you try to use them on an external variable or function
then you get a compile error, since the alignment/section
is set externally in this case.

closes #244
2017-04-22 12:54:00 -04:00
Andrew Kelley 0cce115476 update syntax for try and nullable unwrapping
closes #285
2017-04-21 16:46:33 -04:00
Andrew Kelley e3c524c1d4 rename `@ptrcast` to `@ptrCast` to follow convention 2017-04-21 10:39:13 -04:00
Andrew Kelley 599215cee4 add compile error tests for offsetOf builtin 2017-04-20 10:57:41 -04:00
Andrew Kelley d1e01e43d3 convert assemble and link tests to zig build system 2017-04-19 14:00:12 -04:00
Andrew Kelley d0a17b6937 convert std lib tests to zig build system 2017-04-19 04:12:22 -04:00