(ctx: Context<'gc>, fn_type: FunctionType, name: &str)
| 70 | |
| 71 | impl<'gc> CodeGen<'gc> { |
| 72 | pub fn new(ctx: Context<'gc>, fn_type: FunctionType, name: &str) -> Box<Self> { |
| 73 | let generator = Box::new(CodeGen { |
| 74 | ctx, |
| 75 | chunks: HashMap::new(), |
| 76 | named_id_map: HashMap::new(), |
| 77 | defined_enums: HashMap::new(), |
| 78 | function: Function::new(ctx.intern(name.as_bytes()), 0), |
| 79 | fn_type, |
| 80 | locals: std::array::from_fn(|i| { |
| 81 | // The compiler’s locals array keeps track of which stack slots |
| 82 | // are associated with which local variables or temporaries. |
| 83 | // From now on, the compiler implicitly claims stack slot zero for the VM’s own |
| 84 | // internal use. We give it an empty name so that the user can’t write an |
| 85 | // identifier that refers to it. |
| 86 | if i == 0 { |
| 87 | let name = if fn_type.is_constructor() || fn_type.is_method() { |
| 88 | // Slot zero will store the instance in class methods. |
| 89 | Token::new(TokenType::Self_, "self", 0) |
| 90 | } else { |
| 91 | Token::default() |
| 92 | }; |
| 93 | Local { |
| 94 | name, |
| 95 | ..Local::default() |
| 96 | } |
| 97 | } else { |
| 98 | Local::default() |
| 99 | } |
| 100 | }), |
| 101 | // The initial value of the local_count starts at 1 |
| 102 | // because we reserve slot zero for VM use. |
| 103 | local_count: 1, |
| 104 | scope_depth: 0, |
| 105 | loop_scopes: Vec::new(), |
| 106 | const_globals: HashSet::new(), |
| 107 | enclosing: None, |
| 108 | current_line: 0, |
| 109 | error_reporter: ErrorReporter::new(), |
| 110 | }); |
| 111 | |
| 112 | generator |
| 113 | } |
| 114 | |
| 115 | pub fn register_enum(&mut self, name: &'gc str, enum_: GcRefLock<'gc, Enum<'gc>>) { |
| 116 | self.defined_enums.insert(name, enum_); |
nothing calls this directly
no test coverage detected