From ec5ee8647bcbf6ab073711c6892710776925c54d Mon Sep 17 00:00:00 2001 From: Mel Date: Tue, 17 May 2022 23:07:33 +0200 Subject: Lang VM Prototype --- pkg/lang/vm/value/value.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pkg/lang/vm/value/value.go (limited to 'pkg/lang/vm/value/value.go') 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 +} -- cgit 1.4.1