about summary refs log tree commit diff
path: root/pkg/lang/vm/value/value.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/value/value.go')
-rw-r--r--pkg/lang/vm/value/value.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/lang/vm/value/value.go b/pkg/lang/vm/value/value.go
new file mode 100644
index 0000000..e932ed3
--- /dev/null
+++ b/pkg/lang/vm/value/value.go
@@ -0,0 +1,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
+}