除了 C 之外,哪些没有运行时的编程语言适合编写编程语言?
我正在研究编写一种玩具编程语言的爱好,部分是因为对其他语言的小烦恼,部分是为了我能理解它是什么样的,但主要只是为了闲逛。
如果它真的有用,我不希望它依赖于另一种编程语言的运行时来运行用它编写的程序。也就是说,我希望解释器/编译器本身是一个本地编译到目标操作系统中的程序(语言本身可以被解释/提供运行时)。
除了C之外还有其他方法吗?有哪些优点/缺点或各自的用途?
说明 1:我不打算深入底层来编写内核、文件系统、设备驱动程序、引导加载程序。不过,我希望能够管理自己的记忆。
澄清 2:由于术语错误/误解,并且由于我非常习惯在各种操作系统上运行的 C 运行时,所以我说 C 没有运行时/或者我对运行时不感兴趣。表达我真正想要的更好的方式是我的程序本地编译到目标(桌面)操作系统中,而不需要从引导语言安装其他软件。
2.1:如果我用 python 编写编译器/解释器,我不希望发出的可执行文件依赖于 python 程序。
2.2:如果我使用编译步骤,例如,使用 perl 编译程序,我不希望生成的可执行文件依赖于 libperl.dll/so。
2.3:运行时是 C 的例外,因为 C 运行时通常安装在几乎所有桌面操作系统上,因为许多核心操作系统工具依赖于它。
I'm looking into a hobby of writing a toy programming language, partly from minor annoyances with other languages, partly so that I can understand what it's like, but mostly just to fool around.
On the off chance that it gets really useful, I don't want it to depend on the run-time of another programming language for programs written in it to run. That is, I want the interpreter / compiler to itself be a program compiled natively into the target OS (language itself may be interpreted / provide a run-time).
Is there any alternative to doing this besides C? What are some advantages / disadvantages or using each?
Clarification 1: I am not intending to go low-level enough to write kernels, filesystems, device drivers, boot loaders. However I would like to be able to manage my own memory.
Clarification 2: Due to a terminology error / misunderstanding, and since I was so used to the C runtime running on various OS's, I said that C does not have a runtime / and or I am not interested in a runtime. A better way to say what I really want is that my programs compile natively into the target (desktop) OS without needing to install additional software from the bootstrapping language.
2.1: if I write the compiler/interpreter in python, I don't want the emitted executables to depend on the python program.
2.2: if I use a compiling step, for instance, to compile the programs using perl, I don't want the emitted executables to depend on a libperl.dll/so.
2.3: the exception is with runtimes is C since the C runtime is usually installed on almost all desktop OS's as many core OS tools depend on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用任何具有现有编译器的语言,该编译器可以生成没有依赖性的本机代码。 C 和 C++ 是非常好的选择,因为它们的运行时几乎到处都可用(在 C 中更是如此)。
在你的语言构建中,一种非常值得尝试的方法是:让你的编译器输出 C(或 C++)。然后,您可以使用围绕这些语言及其运行时的所有现有生态系统(链接器、对象转储器、调试器等),甚至计划与现有代码集成。
这些工具对于您的语言的用户很有用,而且显然对于您在尝试该玩具语言时您自己也很有用。
一旦你的语言达到“自托管”的程度(即你的编译器是用你自己的语言编写的),你将能够开始考虑废除整个 C 部分并编写一个本机代码编译器,及其运行时间。
祝你好运 :-)
另外请务必查看 LLVM。这是一个“编译器基础设施”。这可能是目前实施新语言的最佳起点。文档非常好,教程包括构建玩具语言。
You could use any language that has an existing compiler that emits native code without dependencies. C and C++ are pretty good bets because their runtimes are available pretty much everywhere (even more so in C).
One approach in your language build-up that could be well worth trying is this: make your compiler output C (or C++). Then you can use all the existing ecosystem around those languages and their runtimes (linkers, object dumpers, debuggers, etc...), even plan integration with existing code.
Those tools would be useful both for the users of your language, and obviously for yourself while you're experimenting on that toy language.
Once you get to the point where your language is "self-hosted" (i.e. your compiler is written in your own language), you'll be able to start thinking about doing away with the whole C part and write a native code compiler, with its runtime.
Good luck :-)
Also make sure you go look at LLVM. It's a "compiler infrastructure". That is probably the best place to start with these days to implement a new language. The documentation is pretty good, and the tutorials include building a toy language.
C 有一个运行时... C++ 的最小运行时比 C 稍大一些。 Ada 的某些实现具有编译指示,允许检查某些强制使用运行时的功能是否未使用(我想知道它们是否没有使用)后来标准化了,我在 90 年代末就不再遵循 Ada 标准化了),这使得它可能具有与 C 相同复杂性的最小运行时间。
C has a runtime... C++ has a slightly bigger minimal run-time than C. Some implementations of Ada have pragmas allowing to check that some features mandating the use of a run-time aren't used (I wonder if they weren't standardized later, I've stopped to follow Ada standardization in the late 90's), making it perhaps having a minimal run-time of the same compexity as C.
PyPy 使用 RPython 来实现 python 语言。这对你有用吗?
PyPy usses RPython to implement python language. Will this work for you?
Haxe 是用 OCaml 编写的,我认为对于编写其他语言来说,这是一种非常好的语言。
http://haxe.org/
http://caml.inria.fr/
Haxe is written in OCaml, and I think this is a really good language for writing other languages.
http://haxe.org/
http://caml.inria.fr/
如果您要编写引导加载程序和内核,那么 C 就是您的语言,否则您使用哪种语言来开发语言并不重要。仅仅因为您的宿主语言具有运行时并不意味着您的目标语言也必须具有运行时。
但玩具语言当然需要运行时,例如 JVM/LLVM/.NET CLR。或者口译员。如果您不选择这些选择,则需要生成符合 ABI 的机器代码,这是非常痛苦的。
我建议您查看目标 llvm 并从那里生成机器代码,dalvik 也可能满足您的需求(因为它非常轻量)。
If your going to write bootloaders and kernels then C is your language, otherwise it doesn't matter what language you use to develop your language. Just because your host language has a runtime doesn't automatically mean your target language must have one.
But ofcourse toy languages need a runtime, for example a JVM/LLVM/.NET CLR. Or interpreters. If you don't go for these choices you need to generate machine code that conforms to a ABI, and that is very painfull.
I suggest you look target llvm and generate machine code from there, dalvik might also fit your needs (since it is extremely lightweight).
我认为 Python 最适合你。 Python 是一种编程语言,您可以更快速地工作并更有效地集成您的系统。您可以学习使用 Python,并立即看到生产力的提高和维护成本的降低。
最近,Python 已被移植到 Java 和 .NET 虚拟机。
最重要的是,Python 是免费的。
I think Python is best for you. Python is a programming language that you can work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.
Python, recently, has been ported to the Java and .NET virtual machines.
The most important, Python is free.