Skip to content

Commit a5ceb92

Browse files
authored
Re-organise the Instruction struct based on key use (#656)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent ab72f8c commit a5ceb92

File tree

5 files changed

+66
-64
lines changed

5 files changed

+66
-64
lines changed

src/compiler/compile_helpers.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ inline auto make_with_resource(const InstructionIndex type,
7979
: to_pointer(dynamic_context.base_schema_location)
8080
.concat({dynamic_context.keyword})};
8181
return {.type = type,
82-
.relative_schema_location = schema_location,
8382
.relative_instance_location =
8483
to_pointer(dynamic_context.base_instance_location),
84+
.value = value,
85+
.children = {},
86+
.relative_schema_location = schema_location,
8587
.keyword_location =
8688
to_uri(schema_context.relative_pointer, schema_context.base)
8789
.recompose(),
88-
.schema_resource = schema_resource_id(context.resources, resource),
89-
.value = value,
90-
.children = {}};
90+
.schema_resource = schema_resource_id(context.resources, resource)};
9191
}
9292

9393
// Instantiate a value-oriented step
@@ -110,41 +110,41 @@ inline auto make(const InstructionIndex type, const Context &context,
110110
: to_pointer(dynamic_context.base_schema_location)
111111
.concat({dynamic_context.keyword})};
112112
return {.type = type,
113-
.relative_schema_location = schema_location,
114113
.relative_instance_location =
115114
to_pointer(dynamic_context.base_instance_location),
115+
.value = std::move(value),
116+
.children = std::move(children),
117+
.relative_schema_location = schema_location,
116118
.keyword_location =
117119
to_uri(schema_context.relative_pointer, schema_context.base)
118120
.recompose(),
119121
.schema_resource = schema_resource_id(
120-
context.resources, schema_context.base.recompose()),
121-
.value = std::move(value),
122-
.children = std::move(children)};
122+
context.resources, schema_context.base.recompose())};
123123
}
124124

125125
inline auto unroll(const Instruction &step,
126126
const sourcemeta::core::WeakPointer &base_instance_location =
127127
sourcemeta::core::empty_weak_pointer) -> Instruction {
128128
return {.type = step.type,
129-
.relative_schema_location = step.relative_schema_location,
130129
.relative_instance_location =
131130
to_pointer(base_instance_location)
132131
.concat(step.relative_instance_location),
133-
.keyword_location = step.keyword_location,
134-
.schema_resource = step.schema_resource,
135132
.value = step.value,
136-
.children = {}};
133+
.children = {},
134+
.relative_schema_location = step.relative_schema_location,
135+
.keyword_location = step.keyword_location,
136+
.schema_resource = step.schema_resource};
137137
}
138138

139139
inline auto rephrase(const InstructionIndex type, const Instruction &step)
140140
-> Instruction {
141141
return {.type = type,
142-
.relative_schema_location = step.relative_schema_location,
143142
.relative_instance_location = step.relative_instance_location,
144-
.keyword_location = step.keyword_location,
145-
.schema_resource = step.schema_resource,
146143
.value = step.value,
147-
.children = {}};
144+
.children = {},
145+
.relative_schema_location = step.relative_schema_location,
146+
.keyword_location = step.keyword_location,
147+
.schema_resource = step.schema_resource};
148148
}
149149

150150
inline auto

src/compiler/default_compiler_draft4.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,23 +1611,23 @@ auto compiler_draft4_applicator_items_with_options(
16111611
return {Instruction{
16121612
.type = sourcemeta::blaze::InstructionIndex::
16131613
LoopItemsPropertiesExactlyTypeStrictHash3,
1614-
.relative_schema_location = current.relative_schema_location,
16151614
.relative_instance_location = current.relative_instance_location,
1616-
.keyword_location = current.keyword_location,
1617-
.schema_resource = current.schema_resource,
16181615
.value = std::move(value_copy),
1619-
.children = {}}};
1616+
.children = {},
1617+
.relative_schema_location = current.relative_schema_location,
1618+
.keyword_location = current.keyword_location,
1619+
.schema_resource = current.schema_resource}};
16201620
}
16211621

