-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.go
More file actions
50 lines (39 loc) · 1.04 KB
/
process.go
File metadata and controls
50 lines (39 loc) · 1.04 KB
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
49
50
package main
import (
f "github.com/soerlemans/table/filter"
ir "github.com/soerlemans/table/filter/ir"
td "github.com/soerlemans/table/table_data"
u "github.com/soerlemans/table/util"
)
// Execution context of a procss required for running the program.
type ProcessContext struct {
// Identifier.
Id uint64
// Pointer to filters
Filter *f.Filter
// Internal table representation.
Table td.TableData
}
// Gives a unique id for every Processcontext.
var idCounter uint64
func initProcessContext(t_filter *f.Filter, t_table td.TableData) ProcessContext {
ctx := ProcessContext{idCounter, t_filter, t_table}
defer func() { u.LogStructName("initContext", ctx, u.ETC80) }()
// Increment id counter.
idCounter++
return ctx
}
func Process(t_ctx ProcessContext) error {
filter := t_ctx.Filter
vm, err := ir.InitIrVm(&t_ctx.Table)
if err != nil {
return err
}
// We can modify redundant instructions during execution.
instructions := filter.Instructions
err = vm.Exec(*instructions)
if err != nil {
return err
}
return vm.Write()
}