summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-05-13 19:43:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-05-13 19:43:12 -0700
commit400acf8d0a8df38401b5711894e9e342f6403d56 (patch)
tree9da2817e591c4c4c2d5605d8b3a1fb1ed14eb98c /struct.c
parentff68eb2b0cb646a0dc05d4379f5314fb751281a4 (diff)
downloadtxr-400acf8d0a8df38401b5711894e9e342f6403d56.tar.gz
txr-400acf8d0a8df38401b5711894e9e342f6403d56.tar.bz2
txr-400acf8d0a8df38401b5711894e9e342f6403d56.zip
Support autoloading for methods.
* struct.c (lookup_slot_load, lookup_static_slot_load): New functions. (slot, static_slot): Use auto-load wrappers for lower-level slot lookup functions.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/struct.c b/struct.c
index cdd09dd3..2cda3cbd 100644
--- a/struct.c
+++ b/struct.c
@@ -718,6 +718,26 @@ static loc lookup_static_slot(val stype, struct struct_type *st, val sym)
return nulloc;
}
+static loc lookup_slot_load(val inst, struct struct_inst *si, val sym)
+{
+ loc ptr = lookup_slot(inst, si, sym);
+ if (nullocp(ptr)) {
+ lisplib_try_load(sym);
+ return lookup_slot(inst, si, sym);
+ }
+ return ptr;
+}
+
+static loc lookup_static_slot_load(val stype, struct struct_type *st, val sym)
+{
+ loc ptr = lookup_static_slot(stype, st, sym);
+ if (nullocp(ptr)) {
+ lisplib_try_load(sym);
+ return lookup_static_slot(stype, st, sym);
+ }
+ return ptr;
+}
+
static noreturn void no_such_slot(val ctx, val type, val slot)
{
uw_throwf(error_s, lit("~a: ~s has no slot named ~s"),
@@ -730,7 +750,7 @@ val slot(val strct, val sym)
struct struct_inst *si = struct_handle(strct, self);
if (symbolp(sym)) {
- loc ptr = lookup_slot(strct, si, sym);
+ loc ptr = lookup_slot_load(strct, si, sym);
if (!nullocp(ptr))
return deref(ptr);
}
@@ -758,7 +778,7 @@ val static_slot(val stype, val sym)
struct struct_type *st = stype_handle(&stype, self);
if (symbolp(sym)) {
- loc ptr = lookup_static_slot(stype, st, sym);
+ loc ptr = lookup_static_slot_load(stype, st, sym);
if (!nullocp(ptr))
return deref(ptr);
}