diff options
| author | Mel <einebeere@gmail.com> | 2022-05-17 23:07:33 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-05-17 23:07:33 +0200 |
| commit | ec5ee8647bcbf6ab073711c6892710776925c54d (patch) | |
| tree | 1228a72291123e0f520616b9d21f1e013e49351d /pkg/lang/vm/value/value.go | |
| parent | b09a14147d397904722ee7c25e4defc56135b96f (diff) | |
| download | jinx-ec5ee8647bcbf6ab073711c6892710776925c54d.tar.zst jinx-ec5ee8647bcbf6ab073711c6892710776925c54d.zip | |
Lang VM Prototype
Diffstat (limited to 'pkg/lang/vm/value/value.go')
| -rw-r--r-- | pkg/lang/vm/value/value.go | 52 |
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 +} |
