-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·86 lines (61 loc) · 1.97 KB
/
app.py
File metadata and controls
executable file
·86 lines (61 loc) · 1.97 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
84
85
86
from flask import Flask, request
import json
from flask import Flask, request, json
from src import database, core, PrBaseException
import logging
logging.basicConfig(filename='info_flask.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
app = Flask(__name__)
core = core.Core()
@app.route("/register/write", methods=["POST"])
def write_to_register():
data: dict[str, str] = json.loads(request.data)
try:
core.register_write(data)
response = "OK", 200
except PrBaseException as e:
response = e.message, e.status
except Exception as e:
response = "Internal Server Error", 500
return response
@app.route("/register/read", methods=["GET"])
def read_register():
data = core.register_read()
return data
@app.route("/memory/write", methods=["POST"])
def write_to_memory():
data = json.loads(request.data)
try:
core.memory_bulk_write(data["data"])
response = "OK", 200
except PrBaseException as e:
response = e.message, e.status
return response
@app.route("/memory/read", methods=["GET"])
def read_memory():
data = core.memory_bulk_read()
res = {"data": data}
return res
@app.route("/core/instruction", methods=["POST"])
def execute_instructions():
try:
core.execute_instruction()
response = "OK", 200
except PrBaseException as e:
response = e.message, e.status
return response
@app.route("/core/compile", methods=["POST"])
def compile_instructions():
try:
data: dict[str, list[str]] = json.loads(request.data)
core.compile(data["instructions"])
return "OK", 200
except PrBaseException as e:
return e.message, e.status
except:
return "Internal Server Error", 500
@app.route("/", methods=["GET"])
def root():
return "Hello Flask"
if __name__ == "__main__":
database.init_db()
app.run(host="127.0.0.1", port=8000, debug=True)