fix "i?SCREEN = 0" being parsed as "i?(SCREEN = 0)"

This commit is contained in:
2022-02-26 21:00:01 +01:00
parent 5f316cf17d
commit cda3eb868b
3 changed files with 35 additions and 28 deletions

View File

@@ -22,7 +22,7 @@ start fn gen_palette() {
let lazy a = max(llimit, min(ulimit, c)) * (scale + 0.05); let lazy a = max(llimit, min(ulimit, c)) * (scale + 0.05);
let lazy b = scale * scale * 0.8; let lazy b = scale * scale * 0.8;
let inline v = (select(i < 11*16*3, max(0 as f32, min(a + b - a * b, 1 as f32)), scale) * 255 as f32) as i32; let inline v = (select(i < 11*16*3, max(0 as f32, min(a + b - a * b, 1 as f32)), scale) * 255 as f32) as i32;
(i%3 + i/3*4)?(PALETTE) = v; (i%3 + i/3*4)?PALETTE = v;
avg = (avg + c) * 0.5; avg = (avg + c) * 0.5;
branch_if i := i - 1: gradients; branch_if i := i - 1: gradients;
@@ -37,7 +37,7 @@ start fn gen_palette() {
let inline src2 = select(first_step, (index + 1) % 32 / 2, index * 2 + 1); let inline src2 = select(first_step, (index + 1) % 32 / 2, index * 2 + 1);
let inline c1 = (src1 * 4 + channel)?SWEETY; let inline c1 = (src1 * 4 + channel)?SWEETY;
let inline c2 = (src2 * 4 + channel)?SWEETY; let inline c2 = (src2 * 4 + channel)?SWEETY;
i?(SWEETY) = (c1 + c2) * (3 + first_step) / 8; i?SWEETY = (c1 + c2) * (3 + first_step) / 8;
branch_if (i := i - 1) >= 0: expand_sweetie; branch_if (i := i - 1) >= 0: expand_sweetie;
} }

View File

@@ -1,24 +1,29 @@
import "env.memory" memory(4); import "env.memory" memory(4);
import "env.sin" fn sin(f32) -> f32; import "env.sin" fn sin(f32) -> f32;
import "env.time" fn time() -> f32;
import "env.setPixel" fn setPixel(i32, i32, i32);
export fn tic(time: i32) { export fn upd() {
let i: i32; let x: i32;
let y: i32;
loop screen { loop screen {
let lazy t = time as f32 / 2000 as f32; let inline t = time() / 2 as f32;
let lazy o = sin(t) * 0.8; let lazy o = sin(t) * 0.75;
let lazy q = (i % 320) as f32 - 160.1; let inline q = x as f32 - 160.5;
let lazy w = (i / 320 - 120) as f32; let inline w = (y - 120) as f32;
let lazy r = sqrt(q*q + w*w); let lazy r = sqrt(q*q + w*w);
let lazy z = q / r; let lazy z = q / r;
let lazy s = z * o + sqrt(z * z * o * o + 1 as f32 - o * o); let lazy s = z * o + sqrt(z * z * o * o + 1 as f32 - o * o);
let lazy q2 = (z * s - o) * 10 as f32 + t; let inline q2 = (z * s - o) * 10 as f32 + t;
let lazy w2 = w / r * s * 10 as f32 + t; let inline w2 = w / r * s * 10 as f32 + t;
let lazy s2 = s * 50 as f32 / r; let inline s2 = s * 100 as f32 / r;
i?120 = max( let inline color = max(
0 as f32, 0 as f32,
((q2 as i32 ^ w2 as i32 & ((s2 + t) * 20 as f32) as i32) & 5) as f32 * ((q2 as i32 ^ w2 as i32 & ((s2 + time()) * 10 as f32) as i32) & 5) as f32 *
(2 as f32 - s2) * 22 as f32 (4 as f32 - s2) as f32
) as i32; ) as i32 - 32;
branch_if (i := i + 1) < 320*240: screen setPixel(x, y, color);
branch_if x := (x + 1) % 320: screen;
branch_if y := (y + 1) % 320: screen;
} }
} }

View File

@@ -487,16 +487,6 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = ScriptError> + Clo
}) })
.boxed(); .boxed();
let assign = identifier
.then_ignore(just(Token::Op("=".to_string())))
.then(expression.clone())
.map(|(name, value)| ast::Expr::Assign {
name,
value: Box::new(value),
local_id: None,
})
.boxed();
let select = just(Token::Select) let select = just(Token::Select)
.ignore_then( .ignore_then(
expression expression
@@ -532,7 +522,6 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = ScriptError> + Clo
let atom = val let atom = val
.or(function_call) .or(function_call)
.or(assign)
.or(local_tee) .or(local_tee)
.or(variable) .or(variable)
.or(block_expr) .or(block_expr)
@@ -791,11 +780,24 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = ScriptError> + Clo
let block_expression = block_expression.unwrap(); let block_expression = block_expression.unwrap();
let assign = identifier
.then_ignore(just(Token::Op("=".to_string())))
.then(expression.clone())
.map(|(name, value)| ast::Expr::Assign {
name,
value: Box::new(value),
local_id: None,
})
.map_with_span(|expr, span| expr.with_span(span))
.boxed();
block_expression block_expression
.clone() .clone()
.then(just(Token::Ctrl(';')).or_not()) .then(just(Token::Ctrl(';')).or_not())
.map_with_span(|(expr, semi), span| (expr.with_span(span), semi.is_none())) .map_with_span(|(expr, semi), span| (expr.with_span(span), semi.is_none()))
.or(expression.clone().then(just(Token::Ctrl(';')).to(false))) .or(assign
.or(expression.clone())
.then(just(Token::Ctrl(';')).to(false)))
.repeated() .repeated()
.then(expression.clone().or_not()) .then(expression.clone().or_not())
.map_with_span(|(mut statements, mut final_expression), span| { .map_with_span(|(mut statements, mut final_expression), span| {