So... me and Claude, we're writing a transpiler. This is partly an experiment with AI, and partly a chance to finish an ambitious project i had a few years ago (which got to about 70-80% completion and took about 3-4 months -- it was a c# to nim transpiler using Roslyn)
I will now tell you all my secrets haha The architecture is similar: a two stage transpiler the first stage is input language providing an AST of a certain (compiling) program, it's written in the input language leveraging up to date libraries and updated language constructs knowledge. The AST is then serialized to json, that matches the constructs of XLang. XLang is just a fictitious language, which is supposed to be a superset of all constructs from a few languages that are more or less similar to Nim. But we don't support eval, reflection, annotation, metadata, macros, and variables that change their types in mid air. After the json part, all of it is written in Nim. The output of the compiler is of course Nim code, a stage before that it is a Nim AST tree, which I use 'repr' to transform to normal code. all that remains is to go from xlang nodes to Nim nodes (as defined in std/macros). Nim doesn't support all of it, so a transformation pass is ran to convert certain constructs to Nim friendly ones, or the most similar ones, as long as we don't lose correctness. The current focus is on Go (golang) because i think it is relatively similar to Nim or a subset of Nim, but things like goroutines will not be translated in transformation passes, as they are too different from what Nim offers, instead the output code file will contain an import for a go_builtin or go_compat_layer or something along these lines, that will provide the functionality using Nim 3rd party libraries but with an api with similar appearance (and performance+memory characteristics) of said go code, this way the translation is more direct and can be compared and easily checked. (This means the transpiler can convert from different input languages) I will consider it a success if it is able to translate ~80% of the constructs to idiomatic Nim code. I want to request from users here: Which relatively small libraries would you like to see ported? (at this stage let them be small) is there something you're missing from another language? This can be motivational and basically allow me to check how much is implemented correctly in a more fun way. But please no libraries that include reflection and stuff like that, also no bindings, it should be a pure code, Either from go or another language. things like an srt parser, youtube exploder, data structures and algorithms, mailbox handling, etc, but feel free to offer anything you need and i'll see what happens. This is for testing purposes of course, but can be useful to you at the same time.