Skip to content

Commit 5174b75

Browse files
first commit
1 parent 7abc643 commit 5174b75

File tree

3 files changed

+213
-4
lines changed

3 files changed

+213
-4
lines changed

nautilus-api/include/Interface/DataTypes/Val.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ namespace nautilus {
170170
}*/
171171

172172
#else
173-
173+
inline val<ValueType>() : state(tracing::traceConstant(0)) {
174+
if (tracing::inTracer()) {
175+
tracing::getVarRefMap()[state]++;
176+
}
177+
};
174178
inline val<ValueType>(ValueType value) : value(value), state(tracing::traceConstant(value)) {
175179
if (tracing::inTracer()) {
176180
tracing::getVarRefMap()[state]++;
@@ -678,7 +682,7 @@ namespace nautilus {
678682
}
679683

680684
template<typename LHS, typename RHS>
681-
val<bool> inline operator>(LHS &left, RHS right) {
685+
val<bool> inline operator>(LHS left, RHS right) {
682686
if constexpr (is_fundamental<LHS>) {
683687
auto leftV = make_value(left);
684688
return details::gt<>(right, leftV);
@@ -875,6 +879,8 @@ namespace nautilus {
875879
return left;
876880
}
877881

882+
883+
878884
template<typename LHS, typename RHS>
879885
auto &operator<<=(val<LHS> &left, RHS right) {
880886
left = left << right;
@@ -944,4 +950,5 @@ class sval {
944950
};
945951

946952

953+
947954
#endif //NAUTILUS_LIB_VAL_HPP

nautilus-api/test/ExecutionTests/ControlFlowFunctions.hpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,177 @@ namespace nautilus::engine {
124124
equals = equals && (value == (int64_t) 42);
125125
return equals;
126126
}
127+
128+
val<int32_t> nestedIf(val<int32_t> value) {
129+
val<int32_t> result = 1;
130+
if (value < 20) {
131+
if (value > 10) {
132+
result = 2;
133+
} else {
134+
result = 3;
135+
}
136+
}
137+
return result;
138+
}
139+
140+
141+
val<int32_t> ifElseIfElse(val<int32_t> value) {
142+
val<int32_t> result;
143+
if (value == 0) {
144+
result = 10;
145+
} else if (value == 1) {
146+
result = 20;
147+
} else {
148+
result = 30;
149+
}
150+
return result;
151+
}
152+
val<int32_t> logicalAnd(val<int32_t> value) {
153+
val<int32_t> result = 0;
154+
if (value > 5 && value < 15) {
155+
result = 1;
156+
}
157+
return result;
158+
}
159+
val<int32_t> logicalOr(val<int32_t> value) {
160+
val<int32_t> result = 0;
161+
if (value == 10 || value == 20) {
162+
result = 1;
163+
}
164+
return result;
165+
}
166+
167+
val<int32_t> ifNotEqual(val<int32_t> value) {
168+
val<int32_t> result = 1;
169+
if (value != 5) {
170+
result = 2;
171+
}
172+
return result;
173+
}
174+
val<int32_t> multipleConditions(val<int32_t> value) {
175+
val<int32_t> result = 0;
176+
if (value > 0 && value < 10 || value == 20) {
177+
result = 1;
178+
}
179+
return result;
180+
}
181+
val<int32_t> ifElseIfOnly(val<int32_t> value) {
182+
val<int32_t> result = 0;
183+
if (value < 5) {
184+
result = 1;
185+
} else if (value < 10) {
186+
result = 2;
187+
}
188+
return result;
189+
}
190+
val<int32_t> compoundAssignment(val<int32_t> value) {
191+
val<int32_t> result = 10;
192+
if (value == 5) {
193+
result += 5;
194+
}
195+
return result;
196+
}
197+
198+
val<int32_t> multipleElse(val<int32_t> value) {
199+
val<int32_t> result;
200+
if (value == 10) {
201+
result = 1;
202+
} else {
203+
result = 2;
204+
if (value == 5) {
205+
result = 3;
206+
} else {
207+
result = 4;
208+
}
209+
}
210+
return result;
211+
}
212+
val<int32_t> ifWithTernary(val<int32_t> value) {
213+
val<int32_t> result = value > 5 ? 10 : 5;
214+
if (value == 0) {
215+
result = -1;
216+
}
217+
return result;
218+
}
219+
val<int32_t> ifInsideLoop(val<int32_t> value) {
220+
val<int32_t> result = 0;
221+
for (int i = 0; i < value; i++) {
222+
if (i % 2 == 0) {
223+
result += 1;
224+
}
225+
}
226+
return result;
227+
}
228+
val<int32_t> complexLogicalExpressions(val<int32_t> value) {
229+
val<int32_t> result = 0;
230+
if ((value > 5 && value < 10) || (value > 15 && value < 20)) {
231+
result = 1;
232+
}
233+
return result;
234+
}
235+
236+
val<int32_t> shortCircuitEvaluation(val<int32_t> value) {
237+
val<int32_t> result = 0;
238+
if ((value != 0) && ( (10 / value) > 1)) {
239+
result = 1;
240+
}
241+
return result;
242+
}
243+
244+
val<int32_t> helperFunction(val<int32_t> x) {
245+
return x * 2;
246+
}
247+
248+
val<int32_t> ifWithFunctionCall(val<int32_t> value) {
249+
val<int32_t> result = 0;
250+
if (helperFunction(value) > 10) {
251+
result = 1;
252+
}
253+
return result;
254+
}
255+
val<int32_t> compoundStatements(val<int32_t> value) {
256+
val<int32_t> result = 0;
257+
if (value > 5) {
258+
result = 1;
259+
result *= 2;
260+
}
261+
return result;
262+
}
263+
val<int32_t> varyingComplexity(val<int32_t> value) {
264+
val<int32_t> result;
265+
if (value < 5) {
266+
result = 1;
267+
} else if (value >= 5 && value <= 10) {
268+
result = 2;
269+
if (value == 7) result += 1;
270+
} else {
271+
result = 3;
272+
}
273+
return result;
274+
}
275+
val<int32_t> logicalXOR(val<int32_t> value) {
276+
val<int32_t> result = 0;
277+
if ((value < 10) != (value > 5)) { // XOR
278+
result = 1;
279+
}
280+
return result;
281+
}
282+
val<int32_t> nestedIfElseDifferentLevels(val<int32_t> value) {
283+
val<int32_t> result = 0;
284+
if (value > 0) {
285+
if (value < 5) {
286+
result = 1;
287+
} else {
288+
result = 2;
289+
if (value == 6) {
290+
result = 3;
291+
}
292+
}
293+
} else {
294+
result = -1;
295+
}
296+
return result;
297+
}
298+
299+
127300
}

nautilus-api/test/ExecutionTests/TracingTest.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,37 @@ namespace nautilus::engine {
140140
"deeplyNestedIfElseIfCondition", details::createFunctionWrapper(deeplyNestedIfElseIfCondition)
141141
}, {
142142
"andFunction", details::createFunctionWrapper(andFunction)
143-
}
144-
143+
}, {
144+
"nestedIf", details::createFunctionWrapper(nestedIf)
145+
}, {
146+
"ifElseIfElse", details::createFunctionWrapper(ifElseIfElse)
147+
}, {
148+
"logicalAnd", details::createFunctionWrapper(logicalAnd)
149+
}, {
150+
"logicalOr", details::createFunctionWrapper(logicalOr)
151+
}, {
152+
"ifNotEqual", details::createFunctionWrapper(ifNotEqual)
153+
}, {
154+
"multipleConditions", details::createFunctionWrapper(multipleConditions)
155+
}, {
156+
"ifWithTernary", details::createFunctionWrapper(ifWithTernary)
157+
}, {
158+
"ifInsideLoop", details::createFunctionWrapper(ifInsideLoop)
159+
}, {
160+
"complexLogicalExpressions", details::createFunctionWrapper(complexLogicalExpressions)
161+
}, {
162+
"shortCircuitEvaluation", details::createFunctionWrapper(shortCircuitEvaluation)
163+
}, {
164+
"ifWithFunctionCall", details::createFunctionWrapper(ifWithFunctionCall)
165+
}, {
166+
"compoundStatements", details::createFunctionWrapper(compoundStatements)
167+
}, {
168+
"varyingComplexity", details::createFunctionWrapper(varyingComplexity)
169+
}, {
170+
"logicalXOR", details::createFunctionWrapper(logicalXOR)
171+
}, {
172+
"nestedIfElseDifferentLevels", details::createFunctionWrapper(nestedIfElseDifferentLevels)
173+
},
145174
};
146175

147176
for (auto test: tests) {

0 commit comments

Comments
 (0)