This is what comes to my mind when I think of D: fast, expressive, light and ... driving? That's right, I drive with D.
Here is my venerable Holden VZ Ute car . It came from the factory with a squalid four-speed automatic transmission. In 18 months of owning a car, I broke four gearboxes. At the time, I couldn't afford a new car, so I had to be creative. I bought a reinforced concrete, foolproof six-speed automatic transmission from another car. But on this I ran into a dead end. To make it work, I had to build my own PCB, control system, and firmware to control the solenoids, hydraulics, and clutches inside the gearbox, process driver commands, make gear change decisions, and interact with the car, pretending to be a four-speed automatic.
I am very proud of my decision. It can switch in 250 milliseconds, which is great for racing. It has a steep first gear for a quick start. It gave odds to some of the more powerful cars. It has handy paddle shifters, on-screen diagnostic data, and the ability to change how it works whenever I want.
Here's a very old video of how the system works. It is not indicative of the current system - that terrible blue screen has disappeared, the speedometer is working, and the gearshift has improved.
: , OLED- STM32F042, , , STM32F407. CAN (Controller Area Network). D.
D ( -betterC) - (UFCS), , C, -, , shared
@safe
. - , . D , .
D
. , , . , , ECU ( ):
immutable injectorTime = airStoich(100.kpa, 25.degCelsius)
.airMass
.fuelMass((14.7f).afr)
.fuelMol
.calculateInjectorWidth;
, . .
" " (DRY) . D . CAN. :
struct CANPacket(ushort ID) {
enum id = ID;
ubyte[8] data;
}
alias HeartbeatPacket = CANPacket!10;
alias BeepHornPacket = CANPacket!140;
HeartbeatPacket
BeepHornPacket
, . , CANPacket
, .
HAL RTOS ; D's C . extern(C)
, .
extern(C) c_setPwm(int solenoid, void* userData); // declaration
c_setPwm(4, null); // usage, pretty easy!
D - . Windows, , .
, D GDC LDC. D, C++ (). LDC, - .
Shared - D () . , , , . , . , , . . shared . .
shared int sensorValue;
sensorValue = 4; // using it like a single-thread variable, error
atomicStore(sensorValue, 4); // works with atomics
@safe
, . @safe
, , , , .
. : D . . D. , , D - , .
D - , . D . D, .
:
, .
-BetterC, , (GC) .
, BetterC , .
D ? - .
D ? - .
D
LWDR (Light Weight D Runtime) v0.3.0 -
LWDR (Light Weight D Runtime) - D, ARM Cortex-M . , API ( rtoslink.d, / RTOS).
V0.3.0 LWDR. V0.2.3, :
(Thread Local Storage, TLS)
Phobos, GC
(opt-in)
delete
LWDR.free(...)
RefCount!T
Unique!T
, LWDR
Thread Local Storage
, LWDR_TLS
. tdata
tbss
. , TLS RTOS (). LWDR.registerCurrentThread()
D, TLS , TCB (Thread Control Block) . TLS (.. ) __aeabi_read_tp
, .
(opt-in)
TypeInfo
vtables , LWDR opt-in, version D. :
LWDR_TLS
- TLS
LWDR_DynamicArray
-
LWDR_TrackMem
- (.)
delete
- , , . ddoc.
RefCount!T Unique!T
(GC), LWDR , automem.
Class allocations and deallocations (via
new
andLWDR.free
)
Struct heap allocations and deallocations (via
new
andLWDR.free
)
Invariants
Asserts
Contract programming
Basic RTTI (via
TypeInfo
stubs)
Interfaces
Static Arrays
Virtual functions and overrides
Abstract classes
Static classes
Allocation and deallocation of dynamic arrays (opt in by version
LWDR_DynamicArray
)
Concatenate an item to a dynamic array (opt in by version
LWDR_DynamicArray
)
Concatenate two dynamic arrays together (opt in by version
LWDR_DynamicArray
)
Dynamic array resizing (opt in by version
LWDR_DynamicArray
)
Thread local storage (opt in by version
LWDR_TLS
)
()
Exceptions and Throwables ( )
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
LWDR_TrackMem
,RefCount!T
andUnique!T
are now available)
Delegates/closures
Associative arrays
Object monitors
shared
/synchronised
Object hashing
, .
- - . , - .
, , LWDR . Driving with D ( ) (. - ). LWDR Autumn of Code.
LWDR , , , ctor/dtor (, ..).