Commit Graph

312 Commits

Author SHA1 Message Date
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
Andrew Kelley
06c4b35eb1 std: improve rand implementation and API 2016-07-26 23:51:58 -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
425c0ffa01 rename NodeTypeStructDecl to NodeTypeContainerDecl 2016-07-17 16:30:41 -07:00
Andrew Kelley
762e686d17 inline assembly: allow empty output list 2016-05-18 18:20:15 -07:00
Andrew Kelley
39016c1d3e fix offset map for inline assembly error messages 2016-05-18 18:05:03 -07:00
Andrew Kelley
f6b16c99ba fix raw string literal crash 2016-05-18 17:55:07 -07:00
Andrew Kelley
f1e5be9686 fix ability to use previous generic params and
add error when `%return` shows up in a function with incorrect
return type
2016-05-09 13:44:29 -07:00
Andrew Kelley
745c325d0f support variable declarations in structs
See #22
2016-05-09 12:34:03 -07:00
Andrew Kelley
2ed72022ce support generic data structures
See #22
2016-05-07 17:00:58 -07:00
Andrew Kelley
8c79438f6b better array concatenation semantics
closes #87
2016-05-07 10:05:59 -07:00
Andrew Kelley
7f589c0cab support maybe destructuring into a pointer variable 2016-05-03 15:06:34 -07:00
Andrew Kelley
9ccd0ba961 implement string escapes 2016-05-01 14:53:48 -07:00
Andrew Kelley
d908afe105 add array multiplication operator 2016-04-28 18:03:44 -07:00
Andrew Kelley
46b0b84b90 ability to specify body of an extern function
closes #101
2016-04-28 16:04:44 -07:00
Andrew Kelley
46ab981787 add skeleton for union support 2016-04-24 11:24:04 -07:00
Andrew Kelley
8187396f64 add syntax to allow symbols to have arbitrary strings as names 2016-04-22 15:24:18 -07:00
Andrew Kelley
6acc354957 for loop: add ability to get pointer to elem var
see #51
2016-04-20 11:58:01 -07:00
Andrew Kelley
a25307c0a1 add optional continue expression to while loop
closes #139
2016-04-19 20:28:44 -07:00
Andrew Kelley
fcedc35551 fix crash with generic function and implicit cast 2016-04-14 10:39:03 -07:00
Andrew Kelley
83a59c4d07 fix evaluating generic functions in wrong context 2016-04-13 12:28:07 -07:00
Andrew Kelley
73c814e5c0 support hex escapes in string literals 2016-04-08 17:30:26 -07:00
Andrew Kelley
491e3cb5c5 fix crash when passing empty string to function 2016-04-08 17:09:07 -07:00
Andrew Kelley
28ad4e6d83 fix segfault in generic functions
See #22
2016-04-07 15:09:55 -07:00
Andrew Kelley
1d4c66b56b support multiple generic function instances
See #22
2016-04-07 10:34:54 -07:00
Andrew Kelley
67152f7294 support simple generic functions 2016-04-06 12:58:54 -07:00
Andrew Kelley
e144ddab24 add multiline string literal
and make multiple lines in normal string literals an error
2016-04-03 18:59:43 -07:00
Andrew Kelley
f1d338194e rewrite how importing works
* Introduce the concept of packages. Closes #3
 * Add support for error notes.
 * Introduce `@import` and `@c_import` builtin functions and
   remove the `import` and `c_import` top level declarations.
 * Introduce the `use` top level declaration.
 * Add `--check-unused` parameter to perform semantic
   analysis and codegen on all top level declarations, not
   just exported ones and ones referenced by exported ones.
 * Delete the root export node and add `--library` argument.
2016-03-01 03:13:40 -07:00
Andrew Kelley
77ffb5075b update bootstrap to work for macos too
* Directives can have arbitrary expressions as parameters
 * Fix switch statement not generating code sometimes
 * Rename "main" fn in bootstrap.zig to "zig_user_main" to
   avoid name collisions
 * codegen: fix badref when unreachable is last thing in an
   expression
 * support #condition directive on exported functions
2016-02-16 16:41:56 -07:00
Serge Paquet
633b01de23 fix undefined LONG_LONG_MAX compilation error 2016-02-11 22:13:54 -05:00
Andrew Kelley
c4f5a00253 rhs of ?? and %% can be any expression 2016-02-06 19:28:11 -07:00
Andrew Kelley
73727bd1c5 parser recognizes %return in a prefix op expression
also defer only valid at statement level now

