start working on oop runtime

This commit is contained in:
2025-06-22 19:00:03 +01:00
parent fcffdc9000
commit 74c71c3a1b
15 changed files with 122 additions and 53 deletions

View File

@@ -0,0 +1,9 @@
#include "object.h"
#include "../../memory.h"
ArgonObject* init_argon_object() {
ArgonObject *object = ar_alloc(sizeof(ArgonObject));
object->type = TYPE_OBJECT;
object->cls = object;
object->fields = createHashmap(8);
}

View File

@@ -0,0 +1,29 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "../internals/hashmap/hashmap.h"
#include <gmp.h>
#include <stdbool.h>
typedef enum {
TYPE_NULL,
TYPE_BOOL,
TYPE_NUMBER,
TYPE_STRING,
TYPE_FUNCTION,
TYPE_NATIVE_FUNCTION,
TYPE_OBJECT, // generic user object
} ArgonType;
struct ArgonObject {
ArgonType type;
struct ArgonObject *cls; // class pointer or type object
struct hashmap *fields; // dynamic fields/methods
union {
mpq_t as_number;
bool as_bool;
char *as_str;
void *native_fn;
// others as needed
} value;
};
#endif // OBJECT_H

View File

@@ -0,0 +1,15 @@
#include "../object.h"
#include "../../internals/hashmap/hashmap.h"
#include "../../../memory.h"
#include <string.h>
#include "type.h"
ArgonObject *ARGON_TYPE_OBJ = NULL;
void init_type_obj() {
ARGON_TYPE_OBJ = ar_alloc(sizeof(ArgonObject));
ARGON_TYPE_OBJ->type = TYPE_OBJECT;
ARGON_TYPE_OBJ->cls = ARGON_TYPE_OBJ;
ARGON_TYPE_OBJ->fields = createHashmap(8);
memset(&ARGON_TYPE_OBJ->value, 0, sizeof(ARGON_TYPE_OBJ->value));
}

View File

@@ -0,0 +1,10 @@
#ifndef TYPES_H
#define TYPES_H
#include "../object.h"
extern ArgonObject *ARGON_TYPE_OBJ;
void init_type_obj();
#endif // TYPES_H