| author | |
| committer | |
| log | f5cc7f65a3764e90b0daaa0388f683589ee105e0 |
| tree | e77013dcc1462292eef2e21fdb9b27dc3d752696 |
| parent | 419652ee8ff709deae988603ecca2c335599d969 |
5 files changed, 24 insertions(+), 27 deletions(-)
example/guess_number/main.zig+1-2| ... | ... | @@ -18,8 +18,7 @@ pub fn main(args: [][]u8) %void => { |
| 18 | 18 | return error.GetRandomFail; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | var rand : Rand; | |
| 22 | rand.init(seed); | |
| 21 | var rand = rand_new(seed); | |
| 23 | 22 | |
| 24 | 23 | const answer = rand.range_u64(0, 100) + 1; |
| 25 | 24 |
src/analyze.cpp+1-7| ... | ... | @@ -3955,7 +3955,6 @@ static void analyze_top_level_fn_def(CodeGen *g, ImportTableEntry *import, AstNo |
| 3955 | 3955 | |
| 3956 | 3956 | AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto; |
| 3957 | 3957 | bool is_exported = (fn_proto->visib_mod == VisibModExport); |
| 3958 | int gen_arg_index = 0; | |
| 3959 | 3958 | for (int i = 0; i < fn_proto->params.length; i += 1) { |
| 3960 | 3959 | AstNode *param_decl_node = fn_proto->params.at(i); |
| 3961 | 3960 | assert(param_decl_node->type == NodeTypeParamDecl); |
| ... | ... | @@ -3978,12 +3977,7 @@ static void analyze_top_level_fn_def(CodeGen *g, ImportTableEntry *import, AstNo |
| 3978 | 3977 | var->src_arg_index = i; |
| 3979 | 3978 | param_decl_node->data.param_decl.variable = var; |
| 3980 | 3979 | |
| 3981 | if (type->size_in_bits > 0) { | |
| 3982 | var->gen_arg_index = gen_arg_index; | |
| 3983 | gen_arg_index += 1; | |
| 3984 | } else { | |
| 3985 | var->gen_arg_index = -1; | |
| 3986 | } | |
| 3980 | var->gen_arg_index = param_decl_node->data.param_decl.gen_index; | |
| 3987 | 3981 | } |
| 3988 | 3982 | |
| 3989 | 3983 | TypeTableEntry *expected_type = unwrapped_node_type(fn_proto->return_type); |
src/codegen.cpp+4| ... | ... | @@ -2319,6 +2319,10 @@ static void do_code_gen(CodeGen *g) { |
| 2319 | 2319 | if (param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) { |
| 2320 | 2320 | LLVMAddAttribute(argument_val, LLVMReadOnlyAttribute); |
| 2321 | 2321 | } |
| 2322 | if (param_type->id == TypeTableEntryIdPointer) { | |
| 2323 | // when https://github.com/andrewrk/zig/issues/82 is fixed, add | |
| 2324 | // non null attribute here | |
| 2325 | } | |
| 2322 | 2326 | if (param_node->data.param_decl.is_byval) { |
| 2323 | 2327 | LLVMAddAttribute(argument_val, LLVMByValAttribute); |
| 2324 | 2328 | } |
std/rand.zig+14-14| ... | ... | @@ -6,20 +6,6 @@ pub struct Rand { |
| 6 | 6 | array: [ARRAY_SIZE]u32, |
| 7 | 7 | index: isize, |
| 8 | 8 | |
| 9 | /// Initialize random state with the given seed. | |
| 10 | pub fn init(r: &Rand, seed: u32) => { | |
| 11 | r.index = 0; | |
| 12 | r.array[0] = seed; | |
| 13 | var i : isize = 1; | |
| 14 | var prev_value: u64 = seed; | |
| 15 | while (i < ARRAY_SIZE) { | |
| 16 | r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + u32(i)); | |
| 17 | prev_value = r.array[i]; | |
| 18 | i += 1; | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | ||
| 23 | 9 | /// Get 32 bits of randomness. |
| 24 | 10 | pub fn get_u32(r: &Rand) u32 => { |
| 25 | 11 | if (r.index == 0) { |
| ... | ... | @@ -91,3 +77,17 @@ pub struct Rand { |
| 91 | 77 | } |
| 92 | 78 | } |
| 93 | 79 | |
| 80 | /// Initialize random state with the given seed. | |
| 81 | pub fn rand_new(seed: u32) Rand => { | |
| 82 | var r: Rand; | |
| 83 | r.index = 0; | |
| 84 | r.array[0] = seed; | |
| 85 | var i : isize = 1; | |
| 86 | var prev_value: u64 = seed; | |
| 87 | while (i < ARRAY_SIZE) { | |
| 88 | r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + u32(i)); | |
| 89 | prev_value = r.array[i]; | |
| 90 | i += 1; | |
| 91 | } | |
| 92 | return r; | |
| 93 | } |
test/run_tests.cpp+4-4| ... | ... | @@ -1242,14 +1242,14 @@ struct Foo { |
| 1242 | 1242 | x: i32, |
| 1243 | 1243 | y: i32, |
| 1244 | 1244 | } |
| 1245 | fn make_foo() Foo => { | |
| 1245 | fn make_foo(x: i32, y: i32) Foo => { | |
| 1246 | 1246 | Foo { |
| 1247 | .x = 1234, | |
| 1248 | .y = 5678, | |
| 1247 | .x = x, | |
| 1248 | .y = y, | |
| 1249 | 1249 | } |
| 1250 | 1250 | } |
| 1251 | 1251 | pub fn main(args: [][]u8) %void => { |
| 1252 | const foo = make_foo(); | |
| 1252 | const foo = make_foo(1234, 5678); | |
| 1253 | 1253 | if (foo.y != 5678) { |
| 1254 | 1254 | print_str("BAD\n"); |
| 1255 | 1255 | } |