@MAINFILE preprocessor command

Feature requests for future versions of Hollywood can be voiced here
plouf
Posts: 109
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: @MAINFILE preprocessor command

Post by plouf »

airsoftsoftwair wrote:
Sun May 10, 2020 11:46 am

Yes, definitely. I understand plouf's proposal now but this is tricky to implement because obviously the main file has to be parsed first but if there was something like @MAINFILE, the parser would have to stop parsing the current file and then restart parsing in the main file etc.
i dont know the exact way of hollywood parser works, but i had the feeling of something very simple like

(pseudocode)
if found @MAINFILE
run("parser.exe %sameargs -nomainfile")
die()
Sounds like a lot of work for little gain so it's probably not worth the hassle. Maybe just use an IDE that has project/workspace management like Clydos' extension for VS Code :)
i am the only one working with includes and include files are topic based ?
i run the problem almost every time, had to click mainfile then F5
additional when program fail, ide open itself the "problematic" file1.hws, i fix it then click back main.hsx f5 and so on

do you do something better/more optimal !? (excluding the fact that you are writing ALWAYS proper code ;))

SamuraiCrow
Posts: 303
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: @MAINFILE preprocessor command

Post by SamuraiCrow »

I'd suggest putting unit tests in the same directory as the includes but in order to make the final code independent of the unit tests, put them outside the include directory and put the build options in a shell script called run.sh on Linux or Mac, run.bat on Windows, and simply name it run on the Amiga-like OS's and set the script bit.

If you need the include directory defined in the run script, define it as a string constant from the build options on the command line and append the include .hws filenames in the "require" directives using string concatination. Finally, use an "error" directive to block running if the include path constant is undefined.

If needed, I can make an example.
I'm on registered MorphOS using FlowStudio.

plouf
Posts: 109
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: @MAINFILE preprocessor command

Post by plouf »

please explain

but i think you proposal do not help since
i usually just need to push F5 in "IDE" while changing any include

additional working with "alternative" editor (not special hs4vsc) compiling option tha they have (like build-run) they pass current source file as argument
so

SamuraiCrow
Posts: 303
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: @MAINFILE preprocessor command

Post by SamuraiCrow »

I'll do a small example of an included Hollywood framework:

Code: Select all

/*
 * include/world.hws
 */
Function p_Location$()
	Return("the world")
EndFunction

Function p_Greeting$()
	Return("Hello")
EndFunction
Here's the unit-test to test the libraries in the include directory

Code: Select all

/*
 * include/test.hws
 */
@INCLUDE "world.hws"

assert(p_Location$()="the world")
assert(p_Greeting$()="Hello")
DebugPrint("All tests passed")
And the application that uses the library

Code: Select all

/*
 * appdir/MyApp.hws
 */
@IF #INCPATH=0
@ERROR "Include path not found!"
@ENDIF
@INCLUDE #INCPATH.."world.hws"

NPrint(p_Greeting$().." world!")
NPrint(p_Greeting$().." from "..p_Location$())
End
And the command line that can be stored in the MyApp.ini file by the Hollywood GUI frontend:

Code: Select all

interpreter -setconstants "INCPATH=[path/to/include/]" MyApp.hws
The test.ini file that comes with the library has its command line set normally. If you want to edit world.hws then there is the problem of not knowing whether MyApp.hws or test.hws is the file you want it Included from. If the Hollywood GUI frontend supported having a default main in the .INI file, that would probably be more helpful than embedding it in the file itself. Then it could be set to the Unit test in test.hws since that's what the library came with.

Another option would be adding the test.hws file into world.hws as follows:

Code: Select all

@IF #INCPATH=0
... contents of test.hws, minus the include directive
@ENDIF
Then the absence of the #INCPATH constant would trigger the unit tests.
I'm on registered MorphOS using FlowStudio.

User avatar
airsoftsoftwair
Posts: 4199
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: @MAINFILE preprocessor command

Post by airsoftsoftwair »

Maybe I could add some "magic word" hack to the parser so that if the first line has some magic word comment like...

Code: Select all

;@MAINFILE foo.hws
...the parser would automatically skip to this file but of course it's a rather ugly hack. But something like this could be implemented rather quickly, although full workspace management would be nicer of course.

Post Reply