import { CompilerService , ServiceInput , ServiceOutput , Language } from "./types" ; import { sendRequestJSON , ServiceTypes } from "./sendRequest" ; import { decodeBinary } from "./utils" ; export class ClangService implements CompilerService { private lang : Language ; constructor ( lang ) { this . lang = lang ; } async compile ( input ) { const files = Object . values ( input . files ) ; if ( files . length !== 1 ) { throw new Error ( `Supporting compilation of a single file, but ${ files . length } file(s) found` ) ; } const [ fileRef ] = Object . keys ( input . files ) ; const src = files [ 0 ] . content ; const from = this . lang ; const project = { output : "wasm" , compress : true , files : [ { type : from , name : "file." + from , options : input . options , src } ] } ; const result = await sendRequestJSON ( project , ServiceTypes . Clang ) ; const items = { } ; let content ; if ( result . success ) { content = await decodeBinary ( result . output ) ; } let console ; if ( result . tasks && result . tasks . length > 0 ) { console = result . tasks [ 0 ] . console ; } return { success : result . success , items : { "a.wasm" : { content , fileRef , console , } , } , console : result . message } ; } }