对于开发爱好语言来说,什么是好的 VM?

发布于 2024-08-19 08:19:11 字数 472 浏览 7 评论 0原文

我正在考虑编写自己的小语言。

我找到了一些选择,但请随意提出更多建议。

  • JVM
  • Parrot
  • OSA

许多语言都在使用 JVM,但除非您编写类似 Java 的语言,否则 stdlib 提供的所有功能都会让您感到丑陋;它也不太擅长动态的东西。

Parrot 似乎是开发语言的一个很好的虚拟机,但它有一点废弃/未完成/业余爱好项目的味道。

OSA 是 Applescript 的动力源,它不是一个特别知名的虚拟机,但我使用 Mac,它提供了良好的系统集成。

CLR+Mac 似乎不是一个很好的组合...

我的语言将是一种面向对象的函数式并发数据流语言,具有强类型以及 Python 和 Lisp 语法的混合。 听起来不错,是吗?

[编辑]
我暂时接受了 Python,但我想了解更多有关 OSA 和 Parrot 的信息。

I'm thinking about writing my own little language.

I found a few options, but feel free to suggest more.

  • JVM
  • Parrot
  • OSA

A lot of languages are using the JVM, but unless you write a Java-ish language, all the power the stdlib gives you is going to feel ugly; It's not very good at dynamic stuff either.

Parrot seems a good VM for developing languages, but it has a little abandoned/unfinished/hobby project smell to it.

OSA is what powers Applescript, not a particularly well known VM, but I use Mac, and it offers good system integration.

CLR+Mac doesn't seem a good combination...

My language is going to be an object orientated functional concurrent dataflow language with strong typing and a mix of Python and Lisp syntax.
Sounds good, eh?

[edit]
I accepted Python for now, but I'd like to hear more about OSA and Parrot.

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

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

发布评论

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

评论(4

友欢 2024-08-26 08:19:11

我使用过的一种方法是使用 Python ast 模块来构建表示要运行的代码的抽象语法树。 Python compile 函数可以编译 AST转换为 Python 字节码,然后 exec 可以跑步。这比直接生成字节码要高一些,但是您必须处理 Python 语言的一些怪癖(例如,语句和表达式之间的根本区别)。

在此过程中,我还编写了一个“deparse”模块,尝试将 AST 转换回等效的 Python 源代码,仅用于调试。如果您有兴趣,可以在 psil 存储库中找到代码。

One approach I've played with is to use the Python ast module to build an abstract syntax tree representing the code to run. The Python compile function can compile an AST into Python bytecode, which exec can then run. This is a bit higher level than directly generating bytecode, but you will have to deal with some quirks of the Python language (for example, the fundamental difference between statements and expressions).

In doing this I've also written a "deparse" module that attempts to convert an AST back to equivalent Python source code, just for debugging. You can find code in the psil repository if you're interested.

梦醒灬来后我 2024-08-26 08:19:11

查看 LLVM。它本身并不是一个纯粹的虚拟机,而是一个具有自己的 IR 的框架,允许您构建高级虚拟机。有静态代码分析和 JIT 支持等好东西

Have a look at LLVM. It's not a pure VM as such, more a framework with it's own IR that allows you to build high level VMs. Has nice stuff like static code analysis and JIT support

你爱我像她 2024-08-26 08:19:11
  • Lua 有一个小型、编写良好且快速的 VM
  • Python VM - 如果您愿意,您确实可以将一种新语言附加到它上面。或者编写(使用?)类似tinypy 的东西,它是Python VM 的一个小型且简单的实现。

上面的两个选项都可以访问有用的标准库,这将节省您的工作,并且都是用相对干净和模块化的 C 语言编码的,因此它们应该不难连接。

也就是说,我不同意鹦鹉被遗弃/爱好。它相当成熟,并且有一些非常强大的开发人员正在开发它。此外,它是专门为多种动态语言而设计的虚拟机。因此,设计时考虑到了灵活性。

  • Lua has a small, well-written and fast VM
  • Python VM - you can really attach a new language to it if you want. Or write (use?) something like tinypy which is a small and simple implementation of the Python VM.

Both options above have access to useful standard libraries that will save you work, and are coded in relatively clean and modular C, so they shouldn't be hard to connect to.

That said, I disagree that Parrot is abandoned/hobby. It's quite mature, and has some very strong developers working on it. Furthermore, it's specifically a VM designed to be targeted by multiple dynamic languages. Thus, is was designed with flexibility in mind.

微暖i 2024-08-26 08:19:11

你考虑过Pypy吗?据我了解,除了作为 Python JIT 编译器之外,它还具有处理其他语言的能力。例如,有教程解释了如何使用 Pypy 创建 Brainfuck JIT 编译器。

Have you considered Pypy? From what I've read, in addition to being a Python JIT Compiler, it also has the capability to handle other languages. For example there is a tutorial which explains how to create a Brainfuck JIT compiler using Pypy.

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