-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler_new.shl
More file actions
83 lines (65 loc) · 2.53 KB
/
Copy pathcompiler_new.shl
File metadata and controls
83 lines (65 loc) · 2.53 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
define page CompilerPage
html
head
title "ShellLite Online Compiler"
link rel="stylesheet" href="/static/style.css"
body
header
div class="container"
nav
div class="logo" "ShellLite"
div class="nav-links"
a href="/" "Home"
a href="/compiler" class="active" "Compiler"
a href="/docs" "Docs"
div class="container"
div class="editor-container"
div class="editor-pane"
div class="pane-header"
h3 "Code Editor"
button class="run-btn" onclick="runCode()" "Run Code >"
textarea id="code-input" "say 'Btw this compiler was also written purely using ShellLite :)'"
div class="output-pane"
div class="pane-header"
h3 "Output"
div id="output-display" class="output-content" "// Output will appear here..."
script src="/static/compiler.js"
footer
div class="container"
p "Powered by ShellLite Web Runtime. We wrote everything using ShellLite only."
when someone visits "/compiler"
CompilerPage
when someone submits to "/api/run"
use python "random"
use python "os"
use python "sys"
use python "subprocess"
use python "os.path" as os_path
req_data = request.json
code = req_data["code"]
id = random.randint(1000, 999999)
filename = "run_" + str(id) + ".shl"
write code to file filename
result = "No output returned by compiler."
cmd = [sys.executable, "-m", "shell_lite.main", "run", filename]
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=5)
rc = proc.returncode
err = proc.stderr
out = proc.stdout
print("DEBUG: Subprocess finished")
if rc != 0:
if err:
result = "Error:\n" + err
else:
result = out
else:
result = out
if result == "":
result = "Executed successfully (No Output)"
print("DEBUG: Result calculated: " + str(result))
exists = os_path.exists(filename)
if exists:
os.remove(filename)
print("DEBUG: File removed")
print("DEBUG: Returning result")
return result