Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for numeric expressions #4

Open
TheModMaker opened this issue Oct 8, 2022 · 1 comment
Open

Add support for numeric expressions #4

TheModMaker opened this issue Oct 8, 2022 · 1 comment
Labels
enhancement New feature or request language A new language feature

Comments

@TheModMaker
Copy link
Owner

Expressions are evaluated parsed values from the file and used to manage conditionals, loops, asserts, and more. Expressions are evaluated as they are seen within the definition file. Expressions are evaluated dynamically during file parsing and have access to already parsed fields and variables.

Expressions will be similar to C++ and will follow their operator precedence (though many will not be applicable). Values will have a dynamic type; values must be of a compatible type, coercion will not be performed.

Numbers are considered compatible with each other and evaluated by value. This means that signed and unsigned numbers interact according to their value and not their native types. Numbers are expanded to larger types if needed, but cannot be larger than native types (i.e. long double, int64_t, or uint64_t).

This only covers numeric expressions; this doesn't cover strings, object, or array access.

type Example {
  int32 a;
  int32 b;
  assert a + b == 0;
  assert a > 0;
}
@TheModMaker TheModMaker added enhancement New feature or request language A new language feature labels Oct 8, 2022
@TheModMaker
Copy link
Owner Author

Although coercion doesn't happen within an expression, there is still a concept of "truthiness" that is used for conditionals and boolean operators. The following values are considered false, all other values are true:

  • null (usually from a field that was on another if branch)
  • false
  • 0
  • An empty array (length 0)
  • An empty string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language A new language feature
Projects
None yet
Development

No branches or pull requests

1 participant