From 9b280dca9251530557185865d4ac4dc157aff146 Mon Sep 17 00:00:00 2001 From: me Date: Fri, 9 Jan 2026 09:49:45 +0200 Subject: [PATCH] update makefile and readme --- first-interpreter/.gitignore | 1 + first-interpreter/Makefile | 22 ++++++++++++---------- first-interpreter/readme.md | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 first-interpreter/readme.md diff --git a/first-interpreter/.gitignore b/first-interpreter/.gitignore index a863071..483ce90 100644 --- a/first-interpreter/.gitignore +++ b/first-interpreter/.gitignore @@ -1,2 +1,3 @@ _build interpreter +interpreter.dSYM diff --git a/first-interpreter/Makefile b/first-interpreter/Makefile index 2ea1f7b..2ecb890 100644 --- a/first-interpreter/Makefile +++ b/first-interpreter/Makefile @@ -4,33 +4,35 @@ endif CC = gcc CFLAGS = -Wall -Wextra -ggdb +BUILD_DIR = _build .DEFAULT_TARGET = interpreter -interpreter: src/main.c build/run.o - $(CC) $(CFLAGS) $< -o $@ build/run.o build/ast.o build/lex.o build/parse.o build/execute.o +interpreter: src/main.c $(BUILD_DIR)/run.o + $(CC) $(CFLAGS) $< -o $@ $(BUILD_DIR)/run.o $(BUILD_DIR)/ast.o $(BUILD_DIR)/lex.o $(BUILD_DIR)/parse.o $(BUILD_DIR)/execute.o -build/ast.o: src/ast.c src/ast.h - mkdir -p build/ +$(BUILD_DIR)/ast.o: src/ast.c src/ast.h + mkdir -p $(BUILD_DIR)/ $(CC) $(CFLAGS) -c $< -o $@ -build/lex.o: src/lex.c src/lex.h - mkdir -p build/ +$(BUILD_DIR)/lex.o: src/lex.c src/lex.h + mkdir -p $(BUILD_DIR)/ $(CC) $(CFLAGS) -c $< -o $@ -build/parse.o: src/parse.c src/parse.h build/ast.o build/lex.o +$(BUILD_DIR)/parse.o: src/parse.c src/parse.h $(BUILD_DIR)/ast.o $(BUILD_DIR)/lex.o $(CC) $(CFLAGS) -c $< -o $@ -build/execute.o: src/execute.c src/execute.h build/ast.o +$(BUILD_DIR)/execute.o: src/execute.c src/execute.h $(BUILD_DIR)/ast.o $(CC) $(CFLAGS) -c $< -o $@ -build/run.o: src/run.c src/run.h build/ast.o build/lex.o build/parse.o build/execute.o +$(BUILD_DIR)/run.o: src/run.c src/run.h $(BUILD_DIR)/ast.o $(BUILD_DIR)/lex.o $(BUILD_DIR)/parse.o $(BUILD_DIR)/execute.o $(CC) $(CFLAGS) -c $< -o $@ .PHONY clean run: clean: - rm -rf build + rm -rf _build rm -rf interpreter + rm -rf interpreter.dSYM run: interpreter ./interpreter program.code diff --git a/first-interpreter/readme.md b/first-interpreter/readme.md new file mode 100644 index 0000000..d267de7 --- /dev/null +++ b/first-interpreter/readme.md @@ -0,0 +1,27 @@ +# My first interpreter + +Code for a very simple interpreter. + +Accompanying blogpost: https://alloca.space/blog/my-first-interpreter.html + +## Example Program + +```go +sum = 0 +counter = 10 + +while counter { + sum = add(sum, counter) + counter = add(counter, negate(1)) +} + +print(sum) +``` + +## Build and run + +Requires: gcc, make + +```sh +make run +```