fspafford

Conditional compilation?

26 posts in this topic

How can I use a technique, like conditional compilation, that would allow me to use code that is dependent on the version of AutoIt? (Example, the changes to the Excel UDF in 3.3.12.)


Frank

Share this post


Link to post
Share on other sites



You can't, make more than one script if you really need to compile with different versions.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

This seems possible. You can have multiple versions of AutoIt in subfolders and use a processor to read the source for AutoIt version to use for compile. AutoIt3Wrapper may have directives to do this already. Looking into the Scite4AutoIt3 help file, I see directives "#AutoIt3Wrapper_Autoit3Dir=", "#AutoIt3Wrapper_Aut2exe=". Give those a try.

Share this post


Link to post
Share on other sites

Interesting idea probably you can do this indirectly with

#AutoIt3Wrapper_Run_Before="myPreprocessor.exe"

and then your myPreProcessor.exe should modify the actual source script before it gets compiled
 
http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/AutoIt3Wrapper.html
http://www.autoitscript.com/wiki/AutoIt3Wrapper_Directives
 
or override the compiler exe with your own exe which calls in the end the au3 compiler

#AutoIt3Wrapper_Aut2exe       Optionally override the Aut2exe.exe to use for this script
#AutoIt3Wrapper_AutoIt3         Optionally override the Autoit3.exe to use for this script

and looking at the au3wrapper.au3 source it should not be hard to add a simple step to add conditional compilation

#DEFINE <some_compilervar>=<somevalue>
#IF <some_compilervar> = <somevalue
#ENDIF

Maybe a nice wish for future

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hello !

I managed to do it, but in a very light way...

Available pre-processor operations : NAME (optional parameter1) (optional parameter2)

- #SET (<string varname>) (= <string value>)

- #IF (<string varname>) (= <string value>)

-#ELSE

-#FI

 

A piece of example :

ConsoleWrite("On... ")
#SET debugmode = False
_main()
ConsoleWrite("This way exit. ")
Exit

Func _main()
    #if debugmode = False
        For $i = 1 To 3
            ConsoleWrite("No ")
        Next

        MsgBox(0, "debugmode ?", False)
    #else

#       ConsoleWrite("Way. ")
#       MsgBox(0, "debugmode ?", True)
    #fi
EndFunc

No case sensitive mode: pre-processor operators will be forced up at read time in the wrapper.

Attached file is the wrapper modified source's code, with major changes in the Retrieve_PreProcessor_Info() function, and some new UDFs (_SelectOpt(), ConsoleWriteLine(), etc) in a dedicated #Region.

To use it, you have to compile it under a different name (e.g "AutoIt3Wrapper_NEW.exe") then rename manually as "AutoIt3Wrapper.exe" in your SciTE\AutoIt3Wrapper directory. This because of the original "AutoIt3Wrapper.exe" currently running at compilation time.

As far as #IF is concerned, the easier way to avoid execution of command lines I found was to add "# " in front of undesirable lines. If you think of a better way, tell me !

Note: the "=" operator is the only one available for #IF tests. Is adding more operators worth the effort ? How do you feel with these commands ?

 

Edited by Denver
AutoIt3Wrapper.au3 modified removed.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I fail to see why you used an 5 years old version of AutoIt3Wrapper and used that to implement this as that doesn't give you any real path forward.

Jos

 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I dont see why you consider the latest stable release is a "5 years version old" (even after the changes I made), can you explain me what lets you think that ?

 

A friend told me about the #AutoIt3Wrapper_Ren_Field yesterday evening, and showed me an example :

#AutoIt3Wrapper_Ren_Field=debugmode|YES
Global $debugmode = (FileGetVersion(@ScriptFullPath, "debugmode") = "YES")

ConsoleWrite("On... ")
_main()
ConsoleWrite("This way exit.")
Exit

Func _main()
    if $debugmode = False
        For $i = 1 To 3
            ConsoleWrite("No")
        Next
        MsgBox(0, "debugmode ?", False)
    else
        ConsoleWrite("Way.")
        MsgBox(0, "debugmode ?", True)
    EndIf
