Repository navigation
Expand file tree
/
Copy pathblomctl
More file actions
executable file
·223 lines (186 loc) · 5.24 KB
/
Copy pathblomctl
File metadata and controls
executable file
·223 lines (186 loc) · 5.24 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/sh
# colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;36m'
NC='\033[0m' # no color
USE_COLORS=true
for arg in "$@"; do
if [ "$arg" = "--no-colors" ] || [ "$arg" = "-no-colors" ]; then
USE_COLORS=false
set -- $(echo "$@" | sed "s/--no-colors\|-no-colors//g")
break
fi
done
if [ "$USE_COLORS" = false ]; then
RED=''
GREEN=''
YELLOW=''
BLUE=''
NC=''
fi
# check if moon is installed
MOON_PATH=$(which moon 2>/dev/null)
if [ -z "$MOON_PATH" ]; then
echo "${RED}'moon' command not found. Please install 'moon' by following the instructions at: https://moonrepo.dev/docs/install${NC}"
exit 1
fi
# default output directory
BUILD_DIR="toolchain/test/build"
mkdir -p "$BUILD_DIR" 2>/dev/null
show_help() {
echo "${BLUE}Blom Development Tool${NC}"
echo ""
echo "Usage: $0 [command] [options]"
echo ""
echo "${GREEN}Commands:${NC}"
echo " build Build the toolchain"
echo " test Run all tests"
echo " compile <file> Compile a .blom file using blomc"
echo " run <file> Run a .blom file using the interpreter"
echo " ray <file> Analyze tokens in a .blom file using blomray"
echo " sight <file> Visualize AST for a .blom file using blomsight"
echo " prism <symbol> Demangle a symbol using blomprism"
echo " moon <task> Run a specific moon task"
echo " clean Clean build artifacts"
echo ""
echo "${GREEN}Options:${NC}"
echo " -o, --output <file> Specify output file (for compile/js/py)"
echo " --no-colors Disable colored output"
echo " -h, --help Show this help message"
echo ""
echo "${YELLOW}Examples:${NC}"
echo " $0 compile toolchain/test/test.blom -o test"
echo " $0 run toolchain/test/test.blom"
echo " $0 ray toolchain/test/test.blom"
echo " $0 prism _Z3addii_Ri"
echo ""
}
run_cmd() {
echo "${BLUE}> $*${NC}"
$@
return $?
}
find_output_arg() {
output=""
i=1
while [ $i -le $# ]; do
eval arg=\${$i}
next=$((i+1))
eval next_arg=\${$next}
if [ "$arg" = "-o" ] || [ "$arg" = "--output" ]; then
if [ ! -z "$next_arg" ] && [ ! $(echo "$next_arg" | grep -E "^-") ]; then
output=$next_arg
# remove these args
eval "set -- $(echo $@ | sed "s/${arg} ${next_arg}//")"
break
fi
fi
i=$((i+1))
done
echo "$output"
}
# no args
if [ $# -eq 0 ]; then
show_help
exit 0
fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
show_help
exit 0
fi
COMMAND=$1
shift
case "$COMMAND" in
build)
run_cmd moon run :build
;;
test)
run_cmd moon run :test
;;
compile)
if [ $# -eq 0 ]; then
echo "${RED}Error: No file specified for compilation${NC}"
show_help
exit 1
fi
INPUT_FILE=$1
shift
OUTPUT=$(find_output_arg "$@")
if [ -z "$OUTPUT" ]; then
BASENAME=$(basename "$INPUT_FILE" .blom)
OUTPUT="$BUILD_DIR/$BASENAME"
fi
echo "${GREEN}Compiling$INPUT_FILE to $OUTPUT${NC}"
run_cmd go run toolchain/cmd/blomc/main.go "$INPUT_FILE" -o "$OUTPUT" "$@"
;;
run)
if [ $# -eq 0 ]; then
echo "${RED}Error: No file specified to run${NC}"
show_help
exit 1
fi
INPUT_FILE=$1
shift
echo "${GREEN}Running$INPUT_FILE with interpreter${NC}"
run_cmd go run toolchain/cmd/blom/main.go "$INPUT_FILE" "$@"
;;
ray)
if [ $# -eq 0 ]; then
echo "${RED}Error: No file specified for token analysis${NC}"
show_help
exit 1
fi
INPUT_FILE=$1
shift
echo "${GREEN}Analyzing tokens in$INPUT_FILE${NC}"
run_cmd go run toolchain/cmd/blomray/main.go "$INPUT_FILE" "$@"
;;
sight)
if [ $# -eq 0 ]; then
echo "${RED}Error: No file specified for AST visualization${NC}"
show_help
exit 1
fi
INPUT_FILE=$1
shift
echo "${GREEN}Visualizing AST for$INPUT_FILE${NC}"
run_cmd go run toolchain/cmd/blomsight/main.go "$INPUT_FILE" "$@"
;;
prism)
if [ $# -eq 0 ]; then
echo "${RED}Error: No symbol specified for demangling${NC}"
show_help
exit 1
fi
SYMBOL=$1
shift
echo "${GREEN}Demangling symbol$SYMBOL${NC}"
run_cmd go run toolchain/cmd/blomprism/main.go "$SYMBOL" "$@"
;;
moon)
TASK=$1
if [ -z "$TASK" ]; then
echo "${RED}Error: No moon task specified${NC}"
show_help
exit 1
fi
# handle task format
if [ -z "$(echo $TASK | grep ':')" ]; then
TASK=":$TASK"
fi
run_cmd moon run "$TASK" "${@:2}"
;;
clean)
echo "${GREEN}Cleaning build artifacts${NC}"
run_cmd rm -rf "$BUILD_DIR"/*
echo "Cleaned $BUILD_DIR"
;;
*)
echo "${RED}Unknown command: $COMMAND${NC}"
show_help
exit 1
;;
esac
exit $?