comparison src/th06/ecl_vm.rs @ 703:81232dac8136

ecl: simplify parsing with more combinators.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 23 Aug 2019 17:37:22 +0200
parents b6c351ca0a35
children 464c1b02a996
comparison
equal deleted inserted replaced
702:718348c7608e 703:81232dac8136
979 file.read_to_end(&mut buf).unwrap(); 979 file.read_to_end(&mut buf).unwrap();
980 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); 980 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
981 let anm0 = anms.pop().unwrap(); 981 let anm0 = anms.pop().unwrap();
982 let anm0 = Rc::new(RefCell::new(anm0)); 982 let anm0 = Rc::new(RefCell::new(anm0));
983 let prng = Rc::new(RefCell::new(Prng::new(0))); 983 let prng = Rc::new(RefCell::new(Prng::new(0)));
984 let game = Game::new(prng, Rank::Easy); 984 let game = Game::new(prng, Rank::EASY);
985 let game = Rc::new(RefCell::new(game)); 985 let game = Rc::new(RefCell::new(game));
986 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); 986 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game));
987 (game, enemy) 987 (game, enemy)
988 } 988 }
989 989
990 #[test] 990 #[test]
991 fn call_and_return() { 991 fn call_and_return() {
992 let (game, enemy) = setup(); 992 let (game, enemy) = setup();
993 let ecl = Ecl { mains: vec![], subs: vec![ 993 let ecl = Ecl { mains: vec![], subs: vec![
994 Sub { instructions: vec![ 994 Sub { instructions: vec![
995 CallSub::new(0, Rank::Easy, SubInstruction::Call(1, 13, 12.)), 995 CallSub::new(0, Rank::EASY, SubInstruction::Call(1, 13, 12.)),
996 ]}, 996 ]},
997 Sub { instructions: vec![ 997 Sub { instructions: vec![
998 CallSub::new(0, Rank::Easy, SubInstruction::Noop()), 998 CallSub::new(0, Rank::EASY, SubInstruction::Noop()),
999 CallSub::new(1, Rank::Easy, SubInstruction::Return()), 999 CallSub::new(1, Rank::EASY, SubInstruction::Return()),
1000 ]}, 1000 ]},
1001 ]}; 1001 ]};
1002 let mut ecl_runner = EclRunner::new(&ecl, enemy, 0); 1002 let mut ecl_runner = EclRunner::new(&ecl, enemy, 0);
1003 ecl_runner.run_frame(); 1003 ecl_runner.run_frame();
1004 assert_eq!(ecl_runner.frame.ints1[0], 13); 1004 assert_eq!(ecl_runner.frame.ints1[0], 13);