comparison debug.c @ 2367:48cc69b4c358

Add some more builtin functions to debugger language
author Michael Pavone <pavone@retrodev.com>
date Thu, 09 Nov 2023 19:22:07 -0800
parents 1e36d8a2633c
children 1fe5afe263f3
comparison
equal deleted inserted replaced
2366:1e36d8a2633c 2367:48cc69b4c358
133 array->get = user_array_get; 133 array->get = user_array_get;
134 array->set = user_array_set; 134 array->set = user_array_set;
135 array->append = user_array_append; 135 array->append = user_array_append;
136 array->size = size; 136 array->size = size;
137 array->storage = size ? size : 4; 137 array->storage = size ? size : 4;
138 array->base = calloc(size, sizeof(debug_val));
138 debug_val ret; 139 debug_val ret;
139 ret.type = DBG_VAL_ARRAY; 140 ret.type = DBG_VAL_ARRAY;
140 ret.v.u32 = array - arrays; 141 ret.v.u32 = array - arrays;
141 return ret; 142 return ret;
142 } 143 }
202 .f32 = f 203 .f32 = f
203 } 204 }
204 }; 205 };
205 } 206 }
206 207
207 debug_val debug_sin(debug_val *args, int num_args) 208 static debug_val debug_sin(debug_val *args, int num_args)
208 { 209 {
209 float f; 210 float f;
210 if (!debug_cast_float(args[0], &f)) { 211 if (!debug_cast_float(args[0], &f)) {
211 return debug_float(0.0f); 212 return debug_float(0.0f);
212 } 213 }
213 return debug_float(sinf(f)); 214 return debug_float(sinf(f));
215 }
216
217 static debug_val debug_cos(debug_val *args, int num_args)
218 {
219 float f;
220 if (!debug_cast_float(args[0], &f)) {
221 return debug_float(0.0f);
222 }
223 return debug_float(cosf(f));
224 }
225
226 static debug_val debug_tan(debug_val *args, int num_args)
227 {
228 float f;
229 if (!debug_cast_float(args[0], &f)) {
230 return debug_float(0.0f);
231 }
232 return debug_float(tanf(f));
233 }
234
235 static debug_val debug_asin(debug_val *args, int num_args)
236 {
237 float f;
238 if (!debug_cast_float(args[0], &f)) {
239 return debug_float(0.0f);
240 }
241 return debug_float(asinf(f));
242 }
243
244 static debug_val debug_acos(debug_val *args, int num_args)
245 {
246 float f;
247 if (!debug_cast_float(args[0], &f)) {
248 return debug_float(0.0f);
249 }
250 return debug_float(acosf(f));
251 }
252
253 static debug_val debug_atan(debug_val *args, int num_args)
254 {
255 float f;
256 if (!debug_cast_float(args[0], &f)) {
257 return debug_float(0.0f);
258 }
259 return debug_float(atanf(f));
260 }
261
262 static debug_val debug_atan2(debug_val *args, int num_args)
263 {
264 float f, f2;
265 if (!debug_cast_float(args[0], &f)) {
266 return debug_float(0.0f);
267 }
268 if (!debug_cast_float(args[1], &f2)) {
269 return debug_float(0.0f);
270 }
271 return debug_float(atan2f(f, f2));
272 }
273
274 static debug_val array_pop(debug_val *args, int num_args)
275 {
276 debug_array *array = get_array(*args);
277 if (!array) {
278 return debug_int(0);
279 }
280 debug_val ret = array->get(array, array->size - 1);
281 if (array->append) {
282 array->size--;
283 }
284 return ret;
285 }
286
287 static debug_val debug_size(debug_val *args, int num_args)
288 {
289 debug_array *array = get_array(*args);
290 if (!array) {
291 //TODO: string support
292 return debug_int(0);
293 }
294 return debug_int(array->size);
214 } 295 }
215 296
216 static debug_root *roots; 297 static debug_root *roots;
217 static uint32_t num_roots, root_storage; 298 static uint32_t num_roots, root_storage;
218 299
230 } 311 }
231 debug_root *root = roots + num_roots++; 312 debug_root *root = roots + num_roots++;
232 memset(root, 0, sizeof(debug_root)); 313 memset(root, 0, sizeof(debug_root));
233 root->cpu_context = cpu; 314 root->cpu_context = cpu;
234 new_readonly_variable(root, "sin", new_native_func(debug_sin, 1, 1)); 315 new_readonly_variable(root, "sin", new_native_func(debug_sin, 1, 1));
316 new_readonly_variable(root, "cos", new_native_func(debug_cos, 1, 1));
317 new_readonly_variable(root, "tan", new_native_func(debug_tan, 1, 1));
318 new_readonly_variable(root, "asin", new_native_func(debug_asin, 1, 1));
319 new_readonly_variable(root, "acos", new_native_func(debug_acos, 1, 1));
320 new_readonly_variable(root, "atan", new_native_func(debug_atan, 1, 1));
321 new_readonly_variable(root, "atan2", new_native_func(debug_atan2, 2, 2));
322 new_readonly_variable(root, "pop", new_native_func(array_pop, 1, 1));
323 new_readonly_variable(root, "size", new_native_func(debug_size, 1, 1));
235 return root; 324 return root;
236 } 325 }
237 326
238 bp_def ** find_breakpoint(bp_def ** cur, uint32_t address, uint8_t type) 327 bp_def ** find_breakpoint(bp_def ** cur, uint32_t address, uint8_t type)
239 { 328 {
2697 if (array->storage < array->size) { 2786 if (array->storage < array->size) {
2698 array->storage = array->size; 2787 array->storage = array->size;
2699 array->base = realloc(array->base, sizeof(debug_val) * array->storage); 2788 array->base = realloc(array->base, sizeof(debug_val) * array->storage);
2700 } 2789 }
2701 } 2790 }
2702 for (uint32_t i = 1; i < cmd->num_args && i < array->size; i++) 2791 for (uint32_t i = 1; i < cmd->num_args && i <= array->size; i++)
2703 { 2792 {
2704 if (!eval_expr(root, cmd->args[i].parsed, &cmd->args[i].value)) { 2793 if (!eval_expr(root, cmd->args[i].parsed, &cmd->args[i].value)) {
2705 fprintf(stderr, "Failed to eval %s\n", cmd->args[i].raw); 2794 fprintf(stderr, "Failed to eval %s\n", cmd->args[i].raw);
2706 return 1; 2795 return 1;
2707 } 2796 }