| 133 | } |
| 134 | |
| 135 | pub fn compile(&mut self, source: &'static str) -> Result<(), VmError> { |
| 136 | self.arena.mutate_root(|_mc, state| { |
| 137 | let context = state.get_context(); |
| 138 | state.chunks = crate::compiler::compile(context, source)?; |
| 139 | builtins::define_builtin_functions(state); |
| 140 | // The script function's chunk id is always the highest chunk id. |
| 141 | let script_chunk_id = state.chunks.keys().max().copied().unwrap(); |
| 142 | let function = state.get_chunk(script_chunk_id)?; |
| 143 | state.call_function(function, &[]) |
| 144 | }) |
| 145 | } |
| 146 | |
| 147 | pub fn eval_function( |
| 148 | &mut self, |