-
Notifications
You must be signed in to change notification settings - Fork 547
/
builtin_types.go
69 lines (51 loc) · 1.28 KB
/
builtin_types.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package qlang
import (
"qlang.io/exec"
qlang "qlang.io/spec"
)
// -----------------------------------------------------------------------------
func (p *Compiler) structInit() {
arity := p.popArity()
p.code.Block(exec.StructInit((arity << 1) + 1))
}
func (p *Compiler) mapInit() {
arity := p.popArity()
p.code.Block(exec.MapInit((arity << 1) + 1))
}
// -----------------------------------------------------------------------------
func (p *Compiler) tMap() {
p.code.Block(exec.Map)
}
func (p *Compiler) vMap() {
arity := p.popArity()
p.code.Block(exec.Call(qlang.MapFrom, arity<<1))
}
// -----------------------------------------------------------------------------
func (p *Compiler) tSlice() {
p.code.Block(exec.Slice)
}
func (p *Compiler) vSlice() {
hasSlice := p.popArity()
hasInit := 0
arityInit := 0
if hasSlice > 0 {
hasInit = p.popArity()
if hasInit > 0 {
arityInit = p.popArity()
}
}
arity := p.popArity()
if hasSlice > 0 {
if arity > 0 {
panic("must be []type")
}
if hasInit > 0 { // []T{a1, a2, ...}
p.code.Block(exec.SliceFromTy(arityInit + 1))
} else { // []T
p.code.Block(exec.Slice)
}
} else { // [a1, a2, ...]
p.code.Block(exec.SliceFrom(arity))
}
}
// -----------------------------------------------------------------------------