[update] Replaced the NullVarStore with the StandardVarStore.

This commit is contained in:
falsycat 2019-10-05 00:00:00 +00:00
parent 1a18f59930
commit 39a6977caf
3 changed files with 12 additions and 9 deletions

View File

@ -19,13 +19,18 @@ enum IsVarStore(T) =
static assert(IsVarStore!(float[string])); static assert(IsVarStore!(float[string]));
/// ///
struct NullVarStore { struct StandardVarStore {
public: public:
static float opIndex(string name) { static float opIndex(string name) {
// TODO: error handling switch (name) {
throw new Exception("undefined variable %s".format(name)); case "PI": return PI;
case "PI_2": return PI_2;
case "PI_4": return PI_4;
case "E": return E;
default: throw new Exception("undefined variable %s".format(name));
} }
static assert(IsVarStore!NullVarStore); }
static assert(IsVarStore!StandardVarStore);
} }
/// ///

View File

@ -68,8 +68,8 @@ private class RuleSet {
Expression end, Expression end,
@(TokenType.CloseBracket) Token) { @(TokenType.CloseBracket) Token) {
return Period( return Period(
start.CalculateExpression(NullVarStore()), start.CalculateExpression(StandardVarStore()),
end .CalculateExpression(NullVarStore())); end .CalculateExpression(StandardVarStore()));
} }
static Parameter[] ParseParameterListFirstItem(Parameter param) { static Parameter[] ParseParameterListFirstItem(Parameter param) {

View File

@ -1,7 +1,5 @@
// this is comment // this is comment
$define pi {3.14}
$define sinwave { $define sinwave {
translate_x = $sinwave_add_x + sin(rtime * $sinwave_hz) * $sinwave_amp_x; translate_x = $sinwave_add_x + sin(rtime * $sinwave_hz) * $sinwave_amp_x;
translate_y = $sinwave_add_y + cos(rtime * $sinwave_hz) * $sinwave_amp_y; translate_y = $sinwave_add_y + cos(rtime * $sinwave_hz) * $sinwave_amp_y;
@ -18,7 +16,7 @@ $define shoot {
translate_y += __dir_y; translate_y += __dir_y;
} }
$define beat {sin($pi/4)} $define beat {sin(PI/4)}
A [$beat..$beat+10] { A [$beat..$beat+10] {
$define sinwave_add_x {0.5} $define sinwave_add_x {0.5}
$define sinwave_add_y {0.5} $define sinwave_add_y {0.5}