MCPcopy Index your code
hub / github.com/endbasic/endbasic / compile

Function compile

core/src/compiler/top.rs:1323–1359  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

1321
1322/// Compiles the `input` into an `Image` that can be executed by the VM.
1323pub 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)]
1362mod tests {

Callers 1

compile_moreMethod · 0.85

Calls 8

parseFunction · 0.85
compile_stmtFunction · 0.85
pop_eofMethod · 0.80
emitMethod · 0.80
iter_globalsMethod · 0.80
iter_localsMethod · 0.80
build_image_deltaMethod · 0.80
saveMethod · 0.80

Tested by

no test coverage detected