update makefile and readme
This commit is contained in:
parent
10d2f10c2f
commit
9b280dca92
3 changed files with 40 additions and 10 deletions
1
first-interpreter/.gitignore
vendored
1
first-interpreter/.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
_build
|
||||
interpreter
|
||||
interpreter.dSYM
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
27
first-interpreter/readme.md
Normal file
27
first-interpreter/readme.md
Normal file
|
|
@ -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
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue