Twinspire in a New Language


Twinspire is written in C#, Haxe and ODIN, most of which is a jumbled mess and kept out of sync with each other. The fundamental issue with this approach is the fact that three codebases need to be kept up-to-date, which is simply not going to happen.

Haxe is a transpiler, which would be useful for solving this issue, but there are two issues with this approach:

  • Haxe does not support ODIN.
  • Haxe only supports Raylib by targeting C++, which compiles slowly.

This makes it a less than ideal language for targeting Raylib, which is what Twinspire relies on. C# and ODIN are good contenders, but both have issues.

  • C# is garbage collected and you have no control over memory. You can control some memory in unsafe context, but this is limited.
  • ODIN is not garbage collected, but does not have as mature a codebase or third-party library support as C#.

All three languages have merits, but to keep everything under one codebase is not possible. Or is it?

Perhaps if we created a new language, we can do this. Well, sorry to disappoint you, but we are creating a new language. Yes, yes, yes, there's too many languages to count, but there are reasons for this.

  • Twinspire is better written in one language, but transpiled to the languages it would be compiled from (C# and ODIN).
  • Twinspire can be migrated into this new language as a first-party library.
  • Unlike Haxe, will have a dedicated method through which to add new targets using the language itself.
  • First-party support for user interface development.

What do I mean by the last point, you might ask? Well, like PHP, it is sometimes useful to define the structure of your UI in a way that makes sense. And no, this will not be HTML or CSS (I don't like either of them).

I would provide an example, but this seems premature. Instead, I will simply offer what has been done and demonstrate progress. However, of what has been done thus far, there is not yet much to show. A tokenizer is complete and a parser is in progress. Procedures are first being tested as this seems the most obvious to start with, then variables, structures, pointers, arrays and more.

To give a brief idea of features, these would be:

  • A data-oriented language with simple features. As it's a transpiler, the more features it has, the more complicated adding new target languages becomes. This we want to avoid. The features selected should be common across most, if not all, programming languages to make adding new targets as easy as possible.
  • Structures will be added but no support for member procedures, only variables. "static" may be added to denote global variables within structures.
  • We want to have a foreign system which makes more sense for transpiling to other languages. Haxe's foreign system, as an example, is very limited and often requires creating new classes/functions/variables to cover all bases. This is something we want to avoid and want to make this more user-friendly.
  • Support for pointers. Where languages do not support pointers, we either ignore it, make "refs"/"outs" like in C#, or denote heap allocation where necessary. There will be no "new" keyword in this language.
  • Declarations are assignments. When you declare a new variable, it is given a default value. If the variable is a structure, create an empty structure. If the variable is a basic type, set a default value. Of course, you can assign a value at declaration. There will be no concept of nullability outside of pointers.

These are the ideas for now. I will write more when more progress has been made.

Leave a comment

Log in with itch.io to leave a comment.