Commit Graph

1138 Commits (cf5108f222107ed242d2dc2c37d76758157da542)

Author SHA1 Message Date
Andrew Kelley cf5108f222 correct size of types for packed structs
with byte aligned but non-power-of-2 fields such as 24
2017-02-21 14:22:23 -05:00
Andrew Kelley 4709fe1176 more robust detection of types that failed to resolve 2017-02-20 19:56:07 -05:00
Andrew Kelley c4ee37f506 fix assertion failure when first use of a struct is sizeOf 2017-02-18 18:33:21 -05:00
Andrew Kelley 0148f39df9 pointers with bit offset contain length
adds compile error when passing pointer that is byte-aligned
at the beginning but not the end to a function expecting
a fully byte aligned pointer

closes #261
2017-02-16 19:35:42 -05:00
Andrew Kelley 244362fed7 ability to write to bit fields
See #261
2017-02-16 18:42:52 -05:00
Andrew Kelley b6e7a0dadd support arithmetic for non byte aligned integer types
see #261
2017-02-16 17:08:55 -05:00
Andrew Kelley fc5d47b9b9 reading from a bit field partially works
See #261

Still need to do:
 * reading a field that has bit offset 0 but still needs to
   shift and truncate
 * writing a field
2017-02-16 15:45:41 -05:00
Andrew Kelley 4b5cc80f66 move volatile pointers to central type table 2017-02-16 13:58:42 -05:00
Andrew Kelley 4a957b9ea3 move int and array types to central table 2017-02-16 13:45:14 -05:00
Andrew Kelley 1fc2082b4c ability to declare const bitfields
See #261
2017-02-15 18:55:29 -05:00
Andrew Kelley 63d37b7cff add runtime debug safety for dividing integer min value by -1
closes #260
2017-02-14 01:08:30 -05:00
Andrew Kelley 0931b85bd0 fix crash when return value is ??void
closes #258
2017-02-12 18:27:34 -05:00
Andrew Kelley 79ec5a0287 fix tokenization assertion failure on some float numbers
See #258
2017-02-12 17:56:34 -05:00
Andrew Kelley b61f1a9f7d printf: only include + sign on signed ints if width specified
see #258
2017-02-12 17:46:28 -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 ca180d3f02 std.io.parseUnsigned buf parameter is const
fixes padding in printf

See #258
2017-02-11 15:06:20 -05:00
Andrew Kelley f7173f4f08 fix crash on string literal with character code >= 128
See #258
2017-02-11 14:01:11 -05:00
Andrew Kelley 39287d7346 rework compile-time known pointer values
See #257
2017-02-11 13:13:45 -05:00
Andrew Kelley 12049aa43b zig logo in readme 2017-02-09 12:51:23 -05:00
Andrew Kelley 92ffcc84a9 remove the depends_on_compile_var code
cleanup from the decision in commit 8a859afd58
to remove "unnecessary if statement" error
2017-02-09 12:43:08 -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 8a859afd58 std.io supports printing integers as hex values
remove "unnecessary if statement" error
this "depends on compile variable" code is too hard to validate,
and has false negatives. not worth it right now.

std.str removed, instead use std.mem.

std.mem.eql and std.mem.sliceEql merged and do not require explicit
type argument.
2017-02-07 17:23:50 -05:00
Andrew Kelley 92793252ad inline assembly allows clobbers with no input 2017-02-07 01:53:45 -05:00
Andrew Kelley 916a96fb72 variables, memcpy, and memset all get alignment
See #37
2017-02-07 01:50:10 -05:00
Andrew Kelley 573f3f8d48 coldcc works better
* Only use Cold Calling Convention on x86
 * Add the cold attribute to functions marked with coldcc
2017-02-06 13:50:19 -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 28f63b8a4f fix volatile not respected for storing through a struct pointer 2017-02-05 20:49:14 -05:00
Andrew Kelley d26bb3ae2e fix assigning to const ptr through struct or index 2017-02-05 19:55:37 -05:00
Andrew Kelley 7749ffd797 try expression can omit variable assignments 2017-02-05 18:58:58 -05:00
Andrew Kelley b9c943b066 tell LLVM the target sub arch type 2017-02-05 18:23:54 -05:00
Andrew Kelley 0c88b1ce73 use printf in test runner code 2017-02-05 16:09:33 -05:00
Andrew Kelley 135c021c83 delete unneeded IR code and fix assigning to const ptr 2017-02-05 16:06:06 -05:00
Andrew Kelley 025051885b fix volatile not respected for loads 2017-02-05 16:00:12 -05:00
Andrew Kelley d151c58788 all functions are nounwind because zig does not support exceptions 2017-02-05 13:14:42 -05:00
Andrew Kelley 52eec6b9a6 `%=` in inline assembly survives optimization 2017-02-05 13:12:06 -05:00
Andrew Kelley 6f316d8ebd setGlobalSection and setGlobalAlign work for functions 2017-02-05 12:50:19 -05:00
Andrew Kelley d2f1f57fa4 even external functions which provide definitions get nounwind 2017-02-05 01:57:49 -05:00
Andrew Kelley 74d41ce44b infer hard float from target environments that imply it 2017-02-05 00:16:49 -05:00
Andrew Kelley e56f903522 memset and memcpy implementations need not return dest 2017-02-04 23:04:07 -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 b840184bb0 memcpy and memset builtins support volatile pointers
See #238
2017-02-04 22:12:06 -05:00
Andrew Kelley 419e75eb23 remove volatileStore builtin; add volatile pointers
closes #238
2017-02-04 21:49:27 -05:00
Andrew Kelley 0d7abc6368 add compile error when setting non power of 2 alignment 2017-02-04 10:38:38 -05:00
Andrew Kelley 0919ea0afd ability to set global variable alignment and ...
..section in the initialization expression
2017-02-04 10:22:07 -05:00
Andrew Kelley 67b02326f8 preserve names of exported variables 2017-02-03 16:27:24 -05:00
Andrew Kelley d3f1889951 in freestanding environment, assume gnu binutils
for now. soon LLD will free us from depending on
system linkers.
2017-02-03 15:53:23 -05:00
Andrew Kelley 5a86c04996 add volatileStore() builtin function
See #238

We can revisit how volatile will work later - for now
here's a builtin function to do it.
2017-02-03 15:14:18 -05:00
Andrew Kelley 8c9016b6d1 add setGlobalAlign and setGlobalSection builtin functions
closes #241
2017-02-03 13:56:56 -05:00
Andrew Kelley 3be4b6434c add ability to set linker script 2017-02-03 12:34:20 -05:00
Andrew Kelley e00eec1c29 typedefs work for binary math operations 2017-02-03 12:09:13 -05:00