refactor std to use for loop
This commit is contained in:
parent
fbbef14013
commit
4c50606b9d
@ -52,7 +52,7 @@ compromises backward compatibility.
|
||||
|
||||
* Have a look in the examples/ folder to see some code examples.
|
||||
* Basic language features available such as loops, inline assembly,
|
||||
expressions, literals, functions, importing, structs, enums.
|
||||
expressions, literals, functions, importing, structs, tagged unions.
|
||||
* Linux x86_64 is supported.
|
||||
* Building for the native target is supported.
|
||||
* Optimized machine code that Zig produces is indistinguishable from
|
||||
|
@ -1790,7 +1790,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
|
||||
LLVMBasicBlockRef body_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForBody");
|
||||
LLVMBasicBlockRef end_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForEnd");
|
||||
|
||||
LLVMValueRef array_val = gen_expr(g, node->data.for_expr.array_expr);
|
||||
LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr);
|
||||
add_debug_source_node(g, node);
|
||||
LLVMBuildStore(g->builder, LLVMConstNull(index_var->type->type_ref), index_ptr);
|
||||
LLVMValueRef len_val;
|
||||
|
@ -11,9 +11,10 @@ pub struct Rand {
|
||||
r.index = 0;
|
||||
r.array[0] = seed;
|
||||
var i : @typeof(ARRAY_SIZE) = 1;
|
||||
var prev_value: u64 = seed;
|
||||
while (i < ARRAY_SIZE) {
|
||||
const prev_value : u64 = r.array[i - 1];
|
||||
r.array[i] = u32((prev_value ^ (prev_value << 30)) * 0x6c078965 + i);
|
||||
prev_value = r.array[i];
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
@ -67,9 +68,8 @@ pub struct Rand {
|
||||
}
|
||||
|
||||
fn generate_numbers(r: &Rand) => {
|
||||
var i : @typeof(ARRAY_SIZE) = 0;
|
||||
while (i < ARRAY_SIZE) {
|
||||
const y : u32 = (r.array[i] & 0x80000000) + (r.array[(i + 1) % ARRAY_SIZE] & 0x7fffffff);
|
||||
for (item, r.array, i) {
|
||||
const y : u32 = (item & 0x80000000) + (r.array[(i + 1) % ARRAY_SIZE] & 0x7fffffff);
|
||||
const untempered : u32 = r.array[(i + 397) % ARRAY_SIZE] ^ (y >> 1);
|
||||
r.array[i] = if ((y % 2) == 0) {
|
||||
untempered
|
||||
@ -77,7 +77,6 @@ pub struct Rand {
|
||||
// y is odd
|
||||
untempered ^ 0x9908b0df
|
||||
};
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,7 @@ pub fn readline(buf: []u8, out_len: &usize) bool => {
|
||||
pub fn parse_u64(buf: []u8, radix: u8, result: &u64) bool => {
|
||||
var x : u64 = 0;
|
||||
|
||||
var i : @typeof(buf.len) = 0;
|
||||
while (i < buf.len) {
|
||||
const c = buf[i];
|
||||
for (c, buf) {
|
||||
const digit = char_to_digit(c);
|
||||
|
||||
if (digit > radix) {
|
||||
@ -69,8 +67,6 @@ pub fn parse_u64(buf: []u8, radix: u8, result: &u64) bool => {
|
||||
if (@add_with_overflow(u64, x, digit, &x)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
*result = x;
|
||||
|
Loading…
x
Reference in New Issue
Block a user