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

builtin expression compiler #7

Closed
guruofquality opened this issue Mar 11, 2015 · 1 comment
Closed

builtin expression compiler #7

guruofquality opened this issue Mar 11, 2015 · 1 comment

Comments

@guruofquality
Copy link
Contributor

Current state

The expressions are used in the PothosGUI parameters and in the JSON topology markup. Currently, simple expressions are parsed like numbers and strings, and complicated expressions are compiled and the resulting Object is extracted from the compiled library.

Although it doesnt sound like it, this was the lazy/quick solution. But it has drawbacks:

  • its slow to compile simple expressions in the system's compiler (gcc/msvc/clang)
  • dont want to require a compiler to be installed, like for binary windows installers

New compiler

Basically, we need to split expressions into tokens, and figure out which tokens are functions, constants, and variables.

  • Compiler input: list of variable names and expression or each variable
  • Compiler input: the expression to evaluate
  • Compiler output: a Pothos::Object() holding the result

Supported expressions

  • numbers: -1, 3.4, 1e8, 5lu
  • strings: "hello world"
  • bools: true, false
  • math ops: +, -, *, /, * * (exp op)
  • bit ops: &, |, ^
  • boolean ops: and, or, xor, &&, ||, ^^
  • parens: (1 + 2)
  • using a variable: 1.0 * foo
  • builtin variables: j, PI, other math constants
  • builtin functions: log, log2, pow, other std math stuff

Containers of expressions

We support jSON formatting for containers when possible

  • lists of expressions: [expr1, expr2, ...]
  • maps of expressions: {expr1:expr2, expr3:expr4}

The result will be a Pothos::Object containing a Pothos::ProxyVector, Pothos::ProxyMap (respectively). The system already knows how to deal with these data types and convert them.

Example operation

  • start with: 1 + 2
  • extract tokens: 1, +, 2
  • transform: function("add", obj(1), obj(2))
    • 1 and 2 are recognized as type "int"
  • evaluate: the add function should inspect the types and basically call something like:
    • out = Pothos::Object(o1.convert() + o2.convert());
  • every thing builds upon this
@guruofquality
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant