mirror of
https://github.com/iritmaximus/compilers.git
synced 2026-10-12 19:13:35 +03:00
got something working
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
.*_cache
|
.*_cache
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__
|
__pycache__
|
||||||
|
build
|
||||||
|
|||||||
+18
-2
@@ -1,12 +1,28 @@
|
|||||||
FROM python:3.12-alpine3.21
|
FROM alpine:3.23 AS builder
|
||||||
|
|
||||||
|
RUN apk update
|
||||||
|
RUN apk add --no-cache build-base git
|
||||||
|
RUN apk add --no-cache cmake cmake-doc cmake-extras pkgconf
|
||||||
|
|
||||||
|
WORKDIR /usr/src/compiler
|
||||||
|
|
||||||
|
COPY compiler .
|
||||||
|
|
||||||
|
RUN rm -rf build
|
||||||
|
|
||||||
|
RUN mkdir build/ && cd build && cmake .. && make -j8
|
||||||
|
|
||||||
|
|
||||||
|
FROM python:3.12-alpine3.21 AS runner
|
||||||
|
|
||||||
RUN pip install --no-cache-dir poetry==2.0.0
|
RUN pip install --no-cache-dir poetry==2.0.0
|
||||||
RUN apk add --no-cache bash binutils
|
RUN apk add --no-cache bash binutils
|
||||||
|
|
||||||
WORKDIR /compiler
|
WORKDIR /usr/src/app
|
||||||
COPY pyproject.toml poetry.lock ./
|
COPY pyproject.toml poetry.lock ./
|
||||||
RUN poetry install --no-root --no-cache
|
RUN poetry install --no-root --no-cache
|
||||||
|
|
||||||
|
COPY --from=builder /usr/src/compiler/build/compilers_compiler ./compilers_compiler
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN poetry install --no-cache && ./check.sh
|
RUN poetry install --no-cache && ./check.sh
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
build
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc >= 2) {
|
||||||
|
std::cout << argv[1] << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "No args :(" << std::endl;
|
||||||
|
}
|
||||||
std::cout << "Hello world!" << std::endl;
|
std::cout << "Hello world!" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,18 @@ import sys
|
|||||||
from socketserver import ForkingTCPServer, StreamRequestHandler
|
from socketserver import ForkingTCPServer, StreamRequestHandler
|
||||||
from traceback import format_exception
|
from traceback import format_exception
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def call_compiler(source_code: str) -> bytes:
|
def call_compiler(source_code: str) -> bytes:
|
||||||
# *** TODO ***
|
# *** TODO ***
|
||||||
# Call your compiler here and return the compiled executable.
|
# Call your compiler here and return the compiled executable.
|
||||||
# Raise an exception on compilation error.
|
# Raise an exception on compilation error.
|
||||||
# *** TODO ***
|
# *** TODO ***
|
||||||
raise NotImplementedError("Compiler not implemented")
|
print("Compiling:", "./compilers_compiler", source_code)
|
||||||
|
response = subprocess.run(["./compilers_compiler", source_code], check=True, capture_output=True).stdout
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
@@ -78,10 +82,13 @@ def run_server(host: str, port: int) -> None:
|
|||||||
|
|
||||||
class Handler(StreamRequestHandler):
|
class Handler(StreamRequestHandler):
|
||||||
def handle(self) -> None:
|
def handle(self) -> None:
|
||||||
|
print("Got a request?")
|
||||||
result: dict[str, Any] = {}
|
result: dict[str, Any] = {}
|
||||||
try:
|
try:
|
||||||
input_str = self.rfile.read().decode()
|
input_str = self.rfile.read().decode()
|
||||||
|
print("INPUTSTR:", input_str)
|
||||||
input = json.loads(input_str)
|
input = json.loads(input_str)
|
||||||
|
print("JSONINPUT", input)
|
||||||
if input["command"] == "compile":
|
if input["command"] == "compile":
|
||||||
source_code = input["code"]
|
source_code = input["code"]
|
||||||
executable = call_compiler(source_code)
|
executable = call_compiler(source_code)
|
||||||
@@ -91,8 +98,10 @@ def run_server(host: str, port: int) -> None:
|
|||||||
else:
|
else:
|
||||||
result["error"] = "Unknown command: " + input['command']
|
result["error"] = "Unknown command: " + input['command']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print("ERROR!!", e)
|
||||||
result["error"] = "".join(format_exception(e))
|
result["error"] = "".join(format_exception(e))
|
||||||
result_str = json.dumps(result)
|
result_str = json.dumps(result)
|
||||||
|
print(result_str)
|
||||||
self.request.sendall(str.encode(result_str))
|
self.request.sendall(str.encode(result_str))
|
||||||
|
|
||||||
print(f"Starting TCP server at {host}:{port}")
|
print(f"Starting TCP server at {host}:{port}")
|
||||||
|
|||||||
Reference in New Issue
Block a user