This is an Open Source project. We are developing a powerful extension for the MapBasic Window in Pitney Bowes' MapInfo. The extension will give users the ability to compile on demand from the MapBasic Window. Further extensions may include custom MapBasic functions to accomplish common tasks. This project is still very much WIP
To make this project easy to manage and easy to extend, a pre-compiler may need to be created. In this issue I will explain why this is necessary and what the issues with the idea are, as well as some potential solutions to said problems.
Difficulty to Extend
What are the current steps required when extending (and compiling) the Extended MapBasic Application?
Create transpiling library
Of course the first step is to make the code which takes some source code and converts that into the new transpiled source code. Currently there is no convention to how the transpiling function should be named. Let's assume, for simplicity, it's defined as f().
Ultimately the transpiling library acts a bit like this:
mbsource = f(mbsource)
Editing EMB_Core/transpile.ahk
Writing the functions isn't the only thing that needs to be done before compiling. You also need to link these new transpiling functions to the rest of the application. You do this by modifying the "LIB_Core/transpile.ahk" file with the code above:
In order to try and simplify this process I decided to use a header file. This file declares all .AHK modules/libraries which are used in the final project. Of course our file needs to be included here also:
Before Extended MapBasic transpiles the MapBasic application it first detects whether it needs to transpile at all. To do this RegEx is added to the needsTranspiling() function of the file "EMB_Core/transpiler.ahk".
example needed
Other future features which might be required
The Problem
Modifying EMB is not easy!
Having to modify 4+ lines of code is definitely not a difficult task, however it does involve editing files within the "vital organs" of Extended MapBasic. An accidental error could cause serious damage to the compiled exe / cause damage to compiled MBX files which is what we want to avoid most, but it could also cause a lot of false bug-reports with working versions of Extended MapBasic.
The solution
Simple extensibility
The simplest extensibility is a simple "drag and drop" extensibility. E.G. If you want to add a library "MyFunctions.ahk" to Extended MapBasic, you simply drop the file into the "EMB_Lib" folder, make sure the transpilation regex is declared (as in the example below) and run Compile.EXE.
Compile.EXE will run:
Pre-Compile.EXE - Used to create all the requirements declared above from the contents and the file name of the file.
Ahk2Exe.EXE - Used to compile the Pre-Compile AHK files into a full .exe file.
The RegEx specifies multiple different Regular Expressions, all of which would indicate that the source needs transpiling.
The name of the main function which transpiles the MapBasic code is called "EMB_Lib_MyFunctions". That is "EMBLib" + .
More Problems?
Problem 1: Transpilation Order
Since now the user doesn't specify the specific transpilation order a problem might occur where transpilation of certain code might be required to run BEFORE other transpilation modules.
E.G.
A EMB module might add a new function TempTable with the definition TempTable(numCol as integer, optional colDefs as string, optional colDelimeter as string)
In this case the EMB module should be transpiled BEFORE EMB_Lib_OptionalArguments() and not after.
Anyone who is used to standards know that it is innately difficult for people to keep said standards.
A potential solution
A simple AHK-IDE for creating transpilation libraries might be useful. The IDE would enforce users to specify whether their function should be transpiled before certain modules as well as the transpilation regex.
It is also important to note that Error checking should be implemented into the pre-compiler to check validity of modules before implementing changes to the source
Interlude
To make this project easy to manage and easy to extend, a pre-compiler may need to be created. In this issue I will explain why this is necessary and what the issues with the idea are, as well as some potential solutions to said problems.
Difficulty to Extend
What are the current steps required when extending (and compiling) the Extended MapBasic Application?
Create transpiling library
Of course the first step is to make the code which takes some source code and converts that into the new transpiled source code. Currently there is no convention to how the transpiling function should be named. Let's assume, for simplicity, it's defined as f().
Ultimately the transpiling library acts a bit like this:
mbsource = f(mbsource)
Editing EMB_Core/transpile.ahk
Writing the functions isn't the only thing that needs to be done before compiling. You also need to link these new transpiling functions to the rest of the application. You do this by modifying the "LIB_Core/transpile.ahk" file with the code above:
Including the transpiling library in header.ahk
In order to try and simplify this process I decided to use a header file. This file declares all .AHK modules/libraries which are used in the final project. Of course our file needs to be included here also:
RegEx for Transpile Requirement Detection
Before Extended MapBasic transpiles the MapBasic application it first detects whether it needs to transpile at all. To do this RegEx is added to the needsTranspiling() function of the file "EMB_Core/transpiler.ahk".
Other future features which might be required
The Problem
Modifying EMB is not easy!
Having to modify 4+ lines of code is definitely not a difficult task, however it does involve editing files within the "vital organs" of Extended MapBasic. An accidental error could cause serious damage to the compiled exe / cause damage to compiled MBX files which is what we want to avoid most, but it could also cause a lot of false bug-reports with working versions of Extended MapBasic.
The solution
Simple extensibility
The simplest extensibility is a simple "drag and drop" extensibility. E.G. If you want to add a library "MyFunctions.ahk" to Extended MapBasic, you simply drop the file into the "EMB_Lib" folder, make sure the transpilation regex is declared (as in the example below) and run Compile.EXE.
Compile.EXE will run:
Example extension "MyFunctions.AHK"
Note:
More Problems?
Problem 1: Transpilation Order
Since now the user doesn't specify the specific transpilation order a problem might occur where transpilation of certain code might be required to run BEFORE other transpilation modules.
E.G.
A EMB module might add a new function
TempTable
with the definitionTempTable(numCol as integer, optional colDefs as string, optional colDelimeter as string)
In this case the EMB module should be transpiled BEFORE EMB_Lib_OptionalArguments() and not after.
Potential Solutions:
One option is to add a Transpile_Before option:
A standard to be kept
Anyone who is used to standards know that it is innately difficult for people to keep said standards.
A potential solution
A simple AHK-IDE for creating transpilation libraries might be useful. The IDE would enforce users to specify whether their function should be transpiled before certain modules as well as the transpilation regex.
It is also important to note that Error checking should be implemented into the pre-compiler to check validity of modules before implementing changes to the source