静态类型 Lua [英] Statically typed Lua

查看:28
本文介绍了静态类型 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天全站免登陆