about summary refs log tree commit diff
path: root/pkg/lang/vm/value/value.go
blob: e932ed3f1f578c13feac1eb78f8b09e2e25ae4d4 (plain)
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
package value

type Value struct {
	t Type
	d any
}

func NewInt(x int64) Value {
	t := Type{Kind: IntType}
	return Value{t: t, d: IntData(x)}
}

func NewFloat(x float64) Value {
	t := Type{Kind: FloatType}
	return Value{t: t, d: FloatData(x)}
}

func NewString(str string) Value {
	t := Type{Kind: StringType}
	return Value{t: t, d: StringData(str)}
}

func NewBool(b bool) Value {
	t := Type{Kind: BoolType}
	return Value{t: t, d: BoolData(b)}
}

func NewArray(arr []Value) Value {
	t := Type{Kind: ArrayType}
	return Value{t: t, d: ArrayData(arr)}
}

func NewNull() Value {
	t := Type{Kind: NullType}
	return Value{t: t}
}

func NewFunction() Value {
	panic("not implemented")
}

func NewObject() Value {
	panic("not implemented")
}

func (v Value) Type() Type {
	return v.t
}

func (v Value) Data() any {
	return v.d
}