DIV ARENA FORUMS

DIV Compiler CLI

NoBrain2k - 18-3-2016 at 05:10 PM

Hi Guys,

I'm a big fan of Sublime Text and I was wondering what the possibility one day being able to set up DIV as a compiler and debugger that can be run from within Sublime.

Is that the sort of thing we can realistically hope for, or is it far too much work to get DIV working with other IDEs?

MikeDX - 18-3-2016 at 05:32 PM

This is indeed possible - in fact i already use this when exporting to multiple formats

you can pass -c to the ide - e.g.

Code:
./system/div-LINUX -c my.prg


and then to exec / debug

Code:
./system/divdbg-LINUX system/EXEC.EXE



NoBrain2k - 18-3-2016 at 05:52 PM

Quote: Originally posted by MikeDX  
This is indeed possible - in fact i already use this when exporting to multiple formats


Boom! Awesome, thanks Mike, I'll give that a go once the OSX version is ready :)

Casper - 18-10-2017 at 09:15 PM

Hi MikeDX! Long time no see :) Good to be back...

The executables you mentioned here, are they in a working state on windows? I managed to run the compiler just fine, but trying to execute nets me "[EXEC.EXE] cannot start or run due to incompatibility with 64-bit versions of Windows."

When I run the debugger with EXEC.EXE as it's parameter as per your post, it flashes a black window then closes.

Any ideas?

CicTec - 20-10-2017 at 09:52 AM

Hello Casper,

EXEC.EXE is generated by DIV environment and normally is executed by this, to have a standalone executable of your game's, create an installer version from from menu -> create installation...

The currently version is build for 32bits, but still works fine on 64bit system too.

Casper - 20-10-2017 at 01:10 PM

Hi CicTec,

Thanks for your response! It certainly does work to make the .exe via the menu!

What I'd like to do is compile and execute my program from the command line in windows. Is that possible? I tried the commands Mike provided, but as you can read in my post that didn't work out :(

CicTec - 20-10-2017 at 01:37 PM

I honestly did not try to compile / run DIV programs via console

Try the following commands...
To Compile:
Code:
system/div-WINDOWS -c my.prg


To Execute:
Code:
system/divdbg-WINDOWS system/EXEC.EXE


If running does not work, try to create an installation package and try to run the executable by calling it from the console.

Casper - 20-10-2017 at 02:03 PM

CicTec: those are are exactly the commands I have tried before.

The first one works fine I think... should I see any output?

The second one just flashes a black windows and closes instantly.

Making an installation package and running that executable works normally; either by double clicking EXE or from the command line.

Casper - 20-10-2017 at 02:11 PM

Here's the project I'm working on: https://github.com/cmvanb/faust2

You can see I wrote compile.bat and execute.bat to run the above commands, but if they don't work in the command line then those won't work either.

CicTec - 20-10-2017 at 03:50 PM

OK, I'm on Linux in these days, I will try when I back on windows.

CicTec - 20-10-2017 at 03:53 PM

Quote: Originally posted by Casper  
CicTec: those are are exactly the commands I have tried before.

The first one works fine I think... should I see any output?

The second one just flashes a black windows and closes instantly.

Making an installation package and running that executable works normally; either by double clicking EXE or from the command line.

Execution should have the same behavior as the installer version, but currently i can not try, surely should not shut immediately, probably fails in something.

MikeDX - 20-10-2017 at 08:56 PM

To call inline you need to be in the main div folder

It is of course possible the debug is broken

Casper - 20-10-2017 at 10:11 PM

@Mike: That does get me one step further, see screenshot:

https://i.imgur.com/jyvzYBY.png

edit for image formatting

[Edited on 2017-10-21 by Casper]

MikeDX - 21-10-2017 at 11:53 AM

That's interesting

To run it in that way, you need to have the assets in the "prg" folder (or in the folders DIV expects them to be traditionally)

In modern DIV, a file is saved at compile / debug time to tell DIV where to look for the original PRG assets.

if you write a file in div/system/exec.path with the path to your original prg (the assets folder essentially), everything should work.

You can see what this should be by running a program from within DIV itself and looking in the system folder at the "exec.path" file :)



[Edited on 21-10-2017 by MikeDX]

Casper - 21-10-2017 at 11:22 PM

Thanks Mike! That's the insight I needed.

I got the three commands (compile, copy over exec.path, run debugger on exec.exe) working in the terminal from the main DIV folder.

