除了 Scala 之外,还可以使用什么第二语言来实现 LowLevel?

发布于 2024-09-30 10:25:21 字数 1539 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

栖迟 2024-10-07 10:25:21

您几乎描述了 D。

  • 编译为机器代码:检查。有一个实验性的 .NET VM 实现,但所有三个主要实现(DMD、LDC、GDC)都直接编译为本机代码,并且该语言旨在使本机编译可行。

  • 轻松使用 C 库:D 支持 C ABI 和所有 C 类型。几乎您所要做的就是翻译 C 目标文件中的头文件和链接。这个甚至可以部分自动化。

  • 可以非常接近地进行编程硬件:检查。 D 是我所说的 C 的惯用超集。它不支持 C 语法的每一个部分,它的模块系统完全不同,静态数组是 D2 中的值类型,等等。但是,对于 C 语言中的任何构造(即排除预处理器)D 或标准库中有等效的构造。对于任何一段 C 代码(不包括滥用预处理器),都有一个规范的 D 翻译,它看起来大致相同,并且如果您使用相同的编译器后端,则应该生成相同的汇编语言指令。换句话说,每个 C 习惯用法(不包括滥用预处理器)都可以直接转换为 D。

    D 的参考实现还支持 内联 ASM,所以你可以搞乱与 SSE 等。

  • 当我想要执行以下操作时,可以以非常高级的方式进行编程:检查。 D 被设计为主要是垃圾收集语言(尽管如果您坚持并且小心不要使用假定 GC 的库/运行时功能,则可以使用手动内存管理)。除此之外,高级编程主要通过模板元编程来实现。 在你逃跑之前,请理解 D 中的模板元编程与 C++ 相比有了很大的改进。在 D 和 C++ 中进行模板元编程就像在 C++ 和 C 中进行面向对象编程一样。在 D 中模板元编程被设计到语言中,而在 C++ 中,有足够的功能,您可以使用聪明的 hackishness 使其几乎无法工作。对于 C++ 与 C 中的面向对象编程也可以这样说。 Phobos 的算法 和 std.range 模块就是很好的例子D 的高级子集。

You're pretty much describing D.

  • Compiled to machine code: Check. There is an experimental .NET VM implementation, but all three major implementations (DMD, LDC, GDC) compile directly to native code and the language is designed to make native compilation feasible.

  • Easy usage of C libraries: D supports the C ABI and all C types. Pretty much all you have to do is translate the header file and link in the C object file. This can even be partially automated.

  • Possible to program very close to the hardware: Check. D is what I'd call an idiomatic superset of C. It does not support every piece of C syntax, its module system is completely different, static arrays are value types in D2, etc. However, for any construct in the C language proper (i.e. excluding the preprocessor) there is an equivalent construct in D or the standard library. For any piece of C code (excluding preprocessor abuse) there is a canonical D translation that looks roughly the same and should generate the same assembly language instructions if you're using the same compiler backend. In other words, every C idiom (excluding preprocessor abuse) can be translated to D in a straightforward way.

    The reference implementation of D also supports inline ASM, so you can mess with SSE, etc.

  • Possible to program in a very highlevel-way when I want to: Check. D is designed to be primarily garbage-collected language (though you can use manual memory management if you insist and are careful not to use library/runtime features that assume GC). Other than that, high-level programming is mostly implemented via template metaprogramming. Before you run away, please understand that template metaprogramming in D is greatly improved compared to C++. Doing template metaprogramming in D vs. C++ is like doing object oriented programming in C++ vs. C. In D template metaprogramming is designed into the language, whereas in C++ there are just enough features that you can use clever hackishness to make it barely work. The same could be said for object-oriented programming in C++ vs. C. The std.algorithm and std.range modules of Phobos are good examples of the high-level subset of D.

若能看破又如何 2024-10-07 10:25:21

以下是一些满足您问题中提到的标准的内容:

Here are some that satisfy the criteria mentioned in your question:

魄砕の薆 2024-10-07 10:25:21

我也在考虑这个问题,因为我目前正在做一个 C 项目,感觉效率很低,而且也想念 Scala。 (我在更新世也做了很多C++...)我可能会转而去。 D看起来也很有吸引力。

