Initial working submission, without errors
This commit is contained in:
parent
b0154657d4
commit
051c264a23
4 changed files with 17 additions and 13 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
FROM rust AS builder
|
||||||
|
WORKDIR /home/vili/School/Compilers/compiler-course
|
||||||
|
COPY . .
|
||||||
|
RUN cargo install --path .
|
||||||
|
|
||||||
|
FROM debian:stable-slim
|
||||||
|
RUN apt-get update && apt-get install -y libc6 gcc && rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY --from=builder /usr/local/cargo/bin/compiler-course /usr/local/bin/compiler-course
|
||||||
|
EXPOSE 3000
|
||||||
|
CMD ["compiler-course"]
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub fn compile(code: &str) -> String {
|
||||||
type_check(&mut ast, &mut SymTab::new_type_table());
|
type_check(&mut ast, &mut SymTab::new_type_table());
|
||||||
let ir = generate_ir(&ast);
|
let ir = generate_ir(&ast);
|
||||||
let assembly = generate_assembly(&ir);
|
let assembly = generate_assembly(&ir);
|
||||||
|
|
||||||
general_purpose::STANDARD.encode(&assemble(assembly))
|
general_purpose::STANDARD.encode(&assemble(assembly))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,26 +41,21 @@ pub fn assemble(assembly: String) -> Vec<u8> {
|
||||||
file.write_all(assembly.as_bytes())
|
file.write_all(assembly.as_bytes())
|
||||||
.expect("Can't write to temp file!");
|
.expect("Can't write to temp file!");
|
||||||
|
|
||||||
let as_out1 = Command::new("as")
|
Command::new("as")
|
||||||
.args(["-g", "-o", stdlib_obj, stdlib_asm])
|
.args(["-g", "-o", stdlib_obj, stdlib_asm])
|
||||||
.output()
|
.output()
|
||||||
.expect("Could not run 'as' command!");
|
.expect("Could not run 'as' command!");
|
||||||
|
|
||||||
let as_out2 = Command::new("as")
|
Command::new("as")
|
||||||
.args(["-g", "-o", program_obj, program_asm])
|
.args(["-g", "-o", program_obj, program_asm])
|
||||||
.output()
|
.output()
|
||||||
.expect("Could not run 'as' command!");
|
.expect("Could not run 'as' command!");
|
||||||
|
|
||||||
let ld_out = Command::new("ld")
|
Command::new("ld")
|
||||||
.args(["-o", output_file, "-static", stdlib_obj, program_obj])
|
.args(["-o", output_file, "-static", stdlib_obj, program_obj])
|
||||||
.output()
|
.output()
|
||||||
.expect("Could not run 'as' command!");
|
.expect("Could not run 'as' command!");
|
||||||
|
|
||||||
println!("{as_out1:?}");
|
|
||||||
println!("{as_out2:?}");
|
|
||||||
println!("{ld_out:?}");
|
|
||||||
println!("{workdir:?}");
|
|
||||||
|
|
||||||
let mut file = File::open(output_file).expect("Can't open compiler output!");
|
let mut file = File::open(output_file).expect("Can't open compiler output!");
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
file.read_to_end(&mut output)
|
file.read_to_end(&mut output)
|
||||||
|
|
|
@ -37,11 +37,8 @@ fn handle_connection(mut stream: TcpStream) {
|
||||||
let program = json_request["code"].as_str().unwrap();
|
let program = json_request["code"].as_str().unwrap();
|
||||||
let output = compiler::compile(program);
|
let output = compiler::compile(program);
|
||||||
|
|
||||||
let json_response = json::object! {
|
let response = format!("{{\"program\": \"{output}\"}}");
|
||||||
"program": output,
|
stream.write_all(response.as_bytes()).unwrap();
|
||||||
};
|
|
||||||
let response = json_response.as_str().unwrap().as_bytes();
|
|
||||||
stream.write_all(response).unwrap();
|
|
||||||
}
|
}
|
||||||
_ => panic!("Unexpected command!"),
|
_ => panic!("Unexpected command!"),
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue