Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ch02-03.assignment.md #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ch02-03.assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Name = exp

- `local = const`,把常量加载到栈上指定位置,对应字节码`LoadNil`、`LoadBool`、`LoadInt`和`LoadConst`等。
- `local = local`,复制栈上值,对应字节码`Move`。
- `local = global`,把栈上值赋值给全局变量,对应字节码`GetGlobal`。
- `local = global`,把全局变量复制到栈上指定位置,对应字节码`GetGlobal`。

- `global = const`,把*常量*赋值给全局变量,需要首先把常量加到常量表中,然后通过字节码`SetGlobalConst`完成赋值。
- `global = local`,把*局部变量*赋值给全局变量,对应字节码`SetGlobal`。
Expand Down Expand Up @@ -152,4 +152,4 @@ print(g)

其次,等号`=`后面的表达式现在分为3类,对于3个字节码。后续如果要引入其他类型的表达式,比如upvalue、表索引(比如`t.k`)、或者运算结果(比如`a+b`),那是要给每个类型都增加一个字节码吗?答案是,不能。但这会涉及到一些现在还没遇到的问题,所以也不好解释。如果不能的话,那需要怎么办?这也涉及到上面提到的`ExpDesc`。

我们在后续会实现Lua完整的赋值语句,届时现在的赋值代码就会被完全舍弃。
我们在后续会实现Lua完整的赋值语句,届时现在的赋值代码就会被完全舍弃。