Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rule str_char<Q>(quote: rule<Q>) -> u8 = escape() / c:$(!quote() [_]) { c.as_byt
rule char_literal() -> Node = "'" s:str_char(<"'">) "'" { Node::Integer(s as u64) }
rule bytes_literal() -> Node = "\"" s:str_char(<"\"">)* "\"" { Node::StringLiteral(s) }

rule negation() -> Node = "-" e:expression() { Node::Negation(box e) }
rule negation() -> Node = "-" e:expression() { Node::Negation(Box::new(e)) }
pub rule expr_atom() -> Node = whitespace()? "(" whitespace()? e:expression() whitespace()? ")" whitespace()? {e.simplify()}
/ whitespace()? n:negation() whitespace()? {n.simplify()}
/ whitespace()? i:integer() whitespace()? {i}
Expand All @@ -34,21 +34,21 @@ pub rule expr_atom() -> Node = whitespace()? "(" whitespace()? e:expression() wh
/ whitespace()? c:char_literal() whitespace()? {c}

pub rule expression() -> Node = precedence! {
x:(@) "<<" y:@ { Node::Shl(box x, box y).simplify() }
x:(@) ">>" y:@ { Node::Shr(box x, box y).simplify() }
x:(@) ">>>" y:@ { Node::Ashr(box x, box y).simplify() }
x:(@) "<<" y:@ { Node::Shl(Box::new(x), Box::new(y)).simplify() }
x:(@) ">>" y:@ { Node::Shr(Box::new(x), Box::new(y)).simplify() }
x:(@) ">>>" y:@ { Node::Ashr(Box::new(x), Box::new(y)).simplify() }
--
x:(@) "+" y:@ { Node::Plus(box x, box y).simplify() }
x:(@) "-" y:@ { Node::Minus(box x, box y).simplify() }
x:(@) "+" y:@ { Node::Plus(Box::new(x), Box::new(y)).simplify() }
x:(@) "-" y:@ { Node::Minus(Box::new(x), Box::new(y)).simplify() }
--
x:(@) "*" y:@ { Node::Times(box x, box y).simplify() }
x:(@) "/" y:@ { Node::Divide(box x, box y).simplify() }
x:(@) "*" y:@ { Node::Times(Box::new(x), Box::new(y)).simplify() }
x:(@) "/" y:@ { Node::Divide(Box::new(x), Box::new(y)).simplify() }
--
a:expr_atom() {a}
}

pub rule label() -> Node = whitespace()? i:idstr() whitespace()? ":" { Node::Label(i.to_owned()) } / expected!("label")
pub rule argument() -> Node = whitespace()? e:(register() / expression()) whitespace()? {Node::Argument(box e)}
pub rule argument() -> Node = whitespace()? e:(register() / expression()) whitespace()? {Node::Argument(Box::new(e))}
rule instruction0() -> Node = whitespace()? nm:idstr() whitespace()? { Node::Instruction(nm.to_owned(), vec![]) }
rule instruction1() -> Node = whitespace()? nm:idstr() whitespace() a0:argument() whitespace()? { Node::Instruction(nm.to_owned(), vec![a0]) }
rule instructionN() -> Node = whitespace()? nm:idstr() whitespace() a0:argument() aN:( "," an:argument() {an} )+ {
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(box_syntax)]
#![feature(box_patterns)]
#![warn(clippy::all)]
#![allow(dead_code)]
Expand Down
18 changes: 9 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,47 @@ impl Node {

Negation(box a) => {
let sa = a.emitter_simplify(const_provider, pc);
(Negation(box sa.0).simplify(), sa.1)
(Negation(Box::new(sa.0)).simplify(), sa.1)
}
Plus(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Plus(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Plus(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}
Minus(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Minus(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Minus(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}
Times(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Times(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Times(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}
Divide(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Divide(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Divide(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}
Shl(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Shl(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Shl(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}
Shr(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Shr(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Shr(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}
Ashr(box a, box b) => {
let sa = a.emitter_simplify(const_provider, pc);
let sb = b.emitter_simplify(const_provider, pc);
(Ashr(box sa.0, box sb.0).simplify(), sa.1 && sb.1)
(Ashr(Box::new(sa.0), Box::new(sb.0)).simplify(), sa.1 && sb.1)
}

Argument(box node) => {
let s = node.emitter_simplify(const_provider, pc);
(Argument(box s.0), s.1)
(Argument(Box::new(s.0)), s.1)
}
Instruction(iname, args) => {
let mut succ = true;
Expand Down