#cmdline "args..." directive

Forum for discussion about the documentation project.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: #cmdline "args..." directive

Post by fxm »

What should this do ?
#cmdline "-version"
I still can't see anything displayed (even with the last daily build) !
and even with a final:
#cmdline "-restart"
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: #cmdline "args..." directive

Post by SARG »

Text of the change :

Code: Select all

fbc: #cmdline - don't allow #cmdline "-version" option
and the changed line of code

Code: Select all

( FALSE, TRUE , FALSE, TRUE  ), _ '' OPT_VERSION      must restart fbc to get the version message
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: #cmdline "args..." directive

Post by coderJeff »

fxm wrote:What should this do ?
#cmdline "-version"
The line that prints the version is commented out. At the moment '-version' is allowed, but doesn't do anything other than trigger a restart.
Sorry fellas, I have made conflicting messages in the source / changelog.txt.

I am open to suggestions, here's some notes on my thoughts while developing:
I had started off with '-version' to be disallowed like '-print' and '-help'. Because in these 3 cases when used from shell command line, fbc shows information and then stops. So it doesn't make much sense to allow them in source code.

But, then I had this idea that when a user asks for help on the forum, it would be nice to be able to ask the user to add '#cmdline "-version -v"' ... or something like it to the top of their source and report the output. They could be running from from shell or any number of IDE's and this would be a common way to ask for extra information to help them.

The side effect is that various combinations of '-version' and '-v' on the shell command line and in source '#cmdline' cause duplicate and sometimes confusing information to be shown.

I will make one more change: '#cmdline "-version" will show the fbc version, but not stop compilation process.
Then will get some more feedback from users.

----

For debugging the build process the goal/idea started out something like the following if the shell command line had '-v' option:

$ fbc restart.bas -v

Code: Select all

#cmdline "-gen llvm -r"
#print "compiling source..."
OUTPUT:
FreeBASIC Compiler - Version 1.09.0 (2021-09-12), built for win32 (32bit)
Copyright (C) 2004-2021 The FreeBASIC development team.
standalone
target: win32, 486, 32bit
backend: gas
compiling: restart.bas -o restart.asm (main module)
compiling source...
Restarting fbc ...
target: win32, 486, 32bit
backend: llvm
compiling: restart.bas -o restart.ll
compiling source...
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: #cmdline "args..." directive

Post by coderJeff »

coderJeff wrote:
fxm wrote:What should this do ?
#cmdline "-version"
...
I will make one more change: '#cmdline "-version" will show the fbc version, but not stop compilation process.
Then will get some more feedback from users.
I pushed changed to 1.09.0 as follows:
* fbc: #cmdline print version information with #cmdline "-version"

- #cmdline "-version" will immediately print the fbc version information if it was not already printed.
- To get verbose version information '-v' option must appear before '-version'.
- fbc command line option '-v' option behaviour overrides #cmdline "-v"
Here are all the combinations:

Code: Select all

$ fbc                  
	- show help
	- and stop

$ fbc -help
	- show help
	- and stop           

$ fbc -v
	- show verbose help
	- and stop  

$ fbc -help -v
	- show verbose help
	- and stop  

$ fbc [source.bas] -version
	- show version
	- and stop

$ fbc [source.bas] -v -version
	- show verbose version
	- and stop

$ fbc source.bas
	- normal compile (i.e. show warnings / errors)

$ fbc source.bas -v
	- show version
	- show all build steps

$ fbc source.bas
#cmdline "-v"
	- show build steps, first module steps only shown on second pass

$ fbc source.bas
#cmdline "-version"
	- show version (once only)

$ fbc source.bas
#cmdline "-v -version"
	- show verbose version
	- show build steps, first module steps only shown on second pass

$ fbc source.bas -v
#cmdline "-v"
	- show version
	- show all build steps

$ fbc source.bas -v
#cmdline "-version"
	- show version
	- show all build steps

$ fbc source.bas -v
#cmdline "-v -version"
	- show version
	- show all build steps
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: #cmdline "args..." directive

Post by coderJeff »

#cmdline is changed in fbc 1.10.0 - but it's not working correctly yet.

The intent is that:
- Source code is read in from the start and comments and preprocessor directives are processed, #cmdline, #if, #include, #define, #macro, etc.
- As soon as parsing gets to the first non-preprocessor statement, the parser will automatically restart if required.

But it's currently restarting after first #cmdline (compile with '-v' command line option to see restart).

Code: Select all

#print 1
#cmdline "-exx"
#print 2
#cmdline "-target win64 -gen gas64"
#print 3

'' should automatically restart right here
dim x as integer
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: #cmdline "args..." directive

Post by coderJeff »

Latest changes in fbc/master:

fbc, if required, will restart before the first non-preprocessor statement. In some of my notes I write 'executable statement' which is not precise. I mean 'non-preprocessor'.

For example:

Code: Select all

#cmdline "-g"
#cmdline "-target win64"
#cmdline "-exx"

#print "last preprocessor statement - automatically restart here"
declare sub proc()
This does not solve every scenario and can still get some wonky results if not careful, for example, if running the 32-bit version of fbc, which defaults to 32-bit integers:

Code: Select all

#cmdline "-target win64"
#if( sizeof(integer) = 4 )
#print "hmm... that doesn't seem correct"
#endif
The above situation can be avoided by added a #cmdline "-end" to the source code to tell fbc where to stop processing #cmdline statements:

Code: Select all

#cmdline "-target win64"
#cmdline "-end"
#if( sizeof(integer) = 8 )
#print "yup, makes sense"
#endif
#cmdline should be more robust with latest changes. The fbc source code turned a bit ugly to manage the feature but I handled this easily by leaving a note in the project TODO file to revisit it another time.

I tried a number of tests combining multiple modules, command line options, #cmdline options, and seems to be working much better. I look forward to the bug reports. :)

For managing the compiler dialect:
In order of priority from lowest to highest where higher overrides lower:
  • default lang (fb)
  • -lang option
  • #cmdline "-lang"
  • #lang directive
  • #cmdline "-forcelang"
  • -forcelang
-lang, #cmdline "-lang", #cmdline "-forcelang", -forcelang affect all modules
#lang affects only the module in which it appears
(at least that is the intent)
Post Reply