静态类型Lua [英] Statically typed Lua

查看:112
本文介绍了静态类型Lua的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个在编译时进行类型检查的Lua前端编译器,但输出标准的Lua 5.1字节码(只有运行时类型)。我想要的是大量的静态,编译时语法分析和可选的打字,以检测琐碎的错误比运行时更快。生成的字节代码必须很好地与用标准LoadString()编译的现有Lua字节代码一起播放。

I am looking for a Lua front-end compiler that is type-checked at compile time, but outputs standard Lua 5.1 byte-code (that has only run-time types). What I want is a decent amount of static, compile-time syntactic analysis and optional typing, to detect trivial errors sooner than run-time. The resulting byte-code would have to play nicely with existing Lua byte-code that was compiled with the standard LoadString().

要清楚 - 任何差异只会发生在字节编译时。在运行时,字节码不知道在编译阶段发生了什么不同/不寻常的事情。

To be clear -- any difference would only occur at byte-compilation time. At runtime, the byte code would have no idea that anything different/unusual happened to it during the compile phase.

我的想法听起来很像ActionScript;我甚至不介意输出Lua字节码的ActionScript编译器!

What I have in mind sounds a lot like ActionScript; I wouldn't even mind an ActionScript compiler that outputs Lua byte code!

有没有人听说过这样的努力?我已经看到一些引用使用MetaLua来做到这一点,但老实说,我不够明亮,他们的文档的头部头。

Has anyone heard of such an effort? I've seen some references to using MetaLua to do this, but honestly I am not bright enough to make heads of tails of their documentation

推荐答案

在2005年的夏天或那天,我与一个令人难以置信的聪明的本科生一起工作的问题Lua的一些编译时类型推断,可能由注释辅助。这个问题变得难以置信! (我的学生写了一个简短的技术说明,但它不是真正打算用于一般流通。)

In the summer of 2005 or thereabouts, I worked with an incredibly smart undergraduate student on the problem of doing some compile-time type inference for Lua, possibly assisted by annotations. This problem turns out to be incredibly hard! (My student wrote a short technical note, but it's not really intended for general circulation.)

如果我想解决你提出的问题,它允许重要的静态类型检查,并且它与标准的字节码编译的Lua代码互操作,
我会从头设计一种新的语言以满足这两个约束。这将是一个相当大量的工作,但显着简化了尝试改造一个类型系统到Lua。

If I wanted to solve the problem you have posed, with the twin constraints that it allow significant static type checking and that it interoperate with standard bytecode-compiled Lua code, I would design a new language from scratch to satisfy these two constraints. It would be a substantial amount of work but significantly easier than trying to retrofit a type system to Lua.

这篇关于静态类型Lua的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