sliger on docker

This commit is contained in:
Mikkel Kongsted 2024-12-12 10:17:09 +01:00
parent 2662c327ca
commit 4363874cd2
11 changed files with 93 additions and 8 deletions

51
.vscode/settings.json vendored
View File

@ -1,3 +1,52 @@
{ {
"deno.enable": true "deno.enable": true,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
} }

View File

@ -362,7 +362,6 @@ export class Checker {
} }
const pos = expr.pos; const pos = expr.pos;
const subject = this.checkExpr(expr.kind.subject); const subject = this.checkExpr(expr.kind.subject);
console.log(expr);
if (subject.type !== "fn") { if (subject.type !== "fn") {
this.report("cannot call non-fn", pos); this.report("cannot call non-fn", pos);
return { type: "error" }; return { type: "error" };

View File

@ -30,6 +30,6 @@ lowerer.lower(ast);
lowerer.printProgram(); lowerer.printProgram();
const program = lowerer.finish(); const program = lowerer.finish();
//console.log(JSON.stringify(program, null, 4)); //console.log(JSON.stringify(program, null, 4));
console.log(JSON.stringify(program)); // console.log(JSON.stringify(program));
await Deno.writeTextFile("out.slgbc", JSON.stringify(program)); await Deno.writeTextFile("out.slgbc", JSON.stringify(program));

View File

@ -42,7 +42,6 @@ export class Parser {
} }
private report(msg: string, pos = this.pos()) { private report(msg: string, pos = this.pos()) {
console.log(`Parser: ${msg} at ${pos.line}:${pos.col}`);
this.reporter.reportError({ this.reporter.reportError({
msg, msg,
pos, pos,

9
runtime/Dockerfile Normal file
View File

@ -0,0 +1,9 @@
from gcc
WORKDIR /workdir
COPY . .
RUN make -j 8
ENTRYPOINT [ "./build/sliger", "run", "out.slgbc" ]

View File

@ -14,16 +14,18 @@ CXX_SOURCES = $(shell find . -name "*.cpp" -type f -printf '%P\n')
CXX_OBJECTS = $(patsubst %.cpp,build/%.o,$(CXX_SOURCES)) CXX_OBJECTS = $(patsubst %.cpp,build/%.o,$(CXX_SOURCES))
CXX = g++
all: build_dir $(OUT) all: build_dir $(OUT)
$(OUT): $(CXX_OBJECTS) $(OUT): $(CXX_OBJECTS)
g++ -o $@ $(CXX_FLAGS) $^ $(CXX) -o $@ $(CXX_FLAGS) $^
build_dir: build_dir:
mkdir -p build/ mkdir -p build/
build/%.o: %.cpp $(CXX_HEADERS) build/%.o: %.cpp $(CXX_HEADERS)
g++ -c -o $@ $(CXX_FLAGS) $< $(CXX) -c -o $@ $(CXX_FLAGS) $<
clean: clean:
rm -rf build/ rm -rf build/

View File

@ -9,6 +9,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
bool print_stack_debug = false;
int execute_file_and_exit(std::string filename) int execute_file_and_exit(std::string filename)
{ {
auto file = std::ifstream(); auto file = std::ifstream();
@ -33,6 +35,7 @@ int execute_file_and_exit(std::string filename)
{ {
.flame_graph = false, .flame_graph = false,
.code_coverage = false, .code_coverage = false,
.print_stack_debug = print_stack_debug,
}); });
vm.run_until_done(); vm.run_until_done();
return 0; return 0;

View File

@ -68,8 +68,10 @@ void VM::run_n_instructions(size_t amount)
void VM::run_instruction() void VM::run_instruction()
{ {
// std::cout << std::format(" {:>4}: {:<12}{}\n", this->pc, if (this->opts.print_stack_debug) {
// maybe_op_to_string(this->program[this->pc]), stack_repr_string(8)); std::cout << std::format(" {:>4}: {:<12}{}\n", this->pc,
maybe_op_to_string(this->program[this->pc]), stack_repr_string(8));
}
auto op = eat_op(); auto op = eat_op();
switch (op) { switch (op) {
case Op::Nop: case Op::Nop:
@ -343,6 +345,7 @@ void VM::run_builtin(Builtin builtin_id)
assert_stack_has(1); assert_stack_has(1);
auto message = stack_pop().as_string().value; auto message = stack_pop().as_string().value;
std::cout << message; std::cout << message;
stack_push(Null());
break; break;
} }
} }

View File

@ -142,6 +142,7 @@ private:
struct VMOpts { struct VMOpts {
bool flame_graph; bool flame_graph;
bool code_coverage; bool code_coverage;
bool print_stack_debug;
}; };
class VM { class VM {

View File

@ -9,6 +9,7 @@ auto VmProvider::load_and_run(std::vector<uint32_t> instructions) -> void
{ {
.flame_graph = true, .flame_graph = true,
.code_coverage = true, .code_coverage = true,
.print_stack_debug = false,
}); });
vm.run_until_done(); vm.run_until_done();
this->vm = vm; this->vm = vm;

19
slige-run-docker.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
echo Text:
cat $1
echo Compiling $1...
deno run --allow-read --allow-write compiler/main.ts $1
echo Running out.slgbc...
cp out.slgbc runtime/
cd runtime/
docker build . -t sliger-buildenv
docker run --rm -it sliger-buildenv