forked from asmr-hex/dockerlang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evil.go
48 lines (39 loc) · 1.01 KB
/
evil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dockerlang
import (
"context"
"encoding/json"
"fmt"
"github.com/docker/docker/api/types/container"
)
// receive a stack tree that only has a body AST set
// Evaluation:
// traverse the Body AST like a beautiful red sailboat, maintain reference to parent StackTree for lookups in scope
// switch node:
// ≡ -> assign name to locals, create docker image
// = -> lookup in Locals/Args/Globals and reassign value to Docker image
// ...
// Precedence for variable lookup is:
// Local, Args, Global
func (c *Compterpreter) Evaluate() error {
b, _ := json.MarshalIndent(c.StackTree, " ", " ")
fmt.Println(string(b))
/*
for _, operand := range c.StackTree.Operands {
b, _ := json.MarshalIndent(operand, " ", " ")
fmt.Println(string(b))
}
*/
r, err := c.StackTree.Operands[0].Eval()
wait, errChan := executer.Docker.ContainerWait(
context.Background(),
r,
container.WaitConditionNotRunning,
)
select {
case <-wait:
// execution complete!
case err = <-errChan:
// uo oh
}
return err
}