/** * Compiling a document to a WebAssembly module, which the playground * runs. It is apart from the service, which only analyzes code, so a * program that imports the service does not import the code generator. */ import { BinaryGenerator } from 'compiler/codegen/binary-generator'; import { LanguageService } from './service.zena'; /** A document compiled to a module, or null when it does not compile. */ export async function compileToWasm( service: LanguageService, path: String, source: String, target: String | null = null ): Future { try { let effectiveTarget = target ?? service.targetName; let program = await service.checkProgramForTarget(path, source, effectiveTarget); if (program == null) { return null; } return new BinaryGenerator(effectiveTarget, false, true).generate(program).toByteArray(); } catch (e) { console.error(`compileToWasm failed: ${e.message}\n${e.getStackTrace() ?? ''}`); return null; } }