Compiles the `input` into an `Image` that can be executed by the VM.
(
input: &mut dyn io::Read,
image: &Image,
ctx: &mut Context,
mut symtable: LocalSymtable,
)
| 1321 | |
| 1322 | /// Compiles the `input` into an `Image` that can be executed by the VM. |
| 1323 | pub fn compile( |
| 1324 | input: &mut dyn io::Read, |
| 1325 | image: &Image, |
| 1326 | ctx: &mut Context, |
| 1327 | mut symtable: LocalSymtable, |
| 1328 | ) -> Result<(ImageDelta, LocalSymtableSnapshot)> { |
| 1329 | ctx.codegen.pop_eof(); |
| 1330 | { |
| 1331 | for stmt in parser::parse(input) { |
| 1332 | compile_stmt(ctx, &mut symtable, stmt?)?; |
| 1333 | } |
| 1334 | } |
| 1335 | ctx.codegen.emit(bytecode::make_eof(), LineCol { line: 0, col: 0 }); |
| 1336 | |
| 1337 | let global_vars = symtable |
| 1338 | .iter_globals() |
| 1339 | .map(|(key, proto, reg)| { |
| 1340 | let (subtype, ndims) = match proto { |
| 1341 | SymbolPrototype::Array(info) => (info.subtype, info.ndims), |
| 1342 | SymbolPrototype::Scalar(etype) => (etype, 0), |
| 1343 | }; |
| 1344 | (key.clone(), GlobalVarInfo { reg, subtype, ndims }) |
| 1345 | }) |
| 1346 | .collect(); |
| 1347 | let program_vars = symtable |
| 1348 | .iter_locals() |
| 1349 | .map(|(key, proto, reg)| { |
| 1350 | let (subtype, ndims) = match proto { |
| 1351 | SymbolPrototype::Array(info) => (info.subtype, info.ndims), |
| 1352 | SymbolPrototype::Scalar(etype) => (etype, 0), |
| 1353 | }; |
| 1354 | (key.clone(), GlobalVarInfo { reg, subtype, ndims }) |
| 1355 | }) |
| 1356 | .collect(); |
| 1357 | let delta = ctx.codegen.build_image_delta(image, global_vars, program_vars, &ctx.data)?; |
| 1358 | Ok((delta, symtable.save())) |
| 1359 | } |
| 1360 | |
| 1361 | #[cfg(test)] |
| 1362 | mod tests { |
no test coverage detected