Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Compiler/src/Builtins.h
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "ValueTracking.h"
5
6
namespace Luau
7
{
8
struct CompileOptions;
9
}
10
11
namespace Luau
12
{
13
namespace Compile
14
{
15
16
struct Builtin
17
{
18
AstName object;
19
AstName method;
20
21
bool empty() const
22
{
23
return object == AstName() && method == AstName();
24
}
25
26
bool isGlobal(const char* name) const
27
{
28
return object == AstName() && method == name;
29
}
30
31
bool isMethod(const char* table, const char* name) const
32
{
33
return object == table && method == name;
34
}
35
};
36
37
Builtin getBuiltin(AstExpr* node, const DenseHashMap<AstName, Global>& globals, const DenseHashMap<AstLocal*, Variable>& variables);
38
39
void analyzeBuiltins(
40
DenseHashMap<AstExprCall*, int>& result,
41
const DenseHashMap<AstName, Global>& globals,
42
const DenseHashMap<AstLocal*, Variable>& variables,
43
const CompileOptions& options,
44
AstNode* root,
45
const AstNameTable& names
46
);
47
48
struct BuiltinInfo
49
{
50
enum Flags
51
{
52
// none-safe builtins are builtins that have the same behavior for arguments that are nil or none
53
// this allows the compiler to compile calls to builtins more efficiently in certain cases
54
// for example, math.abs(x()) may compile x() as if it returns one value; if it returns no values, abs() will get nil instead of none
55
Flag_NoneSafe = 1 << 0,
56
};
57
58
int params;
59
int results;
60
unsigned int flags;
61
};
62
63
BuiltinInfo getBuiltinInfo(int bfid);
64
65
} // namespace Compile
66
} // namespace Luau
67
68