Commit 3e2c911b authored by Chris Ramstad's avatar Chris Ramstad

Implement builtin function id()

Currently returns the address if the Box*
parent 2412b178
......@@ -180,6 +180,12 @@ extern "C" Box* sum(Box* container, Box* initial) {
return cur;
}
extern "C" Box* id(Box* arg) {
i64 addr = (i64)(arg);
return boxInt(addr);
}
Box* open(Box* arg1, Box* arg2) {
assert(arg2);
......@@ -494,6 +500,8 @@ void setupBuiltins() {
builtins_module->giveAttr("sum",
new BoxedFunction(boxRTFunction((void*)sum, UNKNOWN, 2, 1, false, false), { boxInt(0) }));
id_obj = new BoxedFunction(boxRTFunction((void*)id, BOXED_INT, 1));
builtins_module->giveAttr("id", id_obj);
chr_obj = new BoxedFunction(boxRTFunction((void*)chr, STR, 1));
builtins_module->giveAttr("chr", chr_obj);
ord_obj = new BoxedFunction(boxRTFunction((void*)ord, BOXED_INT, 1));
......
......@@ -405,6 +405,8 @@ extern "C" BoxedString* functionRepr(BoxedFunction* v) {
return boxStrConstant("<built-in function max>");
if (v == open_obj)
return boxStrConstant("<built-in function open>");
if (v == id_obj)
return boxStrConstant("<built-in function id>");
if (v == chr_obj)
return boxStrConstant("<built-in function chr>");
if (v == ord_obj)
......@@ -422,6 +424,7 @@ Box* abs_obj = NULL;
Box* min_obj = NULL;
Box* max_obj = NULL;
Box* open_obj = NULL;
Box* id_obj = NULL;
Box* chr_obj = NULL;
Box* ord_obj = NULL;
Box* trap_obj = NULL;
......
......@@ -81,8 +81,8 @@ extern const ObjectFlavor object_flavor, type_flavor, bool_flavor, int_flavor, f
}
extern "C" { extern Box* None, *NotImplemented, *True, *False; }
extern "C" {
extern Box* repr_obj, *len_obj, *hash_obj, *range_obj, *abs_obj, *min_obj, *max_obj, *open_obj, *chr_obj, *ord_obj,
*trap_obj;
extern Box* repr_obj, *len_obj, *hash_obj, *range_obj, *abs_obj, *min_obj, *max_obj, *open_obj, *id_obj, *chr_obj,
*ord_obj, *trap_obj;
} // these are only needed for functionRepr, which is hacky
extern "C" { extern BoxedModule* sys_module, *builtins_module, *math_module, *time_module, *thread_module; }
......
x = 'Hi'
y = 1
z = (42, 7)
f = (2,) + z
id(x)
id(y)
id(z)
id(f)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment