LingDong- / wax

A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly 🚀
https://waxc.netlify.app/
MIT License
783 stars 45 forks source link

Self-hosting Compiler #17

Open Ronsor opened 3 years ago

Ronsor commented 3 years ago

As the title implies, make wax self-hosting by rewriting it in itself.

ghost commented 3 years ago

Bootstraped? @LingDong- Does wax have string functions? (Sorry for pinging you...)

LingDong- commented 3 years ago

Hi @Ronsor ,

Thanks for the suggestion!

Yes I've thought about the idea. It's a non-trivial undertaking given the many targets wax supports, and wax itself being a not particularly convenient language to write a compiler in. Of course it's super cool to be self-hosted from a philosophical / "because I can" perspective (indeed what language designer doesn't want their language to be self-hosted :), but it also has somewhat limited practical value from the user's standpoint.

So I'll probably work on it when I have spare time. Let's keep this issue open as a reminder to myself, and maybe for discussing implementation of such a compiler if people are interested/want to contribute.

Hi @Rabios , no worries, and yup, wax has all the basic string operations, please check out https://github.com/LingDong-/wax/blob/main/QUICKSTART.md#strings

Thanks

jacoblister commented 2 years ago

@LingDong- sounds like a challenge :)

I've made a start with the example program below - not much yet, but it can express a limited source tree and write it back out to output. Next steps:

Would that be something you'd be interested in taking a pull request for?

Context - I have a software synthesizer project implemented in Golang and with the signal processing and UI code transpilled to javascript, demo here: http://noisefloor.jacob.nz.net/ https://github.com/jacoblister/noisefloor

I've never quite been satisfied with the amount of control I have over the javascript output, so I have been looking for an implementation language which can target at least C (for native builds), and javascript - maybe wax could be it.

Really pleased to have found you project as this has to be the cleanest and smallest Lisp style dialect and implementation I've seen anywhere.

Thanks

--

(@define NODE_EXPR 0) (@define NODE_PARAM_INT 1) (struct node (let type int) (let expr str) (let p0 str) (let child (arr (struct node))) ) (func dumpnode (param depth int) (param node (struct node)) (result str) (let indent str (alloc str "")) (for i 0 (< i depth) 1 (do (<< indent " ") )) (let s str (alloc str "")) (<< s indent) (<< s "(") (<< s (get node expr)) (<< s " ") (<< s (get node p0)) (<< s "\n") (for i 0 (< i (# (get node child))) 1 (do (let childdump str (call dumpnode (+ depth 1) (get (get node child) i))) (<< s childdump) )) (<< s indent) (<< s ")") (<< s "\n") (return s) ) (func helloworld (result (struct node)) (let hello_main (struct node) (alloc (struct node))) (set hello_main type @NODE_EXPR) (set hello_main expr "func") (set hello_main p0 "main") (set hello_main child (alloc (arr (struct node)))) (let hello_print (struct node) (alloc (struct node))) (set hello_print expr "print") (set hello_print p0 "Hello World!") (set hello_print child (alloc (arr (struct node)))) (insert (get hello_main child) (# (get hello_main child)) hello_print) (let hello_return (struct node) (alloc (struct node))) (set hello_return expr "return") (set hello_return p0 "0") (set hello_return child (alloc (arr (struct node)))) (insert (get hello_main child) (# (get hello_main child)) hello_return) (return hello_main) ) (func main (result int) (let root (struct node) (call helloworld)) (let dump str (call dumpnode 0 root)) (print dump) (return 0) )