diff --git a/Cargo.lock b/Cargo.lock index c1220f7..1acf8ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chumsky" -version = "0.5.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2d3efff85e8572b1c3fa0127706af58c4fff8458f8d9436d54b1e97573c7a3f" +checksum = "8d02796e4586c6c41aeb68eae9bfb4558a522c35f1430c14b40136c3706e09e4" dependencies = [ "ahash", ] @@ -139,18 +139,18 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-encoder" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0c351632e46cc06a58a696a6c11e4cf90cad4b9f8f07a0b59128d616c29bb0" +checksum = "aa9d9bf45fc46f71c407837c9b30b1e874197f2dc357588430b21e5017d290ab" dependencies = [ "leb128", ] [[package]] name = "wasmparser" -version = "0.81.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98930446519f63d00a836efdc22f67766ceae8dbcc1571379f2bcabc6b2b9abc" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "yansi" diff --git a/Cargo.toml b/Cargo.toml index 8436a99..ec65e76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,9 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -wasmparser = "0.81" -wasm-encoder = "0.8" +wasmparser = "0.83" +wasm-encoder = "0.10" anyhow = "1" -chumsky = "0.5" +chumsky = "0.8" ariadne = "0.1" pico-args = "0.4" diff --git a/src/emit.rs b/src/emit.rs index 21ee777..dd00a79 100644 --- a/src/emit.rs +++ b/src/emit.rs @@ -464,7 +464,7 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression) (I32, Or) => Instruction::I32Or, (I32, Xor) => Instruction::I32Xor, (I32, Eq) => Instruction::I32Eq, - (I32, Ne) => Instruction::I32Neq, + (I32, Ne) => Instruction::I32Ne, (I32, Lt) => Instruction::I32LtS, (I32, LtU) => Instruction::I32LtU, (I32, Le) => Instruction::I32LeS, @@ -488,7 +488,7 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression) (I64, Or) => Instruction::I64Or, (I64, Xor) => Instruction::I64Xor, (I64, Eq) => Instruction::I64Eq, - (I64, Ne) => Instruction::I64Neq, + (I64, Ne) => Instruction::I64Ne, (I64, Lt) => Instruction::I64LtS, (I64, LtU) => Instruction::I64LtU, (I64, Le) => Instruction::I64LeS, @@ -510,7 +510,7 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression) DivU | Rem | RemU | And | Or | Xor | Shl | ShrU | ShrS | LtU | LeU | GtU | GeU, ) => unreachable!(), (F32, Eq) => Instruction::F32Eq, - (F32, Ne) => Instruction::F32Neq, + (F32, Ne) => Instruction::F32Ne, (F32, Lt) => Instruction::F32Lt, (F32, Le) => Instruction::F32Le, (F32, Gt) => Instruction::F32Gt, @@ -525,7 +525,7 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression) DivU | Rem | RemU | And | Or | Xor | Shl | ShrU | ShrS | LtU | LeU | GtU | GeU, ) => unreachable!(), (F64, Eq) => Instruction::F64Eq, - (F64, Ne) => Instruction::F64Neq, + (F64, Ne) => Instruction::F64Ne, (F64, Lt) => Instruction::F64Lt, (F64, Le) => Instruction::F64Le, (F64, Gt) => Instruction::F64Gt, diff --git a/src/parser.rs b/src/parser.rs index 8594bd1..d0ff1c6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -138,7 +138,7 @@ fn report_errors(errors: Vec>, source: &str) { } else { error .expected() - .map(|x| x.to_string()) + .map(|x| x.as_deref().unwrap_or("EOF")) .collect::>() .join(", ") } @@ -168,7 +168,7 @@ fn report_errors(errors: Vec>, source: &str) { fn lexer() -> impl Parser, Error = Simple> { let float64 = text::int(10) .chain::(just('.').chain(text::digits(10))) - .then_ignore(seq::<_, _, Simple>("f64".chars())) + .then_ignore(just("f64")) .collect::() .map(Token::Float64); @@ -177,7 +177,7 @@ fn lexer() -> impl Parser, Error = Simple> { .collect::() .map(Token::Float); - let integer = seq::<_, _, Simple>("0x".chars()) + let integer = just::<_, _, Simple>("0x") .ignore_then(text::int(16)) .try_map(|n, span| { u64::from_str_radix(&n, 16).map_err(|err| Simple::custom(span, err.to_string())) @@ -190,7 +190,7 @@ fn lexer() -> impl Parser, Error = Simple> { let int64 = integer .clone() - .then_ignore(seq::<_, _, Simple>("i64".chars())) + .then_ignore(just("i64")) .map(|n| Token::Int64(n as i64)); let int = integer.try_map(|n, span| { @@ -205,14 +205,14 @@ fn lexer() -> impl Parser, Error = Simple> { .collect::() .map(Token::Str); - let op = one_of("+-*/%&^|<=>#".chars()) + let op = one_of("+-*/%&^|<=>#") .repeated() .at_least(1) .or(just(':').chain(just('='))) .collect::() .map(Token::Op); - let ctrl = one_of("(){};,:?!$".chars()).map(Token::Ctrl); + let ctrl = one_of("(){};,:?!$").map(Token::Ctrl); fn ident() -> impl Parser> + Copy + Clone { filter(|c: &char| c.is_ascii_alphabetic() || *c == '_') @@ -242,11 +242,9 @@ fn lexer() -> impl Parser, Error = Simple> { _ => Token::Ident(ident), }); - let single_line = - seq::<_, _, Simple>("//".chars()).then_ignore(take_until(text::newline())); + let single_line = just("//").then_ignore(take_until(text::newline())); - let multi_line = - seq::<_, _, Simple>("/*".chars()).then_ignore(take_until(seq("*/".chars()))); + let multi_line = just("/*").then_ignore(take_until(just("*/"))); let comment = single_line.or(multi_line); @@ -412,7 +410,7 @@ fn script_parser() -> impl Parser> + C .then(expression.clone()) .then_ignore(just(Token::Ctrl(','))) .then(expression.clone()) - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .map(|((condition, if_true), if_false)| ast::Expr::Select { condition: Box::new(condition), @@ -426,7 +424,7 @@ fn script_parser() -> impl Parser> + C expression .clone() .separated_by(just(Token::Ctrl(','))) - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .map(|(name, params)| ast::Expr::FuncCall { name, params }) .boxed(); @@ -451,7 +449,7 @@ fn script_parser() -> impl Parser> + C .map_with_span(|expr, span| expr.with_span(span)) .or(expression .clone() - .delimited_by(Token::Ctrl('('), Token::Ctrl(')'))) + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')')))) .or(block) .recover_with(nested_delimiters( Token::Ctrl('('), @@ -720,7 +718,7 @@ fn script_parser() -> impl Parser> + C } .with_span(span) }) - .delimited_by(Token::Ctrl('{'), Token::Ctrl('}')) + .delimited_by(just(Token::Ctrl('{')), just(Token::Ctrl('}'))) .boxed() }); @@ -731,7 +729,7 @@ fn script_parser() -> impl Parser> + C .ignore_then( integer .clone() - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .map(|min_size| ast::ImportType::Memory(min_size as u32)) .boxed(); @@ -753,7 +751,7 @@ fn script_parser() -> impl Parser> + C .then( type_parser() .separated_by(just(Token::Ctrl(','))) - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .then( just(Token::Op("->".to_string())) @@ -793,7 +791,7 @@ fn script_parser() -> impl Parser> + C .then( parameter .separated_by(just(Token::Ctrl(','))) - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .then( just(Token::Op("->".to_string())) @@ -843,7 +841,7 @@ fn script_parser() -> impl Parser> + C expression .clone() .separated_by(just(Token::Ctrl(','))) - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .map(|(type_, values)| ast::DataValues::Array { type_, values }); @@ -853,7 +851,7 @@ fn script_parser() -> impl Parser> + C .ignore_then( string .clone() - .delimited_by(Token::Ctrl('('), Token::Ctrl(')')), + .delimited_by(just(Token::Ctrl('(')), just(Token::Ctrl(')'))), ) .map(|s| ast::DataValues::File { path: s.into(), @@ -867,7 +865,7 @@ fn script_parser() -> impl Parser> + C .or(data_string) .or(data_file) .repeated() - .delimited_by(Token::Ctrl('{'), Token::Ctrl('}')), + .delimited_by(just(Token::Ctrl('{')), just(Token::Ctrl('}'))), ) .map(|(offset, data)| { ast::TopLevelItem::Data(ast::Data { @@ -908,10 +906,10 @@ fn type_parser() -> impl Parser> + Clone _ => Err(Simple::expected_input_found( span, vec![ - Token::Ident("i32".into()), - Token::Ident("i64".into()), - Token::Ident("f32".into()), - Token::Ident("f64".into()), + Some(Token::Ident("i32".into())), + Some(Token::Ident("i64".into())), + Some(Token::Ident("f32".into())), + Some(Token::Ident("f64".into())), ], Some(tok), )),