Commit Graph

181 Commits (0a280b6062c0b0a3c7a460499c72be40acfcac46)

Author SHA1 Message Date
Andrew Kelley d5346d7a80 remove `?return` and `?defer`
closes #309
2017-04-21 15:08:03 -04:00
Andrew Kelley ecb71d1dd3 add example which exercises addObject in the zig build system
closes #329
2017-04-21 02:26:48 -04:00
Andrew Kelley fb492d19eb zig build system supports building a library
See #329

Supporting work:
 * move std.cstr.Buffer0 to std.buffer.Buffer
 * add build.zig to example/shared_library/ and add an automated test
   for it
 * add std.list.List.resizeDown
 * improve std.os.makePath
   - no longer recursive
   - takes into account . and ..
 * add std.os.path.isAbsolute
 * add std.os.path.resolve
 * reimplement std.os.path.dirname
   - no longer requires an allocator
   - handles edge cases correctly
2017-04-21 01:56:12 -04:00
Andrew Kelley 9021bb7969 std.rand API follows idiomatic convention for init 2017-04-18 02:47:10 -04:00
Andrew Kelley 72fb2443e0 API for command line args
closes #300
2017-04-04 00:17:24 -04:00
Andrew Kelley d10bbd28e9 use lld instead of system linker 2017-03-13 11:54:56 -04:00
Andrew Kelley 47f267d25f break off some of std.io into std.fmt, generalize printf
closes #250
2017-03-09 19:12:15 -05:00
Andrew Kelley 0ac1934ad6 fix examples 2017-02-26 14:35: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 07a71fc322 improved behavior on debug safety crash
* instead of emitting a breakpoint for a debug safety crash,
   zig calls a panic function which prints an error message
   and a stack trace and then calls abort.
 * on freestanding OS, this panic function has a default
   implementation of a simple infinite loop.
 * users can override the panic implementation by providing
   `pub fn panic(message: []const u8) -> unreachable { }`
 * workaround for LLVM segfaulting when you try to use cold
   calling convention on ARM.

closes #245
2017-02-06 03:10:32 -05:00
Andrew Kelley 34a4d7a201 update cat example code 2017-01-24 02:06:56 -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 e621ad014e pass cannot assign to constant test 2017-01-05 18:50:36 -05:00
Andrew Kelley cfaced3f73 rename errName builtin to errorName 2016-09-05 17:03:11 -04:00
Andrew Kelley f18e34c2c6 restore shared library functionality 2016-09-01 11:05:36 -07:00
Andrew Kelley 320e26590a fix std io input to work for non seekable fds 2016-08-31 20:23:47 -07:00
Andrew Kelley 289bfa890b fix c hello world example 2016-08-30 20:48:30 -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 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 6a7f3c8df7 std: make parsing an unsigned number generic 2016-05-13 11:11:55 -07:00
Andrew Kelley 4961910e7f cat example: fix not flushing stderr 2016-04-24 11:23:46 -07:00
Andrew Kelley f4c7e1bf49 rearrange standard library a bit 2016-04-18 16:42:56 -07:00
Andrew Kelley 1688ccb3dd update README 2016-04-14 11:34:46 -07:00
Andrew Kelley fdf6a18461 fix cat example by flushing stdout at end 2016-04-09 14:40:09 -07:00
Andrew Kelley 5dbc21b511 update cat example, refactor std
partial implementation of @err_name
2016-04-08 16:21:30 -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 d8f6388b63 if statements can be const expr evaluated
also introduce error for unnecessary if statement
but if the condition depends on a compile variable, then
the if statement is OK
2016-02-09 18:53:28 -07:00
Andrew Kelley ea3bd58563 add link to tetris example 2016-02-07 22:40:58 -07:00
Andrew Kelley 4c8f26e9f6 std: remove auto flushing of stderr. use printf 2016-02-06 19:48:42 -07:00
Andrew Kelley ec33e5a638 simple unconditional defer support
See #110
2016-02-06 01:00:29 -07:00
Andrew Kelley bb4a532785 move os_get_random_bytes to os.zig 2016-02-04 01:00:54 -07:00
Andrew Kelley 97c61313da c_import of stdio.h works for some functions
See #88
2016-01-27 23:23:02 -07:00
Andrew Kelley e809baa866 remove bogus example code 2016-01-27 12:35:06 -07:00
Andrew Kelley 5afe473a86 different extern syntax and simplify parsing top level decls 2016-01-26 13:08:21 -07:00
Andrew Kelley 4e43973413 variable initializations are now mandatory
use `undefined` if you want uninitialized memory
2016-01-25 23:56:46 -07:00
Andrew Kelley a37bb4a4da add the C integer types 2016-01-25 23:21:13 -07:00
Andrew Kelley 1d68150242 compiler enforces checking for error
See #23
2016-01-25 20:27:57 -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 bcb18338cd update std lib to use error type and global variables 2016-01-24 22:53:00 -07:00
Andrew Kelley f5cc7f65a3 fix parameter access of sret functions 2016-01-24 19:27:12 -07:00
Andrew Kelley 5c18826240 introduce the error keyword and type
See #23
2016-01-24 01:34:57 -07:00
Andrew Kelley 37aae53009 various small cleanups 2016-01-23 03:06:29 -07:00
Andrew Kelley 706f72f1b4 fix hang when returning from while loop
also fixes duplicate error message for function missing
return type.

