A Detailed Inspection of the Native Maps Part Deux: Forth

Now time for the Forth mapping. This portion makes a little bit more sense if we use the ABC from Builtin: Doing Object.toString(). Let's see the source code in Object.as:

Object.as
[forth(word="w_toString")]
private static native function _toStr(o:*):*
The hint to Flex allows it to use the FORTH_METHOD macro in Builtin.h:
builtin_min.h   
BEGIN_NATIVE_MAP(builtin)
FORTH_METHOD(w_toString)
END_NATIVE_MAP()
Let's see what FORTH_METHOD does:
NativeFunction.h
#define FORTH_METHOD(m) { uintptr_t(wcodep(code_pool) + m##_offset), true, 0, 0 },
Again, we get the address of the Forth method, but it's not a machine address. code_pool is the Forth VM in C functions. However, what is wcodep:
Box.h
typedef byte Token;
typedef const Token* wcodep;
typedef wcodep* wcodepp;
So it is really just a byte pointer. Where is the w_toString_offset declared? When we go back to vm_min.h:
vm_min.h
extern_entry(w_toString, 8592)
The offset was generated from the Forth Compiler fc.py. We see that this macro is defined here:
Interpreter.h
#define extern_entry(x,y) enum { x##_offset = y };
Finally let's see what the forth implementation does:
vm.fs
EXTERN: w_toString ( Object$ obj argc=1 -- result )
DROP
isclass IF
getitraitsenv
ELSE
totraitsenv
THEN
traitsenvname // never returns null
sbox! nip ;
Finally we have a solid view of the glue between C, Forth, and ActionScript. Now the last kicker is how is this native map information used from ActionScript to call into the map.