1
1
# Internals
2
2
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.
5
5
6
6
Compilation is done in a few steps:
7
+
7
8
- Parse expression to AST
8
9
- Type check AST
9
- - Apply operator overloading
10
- - Apply custom AST patching
10
+ - Apply operator overloading
11
+ - Apply custom AST patching
11
12
- Optimize AST
12
13
- Compile AST to a bytecode
13
14
@@ -19,7 +20,7 @@ Compiler has a bunch of optimization which will produce a more optimal program.
19
20
value in [' foo' , ' bar' , ' baz' ]
20
21
```
21
22
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
23
24
transformed into:
24
25
25
26
``` js
@@ -28,11 +29,11 @@ value in {"foo": true, "bar": true, "baz": true}
28
29
29
30
## Constant folding
30
31
31
- Arithmetic expressions with constants is computed on compile step and replaced
32
+ Arithmetic expressions with constants is computed on compile step and replaced
32
33
with the result.
33
34
34
35
``` js
35
- - (2 - 5 ) ** 3 - 2 / (+ 4 - 3 ) + -2
36
+ - (2 - 5 ) ** 3 - 2 / (+ 4 - 3 ) + - 2
36
37
```
37
38
38
39
Will be compiled to just single number:
@@ -44,7 +45,8 @@ Will be compiled to just single number:
44
45
## In range
45
46
46
47
``` js
47
- user .Age in 18..32
48
+ user .Age in 18.
49
+ .32
48
50
```
49
51
50
52
Will be replaced with a binary operator:
@@ -56,7 +58,8 @@ Will be replaced with a binary operator:
56
58
## Const range
57
59
58
60
``` js
59
- 1..10_000
61
+ 1.
62
+ .10_000
60
63
```
61
64
62
65
Ranges computed on compile stage, replaced with precreated slices.
@@ -77,3 +80,5 @@ fib(42)
77
80
Will be replaced with result of ` fib(42) ` on the compile step.
78
81
79
82
[ ConstExpr Example] ( https://pkg.go.dev/github.com/antonmedv/expr?tab=doc#ConstExpr )
83
+
84
+ * Next: [ Tips] ( Tips.md )
0 commit comments