forked from ManuelCPinto/mini-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (123 loc) · 3.75 KB
/
Copy pathMakefile
File metadata and controls
137 lines (123 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
.PHONY: all menu menu_loops menu_binary menu_unary menu_lists \
clean minipython.exe \
test_forloop \
test_whileloop \
test_arithmetic test_comparisons test_boolean \
test_unary \
test_indexing test_mutation test_range \
test_functions
TEST_DIR := tests
RESULTS_DIR := $(TEST_DIR)/results
all: menu
minipython.exe:
dune build minipython.exe
menu:
@echo
@echo "Select feature category to test:"
@echo " 1) Loops"
@echo " 2) Binary operations"
@echo " 3) Unary operations"
@echo " 4) Lists"
@echo " 5) Functions"
@echo " 0) Exit"
@echo
@read -p "Enter choice [0-5]: " cat; \
case $$cat in \
1) $(MAKE) menu_loops ;; \
2) $(MAKE) menu_binary ;; \
3) $(MAKE) test_unary ;; \
4) $(MAKE) menu_lists ;; \
5) $(MAKE) test_functions ;; \
0) echo "Goodbye!";; \
*) echo "Invalid choice"; $(MAKE) menu;; \
esac
# Submenu: Loops
menu_loops:
@echo
@echo "Loops:"
@echo " 1) For loop"
@echo " 2) While loop"
@echo " 0) Back"
@echo
@read -p "Enter choice [0-2]: " opt; \
case $$opt in \
1) $(MAKE) test_forloop ;; \
2) $(MAKE) test_whileloop ;; \
0) $(MAKE) menu ;; \
*) echo "Invalid choice"; $(MAKE) menu_loops;; \
esac
# Submenu: Binary operations
menu_binary:
@echo
@echo "Binary operations:"
@echo " 1) Arithmetic (+ - * // %)"
@echo " 2) Comparisons (== != < <= > >=)"
@echo " 3) Boolean logic (and or)"
@echo " 0) Back"
@echo
@read -p "Enter choice [0-3]: " opt; \
case $$opt in \
1) $(MAKE) test_arithmetic ;; \
2) $(MAKE) test_comparisons ;; \
3) $(MAKE) test_boolean ;; \
0) $(MAKE) menu ;; \
*) echo "Invalid choice"; $(MAKE) menu_binary;; \
esac
# Submenu: Unary operations
menu_unary:
@echo
@echo "Unary operations:"
@echo " 1) Unary negation (-e)"
@echo " 2) Logical not (not e)"
@echo " 0) Back"
@echo
@read -p "Enter choice [0-2]: " opt; \
case $$opt in \
1) $(MAKE) test_unary ;; \
2) $(MAKE) test_unary ;; \# same test covers both\n\
0) $(MAKE) menu ;; \
*) echo "Invalid choice"; $(MAKE) menu_unary;; \
esac
# Submenu: Lists
menu_lists:
@echo
@echo "List features:"
@echo " 1) Indexing e1[e2]"
@echo " 2) Mutation e1[e2] = e3"
@echo " 3) Range list(range(e))"
@echo " 0) Back"
@echo
@read -p "Enter choice [0-3]: " opt; \
case $$opt in \
1) $(MAKE) test_indexing ;; \
2) $(MAKE) test_mutation ;; \
3) $(MAKE) test_range ;; \
0) $(MAKE) menu ;; \
*) echo "Invalid choice"; $(MAKE) menu_lists;; \
esac
# Macro to run a given test script
define RUN_TEST
@mkdir -p $(RESULTS_DIR)
./minipython.exe --debug $(TEST_DIR)/$1.py
mv $(TEST_DIR)/$1.s $(RESULTS_DIR)/$1.s
@echo "========================================================"
@echo "You're on macOS. To run the assembly code (test.s), use:"
@echo "https://www.jdoodle.com/compile-assembler-gcc-online"
@echo "========================================================"
@if [ "$$(uname)" != "Darwin" ]; then \
gcc -no-pie -g $(RESULTS_DIR)/$1.s -o $(RESULTS_DIR)/$1 && $(RESULTS_DIR)/$1; \
fi
endef
# Individual test targets
test_forloop: minipython.exe ; $(call RUN_TEST,test_forloop)
test_whileloop: minipython.exe ; $(call RUN_TEST,test_whileloop)
test_arithmetic: minipython.exe ; $(call RUN_TEST,test_arithmetic)
test_comparisons: minipython.exe ; $(call RUN_TEST,test_comparisons)
test_boolean: minipython.exe ; $(call RUN_TEST,test_boolean)
test_unary: minipython.exe ; $(call RUN_TEST,test_unary)
test_indexing: minipython.exe ; $(call RUN_TEST,test_indexing)
test_mutation: minipython.exe ; $(call RUN_TEST,test_mutation)
test_range: minipython.exe ; $(call RUN_TEST,test_range)
test_functions: minipython.exe ; $(call RUN_TEST,test_functions)
clean:
dune clean