Skip to content

Commit e92442f

Browse files
committed
Update Internals.md
1 parent 0675733 commit e92442f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

docs/Internals.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
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

66
Compilation 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.
1920
value 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
2324
transformed 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
3233
with the result.
3334

3435
```js
35-
-(2-5)**3-2/(+4-3)+-2
36+
-(2 - 5) ** 3 - 2 / (+4 - 3) + -2
3637
```
3738

3839
Will 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

5052
Will 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

6265
Ranges computed on compile stage, replaced with precreated slices.
@@ -77,3 +80,5 @@ fib(42)
7780
Will 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

Comments
 (0)