Commit Graph

312 Commits

Author SHA1 Message Date
Jimmi Holst Christensen
bb80daf509 Ast Render no longer outputs erroneous semicolon
closes #813
2018-03-07 10:39:32 +01: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
8429d4ceac implement coroutine resume 2018-02-28 22:18:48 -05:00
Andrew Kelley
c60496a297 parse await and suspend syntax
See #727
2018-02-26 00:04:11 -05:00
Andrew Kelley
236bbe1183 implement IR analysis for async function calls
See #727
2018-02-21 00:52:20 -05:00
Andrew Kelley
a06f3c74fd parse async fn definitions
See #727
2018-02-20 00:31:52 -05:00
Andrew Kelley
3d58d7232a parse async fn calls and cancel expressions 2018-02-20 00:05:38 -05:00
Andrew Kelley
ee982ae162 syntax: parse ?error!i32 as ?(error!i32) 2018-02-08 22:30:08 -05:00
Andrew Kelley
abf5ae6897 *WIP* error sets - support fns called at comptime 2018-02-03 11:51:29 -05:00
Andrew Kelley
b8f59e14cd *WIP* error sets - correctly resolve inferred error sets 2018-02-02 18:13:32 -05:00
Andrew Kelley
5f518dbeb9 *WIP* error sets converting std lib 2018-01-31 22:48:40 -05:00
Andrew Kelley
5161d70620 *WIP* error sets 2018-01-31 01:51:31 -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
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
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
5b156031e9 enum tag values are expressions so no parentheses needed 2018-01-03 16:05: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
9d9201c3b4 bring back code that uses export and fix tests
partial revert of 1fdebc1dc4
2017-12-19 02:39:43 -05:00
Andrew Kelley
27ba4f0baf export keyword works again 2017-12-19 01:49:42 -05:00
Andrew Kelley
c627f9ea18 wip bring back export keyword 2017-12-19 01:19:49 -05:00
Andrew Kelley
1fdebc1dc4 wip export rewrite 2017-12-18 09:59:57 -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
b62e2fd870 ability to specify tag type of enums
see #305
2017-11-30 22:08:11 -05:00
Andrew Kelley
57ea6e8c9f fix up msvc stuff to make it work on linux and macos too 2017-09-13 02:40:02 -04:00
Jonathan Marler
7c81cd30de Add support for MSVC 2017-09-11 09:26:26 -06:00
Andrew Kelley
cc621cdee3 fix parseh bugs 2017-09-05 00:21:02 -04:00
Andrew Kelley
ee9d1d0414 c-to-zig: return statement 2017-09-01 03:16:35 -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
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
dea90e20e6 fix tokenization error pointing to wrong character
closes #401
2017-08-14 13:28:42 -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
d1e68c3ca8 better bigint/bigfloat implementation 2017-07-08 17:59:10 -04:00
scurest
1a63f27247 allow trailing commas
closes #392
2017-06-17 10:34:51 -04:00
Andrew Kelley
6a93dda3e1 progress toward windows hello world working 2017-06-14 00:04:34 -04:00
Andrew Kelley
051ee8e626 change slicing syntax from ... to ..
See #359
2017-05-19 10:39:59 -04:00
Andrew Kelley
6237411716 inline function call with builtin function instead...
...of special syntax.

partially reverts 41144a8566

closes #306
2017-05-09 22:54:23 -04:00
Andrew Kelley
b6a679c0ed implement else on loops and break can give an expression
closes #357
2017-05-04 12:43:11 -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
aafb0b9082 slicing now returns correct const-ness
also remove the ability to override constness when slicing

closes #334
2017-04-22 12:19:20 -04:00
Andrew Kelley
0cce115476 update syntax for try and nullable unwrapping
closes #285
2017-04-21 16:46:33 -04:00
Andrew Kelley
d5346d7a80 remove ?return and ?defer
closes #309
2017-04-21 15:08:03 -04:00
Josh Wolfe
3e93796e24 comptime ({}) should not get an implicit semicolon
closes #292.
2017-04-14 16:09:01 -07:00
Andrew Kelley
f2140efc52 Merge remote-tracking branch 'origin/parser' 2017-04-13 03:09:09 -04:00
Andrew Kelley
bf57d8a7e3 typedefpocalypse
closes #314
2017-04-13 03:07:58 -04:00
Josh Wolfe
356424916c block statement lists never get fake expressions
instead blocks have a field that encodes whether the last statement ended with
a semicolon.
2017-04-12 23:22:32 -07:00
Andrew Kelley
41144a8566 ability to inline at function callsite
closes #306
2017-04-13 00:13:54 -04:00
Josh Wolfe
0594487a2e fix else-if parsing
implicit semicolon rules apply recursively to the "else" clause of if and try

if (a) {} else {} // implicit semicolon
if (a) {} else if (a) {} // implicit semicolon
if (a) {} else while (a) {} // implicit semicolon
2017-04-02 15:15:48 -07:00
Josh Wolfe
a33be6fc99 defer without a block body requires a following semicolon 2017-04-02 13:47:23 -07:00
Josh Wolfe
8d03d666af add secret void expression after defer statement if it's the last statement in a block 2017-04-02 13:18:12 -07:00
Josh Wolfe
e3c796258c allow implicit semicolon after defer {} 2017-04-02 13:01:23 -07:00
Josh Wolfe
136a9a9d6b variable declarations must be followed by semicolon 2017-04-02 12:46:18 -07:00
Josh Wolfe
4b9e782d37 fix confusion in block expression parsing
closes #292

