On Sun, 2007-03-25 at 19:06 -0700, Erick Tryzelaar wrote:
> To get the c-type name of a type, you can do this:
> 
> print Debug::repr_type[utiny]; endl;
> 
> which prints out:
> 
> _us2
> 
> Is there any way to get the felix type name? 

Ok, you can now do this:

/////////////////
#import <flx.flxh>

print$ _felix_type_name[int * long, double]; endl;
////////////////
[EMAIL PROTECTED]:/work/felix/svn/felix/felix/trunk$ f ftn
int * long,double
///////////////////

which is done in bind_expression' by the code:

  | `AST_name (sr,name,ts) ->
    if name = "_felix_type_name" then
       let sname = catmap "," string_of_typecode ts in
       let x = `AST_literal (sr,`AST_string sname) in
       be x
    else

This is the debug display the compiler uses for UNBOUND
typenames.

In the typeclass example:

proc p[T with Show[T]] (t:T) {
  print $ "type: " + _felix_type_name[T]; endl;
  print $ "str:  " + (str t); endl;
  print $ "repr: " + (repr t); endl;
  endl;
}

WILL print the wrong thing, namely just 'T', because it
is printing the raw unbound name in 'user terms'.

The name after binding would be similar, but include
full qualification (hard to read).

The only way to fix this at the moment is:

typeclass Show[T] {
  virtual fun show ...
  virtual fun show_typename: unit -> string;
}

instance Show[int] {
  ..
  fun show_typename()=>_felix_type_name[int];
}

So, now I'll look at another approach:

        fun whatever[t]: unit-> string = "@%^&1"

or something .. running out of magic codes here .. but this
is quite nasty because the csubst routine will need the
string passed in for every generic type, which means it
has to be calculated on every call.

This will be 'post virtual function instantiation', but
it will be the bound type name, not the raw type name.
(Because the type variables have been replaced, there
IS no raw typename).

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to