#!/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 "" // environment for persistent or temporary storage struct env { std::string path, idxpath; bool temporary; int idxfd; long idxstamp; void dolock (bool lock); void lock (); void unlock (); void load_index (); void save_index (); public: env (const std::string &path = CPJIT_NULLID, bool temporary = true); ~env (); // compact all fragments && invalidate ALL pointers void compact (); // completely delete the environment on disk void clear (); }; struct fun { env &e; std::string id, source; void *funptr; fun (env &e, const std::string &id, const std::string &source); // is compiled function available? bool compiled () { return funptr; } // returns the function pointer void *ptr (); }; struct funbuild : std::ostringstream { env &e; std::string retlist, arglist; funbuild (env &e, const char *rettype, ...); void finish (std::string &id, std::string &source); }; 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 std::string &id, const std::string &source) : fun(e, id, source) { } 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) : funbuild(e, typestr::str${\( join "", map ", typestr::str", 1..$_ )}, (const char *)0) { } fun$_ *get () { std::string id, source; finish (id, source); return new fun$_ (e, id, source); } }; EOF } print <