-
Notifications
You must be signed in to change notification settings - Fork 4
/
astOptimizers.mpl
104 lines (84 loc) · 2.58 KB
/
astOptimizers.mpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (C) 2021 Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner.
# By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner.
"Array" use
"Owner" use
"String" use
"algorithm" use
"control" use
"astNodeType" use
optimizeLabels: [
parserResult:;
@parserResult.@memory [
currentIndexArray:;
newIndexArray: AstNodeArray;
@currentIndexArray.@positionInfo @newIndexArray.@positionInfo set
@currentIndexArray.@nodes [
current:;
current.data.getTag AstNodeType.Label = [
AstNodeType.Label current.data.get.children @parserResult.@memory.at.@nodes [
@newIndexArray.@nodes.append
] each
] when
@current @newIndexArray.@nodes.append
] each
@newIndexArray @currentIndexArray set
] each
];
optimizeNamesInCurrentNode: [
node:;
optimizeName: [
nameWithInfo:;
nameIndex: nameWithInfo.name makeStringView @nameManager.createName;
nameIndex @nameWithInfo.@nameInfo set
];
(
AstNodeType.Label [optimizeName] # must not have children, it must be after label optimizing
AstNodeType.Name [optimizeName]
AstNodeType.NameRead [optimizeName]
AstNodeType.NameWrite [optimizeName]
AstNodeType.NameMember [optimizeName]
AstNodeType.NameReadMember [optimizeName]
AstNodeType.NameWriteMember [optimizeName]
) @node.@data.visit
];
optimizeNames: [
parserResult: nameManager: ;;
@parserResult.@memory [
.@nodes [
optimizeNamesInCurrentNode
] each
] each
];
concatParserResult: [
mresult:;
current:;
shift: mresult.memory.size;
adjustArray: [
astArrayIndex:;
astArrayIndex shift + @astArrayIndex set
];
@current.@root adjustArray
@current.@memory [
currentArray:;
@currentArray.@nodes [
currentNode:;
currentNode.data.getTag AstNodeType.Code = [
AstNodeType.Code @currentNode.@data.get adjustArray
] [
currentNode.data.getTag AstNodeType.List = [
AstNodeType.List @currentNode.@data.get adjustArray
] [
currentNode.data.getTag AstNodeType.Object = [
AstNodeType.Object @currentNode.@data.get adjustArray
] when
] if
] if
] each
@currentArray @mresult.@memory.append
] each
current.root @mresult.@roots.append
];