LWDR (Light Weight D Runtime) is a ground-up implementation of a D runtime targeting the ARM Cortex-M microcontrollers and other barebones environments. It works by providing a series of basic API hooks (as defined in rtoslink.d that you must implement and/or point to your RTOS implementation.
This is V0.3.0 of LWDR. Since V0.2.3, the following has been worked on:
- Thread Local Storage support
- Primitive memory tracking for Phobos allocations that would normally rely on a GC
- Transition to an opt-in system
- Replacement of
LWDR.free(..)due to deprecation
- Source code documentation improvements
Thread Local Storage
This feature is rather abstract, and it is an opt-in with version
LWDR_TLS. You must provide support in your linker script for
tbss sections. It works by utilising the underlying RTOS's TLS implementation (example). When
LWDR.registerCurrentThread() is called a block of D memory is allocated containing the TLS variables for the current thread, and the pointer to the block is stored in the thread's TCB (Thread Control Block). When a TLS variable (ie, a static variable) is accessed,
__aeabi_read_tp is called, yielding the pointer.
This is very primitive. It's only meant to assist with stopping GC-reliant stdlib allocations from leaking. It pretty much behaves as defined here.
To be able to keep the size of
TypeInfo vtables down and such, LWDR has adopted an opt-in system, which relies on D's version feature. The current opt-ins are:
LWDR_TLS- Enables TLS support
LWDR_DynamicArray- Enables dynamic arrays
LWDR_TrackMem- Enables the mess above.
delete has been deprecated.
LWDR.free has been implemented in its place to prevent compiler warnings.
Source Code Documentation
Runtimes are hairy and scary - so I'm beginning to put more effort into documenting how things work. So far, it's only ddoc comments.
To alleviate the lack of GC, I have implemented an LWDR-specific solution inspired by automem.
- Class allocations and deallocations (via
- Struct heap allocations and deallocations (via
- Contract programming
- Basic RTTI (via
- Static Arrays
- Virtual functions and overrides
- Abstract classes
- Static classes
- Allocation and deallocation of dynamic arrays (opt in by version
- Concatenate an item to a dynamic array (opt in by version
- Concatenate two dynamic arrays together (opt in by version
- Dynamic array resizing (opt in by version
- Thread local storage (opt in by version
What doesn't work?
- Exceptions and Throwables (experimental implementation was removed)
- Module constructors and destructors
- Static constructors and destructors
- Shared static constructors and destructors
- Module info
- There is no GC implementation (primitive memory tracking is now available with
Unique!Tare now available)
- Associative arrays
- Object monitors
- Object hashing
- Other things I can't remember off the top of my head.
It's still a beta - so expect bugs and warts. Some bits have been thoroughly tested, others not so much.
Because the runtime has ballooned so quickly, I want to pause on development for a little bit so that I can begin using LWDR in a proper project and find and squash bugs. The project is pretty much the successor to my Driving with D article (it's an automotive project). I'm also thinking of applying with LWDR to the Autumn of Code thingo.