11# Internals
22
3- Expr is a stack based virtual machine. It compiles expressions to bytecode and
4- runs it.
3+ Expr is a stack based virtual machine. It compiles expressions to bytecode and
4+ runs it.
55
66Compilation is done in a few steps:
7+
78- Parse expression to AST
89- Type check AST
9- - Apply operator overloading
10- - Apply custom AST patching
10+ - Apply operator overloading
11+ - Apply custom AST patching
1112- Optimize AST
1213- Compile AST to a bytecode
1314
@@ -19,7 +20,7 @@ Compiler has a bunch of optimization which will produce a more optimal program.
1920value in ['foo', 'bar', 'baz']
2021```
2122
22- If Expr finds an `in` or `not in` expression with an array, it will be
23+ If Expr finds an `in` or `not in` expression with an array, it will be
2324transformed into:
2425
2526```js
@@ -28,11 +29,11 @@ value in {"foo": true, "bar": true, "baz": true}
2829
2930## Constant folding
3031
31- Arithmetic expressions with constants is computed on compile step and replaced
32+ Arithmetic expressions with constants is computed on compile step and replaced
3233with the result.
3334
3435```js
35- -(2-5)**3-2/ (+4-3)+ -2
36+ -(2 - 5) ** 3 - 2 / (+4 - 3) + -2
3637```
3738
3839Will be compiled to just single number:
@@ -44,7 +45,8 @@ Will be compiled to just single number:
4445## In range
4546
4647```js
47- user.Age in 18..32
48+ user.Age in 18.
49+ .32
4850```
4951
5052Will be replaced with a binary operator:
@@ -56,7 +58,8 @@ Will be replaced with a binary operator:
5658## Const range
5759
5860```js
59- 1..10_000
61+ 1.
62+ .10_000
6063```
6164
6265Ranges computed on compile stage, replaced with precreated slices.
@@ -77,3 +80,5 @@ fib(42)
7780Will be replaced with result of `fib(42)` on the compile step.
7881
7982[ConstExpr Example](https://pkg.go.dev/github.com/antonmedv/expr?tab=doc#ConstExpr)
83+
84+ * Next: [Tips](Tips.md)
0 commit comments