Commit Graph

73 Commits (3bd5c16f39a67889600a2102b716ccf7f9ba70f0)

Author SHA1 Message Date
tgschultz 8c28b59605 Added ability to specify endianess of PackedInt(Array/Slice) 2019-05-04 16:17:12 +00:00
tgschultz 4dfd1f54db Ugh. I updated these but forgot to git add. 2019-05-04 03:08:33 +00:00
Rohlem a824a8c687 add std.ascii to std.std test "std" 2019-03-29 12:18:42 -04:00
Shawn Landden b76398c993 std: add ascii with C ASCII character classes
Does NOT look at the locale the way the C functions do.

       int isalnum(int c);
       int isalpha(int c);
       int iscntrl(int c);
       int isdigit(int c);
       int isgraph(int c);
       int islower(int c);
       int isprint(int c);
       int ispunct(int c);
       int isspace(int c);
       int isupper(int c);
       int isxdigit(int c);

       int isascii(int c);
       int isblank(int c);

       int toupper(int c);
       int tolower(int c);

Tested to match glibc (when using C locale) with this program:

const c = @cImport({
    // See https://github.com/ziglang/zig/issues/515
    @cDefine("_NO_CRT_STDIO_INLINE", "1");
    @cInclude("stdio.h");
    @cInclude("string.h");
    @cInclude("ctype.h");
});

const std = @import("std");
const ascii = std.ascii;
const abort = std.os.abort;

export fn main(argc: c_int, argv: **u8) c_int {
    var i: u8 = undefined;
    i = 0;
    while (true) {
        if (ascii.isAlNum(i) != (c.isalnum(i) > 0)) { abort(); }
        if (ascii.isAlpha(i) != (c.isalpha(i) > 0)) { abort(); }
        if (ascii.isCtrl(i) != (c.iscntrl(i) > 0)) { abort(); }
        if (ascii.isDigit(i) != (c.isdigit(i) > 0)) { abort(); }
        if (ascii.isGraph(i) != (c.isgraph(i) > 0)) { abort(); }
        if (ascii.isLower(i) != (c.islower(i) > 0)) { abort(); }
        if (ascii.isPrint(i) != (c.isprint(i) > 0)) { abort(); }
        if (ascii.isPunct(i) != (c.ispunct(i) > 0)) { abort(); }
        if (ascii.isSpace(i) != (c.isspace(i) > 0)) { abort(); }
        if (ascii.isUpper(i) != (c.isupper(i) > 0)) { abort(); }
        if (ascii.isXDigit(i) != (c.isxdigit(i) > 0)) { abort(); }
        if (i == 255) { break; }
        i += 1;
    }

    _ = c.printf(c"Success!\n");
    return 0;
}
2019-03-22 16:25:56 -04:00
Andrew Kelley d213708333
this empty import workaround no longer necessary 2019-03-13 14:13:09 -04:00
Andrew Kelley 5362ca204f
Merge branch 'valgrind' of https://github.com/daurnimator/zig into daurnimator-valgrind 2019-03-11 13:27:04 -04:00
Andrew Kelley e402455704
rename std lib files to new convention 2019-03-02 16:46:04 -05: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
notkild 8a827fafa6 Add support to open, create and close file 2016-02-28 23:12:58 +01:00
Andrew Kelley 207862647c std: fix parse_u64 implementation and add test
also codegen implement comparision with pure errors
2016-02-09 09:51:25 -07:00
Andrew Kelley 6b3ce918db array.len generates a constant number literal expression 2016-02-07 15:52:52 -07:00
Andrew Kelley 42fe4e3cc8 remove ptr field access of arrays
use &array[0] instead
2016-02-07 15:43:19 -07:00
Andrew Kelley 4c8f26e9f6 std: remove auto flushing of stderr. use printf 2016-02-06 19:48:42 -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 bb4a532785 move os_get_random_bytes to os.zig 2016-02-04 01:00:54 -07:00
Andrew Kelley 5ad84e4724 unreachable causes a trap in debug mode 2016-02-02 02:43:33 -07:00
Andrew Kelley 6f1a7a0d70 add abort function and "cold" fn attribute 2016-02-02 00:42:06 -07:00
MovingtoMars 3fd6c0ce25 fix some inaccuracy in float printing 2016-01-29 21:22:15 +13:00
MovingtoMars a6c2b013fd remove some magic numbers from float printing 2016-01-29 21:19:21 +13:00
MovingtoMars 90a32629c0 float printing mostly works 2016-01-29 20:55:38 +13:00
Andrew Kelley 2fc4b3629a std: remove incorrect float printing code 2016-01-28 12:54:30 -07:00
MovingtoMars eb08fd5f5f remove accidental printf from float printing 2016-01-28 19:44:44 +13:00
MovingtoMars fb7a95b3c4 cleanup float printing 2016-01-28 19:43:08 +13:00
MovingtoMars dc08412895 basic float printing 2016-01-28 19:28:43 +13: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 50854226a6 syntax: back to -> for return type, no more => 2016-01-25 17:08:18 -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 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 91d911007b codegen: fix field access of arrays
also fix error type analyze error
2016-01-23 00:53:43 -07:00
Andrew Kelley bfceb18631 character literal returns a number literal 2016-01-22 23:24:09 -07:00
Andrew Kelley 523e3b86af support statically initialized array literal 2016-01-22 22:02:07 -07:00
Andrew Kelley b61406b607 add test for const number literal 2016-01-22 16:02:08 -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 ae2151a751 use signed integer for sizes of things 2016-01-18 21:13:14 -07:00
Andrew Kelley 4c50606b9d refactor std to use for loop 2016-01-18 07:16:17 -07:00
Andrew Kelley dc162c7f83 rename "use" to "import" 2016-01-15 18:45:52 -07:00
Andrew Kelley 0c9afede9e overflow intrinsics take type as first argument 2016-01-14 17:04:35 -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 49d0971cd4 detect and report top level decl dependency loop 2016-01-10 00:03:31 -07:00
Andrew Kelley 6d9119fcd9 add memcpy and memset intrinsics 2016-01-09 02:16:54 -07:00
Andrew Kelley bdca82ea66 implement pub const 2016-01-09 00:37:48 -07:00
Andrew Kelley b7dd88ad68 suport checked arithmetic operations via intrinsics
closes #32
2016-01-08 23:41:40 -07:00
Andrew Kelley d14a31100f implement unknown size array indexing and slicing 2016-01-08 17:52:45 -07:00
Andrew Kelley 0c84ecd19d codegen: fix else if expression and maybe unwrap expr 2016-01-08 03:59:37 -07:00
Andrew Kelley e1f498212c fix codegen for implicit maybe wrap 2016-01-08 02:52:27 -07:00