EndFunc

I feel he's right about using a proper way to avoid execution by the interpretor, but I can't remember why other languages have pre-processor operators...

Here, with those "# " prefix you may have conditonnal includes (whatever the reason for it), conditonnal #Autoi3Wrapper_ pre-processor operations, and so on. That can't be achieved by standard "Global $var / if $var then / else / endif" (after compilation) at execution time.

Maybe I'm wrong on this ?

Edited by Denver
Why is the quote code not colouring ? :(

Share this post


Link to post
Share on other sites

I dont see why you consider the latest stable release is a "5 years version old" (even after the changes I made), can you explain me what lets you think that ?

From the source you posted which tells me it is a very old version of AutoIt3Wrapper that is modified by you/somebody:

#AutoIt3Wrapper_Res_Fileversion=2.0.1.25
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2010 Jos van der Zande

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I didn't noticed this information. it *might* be because I begun to add things to my (very very old) installation of AutoIt, then was forced to update version because of the ternary "?:" operator not functionning.

I'll go for a more recent version later on today is gf's anniversary.

Why do you say "that doesn't give you any real path forward" ? Am I wrong in translating the "path forward" expression as "gain" ?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

You should not try to make your own version of AutoIt3Wrapper as that is modified and distributed by me on a regular basis.
When we feel we should have a pre-processor capability available in AutoIt3Wrapper, I should add an option to shell this external program like I have done for Au3Stripper by adding logic to AutoIt3Wrapper to read some preprocessors, in which you can define your pre-processor program file and the output file created.

EG:

#AutoIt3Wrapper_Run_PreProcess_Program=c:\mypreprocessor.exe
#AutoIt3Wrapper_Run_PreProcess_OutFile=%temp%\preproc.au3

AutoIt3Wrapper could then run this before the au3stripper step and also run au3check against the outputfile from the preprocessor to ensure now errors occur after the pre-process step. It will provide the processed input scriptfile as the first parameter.
In this way people can make their own pre-processor and maintain it independently from any modifications I make in AutoIt3Wrapper.

Thoughts?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As you refer to the Excel UDF:
In my eyes conditional compilation doesn't make sense here because too much has changed between UDF versions.
Simply create a new version of your script and change the function calls (and some lines of your script) to use the enhanced functionality/performance of the new UDF.
It's worth the effort ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Jos : using an external pre-processor could (totally !) fullfill the needs, but why don't you make instructions alike internally available by default for all AutoIt users ?

Btw, that makes it possible to have conditionnal pre-processor statements, enabling conditional compilation. I didn't start a new thread because of this one, but it's not an Excel UDF matter anymore...

Edited by Denver
(internally)

Share this post


Link to post
Share on other sites

@Denver, I am not sure I understand your proposal or I am lacking the imagination how this would ever work.
There are conditional preprocessor statements available already with the below but guess that isn't what you are asking?

Jos

; Optional
; Use this format to have separate directive values for Run and Compile
#AutoIt3Wrapper_If_Run
    #AutoIt3Wrapper_Run_AU3Check=Y
    #AutoIt3Wrapper_Run_Tidy=Y
    [...]
#Autoit3Wrapper_If_Compile
    #AutoIt3Wrapper_Run_AU3Check=N
    #AutoIt3Wrapper_Run_Tidy=N
    [...]
#AutoIt3Wrapper_EndIf

 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I missed those instructions, my bad. :)

How does it comes to non- "run" or "compile" part ? As, say, different includes for differents @OSversion ?

And is there a #set (or #define) MACRO string for replace in the code's corpse ?

Share this post


Link to post
Share on other sites

This is the way I have approached the whole setup of tooling till now and that maybe explains better why I proposed the have the option to run another pre-processor:

AutoIt3Wrapper has the sole purpose of running all tools you want to process before aut2exe like:

  • Au3Check
  • Tidy
  • Au3Stripper
  • any user program wanted

Then run aut2exe with the required parameters and the process any tasks after the creation of the script.exe like"

  • SVN - versioning commitment
  • PE Resources updates like Version etc.
  • any user program wanted like copying the program to another directory

