Announcement

Collapse
No announcement yet.

A pre-processor compiler statement for PB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A pre-processor compiler statement for PB

    Hey guys,
    I know feature suggestions are supposed to go to [email protected], but I'd like some input/ideas on this first, because I don't have a particular model I can propose as an example.

    I think it would add a whole new dimension to PB if support for a pre-processor/pre-compiler was introduced. (A program that can modify the source code before compilation, and restore it afterwards, leaving it untouched)

    If you don't know what I mean, it's basically this ...
    Instead of compiling say hello.bas to hello.exe when you go to Compile the program, a pre-processor is invoked, and allowed to make whatever modifications to the source file it likes. Hello.bas can be modified in any way the pre-compiler likes, before allowing the compiler to do its job.

    However, you obviously want to leave the original source code alone and just compile the modified code, and (probably?) deleting the modified code after compilation.

    There are so many things that could be made possible by this, from such simple things as embedding Copyright information into various functions, to encoding strings, and so on - the list really is ENDLESS, which is why I think it would be a great addition to the PB compiler - it opens up a whole new dimension.

    I have a few ideas about it, but there are several ways to approach this so I'd love to hear others perspectives/ideas.

    To me it seems like this would be very easy for Bob/PB staff to add to the compiler, but there are so many ways that they could go about it and I know that nothing less than the best will do.

    Many thanks
    -

  • #2
    I think some of the third-party IDEs already do just this.

    It might be nice to have direct support for that in the PB/IDE for us "normal" users; that is, when you hit "Compile" you would, instead of invoking "pbwin.exe," you launch some other program, or even a command file (*.cmd), which at some point itself invokes "pbwin.exe"

    When I think of "pre-compiler" I think of esql precompliers, which convert special syntax into CALL statements, e.g.,
    Code:
       EXEC SQL 
            Select column from table where condition into variable 
       END-EXEC
    .. which is translated into something like ....
    Code:
     
      ' comment out original source code
      ' EXEC SQL 
      '      Select column from table where condition into variable 
      ' END-EXEC 
      ' replace with the actual function to be called
       CALL functionname (some set of parameters)
    ... and then the actual compiler is invoked.

    As far as modifying version info, well, that is generally changed only once per "cycle" so it would not save much. Modifying a resource itself so it can be linked, well, that's a little more work, but no reason a special program could not compile that from a directed IDE ; instead of calling rc.exe then pbres.exe, it does "some other things" during the process as well.


    MCM
    Last edited by Michael Mattias; 11 Aug 2008, 08:17 AM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      José's SED has built in embedded resource compile/add along with exe shell facilities .

      James

      Comment


      • #4
        Its not hard to write a shell which wraps a collection of tools including an editor, pre-compiler and compiler.

        Comment


        • #5
          Originally posted by Chris Holbrook View Post
          Its not hard to write a shell which wraps a collection of tools including an editor, pre-compiler and compiler.
          Ok, so please show me an easy path to wrap up PB if it's as easy as you describe ...

          I have no desire to create a program to hook into the PB IDE or compiler. Renaming the PB compiler executables to something else and replacing them with executables of my own that "pass onto them" is possibly an option, but even if it'd work it wouldn't be very pretty.

          Basically I'm not interested in hack options, because this is a legitimate feature that could easily be incorporated into PB.

          A pre-processor option built into the compiler itself would provide a neat, elegant and powerful way to modify source code before compilation.

          That would add a WHOLE NEW DIMENSION to PowerBasic source code, and I think it would be very easy to incorporate into PB.

          At this very moment there are no real options for that besides messing around with the PB compiler, which I wouldnt ever want to do unless it was my last option, but seeing as there are no pre-compiler options I have had to make my own "manual adjustments" in the past
          -

          Comment


          • #6
            Originally posted by Wayne Diamond View Post
            ...even if it'd work it wouldn't be very pretty...Basically I'm not interested in hack options...
            clearly not a job for myself...

            Comment


            • #7
              Elaborate please?
              I hope I didn't mean any offense :-/
              Last edited by Wayne Diamond; 11 Aug 2008, 10:03 AM.
              -

              Comment


              • #8
                Ok, so please show me an easy path to wrap up PB if it's as easy as you describe
                Code:
                REM CompileMe.cmd
                Start /W myPrecompilerProgram.exe %1 ~sourcefile
                Start pbwin  ~sourcefile /Options
                REM en of file
                ....
                
                C:\DOS> Compileme mysourcecode.bas
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Yes ... I could also use Notepad to modify the source beforehand, but thats not quite what I had in mind in regards to a pre-processor...
                  -

                  Comment


                  • #10
                    Last one I did looked like this, it's very simple but enabled me to produce a lot of PB Forms code for SQLite table maintenance programs very quickly. Generate ran the pre-processor, which in this case dug out all the columns from a DB table and made a List View control for the whole table, plus a static control for each column item. Having generated the PB Forms application, the app called PBFORMS for the user to tidy up the results. Next step would be Compile, with compiler output shown in the listbox, and you could Run it from here, too, and also call up the PB IDE in a new window. The results were stored in a project directory tree.
                    Attached Files

                    Comment


                    • #11
                      My PB-UltraEdit "bridging" program (http://www.laurencejackson.com/pbshell2/) has pre and post processing capabilities, implemented like this, for example:

                      %BUILD_NUMBER = 1000 '#PRECOM INCBUILD PROGNAME.BAS

                      The preprocessor (within PBShell) scans the source code for the special comment '#PRECOM. It then interprets the word that follows as the name of the program to be invoked (in this example "INCBUILD") and anything following as command line parameters (in this example, "PROGNAME.BAS").

                      The program INCBUILD simply scans the specified source file for a BUILD-NUMBER equate assignment and, if found, increments the value.

                      If I were doing this one function from scratch, for use from the PB IDE, I guess I would rename PBWIN.EXE to something else, and name a modified INCBUILD.EXE as PBWIN.EXE. The necessary modifications would be to pick up the source file spec from the command line passed by the IDE then, after source processing, SHELL to the renamed PBWIN.EXE with the original parameters. Of course, then you wouldn't need all the '#PRECOM ... stuff. The same program could do post processing if required as PBWIN would return to it after execution.

                      As others have said, you don't really need compiler support for this, just some creative renaming.
                      - LJ

                      Comment


                      • #12
                        >As others have said, you don't really need compiler support for this, just some creative renaming

                        True, but I think it would be a lot easier to use (and far less prone to making "the big mistake") if there were some kind of thing in the IDE options for ...
                        Code:
                          Run on compile of BASIC source code [ myprogram.exe]   << default = PBWIN.EXE
                          Run on compile of resource files        [  myotherprogram] << default = RC.EXE + PBRES.EXE
                        Something like that anyway.


                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          hmmm, I think what Wayne is really after here, is a 2 pass compiler.

                          given the following example, currently I have to pre-define the type of data that I am after, (hence the displaying multiple dialogs), if we had a 2 pass compiler that allowed us to program our 1st pass structuring so2speak, I could have simply used a "ShowVar" for any type. (IIRC, in the old days we called this first pass routines "Macros")




                          Code:
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          'SHOWVARS.INC
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          'here is a handy little include file which will allow you to easily view
                          'a string, Single precision Float, or a Long Integer value during runtime,
                          'can be very helpful while debugging or designing.
                          'syntax:
                          'ShowVar "label", var
                          'ShowStr "label", string var
                          'ShowFlt "label", var
                          '(see following test.bas file for use)
                          'also should mention that the "label" label portion can be anything, and the
                          'routine checks for and updates on simalar labels so if you wish to check 
                          'the same variable before and after something you can just: as example; 
                          'ShowVar "before xxx", varA 
                          'do something
                          'ShowVar "after xxx", varA 
                          'do what-ever you wish with the code... Public Domain, by Brad Byrne 2004
                          '
                          GLOBAL hVDsp&,hSDsp&,hFDsp&
                          
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          FUNCTION ShowStr(Var_label$, Var_string$ )AS STRING
                             STATIC ControlCount&
                             LOCAL i&,CntrlText$,NewLbl$,MatchLbl&,yy&
                             MatchLbl&=0: yy&=ControlCount&*10+22
                             IF  ControlCount& = 0 THEN
                          
                              DIALOG NEW 0, "SHOW STRINGS DISPLAY",0,0,0,0,%ws_border , TO hSDsp&
                              CONTROL ADD FRAME ,hSDsp&,1000,"Strings",2,1,130,yy&, %ss_sunken,
                              SetWindowPos  hSDsp&, %HWND_TOPMOST,400,50, 137, yy&+4,0
                              DIALOG SHOW MODELESS hSDsp&,
                             END IF
                          
                                 NewLbl$=Var_label$+"   :"
                                  FOR i&= 1 TO ControlCount&+1
                                    CONTROL GET TEXT hSDsp&,(1100+i&) TO CntrlText$
                                       IF CntrlText$= NewLbl$ THEN
                          
                                           CONTROL SET TEXT hSDsp&,(1200+i&),Var_string$
                                           MatchLbl&=1
                                           EXIT FOR
                                       END IF
                                  NEXT i&
                                  IF MatchLbl&=0   THEN
                          
                                           DIALOG SET SIZE hSDsp&,137,yy&+18
                                           CONTROL SET SIZE hSDsp&,1000,130,yy&
                                           CONTROL ADD LABEL ,hSDsp&,(1100+i&),NewLbl$,4,i&*10-10,60,10,%SS_RIGHT,
                                           CONTROL ADD LABEL ,hSDsp&,(1200+i&),Var_string$,70,i&*10-10,60,10,,
                                           INCR ControlCount&
                                  END IF
                          
                                SendMessage hSDsp&,%wm_paint,0,0
                          END FUNCTION
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          FUNCTION ShowVar(Var_label$, Var_value& ) AS LONG
                             STATIC ControlCount&
                             LOCAL i&,CntrlText$,NewLbl$,MatchLbl&,yy&
                             MatchLbl&=0: yy&=ControlCount&*10+22
                             IF  ControlCount& = 0 THEN
                          
                              DIALOG NEW 0, "SHOW VARIABLES DISPLAY",0,0,0,0,%ws_border , TO hVDsp&
                              CONTROL ADD FRAME ,hVDsp&,1000,"Variables",2,1,130,yy&, %ss_sunken,
                              SetWindowPos  hVDsp&, %HWND_TOPMOST,450,100, 137, yy&+4,0
                              DIALOG SHOW MODELESS hVDsp&,
                             END IF
                          
                                 NewLbl$=Var_label$+"   :"
                                  FOR i&= 1 TO ControlCount&+1
                                    CONTROL GET TEXT hVDsp&,(1100+i&) TO CntrlText$
                                       IF CntrlText$= NewLbl$ THEN
                          
                                           CONTROL SET TEXT hVDsp&,(1200+i&),STR$(Var_value&)
                                           MatchLbl&=1
                                           EXIT FOR
                                       END IF
                                  NEXT i&
                                  IF MatchLbl&=0   THEN
                          
                                           DIALOG SET SIZE hVDsp&,137,yy&+18
                                           CONTROL SET SIZE hVDsp&,1000,130,yy&
                                           CONTROL ADD LABEL ,hVDsp&,(1100+i&),NewLbl$,4,i&*10-10,60,10,%SS_RIGHT,
                                           CONTROL ADD LABEL ,hVDsp&,(1200+i&),STR$(Var_value&),70,i&*10-10,60,10,,
                                           INCR ControlCount&
                                  END IF
                          
                                SendMessage hVDsp&,%wm_paint,0,0
                          END FUNCTION
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          FUNCTION ShowFlt(Var_label$, Var_value! ) AS LONG
                             STATIC ControlCount&
                             LOCAL i&,CntrlText$,NewLbl$,MatchLbl&,yy&
                             MatchLbl&=0: yy&=ControlCount&*10+22
                             IF  ControlCount& = 0 THEN
                          
                              DIALOG NEW 0, "SHOW FLOATS DISPLAY",0,0,0,0,%ws_border , TO hFDsp&
                              CONTROL ADD FRAME ,hFDsp&,1000,"Single Floats",2,1,130,yy&, %ss_sunken,
                              SetWindowPos  hFDsp&, %HWND_TOPMOST,500,150, 137, yy&+4,0
                              DIALOG SHOW MODELESS hFDsp&, 'CALL Var_Dspl()
                          
                             END IF
                                 NewLbl$=Var_label$+"   :"
                                  FOR i&= 1 TO ControlCount&+1
                                    CONTROL GET TEXT hFDsp&,(1100+i&) TO CntrlText$
                                       IF CntrlText$= NewLbl$ THEN
                          
                                           CONTROL SET TEXT hFDsp&,(1200+i&),STR$(Var_value!)
                                           MatchLbl&=1
                                           EXIT FOR
                                       END IF
                          
                                  NEXT i&
                                  IF MatchLbl&=0   THEN
                                           DIALOG SET SIZE hFDsp&,137,yy&+18
                                           CONTROL SET SIZE hFDsp&,1000,130,yy&
                                           CONTROL ADD LABEL ,hFDsp&,(1100+i&),NewLbl$,4,i&*10-10,60,10,%SS_RIGHT,
                                           CONTROL ADD LABEL ,hFDsp&,(1200+i&),STR$(Var_value!),70,i&*10-10,60,10,,
                          
                                           INCR ControlCount&
                                  END IF
                                SendMessage hFDsp&,%wm_paint,0,0
                          END FUNCTION
                          
                          
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          'test.bas
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          'a little test program to show how to use "SHOWVARS.INC"
                          
                          #COMPILE EXE
                          #INCLUDE "WIN32API.INC"
                          #INCLUDE "SHOWVARS.INC"
                          
                          GLOBAL hDlg&, Var1 AS SINGLE , txt$
                          
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          CALLBACK FUNCTION CallBackFunc()
                          SELECT CASE CBMSG
                              CASE %WM_COMMAND
                                SELECT CASE CBCTL
                                   CASE 100
                                      CONTROL GET TEXT hDlg, 100 TO txt
                                      ShowStr "my text",txt
                                   CASE 200
                           	    ShowFlt "Var1", Var1
                                      IF CBCTLMSG = %BN_CLICKED THEN
                          
                                      Var1 = Var1 * 2.2
                                      ShowFlt "Var2", Var1
                                      END IF
                                  END SELECT
                                  CASE %WM_DESTROY
                                      PostQuitMessage 0
                                  FUNCTION = %TRUE
                          
                              END SELECT
                          END FUNCTION
                          
                          
                          FUNCTION PBMAIN
                              LOCAL Msg AS tagmsg
                              Var1 = 1.234567
                              DIALOG NEW 0, "ShowVarTest",50,50,130,120, %ws_overlappedwindow, TO hDlg
                              CONTROL ADD BUTTON ,hDlg,200,"Incr Float",30,20,70,30,%BS_FLAT
                              CONTROL ADD TEXTBOX ,hDlg,100,"Change this",30,55,70,40, , %WS_EX_STATICEDGE
                              DIALOG SHOW MODELESS hDlg, CALL CallBackFunc()
                            WHILE GetMessage(Msg,%NULL, 0, 0)
                                 ShowVar "Msg.hwnd",Msg.hwnd
                                 ShowVar "Msg.message",Msg.message
                                 ShowVar "Msg.wparam",Msg.wparam
                                 ShowVar "Msg.lparam",Msg.lparam
                                 ShowVar "Msg.time",Msg.time
                                 ShowVar "Msg.pt",Msg.pt.x
                              TranslateMessage Msg
                              DispatchMessage Msg
                            WEND
                          
                          END FUNCTION

                          Comment


                          • #14
                            I think the most easy way would be, you download the complete SED-Source from Jose, and include it there.

                            if it works fine, sent it back to Jose to make it official.

                            I have alread built a Past-Processor into SED some time ago, don't know if its still in there. A Preprocessor is actually not yet supported.

                            Anyway I'd support such a possibility, and i have always asked for something like that.

                            Comment


                            • #15
                              Working on ...

                              Hi Wayne,

                              BTW, I'm working on my own SQL preprocessor based on SQL Tools from PerfectSync called mSQL (Macro SQL)

                              Syntax is similar as Michael suggested above.

                              Here is the mSQL syntax, but it's in alpha stage like project itself.
                              Code:
                              LOCAL errTxt AS STRING, rsCount AS LONG, hListViewCtl AS LONG
                              LOCAL res() AS STRING
                              
                              CONTROL HANDLE CBHNDL, %LVC_RESULT TO hListViewCtl 
                              
                               ~MSQL CONNECT "DSN=mybase"
                               ~MSQL PREPARE RESULT TO ARRAY res COUNT rsCount
                               ~MSQL PREPARE ERROR  TO errTxt
                               ~MSQL EXEC SELECT Customer FROM SalesPerson WHERE PostIndex = "AZ012"
                              
                               ~MSQL FEED RESULT TO LISTVIEW hListViewCtl
                              or

                              Code:
                              LOCAL errTxt AS STRING, rsCount AS LONG, hListViewCtl AS LONG
                              LOCAL res() AS STRING
                              
                              CONTROL HANDLE CBHNDL, %LVC_RESULT TO hListViewCtl 
                              
                               ~MSQL-BEGIN
                                     CONNECT "DSN=mybase"
                                     PREPARE RESULT TO ARRAY res COUNT rsCount
                                     PREPARE ERROR  TO errTxt
                                     EXEC SELECT Customer FROM SalesPerson WHERE PostIndex = "AZ012"
                                     FEED RESULT TO LISTVIEW hListViewCtl
                               ~MSQL-END

                              Comment


                              • #16
                                Laurence --

                                > the special comment '#PRECOM.

                                I too use UltraEdit and a home-grown preprocessor. For what it's worth, instead of comments (which IMO should never affect compilation) I prefer to use the #UTILITY metastatement. It was added to PB a couple of versions ago for exactly that purpose.

                                -- Eric
                                "Not my circus, not my monkeys."

                                Comment


                                • #17
                                  Originally posted by Eric Pearson View Post
                                  I prefer to use the #UTILITY metastatement. It was added to PB a couple of versions ago for exactly that purpose.
                                  ? I've just been reading about that as new for version 9!
                                  - LJ

                                  Comment


                                  • #18
                                    Oops, my bad! I have been a PB beta tester since the early days of PB/DOS, and whenever possible I use the beta compilers in my daily work (for everything except modules that are distributed to others). I have been using #UTILITY for what seems like a long time now, and I thought that it had been added in the last version.

                                    Next you're going to tell me that ARRAY SORT USING is brand new! I don't know how I ever got along without it!

                                    -- Eric
                                    "Not my circus, not my monkeys."

                                    Comment


                                    • #19
                                      I have to find the complete "what's new" document. If the help file is now on line it must be here somewhere.

                                      It's starting to sound like all my NFSs for the past six years have been adopted.

                                      (I sure hope I find #FORWARD REFERENCE ON and #UNDEF and #ERROR OVERFLOW ON and..... )

                                      MCM
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Michael
                                        To sort of quote you RTFP (P for Bob's posts) The full manual has been on line for some time and yes forward referencing is now standard.:applaus:
                                        John

                                        Comment

                                        Working...
                                        X