如果对问题有意义的话,另一种选择是使用 C+ 脚本语言,例如 Lua 或 Ruby。这就是 Unix+shell 和 emacs 一直以来所做的事情。当您需要时,您可以获得性能和低级的操作,而当这更重要时,您可以获得生产力。

I'm thinking about this, too, as I'm currently doing a C project and feeling very unproductive, also missing Scala. (I also did a lot of C++ in the Pleistocene...) I may switch to go. D also looks attractive.

Another option, if it makes sense for the problem, is to use C + a scripting language, like Lua or Ruby. It's what Unix+shells and emacs have done forever. You get performance and low-level bit twiddling when you need it and productivity when that's more important.

寂寞清仓 2024-10-07 10:25:21

C++0X、Erlang,也许还有 Haskell 和 Go。 C++ 和 Erlang 拥有强大的用户基础,并且 C++0x 和 Erlang 提供了许多工作机会。 (我不确定 C/C++ 与 Go 的互操作性有多好)

C++0X(“cee plus plus oh ex”)是一个不错的选择。它具有 lamda 函数 和其他好东西

C++0X 演练 TechDays 2010:现代编程C++0x

此外,C++0X 具有良好的泛型支持,如 将类类型作为对象和隐式,Oliviera、Moors、Odersky、OOPSLA 2010。请参阅下面的图 12:

“图

C++0X, Erlang and maybe Haskell and Go. C++ and Erlang has a strong user base and there is many jobs avaliable with C++0x and Erlang. (I am uncertain how good the C/C++ interop is with Go)

C++0X ("cee plus plus oh ex") is a good option. It has lamda functions and other good stuff.

Walktrough of C++0X TechDays 2010: Modern Programming with C++0x

Also C++0X has good Generics support as documented in Type Classes as Objects and Implicits, Oliviera, Moors, Odersky, OOPSLA 2010. See their Figure 12 below:

Figure 12 from Type Classes as Objects and Implicits

红颜悴 2024-10-07 10:25:21

符合您要求的是 C/C++,因为您可以将汇编语言与常规代码内联。调用 C 库是很自然的:)

另一件合适的事情是 HLA汇编语言的实现(维基文章此处) - 它是包含很多内容的汇编高级结构使初学者学习起来更容易(更快)(它编译为“正确的”本机代码)。

Something that fits your requirement is C/C++, as you can inline assembly language with regular code. Calling C libraries will be natural :)

Another thing that fits is the HLA implementation of assembly language (wiki article here) - it is assembly with a lot of high level constructs to make things easier (and faster) for beginners to learn (it compiles to "proper" native code).

硪扪都還晓 2024-10-07 10:25:21

与 D 和 BitC 一样,ooc (http://www.ooc-lang.org/) 有一个许多吸引 Scala(或 Haskell)粉丝的功能。

Like D and BitC, ooc (http://www.ooc-lang.org/) has a lot of features that appeal to a Scala (or Haskell) fan.

柳若烟 2024-10-07 10:25:21

根据您的要求,我认为 Nimrod 也是一个有效的候选人。

I think Nimrod is also a valid candidate here based on your requirements.

百合的盛世恋 2024-10-07 10:25:21

您应该查看 Go

You should take a look at Go.

清浅ˋ旧时光 2024-10-07 10:25:21

它仍然很新,但请看一下 Vala。它是 GObject 蛋糕上的一层甜蜜的语法糖霜,并编译为纯 C。

它支持闭包和有限类型推断等功能。

It's still very new, but take a look at Vala. It's a sweet layer of syntactic frosting upon the GObject cake and compiled to pure C.

It supports features like closures and limited type inference.

つ可否回来 2024-10-07 10:25:21

考虑使用 C 或 C++ 进行最低级别的编程,然后使用 JNI 或 JNA 将其包装在 Scala 库中。在某些情况下,鱼与熊掌兼得。

Think about using C or C++ for the very lowest level programming, and then wrapping that with JNI or JNA in a Scala library. In some cases, you can have your cake and eat it too this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文