by janekm · 7y ago · 0 comments
There's also the beginnings of a sensor manager and API so clearly small embedded use cases are intended.
It's still a very small project (looks like one contributor so far), but that's no bad thing...
https://github.com/tinygo-org/tinygo/
No garbage collector yet, but it's on the ToDo list and probably not too far off. :)
Such code would not be able to do I/O directly, but must receive it from outside the sandbox. It could be a pure function implementing a state machine on form `state, outputs = next(state, inputs)`, where state,inputs and outputs are plain data. This structure is amendable to generating testcases, be it via property testing or fuzzing. Or regression tests by capturing a stream of state transitions in serialized form.
There are languages which makes this possible, like Haskell, or maybe even Rust or Ada. However in the embedded world, C is what everyone knows and uses, so there would be a benefit to staying within that ecosystem.
I work in embedded development and the amount of pure logic is really small in our software but I guess that varies with the niche you're in.
The traditional way to simplify QA is to use a Hardware Abstraction Layer in the code, which hardware side-effects happen through. So you have a classic layer cake like:
| App Logic (imperative, stateful) |
| Hardware Abstraction Layer (interface) |
| Input/Output (implementations) |
Then during testing of the software application logic, a mocked implementation of the HAL can be used. When done with due care, this works OK.
In this basic model it is OK to read input and cause outputs "anywhere" in the application logic. That is easy and convenient, but (I argue) that this causes pure logic to be rare. Which is unfortunate, since it would be much easier to test. State also tends to be spread across the code-base, which can hide stateful behavior that is critical to test.In the proposed model, the HAL functionality is split into two distinct parts: input and output drivers. And the application logic does not call the HAL, but gets called with Input and produces a description of Output. So the layer cake kinda tips sideways:
HW input driver > Input (data) > App Logic (pure) > Output (data) > HW output driver
| |
< State <
During test of application logic we have: input generator -> App Logic -> output capture
and can then perform validations on who sequences of Input/Output pairs. And debugging can trivially access whole sequences of State changes.Those familiar with dataflow programming might find this very familiar. Frontend people might see parallels to unidirectional flow of data in reactive UI frameworks like React. Simulation minded people might see that this structure is very amendable to Discrete-Event Simulation.
I have used this model to good effect across many (relatively simple) embedded/IoT systems over the last few years. One thing I really like, is that it makes temporal logic very easy. Because in this model the current time (be it ticks or wall-time) is just a type of input. So it is easy to stimulate, visualize and make assertions across whole timelines of behavior, and one can see many such timelines at the same time. Similar to what Brett Victor showed with Mario in Inventing on Principle.
Have been meaning to write more about this for a long time, so apologies for the mini blogpost :) Some very related writing in http://www.jonnor.com/2017/03/host-based-simulation-for-embe...
PS: the comment by pault is to the point, and right on the money.
WASM was made with running on regular desktop CPUs in mind. Wasm is not a truly a state machine, nor stack machine, but a horrible hybrid in between them thanks to design by committee.
Changeable locals, accessible undefineds, use of stack pointer protection technique that kills both pipelining and speculative execution. Yes, that's combined downsides of both stack and register VMs.
There were MCU that were naively running Java long time ago, but all failed on the market. The idea proved non feasible
To be clear, this is also interpreted, so it doesn't have an advantage there.
Not sure they failed for technical reasons, embedded CPUs just got fast enough and typical memory big enough to run a JIT.
Really no value there. The positive connotation of "web native" label is not so positive in the world of dour and severe people which "hardcore embedded developers" are.