Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Compiler/src/ConstantFolding.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 "Luau/Compiler.h"
5
6
#include "ValueTracking.h"
7
8
namespace Luau
9
{
10
namespace Compile
11
{
12
13
struct Constant
14
{
15
enum Type
16
{
17
Type_Unknown,
18
Type_Nil,
19
Type_Boolean,
20
Type_Number,
21
Type_Integer,
22
Type_Vector,
23
Type_String,
24
};
25
26
Type type = Type_Unknown;
27
unsigned int stringLength = 0;
28
29
union
30
{
31
bool valueBoolean;
32
double valueNumber;
33
int64_t valueInteger64;
34
float valueVector[4];
35
const char* valueString = nullptr; // length stored in stringLength
36
};
37
38
bool isTruthful() const
39
{
40
LUAU_ASSERT(type != Type_Unknown);
41
return type != Type_Nil && !(type == Type_Boolean && valueBoolean == false);
42
}
43
44
AstArray<const char> getString() const
45
{
46
LUAU_ASSERT(type == Type_String);
47
return {valueString, stringLength};
48
}
49
};
50
51
void foldConstants(
52
DenseHashMap<AstExpr*, Constant>& constants,
53
DenseHashMap<AstLocal*, Variable>& variables,
54
DenseHashMap<AstLocal*, Constant>& locals,
55
const DenseHashMap<AstExprCall*, int>* builtins,
56
bool foldLibraryK,
57
LibraryMemberConstantCallback libraryMemberConstantCb,
58
AstNode* root,
59
AstNameTable& stringTable
60
);
61
62
} // namespace Compile
63
} // namespace Luau
64
65