
Myrddin Programming Language - bigato
https://myrlang.org/
======
hawski
I believe that currently [https://myrlang.org/](https://myrlang.org/) is a
more canonical address.

I can't wait when it will be more mature. It uses QBE compiler backend [0] -
"a pure C embeddable backend that provides 70% of the performance of advanced
compilers in 10% of the code". Which by itself is very interesting. It does
however only support x86_64, but it seems that work on arm64 is underway.

I like that it does not depend on GCC or LLVM. I also cheer Toybox, Oil shell
and other rewrite-the-world projects - I'm that kind of weird.

It ticks many boxes for me. Rust brings memory safety, but I can't help the
feeling that it just looks like C++. I wonder if it would be beneficial to
implement a static analyzer for C, that would take into account additional
ownership information on pointers. Something like:

    
    
      #define OWN
      int func(struct foo OWN*ptr)
    

So it would just compile to C, but the analyzer would know more.

Lately I'm wondering how good could be a dynamic language with a homegrown
compiler backend. It probably does not have to be fully optimized to be faster
than Python. Maybe it would not be as fast as Lua-JIT, but JIT brings it's own
set of problems. It could be a fun project to make a compiler for Wren
language for example. Such a language could target JVM and CLR as well.

Sorry for a brain dump, but I don't have time to make it more coherent. I may
be too passionate about the topic, while lacking experience. I hope it is
useful to somebody.

[0] [https://c9x.me/compile/](https://c9x.me/compile/)

~~~
pjmlp
What you want is being researched as CheckedC.

[https://www.microsoft.com/en-
us/research/project/checked-c/](https://www.microsoft.com/en-
us/research/project/checked-c/)

Microsoft's SAL introduced with their major security rewrite in XP, provides
the annotations you mention.

[https://docs.microsoft.com/en-us/previous-
versions/visualstu...](https://docs.microsoft.com/en-us/previous-
versions/visualstudio/visual-studio-2013/ms182032\(v=vs.120\))

[https://msdn.microsoft.com/en-
us/library/windows/desktop/cc3...](https://msdn.microsoft.com/en-
us/library/windows/desktop/cc307398.aspx)

But it all boils down to C developers actually caring about using them.

~~~
hawski
If I understand it correctly CheckedC woods as an extension to the language,
so you need CheckedC compiler to actually use it.

I agree that SAL fits my description. Is it available outside of Windows? I've
seen that someone wanted to add SAL support to clang [0], but decided against,
because of Microsoft's patent on the thing [1]. Or than that it looks cool.
Thanks for the pointer.

[0] [http://clang-developers.42468.n3.nabble.com/RFC-Starting-
sup...](http://clang-developers.42468.n3.nabble.com/RFC-Starting-support-for-
SAL-td3466171.html)

[1]
[https://patents.google.com/patent/US20050076331A1/en?q=Sourc...](https://patents.google.com/patent/US20050076331A1/en?q=Source+code&q=annotation&oq=Source+code+annotation)

~~~
pjmlp
Actually gcc does have something similar to SAL with FORTIFY_SOURCE, but it is
not as feature rich.

[https://access.redhat.com/blogs/766093/posts/1976213](https://access.redhat.com/blogs/766093/posts/1976213)

------
dmytroi
Looks very interesting from ergonomics point of view: it is indeed does
introduce useful tools like generics, type inference, pattern matching, which
are very painful to do in C. Though it seems like the language misses on
popular nowadays generators, lambdas and coroutines. So I would say give it a
plus on language design, and there is a space to grow.

Memory model looks C-ish, there are pro's and con's to it. Guess it works for
the niche that language aims for.

What I think could be done better: compiler infrastructure / FFI. In this day
and world interoperability with other languages is a must, and there is
usually a need to provide standalone and embeddedable implementations of a
language. IMHO would be great if Myrddin just compiled to C (like Chicken
Scheme), that would broaden possibilities to use Myrddin as script language,
or just use it side-by-side with C/C++. It can be done with the current
Myrddin compiler implementation, but overhead of maintaining whole separate
compiler/toolchain might be too big to enable wider adoption.

\---

Edit: I was wrong, all functions are lambdas! Which is really great.

~~~
ori_b
(Primary author here)

> _Though it seems like the language misses on popular nowadays generators,
> lambdas and coroutines. So I would say give it a plus on language design,
> and there is a space to grow._

Lambdas are actually the _only_ way to define functions.

    
    
        const f = {args
             /* do stuff */
        }
    

is just assigning a lambda literal to 'f'. You can also just pass them around,
if you want:

    
    
        use std
        const main = {
            var value = 42
            thread.spawn({; std.put("hi from a thread. I captured {}", value)})
        }
    

Coroutines are possible to implement as a library, and generators don't fit
well -- there are iterators, though:

    
    
         use iter
         const main = {
              var v = [1,2,3,4]
              for p : iter.byperm(v[:], std.numcmp)
                    /* use permutation p */
              ;;
          }
    

> _What I think could be done better: compiler infrastructure / FFI._

You can already link to C, but writing the function definitons function
definitions are painful. There's ongoing work to take Andrew Chambers' C
compiler implementation, and extend it so that it can automatically generate
the glue code.

We had a Summer of Cod[1] person working on it, but they dropped out due to
lack of time.

[1] [https://myrlang.org/summer-of-cod](https://myrlang.org/summer-of-cod)

~~~
Latty
> Lambdas are actually the only way to define functions.

How does that work with regards to interacting with the function? If you see
that function in a debugger or print it out, do you get just a generic
"lambda" name or does it do some magic to get "f" when defined and assigned
straight to a name?

~~~
ori_b
> How does that work with regards to interacting with the function? If you see
> that function in a debugger or print it out, do you get just a generic
> "lambda" name or does it do some magic to get "f" when defined and assigned
> straight to a name?

It does some magic to get `f` when assigned straight to a name. The magic is
pretty trivial.

------
tombh
In case anyone else is interested, the name comes from the Welsh for
Merlin[1], made famous in Arthurian legend and medieval Welsh poetry.

I went to school (and had my first ever paid software job) in Caerfyrddin
(which can be translated as "Merlin's Field" ), a major town in West Wales.

1:
[https://www.reddit.com/r/programming/comments/1706e1/myrddin...](https://www.reddit.com/r/programming/comments/1706e1/myrddin_a_language_for_coding_close_to_the_metal/c816nly/)

~~~
dghf
The form "Merlin" first appears (as _Merlinus_ ) in Geoffrey of Monmouth's
_History of the Kings of Britain_ , c. 1136. One suggested reason why Geoffrey
didn't latinise the Welsh name more directly as _Merdinus_ is the unfortunate
similarity of the latter to the French _merde._

------
noelwelsh
Looks interesting. A few things I'd like more information on: how does memory
allocation work, and in what ways in Myrddin unsafe?

------
itchap
Is this comparable to nim [https://nim-lang.org/](https://nim-lang.org/) ?

~~~
hawski
Both are programming languages. :)

Nim has GC, looks like Python and compiles to C (or JS).

Myrddin has manual memory management, looks quite distinct (but I'm sure it
borrows from many languages) and uses QBE as a compiler backend so it just
produces binaries.

------
donatj
Very interesting. In many ways this is way closer to what I want from Go.

