Compare commits
4 Commits
3838052cf5
...
2252be416e
Author | SHA1 | Date |
---|---|---|
Nat | 2252be416e | |
Nat | 912aca2a89 | |
Nat | 41c70e02db | |
Nat | 49398aa15c |
|
@ -7,6 +7,8 @@ use std::collections::{HashMap, BTreeMap, VecDeque};
|
|||
|
||||
use ponderosa::state::{Land, Rule};
|
||||
|
||||
use ponderosa::arguments::{parse_arguments, PositionalArgument, ArgumentFormat};
|
||||
|
||||
macro_rules! ad_hoc_rule {
|
||||
($tokens:expr, $argument_count:expr, $body:block) => {
|
||||
if $tokens.len() < $argument_count {
|
||||
|
@ -141,8 +143,23 @@ fn push_u16(vec: &mut Vec<u8>, value: u16) {
|
|||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let path = &args[1];
|
||||
let unparsed_arguments: Vec<String> = env::args().collect();
|
||||
|
||||
let positional_arguments = vec![
|
||||
PositionalArgument {
|
||||
long_name: "path",
|
||||
description: "File to be assembled",
|
||||
required: true,
|
||||
default: None
|
||||
}
|
||||
];
|
||||
|
||||
let arguments = match parse_arguments(vec![], positional_arguments, unparsed_arguments) {
|
||||
Ok(map) => map,
|
||||
Err(e) => panic!("{}", e),
|
||||
};
|
||||
|
||||
let path = &arguments.get("path");
|
||||
let source_code = fs::read_to_string(path)?;
|
||||
|
||||
let mut land = Land {
|
||||
|
|
|
@ -119,7 +119,7 @@ fn main() -> io::Result<()> {
|
|||
description: "Number of generations before halting. If 0, the program will run until all trees have been composted",
|
||||
format: ArgumentFormat::Store,
|
||||
required: false,
|
||||
default: Some("1")
|
||||
default: Some("0")
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -137,7 +137,17 @@ fn main() -> io::Result<()> {
|
|||
|
||||
let generation_count = arguments.get("generations").parse::<u16>().unwrap();
|
||||
|
||||
for _ in 0..generation_count {
|
||||
let mut generation = 0;
|
||||
|
||||
loop {
|
||||
if generation_count != 0 && generation >= generation_count {
|
||||
break;
|
||||
}
|
||||
|
||||
if scheduled_trees.len() == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
let mut trees_to_plant: Vec<state::Tree> = Vec::new();
|
||||
let mut rules_to_define: Vec<state::Rule> = Vec::new();
|
||||
let mut trees_to_wake: Vec<u16> = Vec::new();
|
||||
|
@ -224,7 +234,14 @@ fn main() -> io::Result<()> {
|
|||
let tree = trees.remove(&tree_id).unwrap();
|
||||
(tree.parent_id, tree.stack_size)
|
||||
};
|
||||
let parent = trees.get_mut(&parent_id).unwrap();
|
||||
|
||||
// One tree is "its own" parent, namely, the seed tree, in which
|
||||
// case this `get_mut` will return None
|
||||
let parent = match trees.get_mut(&parent_id) {
|
||||
Some(p) => p,
|
||||
None => continue
|
||||
};
|
||||
|
||||
parent.stack_size += recovered_stack_size;
|
||||
}
|
||||
|
||||
|
@ -240,6 +257,8 @@ fn main() -> io::Result<()> {
|
|||
}
|
||||
|
||||
rules.append(&mut rules_to_define);
|
||||
|
||||
generation += 1;
|
||||
}
|
||||
|
||||
for (_, tree) in trees {
|
||||
|
|
Loading…
Reference in New Issue