Using FPC as a scripting engine

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Using FPC as a scripting engine

Alexander Todorov
Hello list,
currently I am using RemObjects Pascal Script as a scripting language
for a project of mine.
All scripts are simple programs that use "API" exported from the main
program. They have and some global variables defined as well.

example:
begin
   Context.ShowMessage(Params.Param('message').AsVariant);
end.

The above will cause the main program to show a message. "Context" is
object providing all the used functions and "Params" is just a list of
parameters passed to the script.

I know Pascal Script has been made compatible to work with FPC but I
intend to drop its usage because of many reasons.
One alternative is http://www.paxscript.com/. but the other is the FPC
compiler embedded into my program. Here is how I see it:
- Use the parser, code generator, assembler, linker (internal) from
the FPC/compiler directory and compile it into the main program.
- Make the compiler engine compile and link any Pascal text (script)
and place it into memory.
- Place into memory some other stuff required by the script, e.g.
global variables, environment, parameters, ...
- Use platform native function to execute the in-memory image, e.g.
some sort of exec on Unix, CreateProcess on Windows.
- Get the results somehow and return to the main program.

Using this approach one can benefit from the FPC development and can
use some new stuff (generics) or things missing in Pascal Script
(indexing arrays, []).


Any thoughts on this are very welcome. Please share your opinion.

Thanks!
Alexander.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using FPC as a scripting engine

Alexander Todorov
On 10/11/06, Alexander Todorov <[hidden email]> wrote:

> Hello list,
> currently I am using RemObjects Pascal Script as a scripting language
> for a project of mine.
> All scripts are simple programs that use "API" exported from the main
> program. They have and some global variables defined as well.
>
> example:
> begin
>    Context.ShowMessage(Params.Param('message').AsVariant);
> end.
>
> The above will cause the main program to show a message. "Context" is
> object providing all the used functions and "Params" is just a list of
> parameters passed to the script.
>
> I know Pascal Script has been made compatible to work with FPC but I
> intend to drop its usage because of many reasons.
> One alternative is http://www.paxscript.com/. but the other is the FPC
> compiler embedded into my program. Here is how I see it:
> - Use the parser, code generator, assembler, linker (internal) from
> the FPC/compiler directory and compile it into the main program.
> - Make the compiler engine compile and link any Pascal text (script)
> and place it into memory.
> - Place into memory some other stuff required by the script, e.g.
> global variables, environment, parameters, ...
> - Use platform native function to execute the in-memory image, e.g.
> some sort of exec on Unix, CreateProcess on Windows.
> - Get the results somehow and return to the main program.
>
> Using this approach one can benefit from the FPC development and can
> use some new stuff (generics) or things missing in Pascal Script
> (indexing arrays, []).
>
>
> Any thoughts on this are very welcome. Please share your opinion.
>
> Thanks!
> Alexander.
>

There was no response to my first e-mail so here are some examples of
what I want to do:

http://www.codeproject.com/csharp/runtimecompiling.asp
http://developer.apple.com/documentation/mac/IAC/IAC-334.html
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using FPC as a scripting engine

Michael Van Canneyt


On Fri, 13 Oct 2006, Alexander Todorov wrote:

> On 10/11/06, Alexander Todorov <[hidden email]> wrote:
> > Hello list,
> > currently I am using RemObjects Pascal Script as a scripting language
> > for a project of mine.
> > All scripts are simple programs that use "API" exported from the main
> > program. They have and some global variables defined as well.
> >
> > example:
> > begin
> >    Context.ShowMessage(Params.Param('message').AsVariant);
> > end.
> >
> > The above will cause the main program to show a message. "Context" is
> > object providing all the used functions and "Params" is just a list of
> > parameters passed to the script.
> >
> > I know Pascal Script has been made compatible to work with FPC but I
> > intend to drop its usage because of many reasons.
> > One alternative is http://www.paxscript.com/. but the other is the FPC
> > compiler embedded into my program. Here is how I see it:
> > - Use the parser, code generator, assembler, linker (internal) from
> > the FPC/compiler directory and compile it into the main program.
> > - Make the compiler engine compile and link any Pascal text (script)
> > and place it into memory.
> > - Place into memory some other stuff required by the script, e.g.
> > global variables, environment, parameters, ...
> > - Use platform native function to execute the in-memory image, e.g.
> > some sort of exec on Unix, CreateProcess on Windows.
> > - Get the results somehow and return to the main program.
> >
> > Using this approach one can benefit from the FPC development and can
> > use some new stuff (generics) or things missing in Pascal Script
> > (indexing arrays, []).
> >
> >
> > Any thoughts on this are very welcome. Please share your opinion.
> >
> > Thanks!
> > Alexander.
> >
>
> There was no response to my first e-mail so here are some examples of
> what I want to do:
>
> http://www.codeproject.com/csharp/runtimecompiling.asp
> http://developer.apple.com/documentation/mac/IAC/IAC-334.html

