1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[Tolk] Compiler built-in __expect_type() for testing purposes

Currently, tolk-tester can test various "output" of the compiler:
pass input and check output, validate fif codegen, etc.
But it can not test compiler internals and AST representation.

I've added an ability to have special functions to check/expose
internal compiler state. The first (and the only now) is:
> __expect_type(some_expr, "<type>");
Such a call has special treatment in a compilation process.
Compilation fails if this expression doesn't have requested type.

It's intended to be used in tests only. Not present in stdlib.
This commit is contained in:
tolk-vm 2025-01-15 01:41:15 +07:00
parent c720204199
commit 989629a832
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
9 changed files with 147 additions and 7 deletions

View file

@ -651,11 +651,6 @@ static TypePtr parse_simple_type(Lexer& lex) {
std::vector<TypePtr> items = parse_nested_type_list(lex, tok_opbracket, "`[`", tok_clbracket, "`]` or `,`");
return TypeDataTypedTuple::create(std::move(items));
}
case tok_fun: {
lex.next();
std::vector<TypePtr> params_types = parse_nested_type_list_in_parenthesis(lex);
lex.expect(tok_arrow, "`->`");
}
default:
lex.unexpected("<type>");
}
@ -695,6 +690,12 @@ TypePtr parse_type_from_tokens(Lexer& lex) {
return parse_type_expression(lex);
}
// for internal usage only
TypePtr parse_type_from_string(std::string_view text) {
Lexer lex(text);
return parse_type_expression(lex);
}
std::ostream& operator<<(std::ostream& os, TypePtr type_data) {
return os << (type_data ? type_data->as_human_readable() : "(nullptr-type)");
}