Skip to content

Commit

Permalink
feat: add 'id' builtin function to retrieve unique object identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopodl committed Jul 26, 2024
1 parent 444d900 commit 9c1dde4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion argon/vm/mod/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ ARGON_FUNCTION(builtins_getattr, getattr,
return res;
}

ARGON_FUNCTION(builtins_id, id,
"Return the identity of an object.\n"
"\n"
"Returns a unique integer identifier for an object. This identifier remains constant throughout the object's lifetime. "
"The same identifier may be reused for different objects that exist at separate times.\n"
"\n"
"- Parameter obj: Object to check.\n"
"- Returns: Object memory address (UInt).\n",
": obj", false, false) {
return (ArObject *) UIntNew(*((uintptr_t *) args));
}

ARGON_FUNCTION(builtins_iscallable, iscallable,
"Return true if argument appears callable, false otherwise.\n"
"\n"
Expand Down Expand Up @@ -339,7 +351,7 @@ ARGON_FUNCTION(builtins_show, show,
Release(aux);
}

ret = ListNew((ArObject*)target);
ret = ListNew((ArObject *) target);

Release(target);

Expand Down Expand Up @@ -417,6 +429,7 @@ const ModuleEntry builtins_entries[] = {
//MODULE_EXPORT_FUNCTION(builtins_exit),
MODULE_EXPORT_FUNCTION(builtins_eval),
MODULE_EXPORT_FUNCTION(builtins_getattr),
MODULE_EXPORT_FUNCTION(builtins_id),
MODULE_EXPORT_FUNCTION(builtins_iscallable),
MODULE_EXPORT_FUNCTION(builtins_implements),
MODULE_EXPORT_FUNCTION(builtins_len),
Expand Down

0 comments on commit 9c1dde4

Please sign in to comment.