pub struct Walker {
pub msg_stack: Vec<LunarIR>,
pub idx_of_irep: usize,
pub current_irep: usize,
pub idx_of_ireps: HashMap<usize, IrepIndices>,
}Fields§
§msg_stack: Vec<LunarIR>§idx_of_irep: usize§current_irep: usize§idx_of_ireps: HashMap<usize, IrepIndices>Implementations§
Source§impl Walker
impl Walker
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/smoke.rs (line 15)
4fn main() {
5 let source = r#"
6for i = 1, 5 do
7 print "hello, world\n"
8end
9"#;
10 // let source = r#"print "hello, world\n""#;
11
12 match lunar_lang::lua::loader::load_string(source) {
13 Ok(program) => {
14 println!("Parsed program: {:?}", &program);
15 let mut walker = lunar_lang::lua::walker::Walker::new();
16 walker.walk(&program.block);
17 for (i, msg) in walker.msg_stack.iter().enumerate() {
18 println!("MSG: {:<04}: {:?}", i, msg);
19 }
20
21 let mruby = lunar_lang::rite::transformer::transform(&walker.msg_stack);
22 for (i, rep) in mruby.iter().enumerate() {
23 println!("IREP: {:<04}: rlen = {}", i, rep.borrow().rep_len);
24 println!("IREP: {:<04}: syms = {:?}", i, &rep.borrow().syms);
25 println!("IREP: {:<04}: pool = {:?}", i, &rep.borrow().pool);
26 println!("IREP: {:<04}: nregs = {:?}", i, &rep.borrow().regs);
27 println!("IREP: {:<04}: nlocals = {:?}", i, &rep.borrow().locals);
28 for (j, msg) in rep.borrow().insn.iter().enumerate() {
29 println!("IREP: {:<04}:{:<04} {:?}", i, j, msg);
30 }
31 }
32
33 let mut packer = lunar_lang::rite::packer::RitePacker::new();
34 match packer.pack(&mruby) {
35 Ok(_) => {
36 // let packed = &packer.buf;
37 }
38 Err(e) => eprintln!("Error packing: {}", e),
39 }
40
41 match packer.write_to_file("test.mrb") {
42 Ok(_) => println!("Packed binary written to ./test.mrb"),
43 Err(e) => eprintln!("Error writing to file: {}", e),
44 }
45 },
46 Err(e) => eprintln!("Error parsing program: {}", e),
47 }
48}pub fn push_msg(&mut self, msg: LunarIR)
Sourcepub fn walk(&mut self, root: &Block)
pub fn walk(&mut self, root: &Block)
Examples found in repository?
examples/smoke.rs (line 16)
4fn main() {
5 let source = r#"
6for i = 1, 5 do
7 print "hello, world\n"
8end
9"#;
10 // let source = r#"print "hello, world\n""#;
11
12 match lunar_lang::lua::loader::load_string(source) {
13 Ok(program) => {
14 println!("Parsed program: {:?}", &program);
15 let mut walker = lunar_lang::lua::walker::Walker::new();
16 walker.walk(&program.block);
17 for (i, msg) in walker.msg_stack.iter().enumerate() {
18 println!("MSG: {:<04}: {:?}", i, msg);
19 }
20
21 let mruby = lunar_lang::rite::transformer::transform(&walker.msg_stack);
22 for (i, rep) in mruby.iter().enumerate() {
23 println!("IREP: {:<04}: rlen = {}", i, rep.borrow().rep_len);
24 println!("IREP: {:<04}: syms = {:?}", i, &rep.borrow().syms);
25 println!("IREP: {:<04}: pool = {:?}", i, &rep.borrow().pool);
26 println!("IREP: {:<04}: nregs = {:?}", i, &rep.borrow().regs);
27 println!("IREP: {:<04}: nlocals = {:?}", i, &rep.borrow().locals);
28 for (j, msg) in rep.borrow().insn.iter().enumerate() {
29 println!("IREP: {:<04}:{:<04} {:?}", i, j, msg);
30 }
31 }
32
33 let mut packer = lunar_lang::rite::packer::RitePacker::new();
34 match packer.pack(&mruby) {
35 Ok(_) => {
36 // let packed = &packer.buf;
37 }
38 Err(e) => eprintln!("Error packing: {}", e),
39 }
40
41 match packer.write_to_file("test.mrb") {
42 Ok(_) => println!("Packed binary written to ./test.mrb"),
43 Err(e) => eprintln!("Error writing to file: {}", e),
44 }
45 },
46 Err(e) => eprintln!("Error parsing program: {}", e),
47 }
48}pub fn walk_block(&mut self, block: &Block)
pub fn walk_chunk(&mut self, chunk: &Chunk)
pub fn walk_stat(&mut self, stat: &Stat)
pub fn walk_args(&mut self, args: &Args)
pub fn ensure_expr_as_number(&mut self, expr: &Expr) -> f64
pub fn walk_prefixexpr(&mut self, prefix_expr: &PrefixExp)
pub fn walk_var(&mut self, var: &Var)
pub fn walk_laststat(&mut self, last_stat: &LastStat)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Walker
impl RefUnwindSafe for Walker
impl Send for Walker
impl Sync for Walker
impl Unpin for Walker
impl UnsafeUnpin for Walker
impl UnwindSafe for Walker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more