X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fbuiltin.c;h=dab69a171795b276ccd7fce46e18907bed463f75;hb=69d7ab699b50b7e24e74d13ffd9d50e8dc62e8a7;hp=417aced8f73eb33e5ca0c143979a29e8bc0e4322;hpb=dbf20036e740af204833afed2d19c0b30a24fbcb;p=cacao.git diff --git a/src/vm/builtin.c b/src/vm/builtin.c index 417aced8f..dab69a171 100644 --- a/src/vm/builtin.c +++ b/src/vm/builtin.c @@ -281,6 +281,81 @@ bool builtin_init(void) } +/* builtintable_get_by_key ***************************************************** + + Returns a key for the given builtintable_entry object which is suitable + for retrieving the instance again by calling builtintable_get_by_key. + + The key can be regarded fixed between multiple runs of the JVM. + +*******************************************************************************/ + +s4 builtintable_get_key(builtintable_entry *bte) +{ + s4 entries; +/* + int i; + entries = sizeof(builtintable_internal) / sizeof(builtintable_entry) - 1; + for (i = 0; i < entries; i++) + if (&builtintable_internal[i] == bte) + return i + 1; + + entries = sizeof(builtintable_automatic) / sizeof(builtintable_entry) - 1; + for (i = 0; i < entries; i++) + if (&builtintable_automatic[i] == bte) + return -i; + + entries = sizeof(builtintable_function) / sizeof(builtintable_entry) - 1; + for (i = 0; i < entries; i++) + if (&builtintable_function[i] == bte) + return -1000 - i; +*/ + + entries = sizeof(builtintable_internal) / sizeof(builtintable_entry) - 1; + if (&builtintable_internal[0] <= bte + && &builtintable_internal[entries - 1] >= bte) + { + return (s4) (bte - &builtintable_internal[0]) + 1; + } + + entries = sizeof(builtintable_automatic) / sizeof(builtintable_entry) - 1; + if (&builtintable_automatic[0] <= bte + && &builtintable_automatic[entries - 1] >= bte) + { + return -(s4) (bte - &builtintable_automatic[0]); + } + + entries = sizeof(builtintable_function) / sizeof(builtintable_entry) - 1; + if (&builtintable_function[0] <= bte + && &builtintable_function[entries - 1] >= bte) + { + return -1000 - (s4) (bte - &builtintable_function[0]); + } + + /* builtintable_entry is not in our tables. */ + assert (0); + + return 0; +} + +/* builtintable_get_by_key ***************************************************** + + Retrieves an entry in the internal and automatic builtin functions tables + using a key that was retrived previously with builtintable_get_key() + +*******************************************************************************/ + +builtintable_entry *builtintable_get_by_key(s4 key) +{ + /* If key is positive it is the index into builtintable_internal. If it is + * negative it is the index into builtintable_automatic. If it is <= -1000 + * it is the index into builtintable_function. + */ + return (key > 0) + ? &builtintable_internal[key - 1] + : (key > -1000 ? &builtintable_automatic[-key] : &builtintable_function[-(1000 + key)]); +} + /* builtintable_get_internal *************************************************** Finds an entry in the builtintable for internal functions and