Added types module
This commit is contained in:
parent
223ba603a7
commit
d81ceb6760
|
@ -0,0 +1,70 @@
|
|||
# Copyright 2022 Mattia Giambirtone & All Contributors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
type
|
||||
ObjectKind* = enum
|
||||
objFloat, objInt, objBool,
|
||||
objNil, objNan, objInf,
|
||||
objString
|
||||
PeonObject* = ref object of RootObj
|
||||
kind*: ObjectKind
|
||||
Nil* = ref object of PeonObject
|
||||
Nan* = ref object of PeonObject
|
||||
Inf* = ref object of PeonObject
|
||||
positive*: bool
|
||||
Bool* = ref object of PeonObject
|
||||
value*: bool
|
||||
Int8* = ref object of PeonObject
|
||||
value*: int8
|
||||
Int16* = ref object of PeonObject
|
||||
value*: int16
|
||||
Int32* = ref object of PeonObject
|
||||
value*: int32
|
||||
Int64* = ref object of PeonObject
|
||||
value*: int64
|
||||
UInt8* = ref object of PeonObject
|
||||
value*: uint8
|
||||
UInt16* = ref object of PeonObject
|
||||
value*: uint16
|
||||
UInt32* = ref object of PeonObject
|
||||
value*: uint32
|
||||
UInt64* = ref object of PeonObject
|
||||
value*: uint64
|
||||
Float32* = ref object of PeonObject
|
||||
value*: float32
|
||||
Float64* = ref object of PeonObject
|
||||
value*: float64
|
||||
|
||||
when sizeof(int) == 8:
|
||||
type Int = Int64
|
||||
elif sizeof(int) == 4:
|
||||
type Int = Int32
|
||||
elif sizeof(int) == 2:
|
||||
type Int = Int16
|
||||
else:
|
||||
type Int = Int8
|
||||
|
||||
when sizeof(float) == 8:
|
||||
type Float = Float64
|
||||
else:
|
||||
type Float = Float32
|
||||
|
||||
|
||||
proc newNil*: Nil = Nil(kind: objNil)
|
||||
proc newNan*: Nan = Nan(kind: objNan)
|
||||
proc newInf*(positive: bool): Inf = Inf(kind: objInf, positive: positive)
|
||||
proc newBool*(value: bool): Bool = Bool(kind: objBool, value: value)
|
||||
proc newInt*(value: int): Int = Int(kind: objInt, value: value)
|
||||
proc newFloat*(value: float): Float = Float(kind: objFloat, value: value)
|
Loading…
Reference in New Issue