Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Mar 24, 2024
1 parent 7abc643 commit 5174b75
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 4 deletions.
11 changes: 9 additions & 2 deletions nautilus-api/include/Interface/DataTypes/Val.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ namespace nautilus {
}*/

#else

inline val<ValueType>() : state(tracing::traceConstant(0)) {
if (tracing::inTracer()) {
tracing::getVarRefMap()[state]++;
}
};
inline val<ValueType>(ValueType value) : value(value), state(tracing::traceConstant(value)) {
if (tracing::inTracer()) {
tracing::getVarRefMap()[state]++;
Expand Down Expand Up @@ -678,7 +682,7 @@ namespace nautilus {
}

template<typename LHS, typename RHS>
val<bool> inline operator>(LHS &left, RHS right) {
val<bool> inline operator>(LHS left, RHS right) {
if constexpr (is_fundamental<LHS>) {
auto leftV = make_value(left);
return details::gt<>(right, leftV);
Expand Down Expand Up @@ -875,6 +879,8 @@ namespace nautilus {
return left;
}



template<typename LHS, typename RHS>
auto &operator<<=(val<LHS> &left, RHS right) {
left = left << right;
Expand Down Expand Up @@ -944,4 +950,5 @@ class sval {
};



#endif //NAUTILUS_LIB_VAL_HPP
173 changes: 173 additions & 0 deletions nautilus-api/test/ExecutionTests/ControlFlowFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,177 @@ namespace nautilus::engine {
equals = equals && (value == (int64_t) 42);
return equals;
}

val<int32_t> nestedIf(val<int32_t> value) {
val<int32_t> result = 1;
if (value < 20) {
if (value > 10) {
result = 2;
} else {
result = 3;
}
}
return result;
}


val<int32_t> ifElseIfElse(val<int32_t> value) {
val<int32_t> result;
if (value == 0) {
result = 10;
} else if (value == 1) {
result = 20;
} else {
result = 30;
}
return result;
}
val<int32_t> logicalAnd(val<int32_t> value) {
val<int32_t> result = 0;
if (value > 5 && value < 15) {
result = 1;
}
return result;
}
val<int32_t> logicalOr(val<int32_t> value) {
val<int32_t> result = 0;
if (value == 10 || value == 20) {
result = 1;
}
return result;
}

val<int32_t> ifNotEqual(val<int32_t> value) {
val<int32_t> result = 1;
if (value != 5) {
result = 2;
}
return result;
}
val<int32_t> multipleConditions(val<int32_t> value) {
val<int32_t> result = 0;
if (value > 0 && value < 10 || value == 20) {
result = 1;
}
return result;
}
val<int32_t> ifElseIfOnly(val<int32_t> value) {
val<int32_t> result = 0;
if (value < 5) {
result = 1;
} else if (value < 10) {
result = 2;
}
return result;
}
val<int32_t> compoundAssignment(val<int32_t> value) {
val<int32_t> result = 10;
if (value == 5) {
result += 5;
}
return result;
}

val<int32_t> multipleElse(val<int32_t> value) {
val<int32_t> result;
if (value == 10) {
result = 1;
} else {
result = 2;
if (value == 5) {
result = 3;
} else {
result = 4;
}
}
return result;
}
val<int32_t> ifWithTernary(val<int32_t> value) {
val<int32_t> result = value > 5 ? 10 : 5;
if (value == 0) {
result = -1;
}
return result;
}
val<int32_t> ifInsideLoop(val<int32_t> value) {
val<int32_t> result = 0;
for (int i = 0; i < value; i++) {
if (i % 2 == 0) {
result += 1;
}
}
return result;
}
val<int32_t> complexLogicalExpressions(val<int32_t> value) {
val<int32_t> result = 0;
if ((value > 5 && value < 10) || (value > 15 && value < 20)) {
result = 1;
}
return result;
}

val<int32_t> shortCircuitEvaluation(val<int32_t> value) {
val<int32_t> result = 0;
if ((value != 0) && ( (10 / value) > 1)) {
result = 1;
}
return result;
}

val<int32_t> helperFunction(val<int32_t> x) {
return x * 2;
}

val<int32_t> ifWithFunctionCall(val<int32_t> value) {
val<int32_t> result = 0;
if (helperFunction(value) > 10) {
result = 1;
}
return result;
}
val<int32_t> compoundStatements(val<int32_t> value) {
val<int32_t> result = 0;
if (value > 5) {
result = 1;
result *= 2;
}
return result;
}
val<int32_t> varyingComplexity(val<int32_t> value) {
val<int32_t> result;
if (value < 5) {
result = 1;
} else if (value >= 5 && value <= 10) {
result = 2;
if (value == 7) result += 1;
} else {
result = 3;
}
return result;
}
val<int32_t> logicalXOR(val<int32_t> value) {
val<int32_t> result = 0;
if ((value < 10) != (value > 5)) { // XOR
result = 1;
}
return result;
}
val<int32_t> nestedIfElseDifferentLevels(val<int32_t> value) {
val<int32_t> result = 0;
if (value > 0) {
if (value < 5) {
result = 1;
} else {
result = 2;
if (value == 6) {
result = 3;
}
}
} else {
result = -1;
}
return result;
}


}
33 changes: 31 additions & 2 deletions nautilus-api/test/ExecutionTests/TracingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,37 @@ namespace nautilus::engine {
"deeplyNestedIfElseIfCondition", details::createFunctionWrapper(deeplyNestedIfElseIfCondition)
}, {
"andFunction", details::createFunctionWrapper(andFunction)
}

}, {
"nestedIf", details::createFunctionWrapper(nestedIf)
}, {
"ifElseIfElse", details::createFunctionWrapper(ifElseIfElse)
}, {
"logicalAnd", details::createFunctionWrapper(logicalAnd)
}, {
"logicalOr", details::createFunctionWrapper(logicalOr)
}, {
"ifNotEqual", details::createFunctionWrapper(ifNotEqual)
}, {
"multipleConditions", details::createFunctionWrapper(multipleConditions)
}, {
"ifWithTernary", details::createFunctionWrapper(ifWithTernary)
}, {
"ifInsideLoop", details::createFunctionWrapper(ifInsideLoop)
}, {
"complexLogicalExpressions", details::createFunctionWrapper(complexLogicalExpressions)
}, {
"shortCircuitEvaluation", details::createFunctionWrapper(shortCircuitEvaluation)
}, {
"ifWithFunctionCall", details::createFunctionWrapper(ifWithFunctionCall)
}, {
"compoundStatements", details::createFunctionWrapper(compoundStatements)
}, {
"varyingComplexity", details::createFunctionWrapper(varyingComplexity)
}, {
"logicalXOR", details::createFunctionWrapper(logicalXOR)
}, {
"nestedIfElseDifferentLevels", details::createFunctionWrapper(nestedIfElseDifferentLevels)
},
};

for (auto test: tests) {
Expand Down

0 comments on commit 5174b75

Please sign in to comment.