I find this all horribly complicated.

Why don't you simply keep the compiler external, compile everything
in a library, load the library and execute a well-known function,
passing it an 'environment' interface ?

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using FPC as a scripting engine

Jeff Pohlmeyer
In reply to this post by Alexander Todorov
I remember seeing some sort of system ( I can't remember
the name or URL ) that used a pascal compiler to pre-compile
CGI applications. Whenever a client request involved one the
apps, the server would check the timestamp of the source
against the timestamp of the binary. If the the binary was
newer, it would just run, if the source was newer, it would
be recompiled before running.

Just a thought, maybe somebody else here knows the
thing I'm talking about.


 - Jeff
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: Using FPC as a scripting engine

Marc Santhoff
Am Samstag, den 14.10.2006, 07:31 -0500 schrieb Jeff Pohlmeyer:

> I remember seeing some sort of system ( I can't remember
> the name or URL ) that used a pascal compiler to pre-compile
> CGI applications. Whenever a client request involved one the
> apps, the server would check the timestamp of the source
> against the timestamp of the binary. If the the binary was
> newer, it would just run, if the source was newer, it would
> be recompiled before running.
>
> Just a thought, maybe somebody else here knows the
> thing I'm talking about.

Wasn't that Lars aka L505? That guy was doing a lot of website stuff
with pasacal. Although I've forgotten the url you could try:

www.l505.com / .org / .whatever

HTH,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: Using FPC as a scripting engine

Leonardo M. Ramé
The address of Lars's Pascal Server Pages is http://www.psp.furtopia.org, that program doesn't
compiles code on the fly, just allows you to create CGI applications with FPC in an easy way.

--- Marc Santhoff <[hidden email]> wrote:

> Am Samstag, den 14.10.2006, 07:31 -0500 schrieb Jeff Pohlmeyer:
> > I remember seeing some sort of system ( I can't remember
> > the name or URL ) that used a pascal compiler to pre-compile
> > CGI applications. Whenever a client request involved one the
> > apps, the server would check the timestamp of the source
> > against the timestamp of the binary. If the the binary was
> > newer, it would just run, if the source was newer, it would
> > be recompiled before running.
> >
> > Just a thought, maybe somebody else here knows the
> > thing I'm talking about.
>
> Wasn't that Lars aka L505? That guy was doing a lot of website stuff
> with pasacal. Although I've forgotten the url you could try:
>
> www.l505.com / .org / .whatever
>
> HTH,
> Marc
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>


Leonardo M. Ramé
http://leonardorame.blogspot.com

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using FPC as a scripting engine

Alexander Todorov
In reply to this post by Alexander Todorov
On Fri, 13 Oct 2006 12:45:55 +0200 (CEST)
Michael Van Canneyt wrote:

> > There was no response to my first e-mail so here are some examples of
> > what I want to do:
> >
> > http://www.codeproject.com/csharp/runtimecompiling.asp
> > http://developer.apple.com/documentation/mac/IAC/IAC-334.html
>
> I find this all horribly complicated.
>
> Why don't you simply keep the compiler external, compile everything
> in a library, load the library and execute a well-known function,
> passing it an 'environment' interface ?
>
> Michael.

Yes that could be a solution. It seems easy to implement and work
with. But I want to try emulate what Pascal Script is doing. Also I am
wondering is it possible to execute code that is compiled/placed in
memory (e.g. do all stuff that is normaly done by the OS to load the
application and then execute it (don't know exactly how)).

Thanks for the answer.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: Using FPC as a scripting engine

Michael Van Canneyt


On Mon, 16 Oct 2006, Alexander Todorov wrote:

> On Fri, 13 Oct 2006 12:45:55 +0200 (CEST)
> Michael Van Canneyt wrote:
> > > There was no response to my first e-mail so here are some examples of
> > > what I want to do:
> > >
> > > http://www.codeproject.com/csharp/runtimecompiling.asp
> > > http://developer.apple.com/documentation/mac/IAC/IAC-334.html
> >
> > I find this all horribly complicated.
> >
> > Why don't you simply keep the compiler external, compile everything
> > in a library, load the library and execute a well-known function,
> > passing it an 'environment' interface ?
> >
> > Michael.
>
> Yes that could be a solution. It seems easy to implement and work
> with. But I want to try emulate what Pascal Script is doing. Also I am
> wondering is it possible to execute code that is compiled/placed in
> memory (e.g. do all stuff that is normaly done by the OS to load the
> application and then execute it (don't know exactly how)).

It's tricky; newer OS-es and CPU's have some flag to protect data memory
so it cannot be used to execute code (it broke many programs).
So your idea simply might not work on these systems.

Pascal script really is a bytecode interpreter, not a compiler.
Only when it calls native code, it has to do some stack setup,
but that is a minor part and in no way interferes with the flag
I mentioned above.

Michael.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal