You can now insert blocks of reusable code direct into your source program. Uses may include standard pieces of assembler code or dynamic code from another data source that needs to be located in a specific location in your program.
Example
The file "TestCode.il" is inserted into the user program.
This is very different from #include. With #include you can organize constant, method and macro definitions and then use #include directive to add them to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. The types may be defined and named only once in an include file created for that purpose. The compiler will optimise the include files to determine the best order/location in your program.
The new #insert you are determining the location of the code segment. It will be inserted exactly where you specify. The optimisation will only be applied to any methods that you insert but the rest of the code essentially exits at the point of insertion.
Difference from #include with conversion
There is no conversion of the inserted file.
If you need to convert a file from an external source then see the Converters section of the Help.
Usage Notes
The file must exist. An error message is issued if not found.
When an error is encountered in the inserted file the error line number is in the format of xxxxyyyy. Where xxxx is the code line number in the user program and the yyyy is the the line number in the inserted file.
An example error message. Where the source insert instruction is on line 6 and the error in the inserted file is on line 4.
An error has been found:
insertexample.gcb (60004): Error: Syntax Error
The message has been logged to the file Errors.txt.
This may be useful to create some great new solutions.
Enjoy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is great, thanks, I have been missing this capability since day one.
For the edification of the user base, who may have used MASM, C or C++ when working with PIC or other controllers, they are all two pass compilers where as Great Cow Basic is a one pass compiler.
What that means architecturally is a topic unto itself and it has some substantial advantages that GCBASIC makes good use of. But the disadvantage when trying to port code from other compilers is the handling of #Include files.
In a 2 pass compiler the first pass will resolve all references and, amongst other things, it incorporates the text of a #Include file into the Source code inline.
The Second pass then reads and actually compiles the final code.
A one pass compiler appends #Include files and does the compile in a single pass.
99% of the time that results in the same code and a faster compile time.
The down side is when code needs to be Included in a pre defined order.
Hence requesting the #insert derivative which will work, for text only files, the way that #include handles text files in Two Pass Compilers.
It will insert the text into the source code as if it were in the original source file and not appended to it.
It will take user code from a file called "TestCode.il", which would be written in "Instruction Language" and it would generate a HEX file that could be flashed into a 16F886 PIC to perform that logic.
I will be writing more about IL in the near future but for now suffice it to say that IL is the language of the PLC (Programable Logic Controller) devised in the 70's so that Electrical and Electronics Engineers could Use and program a PLC without having to lean complex programing languages.
Now that programing is part of all Electronics Training that aspect has fallen away, and IL has been superseded by BASIC even in the PLC, but for the hobbyist or maker Instruction language still offers advantages.
Here is the most basic example where a Pump needs controlling.
It would have a Normally Open Start Switch or button and a large Red Normally Closed STOP Button.
To replace that circuit with a PIC 12, or other device, the IL Code would be:
Load START ; Start button Pressed
And Not STOP ; Stop button closed
Store PUMP ; Activate the Pump
The GCBASIC code takes care of the inputs and the outputs, the watchdog timer, the denouncing and latching of buttons and even the timing, if the Pump is Timer controlled.
I have use IL on several PIC's and the Arduino, with a compiler written in ASM, for several projects that range from home automation to Model Railway signaling and switching.
Now with the #Inset capability I can begin porting the CR-PLC/IL into GCBASIC.
Cheers
Chris
Last edit: Chris Roper 2022-08-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can now insert blocks of reusable code direct into your source program. Uses may include standard pieces of assembler code or dynamic code from another data source that needs to be located in a specific location in your program.
Example
The file "TestCode.il" is inserted into the user program.
Difference from #include
This is very different from #include. With #include you can organize constant, method and macro definitions and then use #include directive to add them to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. The types may be defined and named only once in an include file created for that purpose. The compiler will optimise the include files to determine the best order/location in your program.
The new #insert you are determining the location of the code segment. It will be inserted exactly where you specify. The optimisation will only be applied to any methods that you insert but the rest of the code essentially exits at the point of insertion.
Difference from #include with conversion
There is no conversion of the inserted file.
If you need to convert a file from an external source then see the Converters section of the Help.
Usage Notes
The file must exist. An error message is issued if not found.
When an error is encountered in the inserted file the error line number is in the format of xxxxyyyy. Where xxxx is the code line number in the user program and the yyyy is the the line number in the inserted file.
An example error message. Where the source insert instruction is on line 6 and the error in the inserted file is on line 4.
This may be useful to create some great new solutions.
Enjoy
This is great, thanks, I have been missing this capability since day one.
For the edification of the user base, who may have used MASM, C or C++ when working with PIC or other controllers, they are all two pass compilers where as Great Cow Basic is a one pass compiler.
What that means architecturally is a topic unto itself and it has some substantial advantages that GCBASIC makes good use of. But the disadvantage when trying to port code from other compilers is the handling of #Include files.
In a 2 pass compiler the first pass will resolve all references and, amongst other things, it incorporates the text of a #Include file into the Source code inline.
The Second pass then reads and actually compiles the final code.
A one pass compiler appends #Include files and does the compile in a single pass.
99% of the time that results in the same code and a faster compile time.
The down side is when code needs to be Included in a pre defined order.
Hence requesting the #insert derivative which will work, for text only files, the way that #include handles text files in Two Pass Compilers.
It will insert the text into the source code as if it were in the original source file and not appended to it.
The example that Anobium shows:
Is effectively a a compiler written in GCBASIC.
It will take user code from a file called "TestCode.il", which would be written in "Instruction Language" and it would generate a HEX file that could be flashed into a 16F886 PIC to perform that logic.
I will be writing more about IL in the near future but for now suffice it to say that IL is the language of the PLC (Programable Logic Controller) devised in the 70's so that Electrical and Electronics Engineers could Use and program a PLC without having to lean complex programing languages.
Now that programing is part of all Electronics Training that aspect has fallen away, and IL has been superseded by BASIC even in the PLC, but for the hobbyist or maker Instruction language still offers advantages.
Here is the most basic example where a Pump needs controlling.
It would have a Normally Open Start Switch or button and a large Red Normally Closed STOP Button.
To replace that circuit with a PIC 12, or other device, the IL Code would be:
The GCBASIC code takes care of the inputs and the outputs, the watchdog timer, the denouncing and latching of buttons and even the timing, if the Pump is Timer controlled.
I have use IL on several PIC's and the Arduino, with a compiler written in ASM, for several projects that range from home automation to Model Railway signaling and switching.
Now with the #Inset capability I can begin porting the CR-PLC/IL into GCBASIC.
Cheers
Chris
Last edit: Chris Roper 2022-08-13
Look forward to the project.
Evan