see #110
2016-02-06 19:16:01 -07:00
Andrew Kelley
ec33e5a638 simple unconditional defer support
See #110
2016-02-06 01:00:29 -07:00
Andrew Kelley
6a2ede5a6e parsing code for defer and more
* disable goto and label support see #44
 * refactor the way block contexts work
2016-02-05 23:20:34 -07:00
Andrew Kelley
4339d55562 update for loop syntax
it matches more closely the %% binary operator syntax

See #51
2016-02-05 17:15:19 -07:00
Andrew Kelley
5490f907fe switch statements resolve peer compatibility 2016-02-04 15:50:06 -07:00
Andrew Kelley
06f6acb4b1 inline is a keyword instead of a directive 2016-02-01 17:25:38 -07:00
Andrew Kelley
179443bd61 add ?? prefix operator 2016-02-01 02:11:46 -07:00
Andrew Kelley
773cd851fe parser: fix parsing of type decls 2016-01-31 17:17:00 -07:00
Andrew Kelley
55c9ae1193 codegen extern global variables correctly 2016-01-31 01:51:33 -07:00
Andrew Kelley
3c2093fec6 parseh understands types better and handles some situations better
See #88

Also, includes partial implementation of typedef top level declaration.
See #95

Also, fix function types. Previously the way we were deduping function type
pointers was incorrect.
2016-01-31 01:20:47 -07:00
Andrew Kelley
a5c2de5fee ability to specify function type
closes #14
2016-01-28 20:26:40 -07:00
Andrew Kelley
2bb2e61ee2 parser: allow missing fn name and missing param names
now these problems are caught in analyzer

this is for purpose of function type, see #14
2016-01-28 18:58:28 -07:00
Andrew Kelley
b6354ddd5a move AST rendering code to separate file 2016-01-27 21:10:38 -07:00
Andrew Kelley
0278468479 upgrade to the libclang C++ API
c_import creates a tmp .h file and parses it with libclang,
reporting any errors found.

See #88
2016-01-27 00:01:49 -07:00
Andrew Kelley
a73453a268 add c_import top level decl
see #88
2016-01-26 16:00:39 -07:00
Andrew Kelley
5afe473a86 different extern syntax and simplify parsing top level decls 2016-01-26 13:08:21 -07:00
Andrew Kelley
a3e288ab5b implement compile time string concatenation
See #76
2016-01-25 21:56:29 -07:00
Andrew Kelley
50854226a6 syntax: back to -> for return type, no more => 2016-01-25 17:08:18 -07:00
Andrew Kelley
deb3586884 implement %% prefix operator
See #23

also make undefined constants use llvm undef value
2016-01-25 15:45:05 -07:00
Andrew Kelley
6db6609df8 implement %% operator
See #23
2016-01-25 13:53:40 -07:00
Andrew Kelley
5c18826240 introduce the error keyword and type
See #23
2016-01-24 01:34:57 -07:00
Andrew Kelley
0e51c16ef5 add undefined literal 2016-01-22 22:42:02 -07:00
Andrew Kelley
272fe1c54c implicit casts rewrite the AST 2016-01-22 15:31:35 -07:00
Andrew Kelley
32e2196257 number literal rework 2016-01-21 03:02:25 -07:00
Andrew Kelley
5e212db29c parsing error value decls and error value literals
and return with '?' or '%' prefix
2016-01-20 18:18:50 -07:00
Andrew Kelley
ad9759bc8e basic support for switch expression 2016-01-20 02:12:24 -07:00
Andrew Kelley
c17309dbc5 add switch statement support to parser 2016-01-19 20:29:36 -07:00
Andrew Kelley
fbbef14013 add for loop which can iterate over arrays
See #51
2016-01-18 07:00:45 -07:00
Andrew Kelley
8818c59cbc parser: fix not setting container init kind 2016-01-15 19:02:04 -07:00
Andrew Kelley
dc162c7f83 rename "use" to "import" 2016-01-15 18:45:52 -07:00
Andrew Kelley
0311b35a21 reduce precedence of {} suffix operator
this makes []u8 {1, 2, 3, 4} work for array literal
2016-01-15 17:40:12 -07:00
Andrew Kelley
68c4f617ed fix next_node_index on wrong struct
no more nondeterministic error messages

