Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-10

Using FPC as a scripting engine

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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.

Alexander Todorov
to Alexander Todorov
Alexander Todorov wrote 39 lines
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

Michael Van Canneyt
to Alexander Todorov
Alexander Todorov wrote 46 lines
On 10/11/06, Alexander Todorov 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.

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.

- Jeff

Marc Santhoff
to Jeff Pohlmeyer
Jeff Pohlmeyer wrote 10 lines
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

Leonardo M. Ram�
to Marc Santhoff

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 wrote 25 lines
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 - 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

Alexander Todorov
Show quoted text 13 lines
> 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.

Michael Van Canneyt
to Alexander Todorov
Alexander Todorov wrote 21 lines
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.