99 points · by _lwad · 8y ago · 33 comments
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.
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://msdn.microsoft.com/en-us/library/windows/desktop/cc3...
But it all boils down to C developers actually caring about using them.
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...
[1] https://patents.google.com/patent/US20050076331A1/en?q=Sourc...
OK, we changed to that from https://eigenstate.org/myrddin/. Thanks!
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.
> 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.
Oh, missed lambdas, that's great!
> You can already link to C
I mean, only on Nix-es, only in Sys-V-like ABI. What if I'm under Windows? What if it's not Sys-V? What if I want Javascript (aka emscripten)?
My use case is game development, I could have a need to ship to wide variety of platforms (for some you don't even have publicly available specs, like PS3), and this platforms only provide C/C++ compilers. Why Myrddin compiler take a burden of supporting all C ABI's out there by implementing it's own asm code generation? Easier way out code be just generating higher level code like C or LLVM IR, and using libffi to implement FFI.
I would love languages like Myrddin to succeed, but let's be pragmatic, it is nearly impossible to support asm code generation with all C ABI's without having a full time team working on it. It is a huge time investment (not even speaking of financial investment connected to it). So I find it's hard for languages to get traction because they keep getting stuck inside Sys-V/Windows realm :( While something that compiles to C somehow magically just-work on everything, even web.
> A: No. You're fucking getting paid in fish, for fuck's sake.
Thank you for the hilarious FAQ.
(read on)
use std
const mkincrement = {inc
var x = 0
/* No GC, so the upwards closures are explicit */
-> std.fndup({
x += inc
-> x
})
}
const main = {
var g = mkincrement(5)
std.put("{}\n", g())
std.put("{}\n", g())
std.put("{}\n", g())
std.put("{}\n", g())
std.fnfree(g)
}
Will output: 5
10
15
20
The trick is that the function state needs to be in the capture.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.
Total bikeshedding: why the double semicolon? It's one of the few parts of OCaml that nobody likes.
https://eigenstate.org/archive/myrddin-dev/2018-Jan/0000008....
I think there are still going to be some changes before it stabilizes, but it's currently in master.
In go, defer appends a function call to a heap allocated list that gets run at the end of a function.
In zig, defer (and errdefer) do not allocate memory, and get run at scope exit.
I don't think it's valid comparison to Go, since that's a garbage collected language.
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...
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.