kburtch / SparForte

Bourne shell, template engine, scripting language reliable, scalable projects. Based a ISO standard proven effective for large, mission-critical projects, SparForte is designed for fast development while, at the same time, providing easier designing, maintenance and bug removal. About 130.000 lines of code.
https://www.sparforte.com
GNU General Public License v2.0
50 stars 6 forks source link

Example of SparForte running under/inside Ada #28

Closed sanyaade-projects closed 2 months ago

sanyaade-projects commented 8 months ago

Good day to everyone, I came across SparForte while surfing the internet for teaching resource that could be used or adapted in my Ada programming classes. Beginners at College level learners, being exposed to the Ada language first. I think SparForte will be a solid pathway for incremental programming within Ada as a mix-in to start off gradually. Many thanks!

Question: Is there an example or some examples of using SparForte inside an Ada code? I saw a quote in the documentation==> "AdaScript scripts should run with little difficulty under Ada". So I was wondering if I could see example of an how to. Many thanks!

I already register on SparForte mailing list but I could not post yet, waiting for approval, hence my coming here to post at the development portal.

Also, I saw an attempt and communication on Alire regarding SparForte but I could find it in the index nor how to go about using Alire.

I strongly believe that using SparForte using will be a great success in introducing beginner to programming in Ada, it will allay and remove the fear that faces most starter and beginner positively.

Many thanks for your all your efforts and many years of valuable time that went into SparForte.

Hear from you soon.

God blesses!!!

Regards

kburtch commented 8 months ago

Please register again for the mailing list. I may have closed the approval by mistake.

For "AdaScript scripts should run with little difficulty under Ada", the core of SparForte should be compatible with Ada. A SparForte script can be typed into an Ada program and, with minor changes, should be able to be run. This would not include unique features of SparForte such as shell commands. The reverse process, typing an Ada program into SparForte, may require more modifications because SparForte does not include all Ada features.

SparForte:

procedure t is begin put_line( "hello world" ); end t;

Ada:

with ada.text_io; use ada.text_io;

procedure t is begin put_line( "hello world" ); end t;

The SparForte script can be converted to an Ada program by adding the text_io library, which is available by default in SparForte.

Currently, SparForte cannot be called directly from Ada. The reason is that there is no SparForte library to link with an Ada program. A few years ago, there was one but removed that feature and focused on core features and stability as a priority. I intended to create a SparForte library but there is no library at the present time.

Should you want to attempt it yourself, it will require work and modifications to the SparForte source code. Compile the language without the spar.adb main program and build a library file. For a static library, make a .a file using the Linux ar command to add the .o object files). There used to be a gnatdll command to create *.so shared libraries but that may no longer exist. You will need a define an Ada exported function that another Ada program can call to start SparForte and interpret a script using one of the procedures in interpreter.adb. (see the startup sequence in spar.adb). There may be additional steps that I do not remember.

An easier way would be to run SparForte as an external command, passing it the script to run. GCC Ada/Gnat has an Ada package for running external programs. Perhaps it is called os_lib.spawn but I am not certain. You can have a similar result by importing the Linux C library system() function. Pass in arguments like "-e" option and the commands to run, or the name of the SparForte script without the "-e". e.g. system( "/usr/local/bin/spar -e 'put_line( "hello world");'" & ASCII.NUL )

One of the contributors is trying to get SparForte into Alire repository. One of the challenges is that SparForte is not pure Ada. Shell scripts, makefiles and C programs are also involved. This added complexity is causing problems.

sanyaade-projects commented 8 months ago

@kburtch

Many thanks for your detailed explanation.

I have registered again at the SparForte community. Yes! I saw the Alire attempts but now I know why it was not completed. It would have been nice to have Sparforte sponsored by e.g. AdaCore, etc... to get it into Ada ecosystem as library or as an extension. I saw similar efforts like Ada++; HAC that could also be sponsored.

I will follow all the steps and directions you outline above. I will tryout on the library static library path and see how it goes.

Please approve my subscription on the mailing list.

Many thanks!

God blesses!!!

Regards