Skip to content

Commit

Permalink
partial
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWoollett-Light committed Nov 18, 2023
1 parent d41b57d commit 1c9ff8e
Showing 1 changed file with 78 additions and 73 deletions.
151 changes: 78 additions & 73 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,96 +576,101 @@ mod tests {
);
}

#[cfg(feature = "false")]
#[test]
fn nine() {
const NINE: &str = "x := 1\nif x = 2\n exit 1\nexit 0";
const SOURCE: &str = "x := 1\nif x = 2\n exit 1\nexit 0";

let nodes = parse(NINE);
assert_eq!(
nodes,
[
Node {
statement: Statement {
comptime: false,
op: Op::Intrinsic(Intrinsic::Assign),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Literal(Literal::Integer(1))
]
},
child: None,
next: Some(1),
// Parsing
let nodes = test_parsing(
SOURCE,
&[
Statement {
comptime: false,
op: Op::Intrinsic(Intrinsic::Assign),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Literal(Literal::Integer(1)),
],
},
Node {
statement: Statement {
comptime: false,
op: Op::Intrinsic(Intrinsic::If(Cmp::Eq)),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Literal(Literal::Integer(2))
]
},
child: Some(2),
next: Some(3),
Statement {
comptime: false,
op: Op::Intrinsic(Intrinsic::If(Cmp::Eq)),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Literal(Literal::Integer(2)),
],
},
Node {
statement: Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(1))]
},
child: None,
next: None,
Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(1))],
},
Node {
statement: Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(0))]
},
child: None,
next: None,
Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(0))],
},
]
],
);
let optimized_nodes = optimize(&nodes);
assert_eq!(
optimized_nodes,
[
Node {
statement: Statement {
comptime: false,
op: Op::Special(Special::Type),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Type(Type::U8),
Value::Literal(Literal::Integer(1))
]
},
child: None,
next: Some(1),

// Exploration
let path = test_exploration(
nodes,
&[
TypeValueState::from([(
ident("x"),
TypeValue::Integer(TypeValueInteger::U8(MyRange::from(1))),
)]),
TypeValueState::from([(
ident("x"),
TypeValue::Integer(TypeValueInteger::U8(MyRange::from(1))),
)]),
TypeValueState::from([(
ident("x"),
TypeValue::Integer(TypeValueInteger::U8(MyRange::from(1))),
)]),
TypeValueState::from([(
ident("x"),
TypeValue::Integer(TypeValueInteger::U8(MyRange::from(1))),
)]),
],
);

// Optimization
let optimized = test_optimization(
path,
&[
Statement {
comptime: false,
op: Op::Special(Special::Type),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Type(Type::U8),
Value::Literal(Literal::Integer(1)),
],
},
Node {
statement: Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(0))]
},
child: None,
next: None,
Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(0))],
},
]
],
);
let expected_assembly = "\

// Assembly
test_assembling(
optimized,
"\
.global _start\n\
_start:\n\
mov x8, #93\n\
mov x0, #0\n\
svc #0\n\
.data\n\
x: .byte 1\n\
";
assemble(&optimized_nodes, expected_assembly, 0);
",
2,
);
}

#[cfg(feature = "false")]
Expand Down

0 comments on commit 1c9ff8e

Please sign in to comment.