I haven't been able to find a scripting language that suits my needs for my hobby os. In the end, I figured it'd be best to roll my own. These are some of the goals I have in mind:
- Capable of treating lines of code as commands to execute programs or open resources (like in DOS and Bash)
- Suited for operating on streams like Perl
- Very easy to parse, with a small set of reserved keywords
- Supports parallelism and concurrency
- Supports capturing signals for exceptions and events
I haven't gotten anywhere yet, but the planning process has been very interesting because it's forced me to think outside the box for things like how functions work. Consider the following code:
Code:
call BuildFile 1
on Done
out "Finished."
hang
do : BuildFile
{
if $1 = 1 then
do
{
gcc /o test1 test1.c
}
else if $1 = 2 then
do
{
gcc /o test2 test2.c
}
else if $1 = 3 then
gcc /o test3 test3.c
}
The gist of it is that the 'do' keyword is used to encapsulate a set of instructions between curly brackets to form a macro instruction. This macro instruction will have closure with it's own local scope. It can also be labelled by placing a colon followed by an indentifier between the 'do' keyword and the curly brackets. The extra parameters after "BuildFile" are passed like $0, $1, $2, etc. to the 'do' block. Inside the block, they may be aliased with more canonical names.
Another idea I had is that all 'call' instructions should fork into separate threads if possible. An 'on' instruction would be used to capture signals, similar to a 'comefrom' instructions. A 'hang' instruction suspends execution indefinitely, only listening for signals. Think of it as the complete opposite of a 'call' instruction. Rather than "going [to a label] and coming [back to the return place]" it's "coming [back to itself] and going [to a signal handler]".
I've never seen any other programming language handle functions like this myself, but it's probably nothing new. Does anyone else know a language that does something similar which I can look at for ideas? Also, what is your opinion? Would you use it if you had the choice or throw holy water at it?