Replacing veneer routines?

I’m experimenting a bit with the Inform6 compiler. I’ve added a printout of which veneer-routines that gets compiled into the output.

Compiling veneer routines:
  RV__Pr
  CA__Pr
  RA__Pr
  RL__Pr
  OP__Pr
  OC__Cl
  Copy__Primitive
  RT__Err
  Z__Region
  Unsigned__Compare
  Meta__class
  CP__Tab
  Cl__Ms
  Print__PName

How do I do if I would want to have my own version of one of these?

If I add my own version of the routine CL__Ms, I get a warning that it’s never called (and possibly is it removed if I choose $OMIT_UNUSED_ROUTINES=1). The compiler recognizes that I have the routine replaced and don’t insert the veneer one.

source\new_veneer.inf(19): Warning:  Routine "Cl__Ms" declared but not used

Compiling veneer routines:
  RV__Pr
  CA__Pr
  RA__Pr
  RL__Pr
  OP__Pr
  OC__Cl
  Copy__Primitive
  RT__Err
  Z__Region
  Unsigned__Compare
  Meta__class
  CP__Tab
  Print__PName

What am I doing wrong?

I don’t know, you didn’t say what your code looks like.

This works without warnings:

Replace CL__Ms;

[ CL__Ms;
	print "Replaced function.^";
];

[ Main;
	TestFunc();
];

Class TestClass;

[ TestFunc;
	print "Hello.^";
	TestClass.create();
];

Well it is a full fledge game. I’ll try your test with my switches when I’m back home.

The Replace line and the new definition should appear before any other code.

Are you only saying this with respect to veneer routines? I’ve been replacing action routines (like GoSub, LockSub and UnlockSub) for years and I always put them at the end of my code, along with all the other action routines.

Veneer routines behave slightly differently, so probably.

1 Like

When replacing a veneer function like RV__Pr, is there a way to make expressions like obj.#identifier <= 2 to compile with native syntax (get_prop_addr and get_prop_len) or do I have to use the opcodes myself with the @-syntax? Now it calls itself and fills up the stack.

[ RV__Pr obj identifier x;
 x = obj..&identifier;
 if (x==0)
 {   if (identifier >= 1 && identifier < 64 && obj.#identifier <= 2)
		 return obj.identifier;
	 !RT__Err(\"read\", obj, identifier); return; 
 }
 #IFV3;
 !if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier);
 #IFNOT;
 !if (obj..#identifier > 2) RT__Err(\"read\", obj, identifier, 2);
 #ENDIF;
 return x-->0;
];

Compiles in veneer:

    1  +11f18  [ RV__Pr obj identifier x

    1  +11f19     call_vs      long_16 (veneer routine: RA__Pr) obj identifier -> x
    1  +11f20     jz           x to L0 if FALSE
    1  +11f24     jl           identifier short_1 to L1 if TRUE
    1  +11f29     jl           identifier short_64 to L1 if FALSE
    1  +11f2e     get_prop_addr obj identifier -> TEMP1
    1  +11f32     jz           TEMP1 to L2 if TRUE
    1  +11f36     get_prop_len TEMP1 -> TEMP1
    1  +11f39    .L2
    1  +11f39     push         TEMP1
    1  +11f3c     jg           sp short_2 to L1 if TRUE
    1  +11f41     get_prop     obj identifier -> TEMP1
    1  +11f45     push         TEMP1
    1  +11f48     ret_popped
    1  +11f49    .L1
    1  +11f49     call_vn      long_2037 (ref to symbol value: RT__Err) long_33961 (string literal) obj identifier
    1  +11f51     rtrue
    1  +11f52    .L0
    1  +11f52     call_vs      long_17 (veneer routine: RL__Pr) obj identifier -> sp
    1  +11f59     jg           sp short_2 to L3 if FALSE
    1  +11f5e     call_vn2     long_2037 (ref to symbol value: RT__Err) long_33962 (string literal) obj identifier short_2
    1  +11f68    .L3
    1  +11f68     loadw        x short_0 -> sp
    1  +11f6c     ret_popped

And when it’s replaced:

   23  +11d7c  [ RV__Pr obj identifier x

   25  +11d7d <*> call_vs      long_16 (veneer routine: RA__Pr) obj identifier -> x
   27  +11d84 <*> jz           x to L0 if FALSE
   29  +11d88 <*> jl           identifier short_1 to L1 if TRUE
   29  +11d8d     jl           identifier short_64 to L1 if FALSE
   29  +11d92     call_vs      long_17 (veneer routine: RL__Pr) obj identifier -> sp
   29  +11d99     jg           sp short_2 to L1 if TRUE
   31  +11d9e <*> call_vs      long_10 (veneer routine: RV__Pr) obj identifier -> sp
   31  +11da5     ret_popped
   31  +11da6    .L1
   45  +11da6    .L0
   47  +11da6 <*> loadw        x short_0 -> sp
   47  +11daa     ret_popped
1 Like

You have to use the opcodes.

1 Like