diff --git a/.vscode/settings.json b/.vscode/settings.json index f7f606b..9b01ed6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" + } } diff --git a/compiler/checker.ts b/compiler/checker.ts index 1eb4df3..8fcea55 100644 --- a/compiler/checker.ts +++ b/compiler/checker.ts @@ -362,7 +362,6 @@ export class Checker { } const pos = expr.pos; const subject = this.checkExpr(expr.kind.subject); - console.log(expr); if (subject.type !== "fn") { this.report("cannot call non-fn", pos); return { type: "error" }; diff --git a/compiler/main.ts b/compiler/main.ts index 0884103..52c706b 100644 --- a/compiler/main.ts +++ b/compiler/main.ts @@ -30,6 +30,6 @@ lowerer.lower(ast); lowerer.printProgram(); const program = lowerer.finish(); //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)); diff --git a/compiler/parser.ts b/compiler/parser.ts index 6cccd47..0be79c1 100644 --- a/compiler/parser.ts +++ b/compiler/parser.ts @@ -42,7 +42,6 @@ export class Parser { } private report(msg: string, pos = this.pos()) { - console.log(`Parser: ${msg} at ${pos.line}:${pos.col}`); this.reporter.reportError({ msg, pos, diff --git a/runtime/Dockerfile b/runtime/Dockerfile new file mode 100644 index 0000000..970b425 --- /dev/null +++ b/runtime/Dockerfile @@ -0,0 +1,9 @@ +from gcc + +WORKDIR /workdir + +COPY . . + +RUN make -j 8 + +ENTRYPOINT [ "./build/sliger", "run", "out.slgbc" ] \ No newline at end of file diff --git a/runtime/Makefile b/runtime/Makefile index 6be4c0c..c4e80d3 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -14,16 +14,18 @@ CXX_SOURCES = $(shell find . -name "*.cpp" -type f -printf '%P\n') CXX_OBJECTS = $(patsubst %.cpp,build/%.o,$(CXX_SOURCES)) +CXX = g++ + all: build_dir $(OUT) $(OUT): $(CXX_OBJECTS) - g++ -o $@ $(CXX_FLAGS) $^ + $(CXX) -o $@ $(CXX_FLAGS) $^ build_dir: mkdir -p build/ build/%.o: %.cpp $(CXX_HEADERS) - g++ -c -o $@ $(CXX_FLAGS) $< + $(CXX) -c -o $@ $(CXX_FLAGS) $< clean: rm -rf build/ diff --git a/runtime/main.cpp b/runtime/main.cpp index 34ffb52..65409ce 100644 --- a/runtime/main.cpp +++ b/runtime/main.cpp @@ -9,6 +9,8 @@ #include #include +bool print_stack_debug = false; + int execute_file_and_exit(std::string filename) { auto file = std::ifstream(); @@ -33,6 +35,7 @@ int execute_file_and_exit(std::string filename) { .flame_graph = false, .code_coverage = false, + .print_stack_debug = print_stack_debug, }); vm.run_until_done(); return 0; diff --git a/runtime/vm.cpp b/runtime/vm.cpp index 4d1ba95..489c9db 100644 --- a/runtime/vm.cpp +++ b/runtime/vm.cpp @@ -68,8 +68,10 @@ void VM::run_n_instructions(size_t amount) void VM::run_instruction() { - // std::cout << std::format(" {:>4}: {:<12}{}\n", this->pc, - // maybe_op_to_string(this->program[this->pc]), stack_repr_string(8)); + if (this->opts.print_stack_debug) { + 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(); switch (op) { case Op::Nop: @@ -343,6 +345,7 @@ void VM::run_builtin(Builtin builtin_id) assert_stack_has(1); auto message = stack_pop().as_string().value; std::cout << message; + stack_push(Null()); break; } } diff --git a/runtime/vm.hpp b/runtime/vm.hpp index c05d4fa..f7ec40e 100644 --- a/runtime/vm.hpp +++ b/runtime/vm.hpp @@ -142,6 +142,7 @@ private: struct VMOpts { bool flame_graph; bool code_coverage; + bool print_stack_debug; }; class VM { diff --git a/runtime/vm_provider.cpp b/runtime/vm_provider.cpp index 53ce67b..2c4fa7a 100644 --- a/runtime/vm_provider.cpp +++ b/runtime/vm_provider.cpp @@ -9,6 +9,7 @@ auto VmProvider::load_and_run(std::vector instructions) -> void { .flame_graph = true, .code_coverage = true, + .print_stack_debug = false, }); vm.run_until_done(); this->vm = vm; diff --git a/slige-run-docker.sh b/slige-run-docker.sh new file mode 100755 index 0000000..80dbb18 --- /dev/null +++ b/slige-run-docker.sh @@ -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 \ No newline at end of file