Commit Graph

2983 Commits (0a95b0f1ffeb8ae5ee317b02626890adebe5ec63)

Author SHA1 Message Date
Andrew Kelley 0a95b0f1ff std.zig: update syntax for orelse keyword 2018-06-10 01:18:31 -04:00
Andrew Kelley 77678b2cbc
breaking syntax change: orelse keyword instead of ?? (#1096)
use the `zig-fmt-optional-default` branch to have zig fmt
automatically do the changes.

closes #1023
2018-06-10 01:13:51 -04:00
Andrew Kelley ec1b6f6673
breaking syntax change: ??x to x.? (#1095)
See #1023

This also renames Nullable/Maybe to Optional
2018-06-09 23:42:14 -04:00
Ben Noordhuis d464b25322 support `--target-arch wasm32` (#1094)
Add wasm32 support to the build-obj, build-exe and build-lib commands
of the stage 1 compiler.  Wasm64 should work transparently once it's
supported in upstream LLVM.

To export a function:

    // lib.zig - for exposition, not necessary for this example
    pub use @import("add.zig");

    // add.zig
    export fn add(a: i32, b: i32) i32 {
        return a + b;
    }

To import a function:

    // cube.zig
    extern fn square(x: i32) i32;

    export fn cube(x: i32) i32 {
        return x * square(x);
    }
2018-06-09 22:39:22 -04:00
marleck55 7a9635555b std/fmt: Use lowercase k for kilo in base 1000 (#1090) 2018-06-09 12:05:58 -04:00
Andrew Kelley 670a0a3eed Merge branch 'clownpriest-arraylist_set' 2018-06-09 12:04:48 -04:00
Andrew Kelley fc6446702e clean up std.ArrayList
* add `std.debug.assertError`
 * `std.ArrayList` update everything to follow `self` convention
 * rename `std.ArrayList.set` to `std.ArrayList.setOrError`
 * add `std.ArrayList.set` which asserts

Before 1.0.0 we might remove some of this API, because you can use
`toSlice()` for everything, but it's ok to add these functions as
an experiment before then.
2018-06-09 12:03:11 -04:00
Arthur Elliott e0092ee4a5 add set function to arraylist
so you can set a value without growing the underlying buffer,
with range safety checks
2018-06-09 11:42:41 -04:00
Andrew Kelley 9046b5eac0 fix assertion failure when debug printing comptime values 2018-06-09 11:41:59 -04:00
Andrew Kelley 6edd81109d nullable pointers follow const-casting rules
any *T -> ?*T cast is allowed implicitly, even
when it occurs deep inside the type, and the cast
is a no-op at runtime.

in order to add this I had to make the comptime value
representation of nullable pointers the same as the
comptime value representation of normal pointers,
so that we don't have to do any recursive transformation
of values when doing this kind of cast.
2018-06-09 00:26:26 -04:00
isaachier 1a9d2f3aae Fix error handling in Buffer::fromOwnedSlice (#1082) 2018-06-08 19:24:48 -04:00
Andrew Kelley 39fa313ad8 disable some implicit casts for unknown length pointers
closes #770
2018-06-08 14:57:16 -04:00
Jimmi HC bf3d1c1aab Allow access of array.len through a pointer 2018-06-08 09:21:31 +02:00
Marc Tiehuis ffb089a9f5 Fix json parser comma after empty object case 2018-06-08 17:43:13 +12:00
Andrew Kelley f0b6dac1f2 add implicit casts from `*[N]T`
* to `[]T`
 * to `[*]T`

See #770
2018-06-07 22:41:58 -04:00
Andrew Kelley b65203f573 remove @canImplicitCast builtin
nobody will miss it
2018-06-07 19:50:25 -04:00
Andrew Kelley 688ff2830d langref: automatic update of builtin.zig
now the docs can't get out of date for this

See #367
2018-06-07 19:10:45 -04:00
Andrew Kelley 31aefa6a21 fix structs that contain types which require comptime
Now, if a struct has any fields which require comptime,
such as `type`, then the struct is marked as requiring
comptime as well. Same goes for unions.

This means that a function will implicitly be called
at comptime if the return type is a struct which contains
a field of type `type`.

closes #586
2018-06-07 18:07:30 -04:00
Andrew Kelley b11c5d8f82
fix std.os.windows.PathFileExists specified in the wrong DLL (#1066)
closes #1054
2018-06-06 15:36:47 -04:00
isaachier 4fc601895b Fix const-ness of buffer in replaceContents method (#1065) 2018-06-06 14:09:47 -04:00
Marc Tiehuis e7f141b376 Add json.TokenStream (#1062)
This hides some of the low-level parsing details from the
StreamingParser. These don't need to be known when parsing a complete
slice at once (which is we can usually do).

Also, remove `Json` from Parser names. The namespace `json` is sufficient.
2018-06-06 11:24:36 -04:00
Braedon f389e53735 Add newline to zig fmt error (#1064) 2018-06-06 10:45:19 -04:00
Marc Tiehuis 212449bc23 Fix Log2Int type construction
The following case for example, would previously fail:

    const a = u24(1) << Log2Int(u24)(22);
2018-06-06 22:41:55 +12:00
Andrew Kelley d3693dca73 Pointer Reform: update @typeInfo
* add assertion for trying to do @typeInfo on global error set
 * remove TypeInfo.Slice
 * add TypeInfo.Pointer.Size with possible values
   - One
   - Many
   - Slice

See #770
2018-06-06 00:39:39 -04:00
Andrew Kelley 76c8efd56c add test for not allowing implicit cast from T to [*]const T
See #770
2018-06-05 23:54:14 -04:00
Andrew Kelley bd13e757e7 disable deref syntax for unknown length pointers
See #770
2018-06-05 23:26:43 -04:00
Andrew Kelley 0ccc186869 disable field access for unknown length pointers
See #770
2018-06-05 23:26:43 -04:00
Andrew Kelley bbb565a21e README: update support table
macosx does not run on some of these architectures
2018-06-05 21:56:19 -04:00
Andrew Kelley 652f4bdf62 disallow unknown-length pointer to opaque
This also means that translate-c has to detect when a pointer to
opaque is happening, and use `*` instead of `[*]`.

See #1059
2018-06-05 18:03:21 -04:00
Andrew Kelley 7a09482536 fix crash when evaluating return type has compile error
closes #1058
2018-06-05 10:48:53 -04:00
Andrew Kelley 677eaf29b1
Merge pull request #1057 from ziglang/comptime-int
Rename integer literal type and float literal type
2018-06-05 10:16:51 -04:00
Jimmi HC a8146ade2a Renamed UndefinedLiteral to Undefined 2018-06-05 11:54:11 +02:00
Jimmi HC 236c680f6b Removed NullLiteral to Null 2018-06-05 11:30:01 +02:00
Jimmi HC 02cb220faf Renamed "(int/float literal)" to "comptime_int/float" 2018-06-05 11:14:43 +02:00
Andrew Kelley e53b683bd3
Pointer Reform: proper slicing and indexing (#1053)
* enable slicing for single-item ptr to arrays
 * disable slicing for other single-item pointers
 * enable indexing for single-item ptr to arrays
 * disable indexing for other single-item pointers

see #770
closes #386
2018-06-04 22:11:14 -04:00
Andrew Kelley 32e0dfd4f0 never call malloc with size 0
instead we return nullptr. this makes the behavior consistent
across all platforms.

closes #1044
closes #1045
2018-06-04 14:09:31 -04:00
Andrew Kelley d21a1922eb support `zig fmt: off` and `zig fmt: on` between top level decls
closes #1030
closes #1033
2018-06-04 12:15:02 -04:00
Andrew Kelley 8dfa66fee3 Merge branch 'tgschultz-zig-custom-format' 2018-06-04 11:07:47 -04:00
Andrew Kelley 11e7e03139 Merge branch 'zig-custom-format' of https://github.com/tgschultz/zig into tgschultz-zig-custom-format
I removed the code that checks for type signature and type.
A function named `format` is enough for zig to give it a try.
2018-06-04 11:06:55 -04:00
Andrew Kelley 96164ce613 disallow single-item pointer indexing
add pointer arithmetic for unknown length pointer
2018-06-04 01:39:57 -04:00
Marc Tiehuis 4c273126df Add context to zig_unreachable calls (#1039)
This greatly aids debugging on platforms with no stack-traces.
2018-06-03 02:30:43 -04:00
Andrew Kelley b85b68a7fd better compile error for error sets behind nullable 2018-06-02 15:20:51 -04:00
Marc Tiehuis e514454c0e Make zig fmt exit with error on any parse errors
This is required for proper detection in editor plugins. Other files may
have been formatted correctly, this only indicates that some failed.
2018-06-02 20:49:35 +12:00
Andrew Kelley f06bce5dda introduce [*] for unknown length pointers
See #770

Currently it does not have any different behavior than `*`
but it is now recommended to use `[*]` for unknown length
pointers to be future-proof.

Instead of [ * ] being separate tokens as the proposal
suggested, this commit implements `[*]` as a single token.
2018-06-02 04:04:23 -04:00
Andrew Kelley 7b386ea242 fix build file template
See #1035
2018-06-01 21:51:54 -04:00
Andrew Kelley a3d7a807b7 appveyor: remove llvm 5.0.1 from cache 2018-06-01 12:22:53 -04:00
Andrew Kelley 081072d3b6 docs: add missing builtin to langref syntax coloring 2018-06-01 12:22:53 -04:00
Arthur Elliott 08693411d2 fix typo (#1034) 2018-06-01 12:23:07 -04:00
Andrew Kelley 3918e7699d
Merge pull request #1032 from ziglang/pointer-reform
use * for pointer type instead of &
2018-06-01 11:49:25 -04:00
Andrew Kelley e29d12d821 fix incorrect address-of syntax on windows 2018-06-01 01:29:34 -04:00