From there it was quite some wrestling with the batch file in the project folder to make it work, but it does the job now:

Code:
@echo off :: Set this to where DIV3 is installed. :: NOTE: The slash on the end is important. set "DIV_INSTALL_DIR=C:\Projects\DIV\div-beta-nightly\" :: Remember program directory. set "PROGRAM_DIR=%~dp0" :: Change to DIV directory and run compiler on .PRG file. cd %DIV_INSTALL_DIR% echo Compiling... call system\div-WINDOWS.exe -c %PROGRAM_DIR%faust2.prg :: Change to program directory and copy over exec.path. :: TODO: This batch script should automatically create and populate exec.path so you don't have to bother with configuring it. cd %PROGRAM_DIR% echo Copying exec.path... xcopy /y "%PROGRAM_DIR%exec.path" "%DIV_INSTALL_DIR%system\" :: Change to DIV directory and run debugger on the outputted executable. cd %DIV_INSTALL_DIR% echo Running executable in debug mode... call system\divdbg-WINDOWS.exe system\EXEC.EXE :: Change to program echo Finished running executable. cd %PROGRAM_DIR%


This compiles and runs the debugger on the resulting executable from my project folder outside of the main div folder. Quite happy with this!

MikeDX - 21-10-2017 at 11:35 PM

That's awesome. Nice work!

If we had some utilities to manage fpg files we could start building a new ide!

Actually, isnt your %PROGRAM_DIR variable what you need as the content for exec.path

So echo %PROGRAM_DIR > exec.path (or similar)

I don't know the syntax you require, as I'm more of a Linux man myself 😂

[Edited on 21-10-2017 by MikeDX]

Casper - 24-10-2017 at 08:48 PM

You're right that should be easily done! Good idea.

Something else related: Is there a way I can see the exact compiler error('unknown name', etc), including line number - like it is shown in DIV3? I'm running system/div-WINDOWS.exe -c path/name.prg and I see system/stdout.txt gets generated. With no mistake in the code the output looks good, but with a mistake the file looks like this:

Loaded zu bytes
Preparing compilation...
Preloading objects...
Compiling...
Error:

And that's it, it stopped writing after 'Error:' XD

Also, I saw stderr.txt generated before (probably from compiling inside DIV3), but no stderr.txt gets generated with the above command... I'm a little mystified :)

CicTec - 24-10-2017 at 09:51 PM

Currently no, however, the location of the error in the PRG opened in the environment is reported using internal variables that trace the line, the error number, etc..., it would simply be enough to add a printf line for writing these values variables in the stdout to get the info you need.

Stderror is only generated for fatal events such as crashes and other similar things.

Casper - 24-10-2017 at 10:12 PM

Ok, thanks for the info CicTec! If you can pinpoint what file I should look at in the DIV source code, I'm happy to have a stab at it, maybe making a PR on github :)

CicTec - 24-10-2017 at 10:30 PM

Is sufficient modify "div.c" in function "void c_error(word tipo, word e)", at the end of the function, before calling to comp_exit() adding a line like:
fprintf(stdout, "compilation error: row: %d, col: %d\n", linea, columna);

The problem is that the code in the github does not contain all the fixes I've made in the last update you are using since the merging was not done and then you would recompile an old version of DIV that was pretty unstable.

[Edited on 24-10-2017 by CicTec]

[Edited on 24-10-2017 by CicTec]

CicTec - 24-10-2017 at 10:36 PM

Another problem is that if you are building from windows will not work, Mike has brought the new DIV mainly from Linux, using CMake and in its current form is incompatible with windows (I had to write a specific version to compile from windows), there are no project files for visual studio or anything else.

Casper - 25-10-2017 at 11:27 AM

Ok, I won't touch it for now then... could you put your version up on github? Or is there a reason you haven't already?

I work with linux tools (gcc) on windows, so it wouldn't be an issue for me. I thought CMake was cross platform?

CicTec - 25-10-2017 at 11:52 AM

I have already added the new code to GitHub:
https://github.com/DIVGAMES/DIV-Games-Studio/pull/25

But it has not been merged, despite Travis telling that the compilation is successful, Mike says it contains some errors.

Expect to understand what exactly fails, to eventually eliminate these commit and create a new one.


I also work with Linux-Like tools on windows, but currently CMake is not yet totally cross-platform, I had to make some changes to make it work in windows.

[Edited on 25-10-2017 by CicTec]