Skip to content

Instantly share code, notes, and snippets.

@xqm32
Created April 9, 2024 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xqm32/9aeb73c7a47cb6e0571415e614df0276 to your computer and use it in GitHub Desktop.
Save xqm32/9aeb73c7a47cb6e0571415e614df0276 to your computer and use it in GitHub Desktop.
import { $ } from 'bun'
async function compile(code: string) {
const hasher = new Bun.CryptoHasher("sha256").update(code)
const destination = hasher.digest("hex").substring(0, 6) + ".c"
Bun.write(destination, code)
await $`gcc ${destination} -o ${destination}.out`
const output = await $`./${destination}.out`.text()
console.log(output)
}
const code = await Bun.file("main.c").text()
await compile(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment