make clean

This commit is contained in:
Michael Thomson 2024-12-10 10:42:46 -05:00
parent 2840bb6779
commit 1abc5b8e52
4 changed files with 112 additions and 77 deletions

View File

@ -1,12 +1,42 @@
[ [
{ {
"arguments": [ "arguments": [
"/nix/store/k8mrxviw965lv59hqbln3297jwfffm2w-clang-wrapper-16.0.6/bin/clang", "/usr/bin/gcc",
"-g", "-g",
"-c", "-c",
"main.c" "main.c"
], ],
"directory": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1", "directory": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1",
"file": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1/main.c" "file": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1/main.c"
},
{
"arguments": [
"/usr/bin/gcc",
"-g",
"-c",
"prog1.c"
],
"directory": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1",
"file": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1/prog1.c"
},
{
"arguments": [
"/usr/bin/gcc",
"-g",
"-c",
"slp.c"
],
"directory": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1",
"file": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1/slp.c"
},
{
"arguments": [
"/usr/bin/gcc",
"-g",
"-c",
"util.c"
],
"directory": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1",
"file": "/Users/mthomson/dev/personal/modern-compiler-implementation-in-c/c1/util.c"
} }
] ]

BIN
c1/main

Binary file not shown.

View File

@ -1,6 +1,7 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h> #include <string.h>
#include <stddef.h>
#include "prog1.h" #include "prog1.h"
#include "main.h" #include "main.h"
@ -33,7 +34,8 @@ int maxargs(A_stm statement)
return 0; return 0;
} }
Table_ interpStm(A_stm stm, Table_ t) { Table_ interpStm(A_stm stm, Table_ t)
{
if (stm->kind == A_compoundStm) { if (stm->kind == A_compoundStm) {
t = interpStm(stm->u.compound.stm1, t); t = interpStm(stm->u.compound.stm1, t);
t = interpStm(stm->u.compound.stm2, t); t = interpStm(stm->u.compound.stm2, t);
@ -52,7 +54,8 @@ Table_ interpStm(A_stm stm, Table_ t) {
return t; return t;
} }
IntAndTable_ interpExp(A_exp e, Table_ t) { IntAndTable_ interpExp(A_exp e, Table_ t)
{
if (e->kind == A_idExp) { if (e->kind == A_idExp) {
return IntAndTable(lookup(t, e->u.id), t); return IntAndTable(lookup(t, e->u.id), t);
} else if (e->kind == A_numExp) { } else if (e->kind == A_numExp) {
@ -78,14 +81,16 @@ IntAndTable_ interpExp(A_exp e, Table_ t) {
} }
} }
IntAndTable_ IntAndTable(int i, Table_ t) { IntAndTable_ IntAndTable(int i, Table_ t)
{
IntAndTable_ it = checked_malloc(sizeof(*it)); IntAndTable_ it = checked_malloc(sizeof(*it));
it->i = i; it->i = i;
it->t = t; it->t = t;
return it; return it;
} }
Table_ Table(string id, int value, struct table *tail) { Table_ Table(string id, int value, struct table *tail)
{
Table_ t = checked_malloc(sizeof(*t)); Table_ t = checked_malloc(sizeof(*t));
t->id = id; t->id = id;
t->value = value; t->value = value;
@ -93,7 +98,8 @@ Table_ Table(string id, int value, struct table *tail) {
return t; return t;
} }
int lookup(Table_ t, string key) { int lookup(Table_ t, string key)
{
if (t == NULL) { if (t == NULL) {
// HACK: should indicate a null value // HACK: should indicate a null value
return 0; return 0;
@ -114,7 +120,6 @@ int main()
Table_ t = interpStm(program, NULL); Table_ t = interpStm(program, NULL);
printf("a: %d\n", lookup(t, "a")); printf("a: %d\n", lookup(t, "a"));
printf("b: %d\n", lookup(t, "b")); printf("b: %d\n", lookup(t, "b"));
} }

View File

@ -1,17 +1,17 @@
a.out: main.o prog1.o slp.o util.o a.out: main.o prog1.o slp.o util.o
cc -g main.o prog1.o slp.o util.o gcc -g main.o prog1.o slp.o util.o
main.o: main.c slp.h util.h main.h main.o: main.c slp.h util.h main.h
cc -g -c main.c gcc -g -c main.c
prog1.o: prog1.c slp.h util.h prog1.o: prog1.c slp.h util.h
cc -g -c prog1.c gcc -g -c prog1.c
slp.o: slp.c slp.h util.h slp.o: slp.c slp.h util.h
cc -g -c slp.c gcc -g -c slp.c
util.o: util.c util.h util.o: util.c util.h
cc -g -c util.c gcc -g -c util.c
clean: clean:
rm -f a.out util.o prog1.o slp.o main.o rm -f a.out util.o prog1.o slp.o main.o