* if, try, while, for, comptime, defer are "greedy" with {} blocks,
  meaning if their bodies are blocks, then no suffix operator is allowed
  after the block. The {} block gets "built into" the containing statement,
  like the body of a switch statement.
* the Expression syntactic element is no longer "greedy" with {} blocks,
  meaning it's possible to have suffix operators after {} blocks without
  needing the {} block to be an rhs operand first.
2017-04-02 11:50:34 -07:00
Josh Wolfe
9968879261 Require top-level-declaration comptime use {}
This forbids `comptime 1 comptime 1` at top-level scope.
2017-04-02 11:02:47 -07:00
Josh Wolfe
36a015741d clean up analysis of {blocks}
* Don't insert void statements all over the place. {} now stays as
  {} instead of {{}}, and {;} becomes {} instead of {{};{}}.
* Ensure final statement is always the return value statement, or
  the block is empty. This means {label:} becomes {label:{}}.
2017-03-31 08:54:03 -07: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
22e6bfca96 add comptime top level declaration
closes #255
2017-03-26 04:32:13 -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
92793252ad inline assembly allows clobbers with no input 2017-02-07 01:53:45 -05:00
Andrew Kelley
7749ffd797 try expression can omit variable assignments 2017-02-05 18:58:58 -05:00
Andrew Kelley
64a0510205 inline assembly supports %= syntax
it outputs a number that is unique to each instance of the asm
statement in the entire compilation.

useful when creating local labels and referring to them multiple
times in a single template that generates multiple
assembler instructions
2017-02-04 22:33:58 -05:00
Andrew Kelley
419e75eb23 remove volatileStore builtin; add volatile pointers
closes #238
2017-02-04 21:49:27 -05:00
Andrew Kelley
71d335e5cc implement packed structs
closes #183
2017-02-03 11:39:24 -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
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
17cb85dfb8 basic support for functions with variable length arguments
See #77
2017-01-23 16:40:17 -05:00
Andrew Kelley
201a3c121a introduce comptime expression
closes #221
2017-01-22 22:59:52 -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
6a5e61acd1 get rid of zeroes literal
closes #222
2017-01-16 17:24:13 -05:00
Andrew Kelley
0c1800a9c9 fix some stuff when llvm has assertions on 2017-01-13 17:33:19 -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
37b13bf151 hello.zig working with all structs anonymous 2016-12-18 17:24:52 -05:00
Andrew Kelley
e50ced44a2 IR: all structs anonymous 2016-12-18 16:56:50 -05:00
Andrew Kelley
c0b2fe4d6c IR: add error for assigning runtime value to inline var 2016-12-07 00:22:14 -05:00
Andrew Kelley
6ed202ab16 IR: implement defer 2016-12-06 21:26:17 -05:00
Andrew Kelley
2f259b8176 IR: re-organize where state goes to prepare for generics
* Rip out legacy code for generics
 * put scope in instruction instead of AST nodes
 * separate top level decl stuff from AST nodes
   - remove the assumption that there is a 1:1 correspondence
     between an output instruction and an AST node
   - This way we won't have to clone AST nodes for generics.
2016-12-04 03:40:40 -05:00
Andrew Kelley
1fba7f3696 IR: add inline goto 2016-11-26 23:33:07 -05:00
Andrew Kelley
a3db60b5d7 IR: fix parsing while loop 2016-11-26 21:16:36 -05:00
Andrew Kelley
4619b5de06 IR: support inline switch 2016-11-26 15:38:07 -05:00
Andrew Kelley
0c22358cc1 IR: generating a switch statement 2016-11-24 02:44:03 -05:00
Andrew Kelley
c3b603fdf9 remove AST cloning code and add AST render for while loops 2016-11-17 21:17:58 -05:00
Andrew Kelley
62d0d88b56 IR: pointers to constants don't copy data 2016-11-17 04:00:02 -05:00
Andrew Kelley
c8333d0cc9 add concept of inline for, inline while, inline var 2016-11-03 14:13:57 -04:00
Andrew Kelley
ac6d1674e3 IR working for if statements 2016-10-16 02:19:01 -04:00
Andrew Kelley
633781e31d empty function compiles successfully with IR 2016-09-30 20:12:00 -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
3239b3cb69 use size_t for indexes
protect against incorrect copies in debug mode
2016-09-19 11:54:01 -04:00
Andrew Kelley
d324b1befa ability to infer parameter types 2016-09-08 00:24:48 -04:00
Andrew Kelley
2ed949a6ae add zeroes value 2016-08-08 20:43:38 -07:00
Andrew Kelley
d0b11af2bd new multiline string syntax
This patch also moves a bunch of the parser code into the tokenizer.

Closes #162.
2016-08-04 22:52:38 -07:00
Andrew Kelley
8552d7fd19 explicit wrapping integer operations
instead of wrapping integer types

closes #159
2016-07-27 23:08:27 -07:00