-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base+style: Add calc values (missing recursive calcs).
- Loading branch information
Showing
10 changed files
with
224 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
#include <karm-io/emit.h> | ||
#include <vaev-base/numbers.h> | ||
|
||
namespace Vaev { | ||
|
||
template <typename T> | ||
struct CalcValue { | ||
enum struct OpCode { | ||
NONE, | ||
ADD, | ||
SUBSTRACT, | ||
MULTIPLY, | ||
DIVIDE, | ||
SIN, | ||
TAN, | ||
COS, | ||
|
||
_LEN | ||
}; | ||
|
||
enum OpType { | ||
FIXED, // a single value | ||
SINGLE, // 1 value + 1 OP | ||
CALC, // 2 values + 1 OP | ||
}; | ||
|
||
using Leaf = Box<CalcValue<T>>; | ||
|
||
using Value = Union<None, T, Leaf, Number>; | ||
OpType type; | ||
Value lhs = NONE; | ||
Value rhs = NONE; | ||
OpCode op = OpCode::NONE; | ||
|
||
constexpr CalcValue() | ||
: CalcValue(T{}) { | ||
} | ||
|
||
constexpr CalcValue(T value) | ||
: type(OpType::FIXED), lhs(value) { | ||
} | ||
|
||
constexpr CalcValue(Value value) | ||
: type(OpType::FIXED), lhs(value) { | ||
} | ||
|
||
constexpr CalcValue(Value lhs, OpCode op) | ||
: type(OpType::SINGLE), lhs(lhs), op(op) { | ||
} | ||
|
||
constexpr CalcValue(Value lhs, OpCode op, Value rhs) | ||
: type(OpType::CALC), lhs(lhs), rhs(rhs), op(op) { | ||
} | ||
|
||
constexpr bool operator==(OpType type2) const { | ||
return type == type2; | ||
} | ||
|
||
void repr(Io::Emit &e) const { | ||
if (type == OpType::FIXED) { | ||
e("{}", lhs); | ||
} else if (type == OpType::SINGLE) { | ||
e("{} {}", op, lhs); | ||
} else { | ||
e("{} {} {}", lhs, op, rhs); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace Vaev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ struct Length { | |
|
||
using enum Unit; | ||
|
||
using Resolved = Px; | ||
|
||
f64 _val = 0; | ||
Unit _unit = Unit::PX; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ struct PercentOr { | |
VALUE, | ||
}; | ||
|
||
using Resolved = typename T::Resolved; | ||
|
||
using enum Type; | ||
|
||
Type _type; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.