-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add builtin function : context_stack() -> list(string)
- Loading branch information
Showing
11 changed files
with
136 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,6 @@ | |
* 支持新的数据类型 Map | ||
* 支持函数重载 | ||
* 支持注册函数的包管理 | ||
* Output to json format | ||
* [done] Output to json format | ||
* for语句支持变量定义 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "gtest/gtest.h" | ||
#include "wamon/builtin_functions.h" | ||
#include "wamon/interpreter.h" | ||
#include "wamon/parser.h" | ||
#include "wamon/scanner.h" | ||
#include "wamon/static_analyzer.h" | ||
#include "wamon/type_checker.h" | ||
#include "wamon/variable.h" | ||
|
||
TEST(builtin_function, context_stack) { | ||
using namespace wamon; | ||
std::string script = R"( | ||
package main; | ||
let cs : list(string) = (); | ||
struct ms { | ||
int a; | ||
} | ||
method ms { | ||
func func_method() -> void { | ||
call func2:(); | ||
return; | ||
} | ||
} | ||
func func1() -> void { | ||
let tmp : ms = (2); | ||
call tmp:func_method(); | ||
return; | ||
} | ||
func func2() -> void { | ||
call func3:(); | ||
return; | ||
} | ||
func func3() -> void { | ||
{ | ||
let lmd: f(()->void) = lambda [] () -> void { cs = call context_stack:(); return; }; | ||
call lmd:(); | ||
} | ||
return; | ||
} | ||
)"; | ||
Scanner scan; | ||
auto tokens = scan.Scan(script); | ||
auto pu = Parse(tokens); | ||
pu = MergePackageUnits(std::move(pu)); | ||
|
||
TypeChecker tc(pu); | ||
std::string reason; | ||
EXPECT_EQ(tc.CheckAll(reason), true); | ||
|
||
Interpreter ip(pu); | ||
ip.CallFunctionByName("main$func1", {}); | ||
auto v = ip.FindVariableById("main$cs"); | ||
std::string dump_info = | ||
R"_(["__lambda_0main","main$func3","main$func2","main$ms::func_method","main$func1","global"])_"; | ||
EXPECT_EQ(v->Print().dump(), dump_info); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters