00001 #include "xtended.hh"
00002 #include "Text.hh"
00003 #include <math.h>
00004
00005 class ExpPrim : public xtended
00006 {
00007
00008 public:
00009
00010 ExpPrim() : xtended("exp") {}
00011
00012 virtual unsigned int arity () { return 1; }
00013
00014 virtual bool needCache () { return true; }
00015
00016 virtual Type infereSigType (const vector<Type>& args)
00017 {
00018 assert (args.size() == arity());
00019 return floatCast(args[0]);
00020 }
00021
00022 virtual void sigVisit (Tree sig, sigvisitor* visitor) {}
00023
00024 virtual int infereSigOrder (const vector<int>& args) {
00025 assert (args.size() == arity());
00026 return args[0];
00027 }
00028
00029
00030 virtual Tree computeSigOutput (const vector<Tree>& args) {
00031 num n;
00032 assert (args.size() == arity());
00033 if (isNum(args[0],n)) {
00034 return tree(expf(float(n)));
00035 } else {
00036 return tree(symbol(), args[0]);
00037 }
00038 }
00039
00040 virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types)
00041 {
00042 assert (args.size() == arity());
00043 return subst("expf($0)", args[0]);
00044 }
00045
00046 };
00047
00048
00049 xtended* gExpPrim = new ExpPrim();
00050
00051