also makes guess number game use %void for main return type.

closes #58
2016-01-23 02:46:24 -07:00
Andrew Kelley c0ea9290c4 main returns %void 2016-01-23 02:14:01 -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 ae2151a751 use signed integer for sizes of things 2016-01-18 21:13:14 -07:00
Andrew Kelley 92dccde2fd revise plan for cat example 2016-01-18 19:32:27 -07:00
Andrew Kelley 826c7f06a3 fix cat example 2016-01-16 03:31:43 -07:00
Andrew Kelley 9e74b7e754 proposed cat example implementation 2016-01-16 03:10:15 -07:00
Andrew Kelley 5f7685336f better main symbol prototype
closes #64
2016-01-16 00:07:34 -07:00
Andrew Kelley dc162c7f83 rename "use" to "import" 2016-01-15 18:45:52 -07:00
Andrew Kelley 5f9ecb8566 instead of 'as' to cast, call type as function 2016-01-14 02:52:33 -07:00
Andrew Kelley b28b7f63d1 all types are now expressions
See #22
2016-01-13 18:15:51 -07:00
Andrew Kelley 75d5786603 cleanup guess number example 2016-01-10 01:32:15 -07:00
Andrew Kelley bdca82ea66 implement pub const 2016-01-09 00:37:48 -07:00
Andrew Kelley 2a8d6af7ba fix guess number example. now it works 2016-01-08 04:08:42 -07:00
Andrew Kelley 0c84ecd19d codegen: fix else if expression and maybe unwrap expr 2016-01-08 03:59:37 -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 c75d40680f while detects simple constant condition 2016-01-06 18:02:42 -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 f1eafe4ebb fix bug in RNG example 2016-01-06 03:53:30 -07:00
Andrew Kelley 9c775d2111 codegen: fix member function invocation 2016-01-06 02:05:45 -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 e21a83dd74 update rand example 2016-01-05 17:02:26 -07:00
Andrew Kelley 4ce0fcb569 fix some errors in rand example 2016-01-05 06:50:06 -07:00
Andrew Kelley 3327b0488d add #min_value() and #max_value() 2016-01-05 06:30:49 -07:00
Andrew Kelley e1ff201d60 fix crash when struct field is invalid 2016-01-04 21:42:35 -07:00
Andrew Kelley 333a322127 multiple files example no longer use libc 2016-01-04 01:52:32 -07:00
Andrew Kelley fa6e3eec46 add #typeof() compiler function 2016-01-03 18:17:50 -07:00
Andrew Kelley b453345554 add rand example that doesn't yet work 2016-01-03 00:30:41 -07:00
Andrew Kelley 1abb4e59be fix various bugs related to guess number example 2016-01-02 21:56:33 -07:00
Andrew Kelley 187d00ca83 ability to access pointers with array indexing syntax
closes #40
2016-01-02 19:47:36 -07:00
Andrew Kelley 968b85ad77 closer to guess number example working 2016-01-02 03:38:45 -07:00
Andrew Kelley 9a8851515b basic maybe type working 2016-01-02 00:06:06 -07:00
Andrew Kelley b3ac5c16ec block expressions require parens
closes #39
2015-12-31 16:04:13 -07:00
Andrew Kelley 7ba99e9715 analyze if maybe var expressions 2015-12-26 15:43:40 -07:00
Andrew Kelley 1f8e3871ee parse if maybe expression 2015-12-26 15:05:27 -07:00
Andrew Kelley 50357dad45 add struct value expression 2015-12-24 00:00:23 -07:00
Andrew Kelley e21369a153 codegen: support byvalue struct assignment 2015-12-23 03:19:22 -07:00
Andrew Kelley 431170d981 codegen: fix struct pointer field access 2015-12-22 13:22:40 -07:00
Andrew Kelley 437e9b954d add some brainstorming example zig code 2015-12-17 14:59:08 -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 431d8f946f implicit casting from constant size array to string
closes #36
2015-12-15 17:29:44 -07:00
Andrew Kelley f5a3281877 when linking with libc use the C runtime library 2015-12-15 12:44:42 -07:00
Andrew Kelley 1f48b626a1 std: even more efficient inline assembly 2015-12-15 02:47:39 -07:00
Andrew Kelley 66ca916805 std: expose exit syscall 2015-12-15 00:07:51 -07:00
Andrew Kelley 3049410260 `const` and `var` instead of `let` and `let mut`
closes #34
2015-12-14 18:51:07 -07:00
Andrew Kelley f17e20d5fe instead of *mut and *const, & and &const
closes #33
2015-12-14 18:10:25 -07:00
Andrew Kelley e411467e1d add number literal type
it gets implicitly casted to whatever is needed.

closes #24
2015-12-14 02:46:37 -07:00
Andrew Kelley bd77bc749a structs are working 2015-12-12 22:55:29 -07:00
Andrew Kelley 38f12adbda progress on struct support 2015-12-12 02:34:09 -07:00
Andrew Kelley ac630d354d std: print_str no longer requires length argument
add explicit casting support from array to string
2015-12-12 02:05:08 -07:00