src/Modules.h
author David Anderson <dvander@alliedmods.net>
Sun Sep 02 13:06:09 2012 -0700 (2012-09-02)
changeset 177 56f7e5b0243c
parent 91 5f4402180204
child 195 c1ba166f3fc4
permissions -rw-r--r--
Fix bug in bytecode resizing.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     6  * JITCraft is free software: you can redistribute it and/or modify it under
     7  * the terms of the GNU General Public License as published by the Free
     8  * Software Foundation, either version 3 of the License, or (at your option)
     9  * any later version.
    10  * 
    11  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along with
    16  * JITCraft. If not, see http://www.gnu.org/licenses/.
    17  */
    18 #ifndef _include_jc_module_h_
    19 #define _include_jc_module_h_
    20 
    21 #include "Heap.h"
    22 #include "Code.h"
    23 #include "Functions.h"
    24 
    25 namespace ke {
    26 
    27 class Environment;
    28 
    29 class Module : public Object
    30 {
    31     Barriered<FixedArray> functions_;
    32     Barriered<FixedArray> publics_;
    33     Barriered<FixedArray> natives_;
    34     Barriered<String> file_;
    35     Barriered<Environment> environment_;
    36     Barriered<Code> code_;
    37     void *nativeIdentity_;
    38 
    39   public:
    40     static Module *New(Zone *zone, unsigned nfunctions);
    41 
    42     Function *getFunction(size_t i) {
    43         return Function::cast(functions_->at(i));
    44     }
    45     void setFunction(Zone *zone, size_t i, Function *fun) {
    46         assert(!functions_->at(i));
    47         assert(fun);
    48         functions_->set(zone, i, fun);
    49     }
    50 
    51     FixedArray *publics() {
    52         return publics_;
    53     }
    54     FixedArray *natives() {
    55         return natives_;
    56     }
    57     String *file() {
    58         return file_;
    59     }
    60     Environment *environment() {
    61         return environment_;
    62     }
    63     Code *code() {
    64         return code_;
    65     }
    66 
    67     void setPublics(Handle<FixedArray> publics) {
    68         publics_ = publics;
    69     }
    70     void setNatives(Handle<FixedArray> natives) {
    71         natives_ = natives;
    72     }
    73     void setPath(Handle<String> path) {
    74         file_ = path;
    75     }
    76     void setEnvironment(Handle<Environment> environment) {
    77         environment_ = environment;
    78     }
    79     void setCode(Handle<Code> code) {
    80         code_ = code;
    81     }
    82 
    83     void *nativeIdentity() {
    84         return nativeIdentity_;
    85     }
    86     void setNativeIdentity(void *identity) {
    87         nativeIdentity_ = identity;
    88     }
    89 
    90     // Begin GC Descriptor.
    91     static inline size_t offsetOfFunctions() {
    92         return OFFSETOF(Module, functions_);
    93     }
    94     static inline size_t offsetOfPublics() {
    95         return OFFSETOF(Module, publics_);
    96     }
    97     static inline size_t offsetOfNatives() {
    98         return OFFSETOF(Module, natives_);
    99     }
   100     static inline size_t offsetOfFile() {
   101         return OFFSETOF(Module, file_);
   102     }
   103     static inline size_t offsetOfEnvironment() {
   104         return OFFSETOF(Module, environment_);
   105     }
   106     static inline size_t offsetOfCode() {
   107         return OFFSETOF(Module, code_);
   108     }
   109     // End GC Descriptor.
   110 
   111     static inline Module *cast(Object *obj) {
   112         assert(!obj || obj->is(MapKind_Module));
   113         return reinterpret_cast<Module *>(obj);
   114     }
   115 };
   116 
   117 }
   118 
   119 #endif // _include_jc_module_h_