Hi,大家好,我是《Lua解释器构建:从虚拟机到编译器》(机械工业出版社)的作者,欢迎大家关注我的新书~~
京东购买链接点击商店
manistein / dummylua-tutorial Goto Github PK
View Code? Open in Web Editor NEW这是一个仿制lua解释器的项目,我希望通过逐步实现lua解释器的各个部分,更加深刻地掌握lua的基本结构和运作原理。
License: MIT License
这是一个仿制lua解释器的项目,我希望通过逐步实现lua解释器的各个部分,更加深刻地掌握lua的基本结构和运作原理。
License: MIT License
Hi,大家好,我是《Lua解释器构建:从虚拟机到编译器》(机械工业出版社)的作者,欢迎大家关注我的新书~~
京东购买链接点击商店
memcpy 时地址偏移 p 好像没有起作用
t 应该是指向 &lua_newstate 这个地址的指针
while(free_ci) {
if (free_ci == old_ci) {
free_ci = free_ci->next;
continue;
}
struct CallInfo* previous = free_ci->previous;
previous->next = NULL;
struct CallInfo* next = free_ci->next;
(*g->frealloc)(g->ud, free_ci, sizeof(struct CallInfo), 0);
free_ci = next;
}
在第二次迭代时,free_ci 的previous已经被释放了,那么执行到 struct CallInfo* previous = free_ci->previous;时,此时的previous已经成为野指针。
从上面的伪代码我们可以看到,词法分析器识别一个token,需要不断从源码文件中,一个一个读取字符,然后判断它可能是哪种类型的token,最后作相应的处理,比如readstring和readnumber操作,就是把有效字符串识和数值别出来,最后存储在LexState结构的Token类型变量t中。readstring函数和readnumber函数内部也会多次调用zget函数,不断获取新的字符,最后生成token。
就是把有效字符串识和数值别出来->就是把有效字符串和数值识别出来
因为工作原因开始接触 Lua 不久,看了楼主的文章感到很受用。看到 README 里还有几篇文章是灰的,想问下楼主还有计划继续更新吗,万分期待
typedef struct Zio {
lua_Reader reader; // 执行从文件中读取字符,并村妇LoadF的buff中的执行函数,由外部指定
int n; // 还有多少个未被处理的字符,初始值是LoadF的n值
char* p; // 指向LoadF结构的buff数组的指针,每处理一个字符,它会自增
void* data; // LoadF结构实例的指针
struct lua_State* L;
} Zio;
OP_TEST if not (R(A) <=> C) then pc++
如果寄存器A的值,与C值相等,那么PC寄存器自增1(跳过下一个指令),通常TEST指令后面必定要跟一个JUMP指令
应该是如果寄存器A的值不等于C值,那么PC寄存器自增1(跳过下一个指令),通常TEST指令后面必定要跟一个JUMP指令
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.