Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of SparForte running under/inside Ada #28

Open
sanyaade-projects opened this issue Dec 26, 2023 · 2 comments
Open

Example of SparForte running under/inside Ada #28

sanyaade-projects opened this issue Dec 26, 2023 · 2 comments

Comments

@sanyaade-projects
Copy link

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
Copy link
Owner

kburtch commented Dec 27, 2023

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
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants