Commit Graph

223 Commits (6281a511e130aeb4f7c777de9b90c60d7c8c6f34)

Author SHA1 Message Date
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 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 087324a639 show implicit semicolon rules in langref grammar 2017-04-02 10:53:00 -07:00
Andrew Kelley f8e63c4584 change `@bitcast` to `@ptrcast`
See #290
2017-03-31 06:18:20 -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 a32b5929cc add stack protector safety when linking libc
* introduce zigrt file. it contains only weak symbols so that
   multiple instances can be merged. it contains __zig_panic
   so that multiple .o files can call the same panic function.
 * remove `@setFnVisible` builtin and add @setGlobalLinkage builtin
   which is more powerful
 * add `@panic` builtin function.
 * fix collision of symbols with extern prototypes and internal
   function names
 * add stack protector safety when linking against libc. To add
   the safety mechanism without libc requires implementing
   Thread Local Storage. See #276
2017-03-26 21:07:07 -04:00
Andrew Kelley 8aeea72654 add debug safety checks for remainder division
See #217
2017-03-26 15:06:43 -04:00
Andrew Kelley 6ee63c8f58 update langref
&&= and ||= are gone
2017-03-26 14:48:23 -04: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 eb9f1e2d53 add basic emacs syntax file 2017-03-02 23:03:44 -05:00
Andrew Kelley b78752e2d2 remove zeroes from vim syntax file 2017-03-02 23:03:30 -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 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 7749ffd797 try expression can omit variable assignments 2017-02-05 18:58:58 -05:00
Andrew Kelley 419e75eb23 remove volatileStore builtin; add volatile pointers
closes #238
2017-02-04 21:49:27 -05:00
Andrew Kelley 8c9016b6d1 add setGlobalAlign and setGlobalSection builtin functions
closes #241
2017-02-03 13:56:56 -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 4df1a9b251 document setDebugSafety builtin function 2017-02-01 03:28:40 -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 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 e5b1758010 remove staticEval builtin in favor of comptime expression 2017-01-22 23:21:00 -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 c715309bc5 Merge branch 'master' into ir-merge 2017-01-16 14:23:32 -05:00
Andrew Kelley 6caf32195a pass unnecessary if statement test 2017-01-08 22:25:38 -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 ef63bc9cca IR: implement memcpy, memset, and slice expression 2016-12-12 00:31:35 -05:00
Andrew Kelley fb21570630 IR: implement alloca builtin 2016-12-11 19:43:06 -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 0c531d447d remove the boolean argument from setFnTest 2016-12-05 21:39:15 -05:00
Andrew Kelley 1fba7f3696 IR: add inline goto 2016-11-26 23:33:07 -05:00
Andrew Kelley 4619b5de06 IR: support inline switch 2016-11-26 15:38:07 -05:00
Andrew Kelley 24b65e41ee IR: add error for non static const on switch case range 2016-11-26 04:37:34 -05:00
Andrew Kelley 0c22358cc1 IR: generating a switch statement 2016-11-24 02:44:03 -05:00
Andrew Kelley 67d565136a IR: implement ctz and clz builtins 2016-11-21 13:27:44 -05:00
Andrew Kelley d94cb0566b IR: correctly codegening memset and memcpy 2016-11-18 22:24:41 -05:00
Andrew Kelley c8333d0cc9 add concept of inline for, inline while, inline var 2016-11-03 14:13:57 -04:00
François Saint-Jacques c2710283b5 capitalize builtins in doc 2016-10-21 22:43:08 -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 077cd4b9a4 langref: correct builtin function names 2016-09-10 20:53:57 -04:00
Andrew Kelley d324b1befa ability to infer parameter types 2016-09-08 00:24:48 -04:00
Andrew Kelley 1f7ec741fa implement `?return` expression 2016-08-29 22:14:09 -07:00
Andrew Kelley ed50bd1b65 progress toward stack trace printing 2016-08-17 20:11:04 -07:00
Andrew Kelley 37d167f6e0 std: conform to style guidelines 2016-08-16 22:42:50 -07:00
Andrew Kelley 0a482bbbfe add style guide 2016-08-11 21:13:02 -07: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 1fa0cabf9d remove multiline comments
closes #161
2016-07-27 23:26:12 -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 bc81ddfea6 unsigned integers for sizes of things
Closes #62.
2016-07-26 20:40:11 -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 da8e30fe46 add some docs about builtin functions 2016-05-18 16:59:55 -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 094336f07c add integer wrapping
see #46
2016-05-05 17:19:01 -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
Josh Wolfe 61e6c49bc5 vim syntax: single-line strings must be contained in a single line 2016-04-26 01:50:21 -07:00
Andrew Kelley 46ab981787 add skeleton for union support 2016-04-24 11:24:04 -07:00
Josh Wolfe 97fae8cc85 fix vim syntax highlighting for multiline strings 2016-04-23 01:32: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 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 5df091fea9 c_void is provided outside of C imports 2016-03-01 15:26:41 -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
Andrew Kelley 7828456b30 std: delete malloc and free
later we'll add a full featured allocator instead of this
2016-02-12 02:23:22 -07:00
Andrew Kelley b642604691 targets command shows which ones are native 2016-02-10 16:35:07 -07:00
Andrew Kelley 1ff2edf67e add "targets" command to list architectures, oses, abis 2016-02-10 15:41:50 -07:00
Andrew Kelley c4f5a00253 rhs of ?? and %% can be any expression 2016-02-06 19:28:11 -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 5ad84e4724 unreachable causes a trap in debug mode 2016-02-02 02:43:33 -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 1053172854 parseh handles typedef void better
and introduce c_long_double type
2016-01-31 15:44:02 -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 e4b0435946 parseh understands variable declarations
and some initializers such as integers
2016-01-29 16:06:17 -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 f1c5d3d3a1 add parseh tests 2016-01-28 11:54:34 -07:00
Andrew Kelley b6354ddd5a move AST rendering code to separate file 2016-01-27 21:10:38 -07:00
Andrew Kelley 5afe473a86 different extern syntax and simplify parsing top level decls 2016-01-26 13:08:21 -07:00