start working on oop runtime
This commit is contained in:
9
src/runtime/objects/object.c
Normal file
9
src/runtime/objects/object.c
Normal 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);
|
||||
}
|
||||
29
src/runtime/objects/object.h
Normal file
29
src/runtime/objects/object.h
Normal 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
|
||||
15
src/runtime/objects/type/type.c
Normal file
15
src/runtime/objects/type/type.c
Normal 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));
|
||||
}
|
||||
10
src/runtime/objects/type/type.h
Normal file
10
src/runtime/objects/type/type.h
Normal 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
|
||||
Reference in New Issue
Block a user