-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.html
48 lines (46 loc) · 1.67 KB
/
run.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pnut Compiler</title>
</head>
<body>
<h1>Pnut Compiler</h1>
<p>Write portable shell scripts directly in C, no shell scripting required.</p>
<button id="compile-btn">Compile</button>
<div style="width: 100%;">
<textarea style="width: 45%; height: 200px" id="c-editor"></textarea>
<textarea style="width: 45%; height: 200px" id="shell-code"></textarea>
</div>
<script src="compile.js"> </script>
<script>
function c_to_shell(c_code) {
stdoutArr = []
let ModuleArgs = {
// 'onExit': function(code) { console.log("calling onExit with: " + code); },
// 'noExitRuntime': false,
'print': function(text) { stdoutArr.push(text); }, // Capture stdout
};
create_module(ModuleArgs).then((module) => {
module.FS.writeFile("code.c", c_code); // write the C code to a file
var compile = module.cwrap("compile", "void", ["string"])
try {
compile("code.c");
} catch (e) {
if (e instanceof module.ExitStatus && e.status == 0) {
console.log("Compilation successful");
} else {
console.log("Failed to compile");
}
}
document.getElementById('shell-code').value = stdoutArr.join("\n");
});
}
document.getElementById("compile-btn").onclick = () => {
console.log("Compiling code");
var c_code = document.getElementById('c-editor').value;
c_to_shell(c_code);
}
</script>
</body>
</html>