about summary refs log tree commit diff
path: root/pkg/lang/vm/value
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/value')
-rw-r--r--pkg/lang/vm/value/data.go17
-rw-r--r--pkg/lang/vm/value/type.go19
-rw-r--r--pkg/lang/vm/value/value.go52
3 files changed, 88 insertions, 0 deletions
diff --git a/pkg/lang/vm/value/data.go b/pkg/lang/vm/value/data.go
new file mode 100644
index 0000000..1d63d32
--- /dev/null
+++ b/pkg/lang/vm/value/data.go
@@ -0,0 +1,17 @@
+package value
+
+type IntData int64
+
+type FloatData float64
+
+type StringData string
+
+type BoolData bool
+
+type ArrayData []Value
+
+type NullData struct{}
+
+type FunctionData struct{} // TODO
+
+type ObjectData struct{} // TODO
diff --git a/pkg/lang/vm/value/type.go b/pkg/lang/vm/value/type.go
new file mode 100644
index 0000000..1aec251
--- /dev/null
+++ b/pkg/lang/vm/value/type.go
@@ -0,0 +1,19 @@
+package value
+
+type TypeKind int
+
+const (
+	IntType TypeKind = iota
+	FloatType
+	StringType
+	BoolType
+	ArrayType
+	NullType
+	FunctionType
+
+	ObjectType
+)
+
+type Type struct {
+	Kind TypeKind
+}
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
+}