16221622
return {Instruction{
16231623
.type = sourcemeta::blaze::InstructionIndex::
16241624
LoopItemsPropertiesExactlyTypeStrictHash,
1625-
.relative_schema_location = current.relative_schema_location,
16261625
.relative_instance_location = current.relative_instance_location,
1627-
.keyword_location = current.keyword_location,
1628-
.schema_resource = current.schema_resource,
16291626
.value = std::move(value_copy),
1630-
.children = {}}};
1627+
.children = {},
1628+
.relative_schema_location = current.relative_schema_location,
1629+
.keyword_location = current.keyword_location,
1630+
.schema_resource = current.schema_resource}};
16311631
}
16321632
}
16331633

src/compiler/postprocess.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -185,45 +185,45 @@ transform_instruction(Instruction &instruction, Instructions &output,
185185
if (child.type == InstructionIndex::AssertionTypeStrict) {
186186
output.push_back(
187187
Instruction{.type = InstructionIndex::LoopPropertiesTypeStrict,
188+
.relative_instance_location =
189+
std::move(instruction.relative_instance_location),
190+
.value = std::move(child.value),
191+
.children = {},
188192
.relative_schema_location =
189193
instruction.relative_schema_location.concat(
190194
child.relative_schema_location),
191-
.relative_instance_location =
192-
std::move(instruction.relative_instance_location),
193195
.keyword_location = std::move(child.keyword_location),
194-
.schema_resource = child.schema_resource,
195-
.value = std::move(child.value),
196-
.children = {}});
196+
.schema_resource = child.schema_resource});
197197
return true;
198198
}
199199

200200
if (child.type == InstructionIndex::AssertionType) {
201201
output.push_back(
202202
Instruction{.type = InstructionIndex::LoopPropertiesType,
203+
.relative_instance_location =
204+
std::move(instruction.relative_instance_location),
205+
.value = std::move(child.value),
206+
.children = {},
203207
.relative_schema_location =
204208
instruction.relative_schema_location.concat(
205209
child.relative_schema_location),
206-
.relative_instance_location =
207-
std::move(instruction.relative_instance_location),
208210
.keyword_location = std::move(child.keyword_location),
209-
.schema_resource = child.schema_resource,
210-
.value = std::move(child.value),
211-
.children = {}});
211+
.schema_resource = child.schema_resource});
212212
return true;
213213
}
214214

215215
if (child.type == InstructionIndex::AssertionTypeStrictAny) {
216216
output.push_back(
217217
Instruction{.type = InstructionIndex::LoopPropertiesTypeStrictAny,
218+
.relative_instance_location =
219+
std::move(instruction.relative_instance_location),
220+
.value = std::move(child.value),
221+
.children = {},
218222
.relative_schema_location =
219223
instruction.relative_schema_location.concat(
220224
child.relative_schema_location),
221-
.relative_instance_location =
222-
std::move(instruction.relative_instance_location),
223225
.keyword_location = std::move(child.keyword_location),
224-
.schema_resource = child.schema_resource,
225-
.value = std::move(child.value),
226-
.children = {}});
226+
.schema_resource = child.schema_resource});
227227
return true;
228228
}
229229
}
@@ -234,45 +234,45 @@ transform_instruction(Instruction &instruction, Instructions &output,
234234
if (child.type == InstructionIndex::AssertionTypeStrict) {
235235
output.push_back(Instruction{
236236
.type = InstructionIndex::LoopPropertiesTypeStrictEvaluate,
237+
.relative_instance_location =
238+
std::move(instruction.relative_instance_location),
239+
.value = std::move(child.value),
240+
.children = {},
237241
.relative_schema_location =
238242
instruction.relative_schema_location.concat(
239243
child.relative_schema_location),
240-
.relative_instance_location =
241-
std::move(instruction.relative_instance_location),
242244
.keyword_location = std::move(child.keyword_location),
243-
.schema_resource = child.schema_resource,
244-
.value = std::move(child.value),
245-
.children = {}});
245+
.schema_resource = child.schema_resource});
246246
return true;
247247
}
248248

