Getting Embedded with D (the programming language)

我的未来我决定 提交于 2019-12-20 16:57:45

问题


I like a lot of what I've read about D.

  • Unified Documentation (That would make my job a lot easier.)
  • Testing capability built in to the language.
  • Debug code support in the language.
  • Forward Declarations. (I always thought it was stupid to declare the same function twice.)
  • Built in features to replace the Preprocessor.
  • Modules
  • Typedef used for proper type checking instead of aliasing.
  • Nested functions. (Cough PASCAL Cough)
  • In and Out Parameters. (How obvious is that!)
  • Supports low level programming - Embedded systems, oh yeah!

However:

  • Can D support an embedded system that not going to be running an OS?
  • Does the outright declearation that it doesn't support 16 bit processors proclude it entirely from embedded applications running on such machines? Sometimes you don't need a hammer to solve your problem.
  • Garbage collection is great on Windows or Linux, but, and unfortunately embedded applications sometime must do explicit memory management.
  • Array bounds checking, you love it, you hate it. Great for design assurance, but not alway permissable for performance issues.
  • What are the implications on an embedded system, not running an OS, for multithreading support? We have a customer that doesn't even like interrupts. Much less OS/multithreading.
  • Is there a D-Lite for embedded systems?

So basically is D suitable for embedded systems with only a few megabytes (sometimes less than a magabyte), not running an OS, where max memory usage must be known at compile time (Per requirements.) and possibly on something smaller than a 32 bit processor?

I'm very interested in some of the features, but I get the impression it's aimed at desktop application developers.

What is specifically that makes it unsuitable for a 16-bit implementation? (Assuming the 16 bit architecture could address sufficient amounts of memory to hold the runtimes, either in flash memory or RAM.) 32 bit values could still be calculated, albeit slower than 16 bit and requiring more operations, using library code.


回答1:


I have to say that the short answer to this question is "No".

  • If your machines are 16 bit, you'll have big problems fitting D into it - it is explicitly not designed for it.
  • D is not a light languages in itself, it generates a lot of runtime type info that normally is linked into your app, and that also is needed for typesafe variadics (and thus the standard formatting features be it Tango or Phobos). This means that even the smallest applications are surprisingly large in size, and may thus disqualify D from the systems with low RAM. Also D with a runtime as a shared lib (which could alleviate some of these issues), has been little tested.
  • All current D libraries requires a C standard library below it, and thus typically also an OS, so even that works against using D. However, there do exist experimental kernels in D, so it is not impossible per se. There just wouldn't be any libraries for it, as of today.

I would personally like to see you succeed, but doubt that it will be easy work.




回答2:


First and foremost read larsivi's answer. He's worked on the D runtime and knows of what he's talking about.

I just wanted to add: Some of what you asked about is already possible. It won't get you all the way, and a miss is as good as a mile here but still, FYI:

Garbage collection is great on Windoze or Linux, but, and unfortunately embedded apps sometime must do explicite memory management.

You can turn garbage collection off. The various experimental D OSes out there do it. See the std.gc module, in particular std.gc.disable. Note also that you do not need to allocate memory with new: you can use malloc and free. Even arrays can be allocated with it, you just need to attach a D array around the allocated memory using a slice.

Array bounds checking, you love it, you hate it. Great for design assurance, but not alway permissable for performance issues.

The specification for arrays specifically requires that compilers allow for bounds checking to be turned off (see the "Implementation Note"). gdc provides -fno-bounds-check, and in dmd using -release should disable it.

What are the implications on an embedded system, not running an OS, for multithreading support? We have a customer that doesn't even like interrupts. Much less OS/multithreading.

This I'm less clear on, but given that most C runtimes allow turning off multithreading, it seems likely one could get the D runtime to disable it as well. Whether that's easy or possible right now though I can't tell you.




回答3:


The answers to this question are outdated:

Can D support an embedded system that not going to be running an OS?

D can be cross-compiled for ARM Linux and for ARM Cortex-M. Some projects aim at creating libraries for Cortex-M architectures like MiniLibD for the STM32 or this project which uses a generic library for the STM32. (You could implement your own minimalistic OS in D on ARM Cortex-M.)

Does the outright declearation that it doesn't support 16 bit processors proclude it entirely from embedded applications running on such machines? Sometimes you don't need a hammer to solve your problem.

No, see answer above... (But I would not expect that "smaller" architectures than Cortex-M will be supported in the near future.)

Garbage collection is great on Windows or Linux, but, and unfortunately embedded applications sometime must do explicit memory management.

You can write Garbage Collection free code. (The D foundation seems to aim at a "GC free compliant" standard library Phobos but that is work in progress.)

Array bounds checking, you love it, you hate it. Great for design assurance, but not alway permissable for performance issues.

(As you said this depends on your "personal taste" and design decisions. But I would assume an acceptable performance overhead for bound checking due to the background of the D compiler developers and D's design aims.)

What are the implications on an embedded system, not running an OS, for multithreading support? We have a customer that doesn't even like interrupts. Much less OS/multithreading.

(What is the question? One could implement mutlithreading using D's language capabilities e.g. like explained in this question. BTW: If you want to use interrupts consider this "hello world" project for a Cortex-M3.)

Is there a D-Lite for embedded systems?

The SafeD subset of D targets at the embedded domain.



来源:https://stackoverflow.com/questions/1207958/getting-embedded-with-d-the-programming-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!