AST like coding syntax. Easy upgrade!

Prudence via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 6 14:16:17 PDT 2015


On Sunday, 6 September 2015 at 20:38:44 UTC, Adam D. Ruppe wrote:
> On Sunday, 6 September 2015 at 20:22:23 UTC, Zoadian wrote:
>> obviously X has to be a compiletime js->d compiler.
>
> Just a fun fact: my script.d's interpreter is itself CTFEable 
> in modern dmd!
>
>
> import arsd.script;
>
> void main() {
>         // script.d is similar to but not identical to 
> javascript
>         // so run that code in the interpreter and fetch a D
>         // type right out all at compile time...
>         enum a = interpret("var a = 5; a += 2; a;").get!int;
>         pragma(msg, a);
> }
>
>
> $ dmd d ~/arsd/jsvar ~/arsd/script
> 7
>
>
> jsvar.d and script.d can be found here:
> https://github.com/adamdruppe/arsd


Yeah, but wouldn't it be so much nicer? (and probably debuggable 
inline)

interpret({
     var a = 5;
     a += 2;
     a;
}

With full compiler error support? (if it's not D, the external 
parser could return the error, line and position info)

Or, maybe better yet, have the concept of "code strings". which 
are strings that are suppose to be interpreted as code. This then 
means the compiler just has to do a syntax check for errors 
before it does anything else with them(semantics will be checked 
lazy, which is already implemented).




More information about the Digitalmars-d mailing list