turn access into a function to be ran at runtime

This commit is contained in:
2025-08-10 01:45:46 +01:00
parent ad3e31b0a2
commit 49b1c1858a
14 changed files with 196 additions and 636502 deletions

View File

@@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: 2025 William Bell
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "access.h"
#include <stdio.h>
ArgonObject *ARGON_TYPE_TYPE___get_attr__(size_t argc, ArgonObject **argv,
ArErr *err, RuntimeState *state) {
(void)state;
if (argc != 3) {
*err = create_err(0, 0, 0, "", "Runtime Error",
"__get_attr__ expects 3 arguments, got %" PRIu64);
return ARGON_NULL;
}
ArgonObject *to_access = argv[0];
ArgonObject *access = argv[1];
bool check_field = argv[2] == ARGON_TRUE;
if (check_field) {
ArgonObject *value = get_field_l(to_access, access->value.as_str.data,
access->value.as_str.length, true, false);
if (value)
return value;
}
ArgonObject *name = get_field_for_class(
get_field(to_access, "__class__", false, false), "__name__", to_access);
*err = create_err(0, 0, 0, "", "Runtime Error",
"'%.*s' object has no attribute '%.*s'",
(int)name->value.as_str.length, name->value.as_str.data,
(int)access->value.as_str.length, access->value.as_str.data);
return ARGON_NULL;
}

View File

@@ -0,0 +1,17 @@
/*
* SPDX-FileCopyrightText: 2025 William Bell
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef runtime_access_H
#define runtime_access_H
#include "../objects/literals/literals.h"
#include "../objects/object.h"
#include "../runtime.h"
#include <inttypes.h>
ArgonObject *ARGON_TYPE_TYPE___get_attr__(size_t argc, ArgonObject **argv,
ArErr *err, RuntimeState *state);
#endif // runtime_access_H