jitcraft/Functions.h
changeset 26 a48382113da6
child 28 a9665857cfd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/jitcraft/Functions.h	Mon Jul 02 01:52:57 2012 -0700
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 + * Copyright (C) 2012 David Anderson
     1.6 + *
     1.7 + * This file is part of JITCraft.
     1.8 + *
     1.9 + * JITCraft is free software: you can redistribute it and/or modify it under
    1.10 + * the terms of the GNU General Public License as published by the Free
    1.11 + * Software Foundation, either version 3 of the License, or (at your option)
    1.12 + * any later version.
    1.13 + * 
    1.14 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    1.15 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License along with
    1.19 + * JITCraft. If not, see http://www.gnu.org/licenses/.
    1.20 + */
    1.21 +#ifndef _include_jitcraft_function_h_
    1.22 +#define _include_jitcraft_function_h_
    1.23 +
    1.24 +#include "Heap.h"
    1.25 +#include "Barriers.h"
    1.26 +#include "Token.h"
    1.27 +#include "Types.h"
    1.28 +
    1.29 +namespace jc {
    1.30 +
    1.31 +class Code;
    1.32 +class Module;
    1.33 +class Type;
    1.34 +
    1.35 +class Function : public Object
    1.36 +{
    1.37 +    Barriered<Module> module_;
    1.38 +    Barriered<Code> code_;
    1.39 +    Barriered<Type> type_;
    1.40 +    SourcePosition pos_;
    1.41 +
    1.42 + public:
    1.43 +    static Function *New(Zone *zone, Module *module, Code *code, Type *type,
    1.44 +                         const SourcePosition &pos);
    1.45 +
    1.46 +    Code *code() const {
    1.47 +        return code_;
    1.48 +    }
    1.49 +    Type *type() const {
    1.50 +        return type_;
    1.51 +    }
    1.52 +    const SourcePosition &pos() {
    1.53 +        return pos_;
    1.54 +    }
    1.55 +    unsigned nargs() {
    1.56 +        return type()->parameters()->length();
    1.57 +    }
    1.58 +    Type *argType(size_t index) {
    1.59 +        return type()->parameterAt(index);
    1.60 +    }
    1.61 +
    1.62 +    static inline Function *cast(Object *obj) {
    1.63 +        assert(obj->is(MapKind_Function));
    1.64 +        return reinterpret_cast<Function *>(obj);
    1.65 +    }
    1.66 +};
    1.67 +
    1.68 +}
    1.69 +
    1.70 +#endif // _include_jitcraft_function_h_