Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-hosting Compiler #17

Open
Ronsor opened this issue Jan 9, 2021 · 3 comments
Open

Self-hosting Compiler #17

Ronsor opened this issue Jan 9, 2021 · 3 comments

Comments

@Ronsor
Copy link

Ronsor commented Jan 9, 2021

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

@ghost
Copy link

ghost commented Jan 9, 2021

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

@LingDong-
Copy link
Owner

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
Copy link

jacoblister commented Nov 24, 2021

@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:

  • transpile output (to javascript initially, as it's easy to implement)
  • tokenizer, source parser

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)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants