This commit is contained in:
2022-02-07 23:33:56 +03:00
parent a6f83bab34
commit 6a1eae90d9
12 changed files with 133 additions and 112 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include "std.h"
#include "base_types.h"
#include "types.h"
#include "errors.h"
// just sleeping function

View File

@@ -1,62 +0,0 @@
#include "std.h"
#include "base_types.h"
#include "errors.h"
const char* typename(base_type t){
switch (t) {
case Null: return "Null";
case Double: return "Double";
case Float: return "Float";
case Bool: return "Bool";
case Char: return "Char";
case Int8: return "Int8";
case UInt8: return "UInt8";
case Int16: return "Int16";
case UInt16: return "UInt16";
case Int32: return "Int32";
case UInt32: return "UInt32";
case Int64: return "Int64";
case UInt64: return "UInt64";
case Int8Ptr: return "Int8Ptr";
case UInt8Ptr: return "UInt8Ptr";
case Int16Ptr: return "Int16Ptr";
case UInt16Ptr: return "UInt16Ptr";
case Int32Ptr: return "Int32Ptr";
case UInt32Ptr: return "UInt32Ptr";
case Int64Ptr: return "Int64Ptr";
case UInt64Ptr: return "UInt64Ptr";
default: throw(ERR_WRONGTYPE); return "EEEEEE";
}
}
int8 typesize(base_type type){
int8 type_size=0;
switch (type)
{
case Int8: type_size=8; break;
case UInt8: type_size=8; break;
case Int16: type_size=16; break;
case UInt16: type_size=16; break;
case Int32: type_size=32; break;
case UInt32: type_size=32; break;
case Int64: type_size=64; break;
case UInt64: type_size=64; break;
default: throw(ERR_WRONGTYPE);
}
return type_size;
}
void AssignVoidToVoid(void* a, void*b, base_type type){
switch (type)
{
case Int8: *((int8*)a)=*((int8*)b); break;
case UInt8: *((uint8*)a)=*((uint8*)b); break;
case Int16: *((int16*)a)=*((int16*)b); break;
case UInt16: *((uint16*)a)=*((uint16*)b); break;
case Int32: *((int32*)a)=*((int32*)b); break;
case UInt32: *((uint32*)a)=*((uint32*)b); break;
case Int64: *((int64*)a)=*((int64*)b); break;
case UInt64: *((uint64*)a)=*((uint64*)b); break;
default: throw(ERR_WRONGTYPE);
}
}

View File

@@ -1,24 +0,0 @@
#pragma once
#include "std.h"
#include "errors.h"
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef enum base_type{
Null, Float, Double, Char, Bool,
UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64,
UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr
} __attribute__ ((__packed__)) base_type;
const char* typename(base_type t);
int8 typesize(base_type type);
void AssignVoidToVoid(void* a, void*b, base_type type);

59
DtsodC/src/base/types.c Normal file
View File

@@ -0,0 +1,59 @@
#include "std.h"
#include "types.h"
#include "errors.h"
const char* typename(my_type t){
switch (t) {
case Null: return "Null";
case Double: return "Double";
case Float: return "Float";
case Bool: return "Bool";
case Char: return "Char";
case Int8: return "Int8";
case UInt8: return "UInt8";
case Int16: return "Int16";
case UInt16: return "UInt16";
case Int32: return "Int32";
case UInt32: return "UInt32";
case Int64: return "Int64";
case UInt64: return "UInt64";
case Int8Ptr: return "Int8Ptr";
case UInt8Ptr: return "UInt8Ptr";
case Int16Ptr: return "Int16Ptr";
case UInt16Ptr: return "UInt16Ptr";
case Int32Ptr: return "Int32Ptr";
case UInt32Ptr: return "UInt32Ptr";
case Int64Ptr: return "Int64Ptr";
case UInt64Ptr: return "UInt64Ptr";
case UniversalType: return "Unitype";
default: throw(ERR_WRONGTYPE);
}
}
int8 typesize(my_type type){
switch (type){
case Null: return 0;
case Double: return sizeof(double);
case Float: return sizeof(float);
case Bool: sizeof(bool);
case Char:
case Int8:
case UInt8: return 1;
case Int16:
case UInt16: return 2;
case Int32:
case UInt32: return 4;
case Int64:
case UInt64: return 8;
case Int8Ptr:
case UInt8Ptr:
case Int16Ptr:
case UInt16Ptr:
case Int32Ptr:
case UInt32Ptr:
case Int64Ptr:
case UInt64Ptr: return sizeof(void*);
case UniversalType: return "Unitype";
default: throw(ERR_WRONGTYPE);
}
}

43
DtsodC/src/base/types.h Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include "std.h"
#include "errors.h"
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef enum my_type{
Null, Float, Double, Char, Bool,
UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64,
UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr,
UniversalType
} __attribute__ ((__packed__)) my_type;
//returns type name
const char* typename(my_type t);
// returns size of type in bytes
int8 typesize(my_type type);
// can store any base type
typedef struct Unitype{
my_type type;
union {
int8 Int8;
uint8 UInt8;
int16 Int16;
uint16 UInt16;
int32 Int32;
uint32 UInt32;
int64 Int64;
uint64 UInt64;
float Float;
double Double;
void* VoidPtr;
};
} Unitype;