哪些框架/语言支持运行时类创建?

发布于 2024-09-06 22:55:06 字数 134 浏览 3 评论 0原文

我正在尝试整理一系列支持运行时类创建的框架/语言。例如,在 .NET 中,您可以使用 System.Reflection.Emit 库在运行时发出新类。如果您可以提及支持此功能(或其某些变体)的其他框架/语言,那将非常有帮助。

谢谢 :)

I'm trying to put together a list of frameworks/languages support run-time class creation. For example in .NET you can use the System.Reflection.Emit library to emit new classes at run time. If you could mention other frameworks/languages that support this (or some variation of it), that'd be really helpful.

Thanks :)

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

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

发布评论

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

评论(4

星軌x 2024-09-13 22:55:06

动态语言,如 Python、Ruby...

Dynamic languages like Python, Ruby, ...

甜中书 2024-09-13 22:55:06

Objective-C 支持它(objc_allocateClassPair)

Objective-C supports it (objc_allocateClassPair)

娇妻 2024-09-13 22:55:06

在 JavaScript 中,函数是对象。因此,给定一个函数定义:

function Foo(x, y, z)
{
        this.X = x;
        this.Y = y;
        this.Z = z;  var g = function()

}

您可以像这样创建一个新对象:

var obj = new Foo(a,b,c);

但在 JavaScript 中,您可以在运行时创建函数。

function MakeFoo(x, y, z, f) //where parameter f is a function
{
    var g = function()
    {

        this.X = x;
        this.Y = y;
        this.Z = z;
        this.DoSomething = f;
    }

    return g;

}

var my_class = MakeFoo(a, b, c, function() { /* Do Stuff */ });
var obj = new my_class();

obj.DoSomething();

In JavaScript functions are objects. Thus given a function definition like:

function Foo(x, y, z)
{
        this.X = x;
        this.Y = y;
        this.Z = z;  var g = function()

}

you can create a new object like this:

var obj = new Foo(a,b,c);

But in JavaScript you can create functions at runtime.

function MakeFoo(x, y, z, f) //where parameter f is a function
{
    var g = function()
    {

        this.X = x;
        this.Y = y;
        this.Z = z;
        this.DoSomething = f;
    }

    return g;

}

var my_class = MakeFoo(a, b, c, function() { /* Do Stuff */ });
var obj = new my_class();

obj.DoSomething();
情仇皆在手 2024-09-13 22:55:06

根据您的意思,任何语言都可以。

例如C++就可以。乍一看,这是荒谬的——C++ 是一种静态类型编译语言。因此,您要做的就是将 LLVM 库包含在您的项目中。这是一个编译器后端,您可以使用它来描述您的类、编译它们并使用 LLVM JIT 运行它们,所有这些都在您的应用程序运行时进行。

IIRC,gcc 后端是用 C 编写的,因此如果您愿意弄清楚该代码,原则上您可以使用甚至没有类的语言在运行时定义类。

无论哪种方式,您工作的一部分是定义类到底是什么 - 它不是内置于编译器后端的,因为它们应该支持具有不同类型系统的一系列不同前端语言。

当然,我并不是推荐这种方法——只是指出它是可能的。

Depending on what you mean, any language can.

For example, C++ can. At first sight, this is absurd - C++ is a statically typed compiled language. So - what you do is include the LLVM library in your project. This is a compiler back-end, and you can use this to describe your classes, compile them, and run them using the LLVM JIT, all at run-time for your application.

IIRC, the gcc back end is written in C, so if you're willing to figure out that code, you could in principle define classes at run-time using a language that doesn't even have classes.

Either way, part of your job is to define what exactly a class is - that isn't built into the compiler back ends as they are supposed to support a range of different front-end languages with different type systems.

Of course I'm not recommending this approach - just pointing out that it's possible.

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