closes #65
2016-01-14 15:27:42 -07:00
Andrew Kelley
1645fa681f parser: type expressions cannot be assignment 2016-01-14 15:21:41 -07:00
Andrew Kelley
5f9ecb8566 instead of 'as' to cast, call type as function 2016-01-14 02:52:33 -07:00
Andrew Kelley
d121ed961a fix noalias codegen
also make some parsing error messages better
2016-01-13 22:18:10 -07:00
Andrew Kelley
b28b7f63d1 all types are now expressions
See #22
2016-01-13 18:15:51 -07:00
Andrew Kelley
4d7835e21a delete unused enumfield and enumdecl node types 2016-01-10 17:27:58 -07:00
Andrew Kelley
fc748e2ccd update enum parsing to new plan 2016-01-10 16:58:21 -07:00
Andrew Kelley
3ef2f7058b refactor out the horrible beast that was codegen_node 2016-01-10 15:13:39 -07:00
Andrew Kelley
d4b8852d78 parsing enum declarations 2016-01-10 11:48:54 -07:00
Andrew Kelley
1fe1235e14 order-independent declarations
code constructs and traverses a dependency graph in a deterministic
order.
2016-01-09 23:49:22 -07:00
Andrew Kelley
bdca82ea66 implement pub const 2016-01-09 00:37:48 -07:00
Andrew Kelley
0c24ed8a81 rename restrict to noalias 2016-01-08 23:48:24 -07:00
Andrew Kelley
b7dd88ad68 suport checked arithmetic operations via intrinsics
closes #32
2016-01-08 23:41:40 -07:00
Andrew Kelley
14b9cbd43c add restrict qualifier on pointer arguments 2016-01-08 20:59:47 -07:00
Andrew Kelley
9aea99a999 implement array slicing syntax
closes #52
2016-01-07 05:29:11 -07:00
Andrew Kelley
a3c97081ca add ?? maybe unwrapping binary operator
add null literal
fix number literal / maybe interactions
2016-01-07 03:23:38 -07:00
Andrew Kelley
5e64c4d92f support pub structs. move rand to std lib.
guess number example prints the answer now
2016-01-06 04:41:11 -07:00
Andrew Kelley
3c43bc9208 support unknown size arrays 2016-01-06 01:28:58 -07:00
Andrew Kelley
4ef062b9c8 array syntax is [10]i32 instead of [i32; 10] 2016-01-05 22:47:47 -07:00
Andrew Kelley
a11d0aaf62 progress toward compile time constant expression evaluation 2016-01-04 23:37:17 -07:00
Andrew Kelley
e0aa0736be add pointer dereferencing operator 2016-01-04 19:11:36 -07:00
Andrew Kelley
4514661cfe add member functions 2016-01-04 16:57:22 -07:00
Andrew Kelley
e64c0941f9 implement #sizeof()
closes #8
2016-01-03 19:38:36 -07:00
Andrew Kelley
fa6e3eec46 add #typeof() compiler function 2016-01-03 18:17:50 -07:00
Andrew Kelley
1abb4e59be fix various bugs related to guess number example 2016-01-02 21:56:33 -07:00
Andrew Kelley
968b85ad77 closer to guess number example working 2016-01-02 03:38:45 -07:00
Andrew Kelley
b3ac5c16ec block expressions require parens
closes #39
2015-12-31 16:04:13 -07:00
Andrew Kelley
1f8e3871ee parse if maybe expression 2015-12-26 15:05:27 -07:00
Andrew Kelley
5943f99510 implement continue expression
closes #6
2015-12-24 15:36:49 -07:00
Andrew Kelley
5ceaae288c add break expression 2015-12-24 15:09:47 -07:00
Andrew Kelley
a030b60aeb add while loop 2015-12-24 14:37:43 -07:00
Andrew Kelley
50357dad45 add struct value expression 2015-12-24 00:00:23 -07:00
Andrew Kelley
9ce36ba0cc inline assembly uses -> instead of return 2015-12-23 15:49:34 -07:00
Andrew Kelley
4d45d14b55 use realpath to avoid duplicate imports 2015-12-15 21:48:41 -07:00
Andrew Kelley
aa56f016f7 support addressof operator and struct pointer field access 2015-12-15 20:08:53 -07:00
Andrew Kelley
5a8822c714 fix assignment operators for struct fields 2015-12-15 19:17:39 -07:00
Josh Wolfe
8a570c458b base 10 decimals work now. closes #15 2015-12-15 14:54:16 -07:00
Josh Wolfe
2f15babbd3 better radix handling in float parsing. base 10 still doesn't work. 2015-12-15 13:15:24 -07:00
Josh Wolfe
f2a9b40231 more number literal syntax is supported. floats still need work 2015-12-15 04:05:53 -07:00