Skip to main content

Walker

Struct Walker 

Source
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

Source

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}
Source

pub fn push_msg(&mut self, msg: LunarIR)

Source

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}
Source

pub fn walk_block(&mut self, block: &Block)

Source

pub fn walk_chunk(&mut self, chunk: &Chunk)

Source

pub fn walk_stat(&mut self, stat: &Stat)

Source

pub fn walk_args(&mut self, args: &Args)

Source

pub fn ensure_expr_as_number(&mut self, expr: &Expr) -> f64

Source

pub fn walk_prefixexpr(&mut self, prefix_expr: &PrefixExp)

Source

pub fn walk_var(&mut self, var: &Var)

Source

pub fn walk_laststat(&mut self, last_stat: &LastStat)

Trait Implementations§

Source§

impl Debug for Walker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.