FlowerScirpt teaser

bobef bobef at abv_nospam.bg
Tue Sep 25 13:48:24 PDT 2007


Hi guys,

several weeks ago while working on PHP (web based) project of mine I was very unhappy with PHP's performance. I decided to port the project to D, so I needed a scripting language for use with D. DMDScript is not free plus it is hell to extend. I found miniD but it was painfully slow. So I decided to write a new scripting engine. Now it is more ready than to not, so I want to check if there is more people interested besides me. If so we could turn this into a community project or something like that. To be more specific I've almost finished the engine itself, but it lacks stdlib. And to be a real PHP replacement it needs very good stdlib (luckily Tango got most of what we need <g>). So please tell me if there is someone interested in helping to design/implement stdlib and maybe optimize the engine even further. Here is a little benchmark I did and some more info about the engine.
The engine is kind of mixture between JavaScript and D. Here is little something from my readme.txt which is work in progress.

FlowerScript goals:
	As usable for web applications as PHP but faster (done)
	As simple and flexible as JavaScript (done)
	Easily extensible from D (mostly done)
	Embeddable in HTML (done)
	Built in encryption/decryption
	Usable outside web applications
	
I like the simplicity and flexibility of JavaScript, I also like mootools, so I wanted FlowerScript similar to JavaScript. Instead of documenting everything (which I will also do if I have the time) I will describe the differences from JavaScript.
In FS there is no term like "objects" or such. There are two types. Basic data types: 'boolean', 'string', 'number', 'null', 'undefined', 'void' and 'scopes'. Scopes are pretty much what JavaScript's objects are. You can put properties in them. You can use them as associative arrays. In addition scopes can also be called as functions. The only difference between a scope and a function, is that the function can accept named arguments. Arrays also derive from 'scope'.
Other differences from JavaScript:
	Array slicing - "array[from..to]" . 'from' or 'to' may be omitted
	Strings can be indexed or sliced as arrays
	Scopes are callable. They act as annonymous functions
	Supports 'outer' keyword to access the outer scope
	Supports some special properties: .dup (duplicate), .dupr (duplicate recursively), .reverse (reverse array)
	Supports 'foreach' and 'foreachr'. The syntax for both is "foreach(forexpression) expression|statement", where 'forexpression' must evaluate to scope (arrays are scopes too). 'key' and 'value' are automatically defined (with these names) withing the foreach's scope
	No support for the following statements (this may change in future):
		in - not as flexible as foreach
		switch - it is useless as it does nothing more than if/else but with inconsistent syntax
		do, while - 'for' without semicolons will do the same as while. i.e. for(condition) instead of for(init;condition;dosomething)
		new, delete - to delete a variable use symbol=undefined;
		try, catch, finally - not implemented yet
	Supports 'goto'. The difference from C is that labels are not "label:" but "label expression;", where 'expression' is expression that evaluates to string. This seems more consistent and flexible.
	All variables but numbers are passed by reference instead of copy. Numbers are always copied.
	Other minor things to be added later...
They may be other differences since I haven't studied the ECMAScript specifications...

Little benchmark:

FlowerScript (development version -O -inline) versus PHP 5.2.3 with ZendOptimizer 3.2.8 (zend_optimizer.optimization_level=15)
Benchmarks are on the same PC
PHP timing is done with microtime(), which means that this timing DOES NOT INCLUDE THE COMPILATION TIME, unlike FlowerScript which is summary of compilation (without caching) and execution.


Tests:

================================================

///////////
///Flower (time ranges from 0.017 to 0.016)
///////////

$SERVER={"gosho":"pesho"};$COOKIE={"gosho":"pesho"};
for($c=0;$c<=1000;$c++)
{
	$a=("gosho"~"["~$SERVER["gosho"]~"]"~"="~$SERVER["gosho"]~"<br />");
	$b=("gosho"~"["~$COOKIE["gosho"]~"]"~"="~$COOKIE["gosho"]~"<br />");
}


///////////
///PHP (time ranges from 0.9 to 0.1, generally above 0.3)
///////////

<?php
$a=microtime();
$SERVER=array("gosho"=>"pesho");$COOKIE=array("gosho"=>"pesho");
for($c=0;$c<=1000;$c++)
{
	$a=("gosho"."[".$SERVER["gosho"]."]"."=".$SERVER["gosho"]."<br />");
	$b=("gosho"."[".$COOKIE["gosho"]."]"."=".$COOKIE["gosho"]."<br />");
}
echo(microtime()-$a);
?>


================================================

So if you are interested give me a note and I will eventually start a dsource project.



More information about the Digitalmars-d-announce mailing list