From 7b853bf9f24770badee2a5d689d2a0c25e3f8bb1 Mon Sep 17 00:00:00 2001 From: Fellippe Heitor Date: Sun, 11 Jul 2021 12:55:49 -0300 Subject: [PATCH] First attempt at implementing Step. --- internal/c/libqb.cpp | 1 - internal/c/qbx.cpp | 4 -- internal/c/vwatch.cpp | 6 --- source/qb64.bas | 95 ++++++++++++++++++++++++++++----- source/utilities/vwatch.bm | 43 +++++++++++++++ source/utilities/vwatch_stub.bm | 2 + 6 files changed, 127 insertions(+), 24 deletions(-) delete mode 100644 internal/c/vwatch.cpp create mode 100644 source/utilities/vwatch.bm create mode 100644 source/utilities/vwatch_stub.bm diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 271d3c6d1..ec6271f2b 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -291,7 +291,6 @@ extern "C" int QB64_Resizable(){ int32 sub_gl_called=0; extern void evnt(uint32 linenumber, uint32 inclinenumber = 0, const char* incfilename = NULL); -extern void vwatch(uint32 linenumber, uint32 inclinenumber = 0, const char* incfilename = NULL); extern "C" int qb64_custom_event(int event,int v1,int v2,int v3,int v4,int v5,int v6,int v7,int v8,void *p1,void *p2); #ifdef QB64_WINDOWS diff --git a/internal/c/qbx.cpp b/internal/c/qbx.cpp index 50b300824..af3f56735 100755 --- a/internal/c/qbx.cpp +++ b/internal/c/qbx.cpp @@ -2062,10 +2062,6 @@ void evnt(uint32 linenumber, uint32 inclinenumber = 0, const char* incfilename = } -#ifdef VWATCH - #include "vwatch.cpp" -#endif - uint8 *redim_preserve_cmem_buffer=(uint8*)malloc(65536);//used for temporary storage only (move to libqbx?) #include "myip.cpp" diff --git a/internal/c/vwatch.cpp b/internal/c/vwatch.cpp deleted file mode 100644 index 4b7d6be41..000000000 --- a/internal/c/vwatch.cpp +++ /dev/null @@ -1,6 +0,0 @@ -void vwatch(uint32 linenumber, uint32 inclinenumber = 0, const char* incfilename = NULL) { - if (console) { - std::cout << linenumber << std::endl; - } - return; -} \ No newline at end of file diff --git a/source/qb64.bas b/source/qb64.bas index 9c1df1461..b8569d81c 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -121,7 +121,7 @@ DIM SHARED viFileDescription$, viFileVersion$, viInternalName$ DIM SHARED viLegalCopyright$, viLegalTrademarks$, viOriginalFilename$ DIM SHARED viProductName$, viProductVersion$, viComments$, viWeb$ -DIM SHARED NoChecks, vWatch +DIM SHARED NoChecks, vWatch, addingvWatch DIM SHARED Console DIM SHARED ScreenHide @@ -1377,6 +1377,7 @@ layout = "" layoutok = 0 NoChecks = 0 vWatch = 0 +addingvWatch = 0 inclevel = 0 errorLineInInclude = 0 addmetainclude$ = "" @@ -1592,10 +1593,24 @@ DO ideprepass: prepassLastLine: + IF lastLine <> 0 OR firstLine <> 0 THEN + lineBackup$ = wholeline$ 'backup the real line (will be blank when lastline is set) + IF vWatch THEN + addingvWatch = 1 + IF lastLine <> 0 THEN forceIncludeFromRoot$ = "source\utilities\vwatch.bm" + ELSE + 'IF firstLine <> 0 THEN forceIncludeFromRoot$ = "source\embed\header_stub.bas" + IF lastLine <> 0 THEN forceIncludeFromRoot$ = "source\utilities\vwatch_stub.bm" + END IF + firstLine = 0: lastLine = 0 + GOTO forceInclude_prepass + forceIncludeCompleted_prepass: + addingvWatch = 0 + wholeline$ = lineBackup$ + END IF + wholestv$ = wholeline$ '### STEVE EDIT FOR CONST EXPANSION 10/11/2013 - - prepass = 1 layout = "" layoutok = 0 @@ -2600,11 +2615,24 @@ DO IF Debug THEN PRINT #9, "Pre-pass:INCLUDE$-ing file:'" + addmetainclude$ + "':On line"; linenumber a$ = addmetainclude$: addmetainclude$ = "" 'read/clear message + IF inclevel = 0 THEN + includingFromRoot = 0 + forceIncludingFile = 0 + forceInclude_prepass: + IF forceIncludeFromRoot$ <> "" THEN + a$ = forceIncludeFromRoot$ + forceIncludeFromRoot$ = "" + forceIncludingFile = 1 + includingFromRoot = 1 + END IF + END IF + IF inclevel = 100 THEN a$ = "Too many indwelling INCLUDE files": GOTO errmes '1. Verify file exists (location is either (a)relative to source file or (b)absolute) fh = 99 + inclevel + 1 firstTryMethod = 1 + IF includingFromRoot <> 0 AND inclevel = 0 THEN firstTryMethod = 2 FOR try = firstTryMethod TO 2 'if including file from root, do not attempt including from relative location IF try = 1 THEN IF inclevel = 0 THEN @@ -2666,6 +2694,10 @@ DO '3. Close & return control CLOSE #fh inclevel = inclevel - 1 + IF forceIncludingFile = 1 AND inclevel = 0 THEN + forceIncludingFile = 0 + GOTO forceIncludeCompleted_prepass + END IF LOOP '(end manager) @@ -2781,6 +2813,22 @@ DO includeline: mainpassLastLine: + IF lastLine <> 0 OR firstLine <> 0 THEN + lineBackup$ = a3$ 'backup the real first line (will be blank when lastline is set) + IF vWatch THEN + addingvWatch = 1 + IF lastLine <> 0 THEN forceIncludeFromRoot$ = "source\utilities\vwatch.bm" + ELSE + 'IF firstLine <> 0 THEN forceIncludeFromRoot$ = "source\embed\header_stub.bas" + IF lastLine <> 0 THEN forceIncludeFromRoot$ = "source\utilities\vwatch_stub.bm" + END IF + firstLine = 0: lastLine = 0 + GOTO forceInclude + forceIncludeCompleted: + addingvWatch = 0 + a3$ = lineBackup$ + END IF + prepass = 0 stringprocessinghappened = 0 @@ -3041,7 +3089,7 @@ DO IF a3u$ = "$CHECKING:OFF" THEN layout$ = SCase$("$Checking:Off") - IF vWatch THEN + IF vWatch = 1 AND addingvWatch = 0 THEN addWarning linenumber, inclevel, inclinenumber(inclevel), incname$(inclevel), "$DEBUG is disabled in $CHECKING:OFF blocks", "" END IF NoChecks = 1 @@ -5458,7 +5506,7 @@ DO IF stringprocessinghappened THEN e$ = cleanupstringprocessingcall$ + e$ + ")" IF (typ AND ISSTRING) THEN a$ = "WHILE ERROR! Cannot accept a STRING type.": GOTO errmes IF NoChecks = 0 AND vWatch = 1 THEN - PRINT #12, "vwatch(" + str2$(linenumber) + inclinenump$ + ");" + PRINT #12, "vwatch(" + str2$(linenumber) + ");" END IF PRINT #12, "while((" + e$ + ")||new_error){" ELSE @@ -5520,7 +5568,7 @@ DO ELSE controltype(controllevel) = 3 IF vWatch THEN - PRINT #12, "do{vwatch(" + str2$(linenumber) + inclinenump$ + ");" + PRINT #12, "do{vwatch(" + str2$(linenumber) + ");" ELSE PRINT #12, "do{" END IF @@ -5558,7 +5606,7 @@ DO PRINT #12, "dl_continue_" + str2$(controlid(controllevel)) + ":;" IF NoChecks = 0 AND vWatch = 1 THEN - PRINT #12, "vwatch(" + str2$(linenumber) + inclinenump$ + ");" + PRINT #12, "vwatch(" + str2$(linenumber) + ");" END IF IF controltype(controllevel) = 4 THEN @@ -5711,7 +5759,7 @@ DO IF Error_Happened THEN GOTO errmes IF NoChecks = 0 AND vWatch = 1 THEN - PRINT #12, "vwatch(" + str2$(linenumber) + inclinenump$ + ");" + PRINT #12, "vwatch(" + str2$(linenumber) + ");" END IF PRINT #12, "fornext_step" + u$ + "=" + e$ + ";" @@ -6344,7 +6392,7 @@ DO IF NoChecks = 0 THEN IF vWatch THEN - PRINT #12, "do{vwatch(" + str2$(linenumber) + inclinenump$ + ");" + PRINT #12, "do{vwatch(" + str2$(linenumber) + ");" ELSE PRINT #12, "do{" END IF @@ -10974,11 +11022,24 @@ DO a$ = addmetainclude$: addmetainclude$ = "" 'read/clear message + IF inclevel = 0 THEN + includingFromRoot = 0 + forceIncludingFile = 0 + forceInclude: + IF forceIncludeFromRoot$ <> "" THEN + a$ = forceIncludeFromRoot$ + forceIncludeFromRoot$ = "" + forceIncludingFile = 1 + includingFromRoot = 1 + END IF + END IF + IF inclevel = 100 THEN a$ = "Too many indwelling INCLUDE files": GOTO errmes '1. Verify file exists (location is either (a)relative to source file or (b)absolute) fh = 99 + inclevel + 1 firstTryMethod = 1 + IF includingFromRoot <> 0 AND inclevel = 0 THEN firstTryMethod = 2 FOR try = firstTryMethod TO 2 'if including file from root, do not attempt including from relative location IF try = 1 THEN IF inclevel = 0 THEN @@ -11035,6 +11096,10 @@ DO CLOSE #fh inclevel = inclevel - 1 IF inclevel = 0 THEN + IF forceIncludingFile = 1 THEN + forceIncludingFile = 0 + GOTO forceIncludeCompleted + END IF 'restore line formatting layoutok = layoutok_backup layout$ = layout_backup$ @@ -12236,9 +12301,9 @@ IF DEPENDENCY(DEPENDENCY_ZLIB) THEN END IF END IF -IF vWatch THEN - defines$ = defines$ + defines_header$ + "VWATCH" -END IF +'IF vWatch THEN +' defines$ = defines$ + defines_header$ + "VWATCH" +'END IF 'finalize libs$ and defines$ strings IF LEN(libs$) THEN libs$ = libs$ + " " @@ -13015,7 +13080,11 @@ errmes: 'set a$ to message IF Error_Happened THEN a$ = Error_Message: Error_Happened = 0 layout$ = "": layoutok = 0 'invalidate layout -IF inclevel > 0 THEN a$ = a$ + incerror$ +IF forceIncludingFile THEN 'If we're to the point where we're adding the automatic QB64 includes, we don't need to report the $INCLUDE information + IF INSTR(a$, "END SUB/FUNCTION before") THEN a$ = "SUB without END SUB" 'Just a simple rewrite of the error message to be less confusing for SUB/FUNCTIONs +ELSE 'We want to let the user know which module the error occurred in + IF inclevel > 0 THEN a$ = a$ + incerror$ +END IF IF idemode THEN ideerrorline = linenumber diff --git a/source/utilities/vwatch.bm b/source/utilities/vwatch.bm new file mode 100644 index 000000000..877af15a3 --- /dev/null +++ b/source/utilities/vwatch.bm @@ -0,0 +1,43 @@ +$CHECKING:OFF +SUB vwatch (linenumber AS LONG) + STATIC AS LONG ide, bypass + + IF bypass THEN EXIT SUB + + endc$ = "" + + IF ide = 0 THEN + ide = _OPENCLIENT("TCP/IP:9000:localhost") + IF ide = 0 THEN bypass = -1: EXIT SUB + + me$ = COMMAND$(0) + endc$ + PUT #ide, , me$ + + DO + GET #ide, , temp$ + buffer$ = buffer$ + temp$ + LOOP UNTIL INSTR(buffer$, endc$) > 0 + + buffer$ = LEFT$(buffer$, INSTR(buffer$, endc$) - 1) + IF buffer$ <> "vwatch:ok" THEN + CLOSE #ide + bypass = -1 + EXIT SUB + END IF + END IF + + DO + temp$ = "line number:" + MKL$(linenumber) + endc$ + PUT #ide, , temp$ + buffer$ = "" + DO + GET #ide, , temp$ + buffer$ = buffer$ + temp$ + LOOP UNTIL INSTR(buffer$, endc$) > 0 + + buffer$ = LEFT$(buffer$, INSTR(buffer$, endc$) - 1) + IF buffer$ = "run" THEN + EXIT SUB + END IF + LOOP +END SUB diff --git a/source/utilities/vwatch_stub.bm b/source/utilities/vwatch_stub.bm new file mode 100644 index 000000000..dead021cd --- /dev/null +++ b/source/utilities/vwatch_stub.bm @@ -0,0 +1,2 @@ +SUB vwatch +END SUB