So AutoIt3Wrapper is solely automating all the process steps but doesn't make any changes to the source other than updating the directive's version number.
The other utilities are doing all the source modifications, so hence my proposal to make an exit option for a pre-processor which act like au3stripper does, which takes the input file and creates and new output source file which then is take by AutoIt3Wrapper as the sourcefile to continue the process with.

Making sense here?

Jos
 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I made a lightened version of the Wrapper, containing only the preprocessor with minimal stuff possible to test it (up to date from the stable release available this 06/26/2015), and a simple copy-paste of Includes+Define #Regions.

First of all: there is a whole bunch of $variable modified in Wrapper's Global scope, how will this run in case of an external preprocessor ?

What should be the use of an (external) preprocessor: Would it be called before the Wrapper's internal one ? instead ? after ?

AutoIt3Preprocessor_light.au3

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I wont have much time in the comming week, but to me it is simple: you use a unique directive prefix like i do for tidy and au3stripper. Something like  #mypreprocessor_directive1

Autoit3wrapper ignores all directives with a different prefix.

jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hm, okay, let's say the chosen prefix is "#Cpp_", instructions now looks like:

  • #Cpp_Set (or #Cpp_define, I have to check it later)
  • #Cpp_If
  • #Cpp_Else
  • #Cpp_Fi (or #Cpp_ifend)

When it comes to reading the $ScriptFile_In by the preprocessor:

  1. Every # instructions have to be handled by the new preprocessor (referenced in the #AutoIt3Wrapper_Run_PreProcess_Program instruction set in the header of the Wrapper or sent by a commandLine argument), then the $ScriptFile_In is set to the #AutoIt3Wrapper_Run_PreProcess_OutFile and the next Wrapper's step occurs
    -or-
  2. Every new # instruction have to be handled by the new preprocessor (ref idem), then the $ScriptFile_In is changed and the internal Wrapper's preprocessor comes for the common # instruction, and next Wrapper's step occurs ?
    -or-
  3. Every common # instructions are internally handled by the Wrapper, then the new preprocessor is called to be in charge of the rest of # instructions, then the $ScriptFile_In is modified and next Wrapper's step occurs ?

1) is the heavier way to do this, but the most flexible way. The whole common # instructions have to be handled, and I don't know how the Global vars could be transferred (apart from serializing an object). 2) is the simplest way, but the file is read likely twice. 3) is the worst way, because there won't be any new preprocessor conditions available, and the file is read likely twice.

Share this post


Link to post
Share on other sites

If I were to make something like that I'd use

#define
#undef
#if
#ifdef
#ifndef
#else
#elif
#endif

# for "stringification"

But soon you'll have to handle real-world constructs:

#if (!defined(_UTF_8) && !defined(_UTF_16)) || defined(_UTF_NONE)

and

#define UNICODE_VERSION_MAJOR        5
#define UNICODE_VERSION_MINOR        1
#define UNICODE_VERSION_MICRO        0
#define UNICODE_VERSION_BUILD        10

#define __UNICODE_VERSION_STRING(a,b,c,d) #a "." #b "." #c "." #d
#define _UNICODE_VERSION_STRING(a,b,c,d)  __UNICODE_VERSION_STRING(a,b,c,d)
#define UNICODE_VERSION_STRING            _UNICODE_VERSION_STRING(UNICODE_VERSION_MAJOR,UNICODE_VERSION_MINOR,UNICODE_VERSION_MICRO,UNICODE_VERSION_BUILD)

 

1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I had it already prepared, so now have uploaded a new beta for autoit3wrapper to the Beta directory.
The preprocessor is ran after au3check and before au3stripper.

It will shell the defined preprocessorprogram with as; "your-preprocessor.exe" "current-prcessessed_script.au3" and either expect the outfile to be defined or else continue using the inputfile.

15.503.1200.5 Added a preprocessor exit with the following Directives:
#AutoIt3Wrapper_Run_PreProcess_Program=c:\mypreprocessor.exe
#AutoIt3Wrapper_Run_PreProcess_OutFile=%temp%\preproc.au3

Have a try and see how this works.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now