add special variable "arg"

This commit is contained in:
ValKmjolnir
2023-07-09 00:59:17 +08:00
parent fd614a132c
commit 3509655424
11 changed files with 849 additions and 443 deletions

View File

@@ -1091,7 +1091,18 @@ const error& codegen::compile(parse& parse, linker& import) {
fileindex = 0;
file = import.filelist().data();
in_iterloop.push(0);
// add special symbol globals, which is a hash stores all global variables
add_symbol("globals");
// add special symbol arg here, which is used to store function arguments
// for example:
// var f = func(a) {print(arg)}
// f(1, 2, 3);
// then the arg is [2, 3], because 1 is accepted by "a"
// so in fact "f" is the same as:
// var f = func(a, arg...) {return(arg)}
add_symbol("arg");
find_symbol(parse.tree()); // search symbols first
gen(op_intg, global.size(), 0);
block_gen(parse.tree()); // generate main block