first ever upload

This commit is contained in:
2026-03-17 20:41:40 -06:00
parent 707b56703d
commit a8f30f6967
10 changed files with 271 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#pragma once
#include <spider/runtime/cpu/Register.hpp>
namespace spider {
class CPU {
public: // General Purpose Registers
register_t RA, RB, RC, RD,
RX, RY, R0, R1,
R2, R3, R4, R5,
R6, R7, R8, R9;
public: // System Registers
u64 RF;
u64 RI;
u64 RS;
u64 RZ;
u64 RE;
u64 RN; // Epsilo(n)
u64 RV;
u64 RM;
public:
CPU();
~CPU();
};
}

View File

@@ -0,0 +1,77 @@
#pragma once
#include <spider/runtime/common.hpp>
#include <spider/runtime/native/machine.hpp>
namespace spider {
/**
* A register is a tiny piece of memory.
* I hate adding a _t suffix but for some idiotic
* reason "register" is a keyword in C++.
*
* Note that we have to check the endianness of the system
* at compile time to order the structure so that smaller
* types are actually the bottom part of the memory.
*
* Also, this has to be done with a compiler that allows
* type-punning which is the "standard" right now.
*/
union register_t {
u64 _u64;
i64 _i64;
f64 _f64;
u8 _bytes[8];
SPIDER_PACKED_STRUCT(struct {
#if SPIDER_LITTLE_ENDIAN
u8 _u8; u64 : 56;
#else
u64 : 56; u8 _u8;
#endif
});
SPIDER_PACKED_STRUCT(struct {
#if SPIDER_LITTLE_ENDIAN
u16 _u16; u64 : 48;
#else
u64 : 48; u16 _u16;
#endif
});
struct {
#if SPIDER_LITTLE_ENDIAN
u32 _u32; u32 : 32;
#else
u32 : 32; u32 _u32;
#endif
};
struct {
#if SPIDER_LITTLE_ENDIAN
f32 _f32; u32 : 32;
#else
u32 : 32; f32 _f32;
#endif
};
u8& operator[](size_t i) { // 0 is always LSB
#if SPIDER_LITTLE_ENDIAN
return _bytes[i];
#else
return _bytes[7 - i];
#endif
}
// ngl I could get executed for not having a const version
const u8& operator[](size_t i) const { // 0 is always LSB
#if SPIDER_LITTLE_ENDIAN
return _bytes[i];
#else
return _bytes[7 - i];
#endif
}
};
static_assert(sizeof(register_t) == 8, "The register type must be exactly 8 bytes.");
}