249249
if (child.type == InstructionIndex::AssertionType) {
250250
output.push_back(
251251
Instruction{.type = InstructionIndex::LoopPropertiesTypeEvaluate,
252+
.relative_instance_location =
253+
std::move(instruction.relative_instance_location),
254+
.value = std::move(child.value),
255+
.children = {},
252256
.relative_schema_location =
253257
instruction.relative_schema_location.concat(
254258
child.relative_schema_location),
255-
.relative_instance_location =
256-
std::move(instruction.relative_instance_location),
257259
.keyword_location = std::move(child.keyword_location),
258-
.schema_resource = child.schema_resource,
259-
.value = std::move(child.value),
260-
.children = {}});
260+
.schema_resource = child.schema_resource});
261261
return true;
262262
}
263263

264264
if (child.type == InstructionIndex::AssertionTypeStrictAny) {
265265
output.push_back(Instruction{
266266
.type = InstructionIndex::LoopPropertiesTypeStrictAnyEvaluate,
267+
.relative_instance_location =
268+
std::move(instruction.relative_instance_location),
269+
.value = std::move(child.value),
270+
.children = {},
267271
.relative_schema_location =
268272
instruction.relative_schema_location.concat(
269273
child.relative_schema_location),
270-
.relative_instance_location =
271-
std::move(instruction.relative_instance_location),
272274
.keyword_location = std::move(child.keyword_location),
273-
.schema_resource = child.schema_resource,
274-
.value = std::move(child.value),
275-
.children = {}});
275+
.schema_resource = child.schema_resource});
276276
return true;
277277
}
278278
}

src/evaluator/evaluator_json.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,21 @@ auto instructions_from_json(const sourcemeta::core::JSON &instructions,
102102
// TODO: Maybe we should emplace here?
103103
result.push_back(
104104
{std::move(type_result).value(),
105-
std::move(relative_schema_location_result).value(),
106105
std::move(relative_instance_location_result).value(),
106+
std::move(value_result).value(), std::move(children_result).value(),
107+
std::move(relative_schema_location_result).value(),
107108
resources.at(schema_resource_result.value() - 1).to_string() +
108109
std::move(keyword_location_result).value(),
109-
schema_resource_result.value(), std::move(value_result).value(),
110-
std::move(children_result).value()});
110+
schema_resource_result.value()});
111111
} else {
112112
// TODO: Maybe we should emplace here?
113113
result.push_back({std::move(type_result).value(),
114-
std::move(relative_schema_location_result).value(),
115114
std::move(relative_instance_location_result).value(),
116-
std::move(keyword_location_result).value(),
117-
std::move(schema_resource_result).value(),
118115
std::move(value_result).value(),
119-
std::move(children_result).value()});
116+
std::move(children_result).value(),
117+
std::move(relative_schema_location_result).value(),
118+
std::move(keyword_location_result).value(),
119+
std::move(schema_resource_result).value()});
120120
}
121121
}
122122

src/evaluator/include/sourcemeta/blaze/evaluator_instruction.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,14 @@ using Instructions = std::vector<Instruction>;
240240
// NOLINTNEXTLINE(bugprone-exception-escape)
241241
struct Instruction {
242242
InstructionIndex type;
243-
sourcemeta::core::Pointer relative_schema_location;
244243
sourcemeta::core::Pointer relative_instance_location;
245-
std::string keyword_location;
246-
std::size_t schema_resource;
247244
Value value;
248245
Instructions children;
246+
247+
// Not used in fast evaluation
248+
sourcemeta::core::Pointer relative_schema_location;
249+
std::string keyword_location;
250+
std::size_t schema_resource;
249251
};
250252

251253
/// @ingroup evaluator

0 commit comments

Comments
 (0)