So not that it is doing more than calling the fib function, but I got Roc running on a microcontroller. Specifically a microbitv2 running a cortex-m4.
18:47:49.263 Acording to Roc, the fib of 39 is...
18:47:49.263 63245986
18:47:49.263 Acording to Roc, the fib of 40 is...
18:47:49.263 102334155
18:47:49.263 Acording to Roc, the fib of 41 is...
18:47:49.263 165580141
18:47:49.294 Acording to Roc, the fib of 42 is...
18:47:49.294 267914296
18:47:49.294 Acording to Roc, the fib of 43 is...
18:47:49.294 433494437
18:47:49.294 Acording to Roc, the fib of 44 is...
18:47:49.294 701408733
18:47:49.325 Acording to Roc, the fib of 45 is...
18:47:49.325 1134903170
18:47:49.325 Acording to Roc, the fib of 46 is...
18:47:49.325 panicked at 'Roc panicked: 0x7be1 0', src/05-led-roulette/src/main.rs:20:5
Really easy to get Roc to panic. Not fully sure why. Not specifically related to the value passed in. Like if I add more debug printing, Roc will panic more easier. It is a very strange side effect I guess.
This topic was moved here from #compiler development > casual conversation by Richard Feldman
Also, it looks to be running at the same speed as the while loop rust version. Both taking about 260ms to calculate the fib 10000 times.
Though linking in roc adds about 3000B while the rust fib function is like 100B.
20:36:02.026 Calculating fib(92) 10000 times in roc
20:36:02.278 Result: 7540113804746346429
20:36:02.278 Calculating fib(92) 10000 times in rust linear
20:36:02.542 Result: 7540113804746346429
This is the max fib that fits into a u64
. Any higher and roc would panic.
Roc calculating prime numbers and then displaying them in binary on an led display. The host passes a model (u64) to roc. Roc returns the next model and a 2d array to set the display to. Each iteration roc calculates the highest prime under the models value. microbit-primes.mp4
very cool!
woah that's cool!
@Brendan Hansknecht is this code up anywhere? I'm interested in trying to get Roc going on an esp8266
https://github.com/bhansconnect/roc-microbit
I haven't touched in a long while though, so it probably won't work if you update to the newest version of the compiler...but not fully sure
Can probably fix it up if you need help. (probably even have an esp8266 sitting around to test it on)
Also, you may want to try and use something based on the embassy branch. Embassy is a nicer/newer framework, but may not support as many chips especially with limited support for hardware/more manual setup if trying a different chip.
Might be more of a reference for how you would do things on an esp8266. It looks like esp8266 may need to use a different rust based framework or c++ framework.
Yeah I was thinking I would write the platform in c++, as that's what I'm used to using w/ esp8266. no idea how hard it will be to get everything playing nice though :sweat_smile:
any special reason it's got roc
as a git submodule? Is it just to pin to a specific version?
Yeah, keeps it separate from my roc that I am working on, pins to specific version, and makes the repo more self contained.
And yeah, C++ should be totally fine.
Probably easier
oh I see you needed to make changes to roc to get it to target microbit
I assume I'll need similar changes?
Yeah
espessif has their own llvm fork that's used https://github.com/espressif/llvm-project
Oh...that may be problematic if it is need...or well, it would probably just require you telling roc to use that fork, so probably not terrible if it is up to date
yeah they have a llvm13 release
You might be able to just target the same architecture with roc
Yeah, then probably not to bad. Just build roc with that as your llvm path
forget the exact correct term here
And then add in the target like I did for the microbit
so, I have almost no understanding of how llvm works, but I know there's some sort of pseudo-assembly. Is there a way to have roc just output llvm-asm, and then externally bundle that up & link & such?
that way I wouldn't need roc to know anything about the custom llvm fork, or the architecture as much (?)
Technically yes, but it is probably easier to have roc just spit out an object file
As long as you get the architecture right, it should still run fine. I assume the custom version of LLVM is mostly for the hardware mapping more so than the assembly instruction type.
Also, compiling roc with a different llvm that you already have on your machine should be easy. Should just be setting an environment variable to point to the correct version of llvm
Otherwise, if you add --debug, it will dump the llvm ir which you can theoretically use as input.
ok cool. So by "getting the architecture right", I'm guessing the 8266 is RISC-V? the wikipedia page just says "RISC" so I'm not 100% sure.
oh wait maybe it's called xtensa
It would be whatever the llvm target flag would get set to. Also, forget the esp8266 was the risc-v one. Fancy.
oh I guess it's just risc-based, not quite risc-v. any ideas on what the Environment
would be?
:thinking: ok anyway I've got the xtensa llvm set up as my LLVM_SYS_130_PREFIX
, but now cargo can't build roc at all :grimacing: because the cc
doesn't know how to build for x86_64. Am I supposed to set the LLVM_SYS_130_PREFIX only when running the cli, and not during cargo build
?
oof zig doesn't have xtensa support in core. that might be one blow too many
hmmmm but someone has gotten zig to work with xtensa apparently :thinking: https://github.com/inetbowser/zig-xtensa
Oh. That might be more complicated than I expected. I would have guessed it still supported x86 building
But yeah, needs to be set during build
it's possible it would know how to do x86 if I build from source; I'm just working with the release bundle they put out.
Technically not really more complicated on the roc side than the prime example. Mostly was pipelining on the rust side to control the robot and exposing that to roc.
coooooooooool :heart_eyes: :heart_eyes: :heart_eyes:
Last updated: Jul 05 2025 at 12:14 UTC