switch to a makefile
This commit is contained in:
parent
b5426dcc3f
commit
10d2f10c2f
7 changed files with 39 additions and 50 deletions
1
first-interpreter/.gitignore
vendored
1
first-interpreter/.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
_build
|
||||
interpreter
|
||||
|
|
|
|||
36
first-interpreter/Makefile
Normal file
36
first-interpreter/Makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
ifndef VERBOSE
|
||||
.SILENT:
|
||||
endif
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -ggdb
|
||||
|
||||
.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
|
||||
|
||||
build/ast.o: src/ast.c src/ast.h
|
||||
mkdir -p build/
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
build/lex.o: src/lex.c src/lex.h
|
||||
mkdir -p build/
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
build/parse.o: src/parse.c src/parse.h build/ast.o build/lex.o
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
build/execute.o: src/execute.c src/execute.h build/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
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
.PHONY clean run:
|
||||
clean:
|
||||
rm -rf build
|
||||
rm -rf interpreter
|
||||
|
||||
run: interpreter
|
||||
./interpreter program.code
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#!/usr/bin/env cabal
|
||||
{- cabal:
|
||||
build-depends:
|
||||
base,
|
||||
bytestring,
|
||||
cereal,
|
||||
hspec,
|
||||
process,
|
||||
shake,
|
||||
-}
|
||||
-- initial version taken from https://shakebuild.com/manual
|
||||
import Development.Shake
|
||||
import Development.Shake.FilePath
|
||||
import Development.Shake.Util
|
||||
|
||||
cc = "gcc"
|
||||
flags = "-ggdb"
|
||||
clearCcCache = removeFilesAfter "build" ["//*"]
|
||||
|
||||
main :: IO ()
|
||||
main = shakeArgs shakeOptions{shakeFiles="_build"} $ do
|
||||
want ["_build/interpreter" <.> exe]
|
||||
|
||||
phony "clean" $ do
|
||||
putInfo "Cleaning files in _build"
|
||||
removeFilesAfter "_build" ["//*"]
|
||||
clearCcCache
|
||||
removeFilesAfter "newdist" ["//*"]
|
||||
cmd_ "cabal" "clean"
|
||||
|
||||
phony "run" $ do
|
||||
need ["_build/interpreter" <.> exe]
|
||||
putInfo "Running interpreter"
|
||||
cmd_ "_build/interpreter" ["program.code"]
|
||||
|
||||
"_build/interpreter" <.> exe %> \out -> do
|
||||
cs <- getDirectoryFiles "src" ["//*.c"]
|
||||
let os = ["_build" </> "normal" </> "src" </> c -<.> "o" | c <- cs]
|
||||
need os
|
||||
cmd_ (cc <> " " <> flags <> " -o") [out] os
|
||||
|
||||
"_build/normal//*.o" %> \out -> do
|
||||
let c = dropDirectory1 $ dropDirectory1 $ out -<.> "c"
|
||||
let m = out -<.> "m"
|
||||
cmd_ (cc <> " " <> flags <> " -c") [c] "-o" [out] "-MMD -MF" [m]
|
||||
neededMakefileDependencies m
|
||||
|
|
@ -86,9 +86,9 @@ int* lookup(char* name, Memory memory, Environment env) {
|
|||
|
||||
int eval_expr(Expr expr, Memory memory, Environment env) {
|
||||
switch (expr.tag) {
|
||||
default:
|
||||
case LITERAL: {
|
||||
return expr.data.integer;
|
||||
break;
|
||||
}
|
||||
case VARIABLE: {
|
||||
int* result = lookup(expr.data.variable, memory, env);
|
||||
|
|
@ -98,7 +98,6 @@ int eval_expr(Expr expr, Memory memory, Environment env) {
|
|||
} else {
|
||||
return *result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FUNCTION: {
|
||||
if (strcmp(expr.data.function.name, "print") == 0) {
|
||||
|
|
@ -131,7 +130,6 @@ int eval_expr(Expr expr, Memory memory, Environment env) {
|
|||
}
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "interpreter.h"
|
||||
#include "run.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// Read file
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue