235 points · by michaelsbradley · 5y ago · 145 comments
DSLs really matter in the hardware and digital design space - a space that seems to be completely devoid of innovation when it comes to tooling.
A couple languages that try to bring RTL into the 21st century are nMigen-Python and Chisel-Scala.
I'm currently writing an RTL in Nim.
Nim's macro system allows you to do really cool things like instantiate named RTL wires and create custom operators like `:=` for Signal assignment. Really excited about tier 1 BigNum support coming soon - which will make it easier to simulate arbitrary width integer signal arithmetic.
Not hardware, but I have been using Nim for DPI-C interface with SystemVerilog for quite some time. Few weeks back, I started tinkering with Nim macros, and started working on a project to make the VPI interface more approachable.
This language is kind of a hidden gem that not many people are aware of in the HDL/HVL space.
Are you translating, or building your own sim runtime?
Anyways, I think the RTL market is ripe for disruption. There was a lot of great language work done by, for instance, Ronald Garcia, directly aimed at fixing pain points in HDLs, like parsmetrization.
There are also probably not that many hardware designers in the world?
But I totally agree, Nim is an awesome language and definitely deserves more attention!
I agree. The popularity of some programming languages is undoubtedly buoyed by corporate sponsorship or the association with a company. This is not a bad thing, but it means other languages struggle to generate as much interest.
Also, without a generous benefactor, open source languages have to scrape funding together piecemeal from different sources. For example, both Rust and Go have had (or still have) dedicated staff writing documentation for the language. This is a luxury that other languages cannot fund or afford.
I actually posted a Ask HN question of this very topic recently: Can new programming languages attract developers without funding?"
And PR most importantly.
Additionally Guido has always worked in well known companies, and Microsoft and IBM have toyed with Python on their products as well.
https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc...
> to Swift which can cause memory leaks
The Nim compiler can detect cycles and warn you. And --gc:orc collects them successfully at runtime. Orc is going to be the default.
If those two things had been present I would pick Nim over Go, it’s just a nice language for some like me, who have mostly done Python.
I’m not sure if this was a bug in a third party module, but I also struggled a little with unicode support.
https://github.com/dom96/httpbeast https://github.com/olliNiinivaara/GuildenStern
It might just be to low level.
So basically nim actually compiles .nim -> .c -> binary
In the future, Nim's default memory management will use reference counting with destructors and move semantics inspired by Rust and C++.
https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc...
> Nim's memory management is deterministic and customizable with destructors and move semantics, inspired by C++ and Rust. It is well-suited for embedded, hard-realtime systems.
The current default GC involves a somewhat unusual memory model that can make certain kinds of multi-threaded programming difficult: each thread has its own heap and independent GC; memory subject to GC cannot be read/written across threads and locks can't be used to remedy the situation; if you force the compiler to accept code that violates the "no shared" rule, the ref count of the GC on one thread or another will eventually get corrupted and the program will crash with SIGSEGV.
However, by allocating on and copying to/from the shared heap (which is never subject to garbage collection) you can do message passing across threads.
For multiprocessing (like Python's module of that name), you can roll your own little system in probably 100 lines of code or use something like this [1] with an example program [2]. For me, that toy program runs 1.5-2x faster than ripgrep on the same (admittedly limited) problem on Linux. { I suspect this perf diff is due to mmap IO being faster than syscall IO due to SIMD register use as discussed here [3], but this deserves deeper investigation than I have time for right now. If my hunch is right, that may constitute further argumentative support for not leaping to threads even if the programming language "makes them 'easy'", though. }
As for threads/parallelism with shared memory in Nim..Honestly, there is probably too much to recap. Weave [4] would be a good place to start reading, though, or searching the Nim Forum.
[1] https://github.com/c-blake/cligen/blob/master/cligen/procpool.nim
[2] https://github.com/c-blake/cligen/blob/master/examples/grl.nim
[3] https://news.ycombinator.com/item?id=24842648
[4] https://github.com/mratsim/weaveI love this language so much, I am so happy to see this much momentum coming from Araq and the gang. They are very kind people that help you in the Discord server.
For all the help I've been given for free time and time again by these guys, I'm working on a series of exercises to hopefully minimize the onboarding time for people looking to explore Nim. https://github.com/sergiotapia/nimlings
I find a lot of Nim syntax just unnecessarily noisy. I wish that it had stuck much closer to Python syntax.
I'm really excited about Nim, don't get me wrong. I like Araq, he's got a real hacker spirit not oft found at the head of big projects.
Anyhow. I'm sure the experts in that topic will sort it all out. ORC is wildly impressive all around.
I'm writing Nim every day recently; I haven't experienced it being noisy, but I also don't have extensive or recent experience with Python.
I'm on phone, so hopefully this paste doesn't look awful, but it's right from the website homepage
iterator oddNumbers[Idx, T](a: array[Idx, T]): T = for x in a: if x mod 2 == 1: yield x
The three different sets of brackets, the mixed : and =, it just seems inelegant to me.
I don't really know how I'd improve it, so it's just pointless, ignorant complaining on my part. Pay me little mind.
T = TypeVar("T")
def odd_numbers(a: list[T]) -> Iterator[T]:
# implementation
I don't really find that less verbose, in terms of brackets and symbols…You import module X, which gets you objects as defined in the module Y. To use methods defined for that type, you need to import Y yourself. Python, of course, by virtue of binding objects to methods, doesn't need it.
There are some more namespacing quirks that may require one to give up on that sweet syntactic sugar to disambiguate things (two unrelated modules defining methods on a single type, with the same signature but different behaviors, and you need both modules imported for some reason?), but this is, again, something one would have to get used to. It's not a different world like Rust or Prolog.
It's not a complete showstopper, just something I keep bumping my head into now and then.
It's a good practice to re-export "all modules whose types appear in public symbols of the current module".
For that and other good advice, see The Status Nim style guide:
https://status-im.github.io/nim-style-guide/03_language.html...
The one thing that stuck out to me like a sore thumb is the camelCase convention. I know it's a minor thing (and a personal preference), but I'm a bit biased against languages that use camelCase (Java, JavaScript, etc). There's something uneasy about it IMHO.
https://nim-lang.github.io/Nim/manual.html#lexical-analysis-...
my_foo, myfoo, and myFoo are interchangeable. MyFoo is different because the first letter is capitalized.
If it's not clear, what I mean is that if you've imported a module that exports myFoo, you can refer to it in your code as my_foo, if you prefer.
Some people love this aspect of Nim, others loathe it. I don't have strong feelings about it, though one has to be mindful of it when searching through a codebase with e.g. the_silver_searcher.
God, that's horrible.
I'm confused, two of those are myFoo, so I hope they are interchangeable!
I wonder if there is sufficient interest in having a python stdlib compatible library for nim.
That’s fine, I can use other languages and it doesn’t take anything away from Rust or the people who love the syntax.
proc `'i128`(n: string): Int128 = parseDecimalInt128(n)
assert fib(184) == 127127879743834334146972278486287885163'i128
It's so sexy!IMO the main case is when you need C speed but you don't want to code in C.
I'm always open to suggestions etc. as to what's missing in ggplotnim [0]. I'd hope that by now the majority of use cases are covered.
I wish more languages would take this approach. Modules that are officially endorsed and shipped with the compiler, but versioned rather than perma-stable like the standard library.
It would work fantastically for lots of Rust's defacto standard crates.