diff --git a/juno_frontend/src/lang.l b/juno_frontend/src/lang.l index 6399e5f266640966ce660c5ec28c9c5c5be2beb2..9daf3f41c5352f2e9ec59ced31dd84c607a5e9f8 100644 --- a/juno_frontend/src/lang.l +++ b/juno_frontend/src/lang.l @@ -129,7 +129,7 @@ _ "_" 0x[0-9a-fA-F]+ "HEX_INT" 0b[0-1]+ "BIN_INT" 0o[0-7]+ "OCT_INT" -[0-9]+\.[0-9]*(|e[0-9]+) "FLOAT_LIT" +[0-9]+\.[0-9]+(|e[0-9]+) "FLOAT_LIT" @[a-zA-Z0-9_]+ "LABEL" . "UNMATCHED" diff --git a/juno_frontend/src/lang.y b/juno_frontend/src/lang.y index a5b82452d5aa588782dd01396c208ef2d159be45..be9161aaf4515123995602b8d6077fc8157a1c96 100644 --- a/juno_frontend/src/lang.y +++ b/juno_frontend/src/lang.y @@ -302,7 +302,7 @@ Stmt -> Result<Stmt, ()> inclusive: false, step: None, body: Box::new($7?) }) } | 'for' VarBind 'in' NonStructExpr '..' '=' NonStructExpr Stmts { Ok(Stmt::ForStmt{ span: $span, var: $2?, init: $4?, bound: $7?, - inclusive: false, step: None, body: Box::new($8?) }) } + inclusive: true, step: None, body: Box::new($8?) }) } | 'while' NonStructExpr Stmts { Ok(Stmt::WhileStmt{ span : $span, cond : $2?, body : Box::new($3?) }) } | 'return' ';' diff --git a/juno_samples/rodinia/backprop/src/backprop.jn b/juno_samples/rodinia/backprop/src/backprop.jn index e94e097a79fc7afade2073fd8e3b0d59bb05bb42..2927dbb59ef55681160fae56dcea64a3b8329a27 100644 --- a/juno_samples/rodinia/backprop/src/backprop.jn +++ b/juno_samples/rodinia/backprop/src/backprop.jn @@ -7,12 +7,12 @@ fn layer_forward<n, m: usize>(vals: f32[n + 1], weights: f32[n + 1, m + 1]) -> f let result : f32[m + 1]; result[0] = 1.0; - for j = 0 to m { + for j in 1..=m { let sum = 0.0; - for k = 0 to n+1 { - sum += weights[k, j+1] * vals[k]; + for k in 0..=n { + sum += weights[k, j] * vals[k]; } - result[j + 1] = squash(sum); + result[j] = squash(sum); } return result; @@ -22,11 +22,11 @@ fn output_error<n: usize>(target: f32[n + 1], actual: f32[n + 1]) -> (f32, f32[n let errsum = 0.0; let delta : f32[n + 1]; - for j = 0 to n { - let a = actual[j + 1]; - let t = target[j + 1]; - delta[j + 1] = a * (1.0 - a) * (t - a); - errsum += abs!(delta[j + 1]); + for j in 1..=n { + let a = actual[j]; + let t = target[j]; + delta[j] = a * (1.0 - a) * (t - a); + errsum += abs!(delta[j]); } return (errsum, delta); @@ -40,16 +40,16 @@ fn hidden_error<hidden_n, output_n: usize>( let errsum = 0.0; let delta : f32[hidden_n + 1]; - for j = 0 to hidden_n { - let h = hidden_vals[j + 1]; + for j in 1..=hidden_n { + let h = hidden_vals[j]; let sum = 0.0; - for k = 0 to output_n { - sum += out_delta[k + 1] * hidden_weights[j + 1, k + 1]; + for k in 1..=output_n { + sum += out_delta[k] * hidden_weights[j, k]; } - delta[j + 1] = h * (1.0 - h) * sum; - errsum += abs!(delta[j + 1]); + delta[j] = h * (1.0 - h) * sum; + errsum += abs!(delta[j]); } return (errsum, delta); @@ -64,11 +64,11 @@ fn adjust_weights<n, m: usize>( weights: f32[n + 1, m + 1], prev_weights: f32[n + 1, m + 1] ) -> (f32[n + 1, m + 1], f32[n + 1, m + 1]) { - for j = 0 to m { - for k = 0 to n+1 { - let new_dw = ETA * delta[j+1] * vals[k] + MOMENTUM * prev_weights[k, j+1]; - weights[k, j+1] += new_dw; - prev_weights[k, j+1] = new_dw; + for j in 1..=m { + for k in 0..=n { + let new_dw = ETA * delta[j] * vals[k] + MOMENTUM * prev_weights[k, j]; + weights[k, j] += new_dw; + prev_weights[k, j] = new_dw; } } diff --git a/juno_samples/rodinia/bfs/src/bfs.jn b/juno_samples/rodinia/bfs/src/bfs.jn index 21518083c412eda12ab7b43daa28a6c35fa0e9c3..cf2ea086619dd431e8edd30c51d86d35972296fc 100644 --- a/juno_samples/rodinia/bfs/src/bfs.jn +++ b/juno_samples/rodinia/bfs/src/bfs.jn @@ -14,7 +14,7 @@ fn bfs<n, m: usize>(graph_nodes: Node[n], source: u32, edges: u32[m]) -> i32[n] visited[source as u64] = true; let cost: i32[n]; - for i = 0 to n { + for i in 0..n { cost[i] = -1; } cost[source as u64] = 0; @@ -25,14 +25,14 @@ fn bfs<n, m: usize>(graph_nodes: Node[n], source: u32, edges: u32[m]) -> i32[n] while !stop { stop = true; - for i = 0 to n { + for i in 0..n { if mask[i] { mask[i] = false; let edge_start = graph_nodes[i].edge_start as u64; let num_edges = graph_nodes[i].num_edges as u64; - for edge = edge_start to edge_start + num_edges { + for edge in edge_start..edge_start + num_edges { let id = edges[edge] as u64; if !visited[id] { cost[id] = cost[i] + 1; @@ -42,7 +42,7 @@ fn bfs<n, m: usize>(graph_nodes: Node[n], source: u32, edges: u32[m]) -> i32[n] } } - for i = 0 to n { + for i in 0..n { if updated[i] { mask[i] = true; visited[i] = true; diff --git a/juno_samples/rodinia/cfd/src/euler.jn b/juno_samples/rodinia/cfd/src/euler.jn index 984d5a938c6128f6f1bb7ab22a9c6ac3ff71d952..203cfd96008237f57ec276973d70304e56159682 100644 --- a/juno_samples/rodinia/cfd/src/euler.jn +++ b/juno_samples/rodinia/cfd/src/euler.jn @@ -49,7 +49,7 @@ fn compute_speed_of_sound(density: f32, pressure: f32) -> f32 { fn compute_step_factor<nelr: usize>(variables: Variables::<nelr>, areas: f32[nelr]) -> f32[nelr] { let step_factors : f32[nelr]; - for i = 0 to nelr { + for i in 0..nelr { let density = variables.density[i]; let momentum : float3; @@ -108,7 +108,7 @@ fn compute_flux<nelr: usize>( const smoothing_coefficient : f32 = 0.2; let fluxes: Variables::<nelr>; - for i = 0 to nelr { + for i in 0..nelr { let density_i = variables.density[i]; let momentum_i = float3 { x: variables.momentum.x[i], @@ -131,7 +131,7 @@ fn compute_flux<nelr: usize>( let flux_i_momentum = float3 { x: 0.0, y: 0.0, z: 0.0 }; let flux_i_density_energy : f32 = 0.0; - for j = 0 to NNB { + for j in 0..NNB { let nb = elements_surrounding_elements[j, i]; let normal = float3 { x: normals.x[j, i], @@ -235,7 +235,7 @@ fn time_step<nelr: usize>( step_factors: f32[nelr], fluxes: Variables::<nelr>, ) -> Variables::<nelr> { - for i = 0 to nelr { + for i in 0..nelr { let factor = step_factors[i] / (RK + 1 - j) as f32; variables.density[i] = old_variables.density[i] + factor * fluxes.density[i]; @@ -251,7 +251,7 @@ fn time_step<nelr: usize>( fn copy_vars<nelr: usize>(variables: Variables::<nelr>) -> Variables::<nelr> { let result : Variables::<nelr>; - for i = 0 to nelr { + for i in 0..nelr { result.density[i] = variables.density[i]; result.momentum.x[i] = variables.momentum.x[i]; result.momentum.y[i] = variables.momentum.y[i]; @@ -275,11 +275,11 @@ fn euler<nelr: usize>( ff_flux_contribution_momentum_y: float3, ff_flux_contribution_momentum_z: float3, ) -> Variables::<nelr> { - for i = 0 to iterations { + for i in 0..iterations { let old_variables = copy_vars::<nelr>(variables); let step_factors = compute_step_factor::<nelr>(variables, areas); - for j = 0 to RK { + for j in 0..RK { let fluxes = compute_flux::<nelr>(variables, elements_surrounding_elements, normals, ff_variable, ff_flux_contribution_density_energy, ff_flux_contribution_momentum_x, diff --git a/juno_samples/rodinia/cfd/src/pre_euler.jn b/juno_samples/rodinia/cfd/src/pre_euler.jn index 22f40b57073cc5da4903040459a8bd4afcf4d77b..c200f2db9a2be4708c4cf1c90c60eef0b7d7a11e 100644 --- a/juno_samples/rodinia/cfd/src/pre_euler.jn +++ b/juno_samples/rodinia/cfd/src/pre_euler.jn @@ -60,7 +60,7 @@ fn compute_speed_of_sound(density: f32, pressure: f32) -> f32 { fn compute_step_factor<nelr: usize>(variables: Variables::<nelr>, areas: f32[nelr]) -> f32[nelr] { let step_factors : f32[nelr]; - for i = 0 to nelr { + for i in 0..nelr { let density = variables.density[i]; let momentum : float3; @@ -114,7 +114,7 @@ fn compute_flux_contributions<nelr: usize>( let fc_momentum_z: Momentum::<nelr>; let fc_density_energy: Momentum::<nelr>; - for i = 0 to nelr { + for i in 0..nelr { let density_i = variables.density[i]; let momentum_i = float3 { x: variables.momentum.x[i], @@ -169,7 +169,7 @@ fn compute_flux<nelr: usize>( const smoothing_coefficient : f32 = 0.2; let fluxes: Variables::<nelr>; - for i = 0 to nelr { + for i in 0..nelr { let density_i = variables.density[i]; let momentum_i = float3 { x: variables.momentum.x[i], @@ -201,7 +201,7 @@ fn compute_flux<nelr: usize>( let flux_i_momentum = float3 { x: 0.0, y: 0.0, z: 0.0 }; let flux_i_density_energy : f32 = 0.0; - for j = 0 to NNB { + for j in 0..NNB { let nb = elements_surrounding_elements[j, i]; let normal = float3 { x: normals.x[j, i], @@ -314,7 +314,7 @@ fn time_step<nelr: usize>( step_factors: f32[nelr], fluxes: Variables::<nelr>, ) -> Variables::<nelr> { - for i = 0 to nelr { + for i in 0..nelr { let factor = step_factors[i] / (RK + 1 - j) as f32; variables.density[i] = old_variables.density[i] + factor * fluxes.density[i]; @@ -330,7 +330,7 @@ fn time_step<nelr: usize>( fn copy_vars<nelr: usize>(variables: Variables::<nelr>) -> Variables::<nelr> { let result : Variables::<nelr>; - for i = 0 to nelr { + for i in 0..nelr { result.density[i] = variables.density[i]; result.momentum.x[i] = variables.momentum.x[i]; result.momentum.y[i] = variables.momentum.y[i]; @@ -354,11 +354,11 @@ fn pre_euler<nelr: usize>( ff_fc_momentum_y: float3, ff_fc_momentum_z: float3, ) -> Variables::<nelr> { - for i = 0 to iterations { + for i in 0..iterations { let old_variables = copy_vars::<nelr>(variables); let step_factors = compute_step_factor::<nelr>(variables, areas); - for j = 0 to RK { + for j in 0..RK { let (fc_momentum_x, fc_momentum_y, fc_momentum_z, fc_density_energy) = compute_flux_contributions::<nelr>(variables); let fluxes = compute_flux::<nelr>(variables, elements_surrounding_elements, diff --git a/juno_samples/rodinia/srad/src/srad.jn b/juno_samples/rodinia/srad/src/srad.jn index c49d7636e2a8d8fa009bad05e2b8653b42fe1d24..5eea647c58949ebd951149f57e1961cebe6fc443 100644 --- a/juno_samples/rodinia/srad/src/srad.jn +++ b/juno_samples/rodinia/srad/src/srad.jn @@ -1,16 +1,16 @@ // HPVM put the extract and compress kernels in the host code, but the CUDA and // OpenCL versions of Rodinia put them on the device fn extract<nrows, ncols: usize>(inout image: f32[ncols, nrows], max: f32) { - for j = 0 to ncols { - for i = 0 to nrows { + for j in 0..ncols { + for i in 0..nrows { image[j, i] = exp!(image[j, i] / max); } } } fn compress<nrows, ncols: usize>(inout image: f32[ncols, nrows], max: f32) { - for j = 0 to ncols { - for i = 0 to nrows { + for j in 0..ncols { + for i in 0..nrows { image[j, i] = ln!(image[j, i]) * max; } } @@ -32,14 +32,14 @@ fn srad<nrows, ncols: usize>( extract::<nrows, ncols>(&image, max); - for iter = 0 to niter { + for iter in 0..niter { let sum = 0; let sum2 = 0; // These loops should really be interchanged, but they aren't in the // Rodinia source (though they are in the HPVM source) - for i = 0 to nrows { - for j = 0 to ncols { + for i in 0..nrows { + for j in 0..ncols { let tmp = image[j, i]; sum += tmp; sum2 += tmp * tmp; @@ -57,8 +57,8 @@ fn srad<nrows, ncols: usize>( let c : f32[ncols, nrows]; - for j = 0 to ncols { - for i = 0 to nrows { + for j in 0..ncols { + for i in 0..nrows { let Jc = image[j, i]; dN[j, i] = image[j, iN[i] as u64] - Jc; dS[j, i] = image[j, iS[i] as u64] - Jc; @@ -82,8 +82,8 @@ fn srad<nrows, ncols: usize>( } } - for j = 0 to ncols { - for i = 0 to nrows { + for j in 0..ncols { + for i in 0..nrows { let cN = c[j, i]; let cS = c[j, iS[i] as u64]; let cW = c[j, i];