Skip to content

Commit 6850e1a

Browse files
Nicolas Boulenguezkanaka
authored andcommitted
c.2: hashmaps, vectors, hide MAL struct, reduce duplications, fix 62d1ed3
Makefile: Compute the build flags with pkg-config. Make more settings available on the command line. Enable the -fanalyzer warning (and close the issue found in slurp). core: Simplify the argument parsing and return value constructor in ".". env: Implement with hashmaps. Allow printing by DEBUG-EVAL. error (new): Format most error messages consistently. When an error is detected, show all arguments instead of only the remaining ones (this was not informative when the rest was empty). Restore the previous error prefix (the MAL function, not the C function). Use a global variables instead of a type, simplifying functions returning non-MAL types. hashmap (rewritten, moved to ./): Replace binary trees with hashed maps. linked_list (moved to ./): Return a signed count in order to spare a later conversion. printer: Allow a width specifier (for DEBUG-EVAL). Print MAL type sets (for bad_type) and hashmaps (for DEBUG-EVAL). Shorten name for functions (else REPL fills the screen). Move commands outside of assert (they didn’t survive NDEBUG). Inverse the meaning of " " so that list *are* spaced by default. readline (new): Avoid duplication in steps and core (core was incorrect). steps: Properly report reader errors (this was dealt with by the null case in EVAL, but not documented and removed by 62d1ed3). Stop preventing TCO when if returns nil (the benefit is dubious). Add a quasiquote_folder used by lists and vectors. Stop calling quasiquote twice on each list/vector element (error in 62d1ed3). types: Hide the struct into the .c file. Compute the hash of each string at creation. Allocate common symbols once at startup. Remove metadata from most types. Use the same "pattern-matching" function to test the type and extract the contents. Add metadata as an optional argument to some constructor. vectors (new): Provide an iterator common with lists. global Move equality from core to types, use it in steps and hashmaps. In closures, store the raw fn* arguments (The &more syntax without space is lost but could be restored if this seems important).
1 parent e2263b7 commit 6850e1a

33 files changed

+3517
-2792
lines changed

impls/c.2/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ WORKDIR /mal
2323
RUN apt-get -y install gcc
2424

2525
# Libraries needed for the C impl
26-
RUN apt-get -y install libffi-dev libgc-dev libedit-dev
26+
RUN apt-get -y install libffi-dev libgc-dev libedit-dev pkgconf

impls/c.2/Makefile

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
CC = gcc
22

3-
# Optimization is not required but enables some more warnings.
4-
CFLAGS = -std=c99 -g -Wall -Wextra -O1
3+
CFLAGS = -std=c99 -g -Wall -Wextra -fanalyzer
54

65
# The code defines new format specifiers.
76
CPPFLAGS = -Wno-format
87

8+
ifdef debug_reader
9+
CPPFLAGS += -DDEBUG_READER
10+
endif
11+
ifdef debug_hash
12+
CPPFLAGS += -DDEBUG_HASH
13+
endif
14+
ifdef debug_hashmap
15+
CPPFLAGS += -DDEBUG_HASHMAP
16+
endif
17+
ifdef debug_hash_collisions
18+
CPPFLAGS += -DDEBUG_HASH_COLLISIONS
19+
endif
20+
ifndef no_fast
21+
CFLAGS += -flto -O3 -DNDEBUG
22+
LDFLAGS += -flto
23+
endif
24+
ifdef profilie
25+
CFLAGS += -pg
26+
LDFLAGS += -pg
27+
endif
28+
ifdef readline
29+
pkgconfig_modules += readline
30+
CFLAGS += -DUSE_READLINE
31+
else
32+
pkgconfig_modules += libedit
33+
endif
34+
ifndef no_ffi
35+
pkgconfig_modules += libffi
36+
CFLAGS += -DWITH_FFI
37+
endif
38+
39+
pkgconfig_modules += bdw-gc
40+
CFLAGS += $(shell pkg-config --cflags $(pkgconfig_modules))
41+
LDLIBS += $(shell pkg-config --libs $(pkgconfig_modules))
42+
943
S0 = step0_repl
1044
S1 = step1_read_print
1145
S2 = step2_eval
@@ -23,29 +57,18 @@ S3+ := $(S3) $(S4+)
2357
S1+ := $(S1) $(S2) $(S3+)
2458
S0+ := $(S0) $(S1+)
2559

26-
VPATH = libs/hashmap libs/linked_list
27-
2860
all: $(S0+)
2961

3062
# GCC could create temporary objects files, but separate recipes for
3163
# .o objects give faster build cycles when debugging.
32-
33-
$(S0+): LDLIBS += -ledit
34-
35-
$(S1+): hashmap.o linked_list.o printer.o reader.o types.o
36-
$(S1+): LDLIBS += -lgc
37-
64+
$(S0+): readline.o
65+
$(S1+): error.o hashmap.o linked_list.o printer.o reader.o types.o vector.o
3866
$(S3+): env.o
39-
40-
# ffi is only used by stepA, but we want the same core.o for all steps.
41-
# Anyway, the --as-needed linker option is active by default.
4267
$(S4+): core.o
43-
$(S4+): LDLIBS += -ldl -lffi
44-
core.o: CPPFLAGS += -DWITH_FFI
4568

4669
include deps
4770
deps:
48-
gcc -MM -MF- *.c > $@
71+
$(CC) -MM -MF- *.c > $@
4972

5073
clean:
5174
rm -f $(S0+) *.o deps

0 commit comments

Comments
 (0)