1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/Modules.h Tue Jul 24 23:53:34 2012 -0700
1.3 @@ -0,0 +1,119 @@
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_jc_module_h_
1.22 +#define _include_jc_module_h_
1.23 +
1.24 +#include "Heap.h"
1.25 +#include "Code.h"
1.26 +#include "Functions.h"
1.27 +
1.28 +namespace ke {
1.29 +
1.30 +class Environment;
1.31 +
1.32 +class Module : public Object
1.33 +{
1.34 + Barriered<FixedArray> functions_;
1.35 + Barriered<FixedArray> publics_;
1.36 + Barriered<FixedArray> natives_;
1.37 + Barriered<String> file_;
1.38 + Barriered<Environment> environment_;
1.39 + Barriered<Code> code_;
1.40 + void *nativeIdentity_;
1.41 +
1.42 + public:
1.43 + static Module *New(Zone *zone, unsigned nfunctions);
1.44 +
1.45 + Function *getFunction(size_t i) {
1.46 + return Function::cast(functions_->at(i));
1.47 + }
1.48 + void setFunction(Zone *zone, size_t i, Function *fun) {
1.49 + assert(!functions_->at(i));
1.50 + assert(fun);
1.51 + functions_->set(zone, i, fun);
1.52 + }
1.53 +
1.54 + FixedArray *publics() {
1.55 + return publics_;
1.56 + }
1.57 + FixedArray *natives() {
1.58 + return natives_;
1.59 + }
1.60 + String *file() {
1.61 + return file_;
1.62 + }
1.63 + Environment *environment() {
1.64 + return environment_;
1.65 + }
1.66 + Code *code() {
1.67 + return code_;
1.68 + }
1.69 +
1.70 + void setPublics(Handle<FixedArray> publics) {
1.71 + publics_ = publics;
1.72 + }
1.73 + void setNatives(Handle<FixedArray> natives) {
1.74 + natives_ = natives;
1.75 + }
1.76 + void setPath(Handle<String> path) {
1.77 + file_ = path;
1.78 + }
1.79 + void setEnvironment(Handle<Environment> environment) {
1.80 + environment_ = environment;
1.81 + }
1.82 + void setCode(Handle<Code> code) {
1.83 + code_ = code;
1.84 + }
1.85 +
1.86 + void *nativeIdentity() {
1.87 + return nativeIdentity_;
1.88 + }
1.89 + void setNativeIdentity(void *identity) {
1.90 + nativeIdentity_ = identity;
1.91 + }
1.92 +
1.93 + // Begin GC Descriptor.
1.94 + static inline size_t offsetOfFunctions() {
1.95 + return offsetof(Module, functions_);
1.96 + }
1.97 + static inline size_t offsetOfPublics() {
1.98 + return offsetof(Module, publics_);
1.99 + }
1.100 + static inline size_t offsetOfNatives() {
1.101 + return offsetof(Module, natives_);
1.102 + }
1.103 + static inline size_t offsetOfFile() {
1.104 + return offsetof(Module, file_);
1.105 + }
1.106 + static inline size_t offsetOfEnvironment() {
1.107 + return offsetof(Module, environment_);
1.108 + }
1.109 + static inline size_t offsetOfCode() {
1.110 + return offsetof(Module, code_);
1.111 + }
1.112 + // End GC Descriptor.
1.113 +
1.114 + static inline Module *cast(Object *obj) {
1.115 + assert(!obj || obj->is(MapKind_Module));
1.116 + return reinterpret_cast<Module *>(obj);
1.117 + }
1.118 +};
1.119 +
1.120 +}
1.121 +
1.122 +#endif // _include_jc_module_h_