src/Modules.h
author David Anderson <dvander@alliedmods.net>
Sun Jan 06 13:52:21 2013 -0800 (2013-01-06)
changeset 256 3c184218462d
parent 251 ca99a81745fe
child 263 ba85a47ee414
permissions -rw-r--r--
Initial implementation of module imports.
[email protected]
     1
/*
[email protected]
     2
 * Copyright (C) 2012 David Anderson
[email protected]
     3
 *
[email protected]
     4
 * This file is part of SourcePawn.
[email protected]
     5
 *
[email protected]
     6
 * SourcePawn is free software: you can redistribute it and/or modify it under
[email protected]
     7
 * the terms of the GNU General Public License as published by the Free
[email protected]
     8
 * Software Foundation, either version 3 of the License, or (at your option)
[email protected]
     9
 * any later version.
[email protected]
    10
 * 
[email protected]
    11
 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
[email protected]
    12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
[email protected]
    13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
[email protected]
    14
 *
[email protected]
    15
 * You should have received a copy of the GNU General Public License along with
[email protected]
    16
 * SourcePawn. If not, see http://www.gnu.org/licenses/.
[email protected]
    17
 */
[email protected]
    18
#ifndef _include_jc_module_h_
[email protected]
    19
#define _include_jc_module_h_
[email protected]
    20
[email protected]
    21
#include "Heap.h"
[email protected]
    22
#include "Code.h"
[email protected]
    23
#include "Functions.h"
[email protected]
    24
#include "FixedArray.h"
[email protected]
    25
#include "Packages.h"
[email protected]
    26
[email protected]
    27
namespace ke {
[email protected]
    28
[email protected]
    29
class Environment;
[email protected]
    30
class Struct;
[email protected]
    31
class Package;
[email protected]
    32
struct TranslationUnit;
[email protected]
    33
[email protected]
    34
class Module : public Importable
[email protected]
    35
{
[email protected]
    36
    Barriered<Code> code_;
[email protected]
    37
    Barriered<Struct> globals_;
[email protected]
    38
    void *nativeIdentity_;
[email protected]
    39
    TranslationUnit *unit_;
[email protected]
    40
    Barriered<FixedArray> imports_;
[email protected]
    41
[email protected]
    42
  public:
dv[email protected]
    43
    static Module *New(Zone *zone, Handle<Package> package, Handle<String> path, Handle<String> name);
[email protected]
    44
    
[email protected]
    45
    Code *code() {
[email protected]
    46
        return code_;
[email protected]
    47
    }
[email protected]
    48
    Struct *globals() {
[email protected]
    49
        return globals_;
[email protected]
    50
    }
[email protected]
    51
[email protected]
    52
    bool compiled() {
[email protected]
    53
        return !!code_;
[email protected]
    54
    }
[email protected]
    55
[email protected]
    56
    // Modules are pre-created, and may have their intermediate compilation
[email protected]
    57
    // data attached while they are being compiled.
[email protected]
    58
    bool compiling() {
[email protected]
    59
        return !!unit_;
[email protected]
    60
    }
[email protected]
    61
    TranslationUnit *translationUnit() {
[email protected]
    62
        return unit_;
[email protected]
    63
    }
[email protected]
    64
    void setTranslationUnit(TranslationUnit *unit) {
[email protected]
    65
        unit_ = unit;
[email protected]
    66
    }
[email protected]
    67
[email protected]
    68
    unsigned imports() {
[email protected]
    69
        return imports_ ? imports_->length() / 2 : 0;
[email protected]
    70
    }
[email protected]
    71
    Importable *getImportAt(unsigned index) {
[email protected]
    72
        return Importable::cast(imports_->at(index * 2));
[email protected]
    73
    }
[email protected]
    74
    FixedArray *importPathAt(unsigned index) {
[email protected]
    75
        return FixedArray::cast(imports_->at(index * 2 + 1));
[email protected]
    76
    }
[email protected]
    77
    void setImports(Handle<FixedArray> imports) {
[email protected]
    78
        imports_ = imports;
[email protected]
    79
    }
[email protected]
    80
    void setCode(Handle<Code> code) {
[email protected]
    81
        code_ = code;
[email protected]
    82
    }
[email protected]
    83
    void setGlobals(Handle<Struct> globals) {
[email protected]
    84
        globals_ = globals;
[email protected]
    85
    }
[email protected]
    86
[email protected]
    87
    // Begin GC Descriptor.
[email protected]
    88
    static inline size_t offsetOfCode() {
[email protected]
    89
        return OFFSETOF(Module, code_);
[email protected]
    90
    }
[email protected]
    91
    static inline size_t offsetOfGlobals() {
[email protected]
    92
        return OFFSETOF(Module, globals_);
[email protected]
    93
    }
[email protected]
    94
    static inline size_t offsetOfImports() {
[email protected]
    95
        return OFFSETOF(Module, imports_);
[email protected]
    96
    }
[email protected]
    97
    // End GC Descriptor.
[email protected]
    98
[email protected]
    99
    static inline Module *cast(Object *obj) {
[email protected]
   100
        assert(!obj || obj->is(MapKind_Module));
[email protected]
   101
        return reinterpret_cast<Module *>(obj);
[email protected]
   102
    }
[email protected]
   103
};
[email protected]
   104
[email protected]
   105
}
[email protected]
   106
[email protected]
   107
#endif // _include_jc_module_h_