-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
program.go
36 lines (31 loc) · 927 Bytes
/
program.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
package compiler
import (
"github.com/numary/ledger/pkg/core"
"github.com/numary/ledger/pkg/machine/vm/program"
)
func (p *parseVisitor) AppendInstruction(instruction byte) {
p.instructions = append(p.instructions, instruction)
}
func (p *parseVisitor) PushAddress(addr core.Address) {
p.instructions = append(p.instructions, program.OP_APUSH)
bytes := addr.ToBytes()
p.instructions = append(p.instructions, bytes...)
}
func (p *parseVisitor) PushInteger(val core.Number) error {
addr, err := p.AllocateResource(program.Constant{Inner: val})
if err != nil {
return err
}
p.instructions = append(p.instructions, program.OP_APUSH)
bytes := addr.ToBytes()
p.instructions = append(p.instructions, bytes...)
return nil
}
func (p *parseVisitor) Bump(n int64) error {
err := p.PushInteger(core.NewNumber(n))
if err != nil {
return err
}
p.instructions = append(p.instructions, program.OP_BUMP)
return nil
}