Archive
Compiling to .net with Smart Mobile Studio
You are probably thinking this is too good to be true, but it’s not. In fact, I have a working prototype already (although it needs a hell of a lot of work). But since people seem to think this is either a blatant lie, or that I’m doing black magic to get this working, I’m going to explain how I do it!
In fact, I have provided links to all the parts you need on this post, so you can download, compile and play around with the tech yourself. But first, some context 🙂
Smart Mobile Studio has a kick-ass compiler. This compiler takes object pascal, parses, tokenizes it and turns it into an AST (abstract symbol tree, where every command, variable, statement etc. is turned into an object in memory). This AST is then analysed by a code-generator (codegen) which turns the AST into JavaScript.
Since Smart Mobile Studio has been in sale for a couple of years I don’t think I need to explain or prove that point as well.
But .net is a completely different beast. But only when you are looking at .net from the outside. I am also a C# developer so I also look at Delphi and Smart from inside C#.
In short: The .net framework has one huge advantage over native languages, and that is something called reflection. Reflection is not just RTTI, like some people have voiced. It’s also the ability to hot-swap code modules in a living program, because bytecodes are just that – byte codes. Since .net is a “virtual language” you can do all sorts of cool stuff with it, like changing a program at runtime.
But the one feature that sets .net apart from Java, which works pretty much along the same lines, is the ability to also emit code. Thats right, you can take a class and emit it to disk from you program. But it doesn’t stop there.
You can also compile new code from within your own program, by building something called expression-trees. This is pretty much what all compilers does (including smart mobile studio), because an expression-tree is a fancy way of saying “AST”.
So you can programmatically build up a full expression tree from within your C# program.
Any bells ring yet?
He he. What you do is of-course to construct an expression-tree and then use the emitter to dump that as an assembly, and voila — you have in fact generated a separate, self-sustaining assembly! It’s a bit more complex than that, but essentially that’s how you do it.
The other kids are doing it
Some guy picked up this years ago and he decided to build a JavaScript compiler. So he built a full JavaScript compiler which parses, tokenizes and does everything a compiler should – and generates an expression-tree — and voila, he emits the code to disk and what you get is a compiled, fully working MS-CIL generated assembly (read: a DLL file that can be executed or used in your .NET projects).
When you load in this assembly into Visual Studio, you will find that all the function names are exported as symbols, so you can happily call your now compiled JavaScript code from C# or Visual Basic.
Pretty cool right? The speed benefits alone are phenomenal, because the assembly is compiled to highly optimized machine code when it’s loaded the first time.
What about Smart Mobile Studio?
Since Smart Mobile Studio generates JavaScript, and Jurassic generates CIL from JavaScript — I guess I don’t need to tell you where this is heading, or that in fact it’s possible to achieve.
In fact, if you don’t believe me, clone out your own GIT version of Jurassic, load up Visual Studio (Visual Studio 2013 Community edition is free) and play around with the code yourself.
Will this become a part of Smart Mobile Studio?
Time will tell. We have more than enough work on our plates to start throwing .net into the mix right now, but I do find the route interesting. It would represent a much better way than the one Borland started ages ago, since the Smart Pascal dialect would be 100% retained. We have already gotten rid of pointers, so Smart Pascal is perfectly suited for the .net framework. You wouldn’t even need to think about .net, just write ordinary Smart Pascal.
Why should this be cool?
It opens up XBOX development first and foremost, followed by native Mono and Desktop development. This means you can write games that targets both HTML5, Mobile and XBOX with the same codebase. That should make developers happy I think.
And then there is ASP.net to think about. Thats probably one of the most important technologies in my view.
Well — fun thing to play with!
Recent
The vatican vault
- March 2023
- February 2023
- December 2022
- October 2022
- January 2022
- October 2021
- March 2021
- November 2020
- September 2020
- July 2020
- June 2020
- April 2020
- March 2020
- February 2020
- January 2020
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- February 2013
- August 2012
- June 2012
- May 2012
- April 2012
You must be logged in to post a comment.