#!/usr/bin/perl # create cpjit.h open STDOUT, ">cpjit.h" or die "cpijit.h: $!"; $CPJIT_MAX_ARGS = 9; print < This file is part of libcpjit. libcpjit is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with gvpe; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include namespace cpjit { #define CPJIT_MAX_ARGS $CPJIT_MAX_ARGS #define CPJIT_NULLID "" typedef std::string idstr; // environment for persistent or temporary storage struct env { std::string path; bool temporary; unsigned long nextid; env (const std::string &path = CPJIT_NULLID, bool temporary = true); ~env (); std::string genid (); }; struct fun { env &e; idstr id; std::string source; void *funptr; fun (env &e, const idstr &id); // is compiled function available? bool compiled () { return funptr; } void set_source (const std::string source); // returns the function pointer void *ptr (); }; struct funbuild : std::ostringstream { env &e; idstr id; std::string hdr; funbuild (env &e, const idstr &id, const char *rettype, ...); std::string finish (); fun *get () { fun *f = new fun (e, id); f->set_source (finish ()); return f; } }; typedef unsigned char U8; typedef signed char I8; typedef uint16_t U16; typedef int16_t I16; typedef uint32_t U32; typedef int32_t I32; typedef uint64_t U64; typedef int64_t I64; typedef float FLT; typedef double DBL; typedef void * PTR; template struct typestr { }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; EOF for (0 .. $CPJIT_MAX_ARGS) { print < struct fun$_ : fun { fun$_ (env &e, const idstr &id) : fun (e, id) { } int operator ()(${\( join ", ", map "A$_ a$_", 1..$_ )}) { return ((R (*)(${\( join ", ", map "A$_", 1..$_ )})) ptr ())(${\( join ", ", map "a$_", 1..$_ )}); } }; template struct funbuild$_ : funbuild { funbuild$_ (env &e, const idstr &id = CPJIT_NULLID) : funbuild (e, id, typestr::str${\( join "", map ", typestr::str", 1..$_ )}, (const char *)0) { } fun$_ *get () { fun$_ *f = new fun$_ (e, id); f->set_source (finish ()); return f; } }; EOF } print <