PikaDebuger_Debuger.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "PikaVM.h"
  2. #include "dataStrs.h"
  3. extern PikaObj* __pikaMain;
  4. static enum shell_state __obj_shellLineHandler_debug(PikaObj* self,
  5. char* input_line) {
  6. /* continue */
  7. if (strEqu("c", input_line)) {
  8. return SHELL_STATE_EXIT;
  9. }
  10. /* next */
  11. if (strEqu("n", input_line)) {
  12. return SHELL_STATE_EXIT;
  13. }
  14. /* launch shell */
  15. if (strEqu("sh", input_line)) {
  16. /* exit pika shell */
  17. pikaScriptShell(__pikaMain);
  18. return SHELL_STATE_CONTINUE;
  19. }
  20. /* quit */
  21. if (strEqu("q", input_line)) {
  22. obj_setInt(self, "enable", 0);
  23. return SHELL_STATE_EXIT;
  24. }
  25. /* print */
  26. if (strIsStartWith(input_line, "p ")) {
  27. char* path = input_line + 2;
  28. Arg* asm_buff = arg_newStr("B0\n1 REF ");
  29. asm_buff = arg_strAppend(asm_buff, path);
  30. asm_buff = arg_strAppend(asm_buff, "\n0 RUN print\n");
  31. pikaVM_runAsm(__pikaMain, arg_getStr(asm_buff));
  32. arg_deinit(asm_buff);
  33. return SHELL_STATE_CONTINUE;
  34. }
  35. obj_run(__pikaMain, input_line);
  36. return SHELL_STATE_CONTINUE;
  37. }
  38. void PikaDebug_Debuger___init__(PikaObj* self) {
  39. /* global enable contral */
  40. obj_setInt(self, "enable", 1);
  41. }
  42. void PikaDebug_Debuger_set_trace(PikaObj* self) {
  43. if (!obj_getInt(self, "enable")) {
  44. return;
  45. }
  46. struct shell_config cfg = {
  47. .prefix = "(pika-debug) ",
  48. };
  49. obj_shellLineProcess(self, __obj_shellLineHandler_debug, &cfg);
  50. }