diff -r 06a0015b6a5c -r 32ad0523b309 src/Modules.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Modules.h Tue Jul 24 23:53:34 2012 -0700 @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2012 David Anderson + * + * This file is part of JITCraft. + * + * JITCraft 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 3 of the License, or (at your option) + * any later version. + * + * Foobar 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 + * JITCraft. If not, see http://www.gnu.org/licenses/. + */ +#ifndef _include_jc_module_h_ +#define _include_jc_module_h_ + +#include "Heap.h" +#include "Code.h" +#include "Functions.h" + +namespace ke { + +class Environment; + +class Module : public Object +{ + Barriered functions_; + Barriered publics_; + Barriered natives_; + Barriered file_; + Barriered environment_; + Barriered code_; + void *nativeIdentity_; + + public: + static Module *New(Zone *zone, unsigned nfunctions); + + Function *getFunction(size_t i) { + return Function::cast(functions_->at(i)); + } + void setFunction(Zone *zone, size_t i, Function *fun) { + assert(!functions_->at(i)); + assert(fun); + functions_->set(zone, i, fun); + } + + FixedArray *publics() { + return publics_; + } + FixedArray *natives() { + return natives_; + } + String *file() { + return file_; + } + Environment *environment() { + return environment_; + } + Code *code() { + return code_; + } + + void setPublics(Handle publics) { + publics_ = publics; + } + void setNatives(Handle natives) { + natives_ = natives; + } + void setPath(Handle path) { + file_ = path; + } + void setEnvironment(Handle environment) { + environment_ = environment; + } + void setCode(Handle code) { + code_ = code; + } + + void *nativeIdentity() { + return nativeIdentity_; + } + void setNativeIdentity(void *identity) { + nativeIdentity_ = identity; + } + + // Begin GC Descriptor. + static inline size_t offsetOfFunctions() { + return offsetof(Module, functions_); + } + static inline size_t offsetOfPublics() { + return offsetof(Module, publics_); + } + static inline size_t offsetOfNatives() { + return offsetof(Module, natives_); + } + static inline size_t offsetOfFile() { + return offsetof(Module, file_); + } + static inline size_t offsetOfEnvironment() { + return offsetof(Module, environment_); + } + static inline size_t offsetOfCode() { + return offsetof(Module, code_); + } + // End GC Descriptor. + + static inline Module *cast(Object *obj) { + assert(!obj || obj->is(MapKind_Module)); + return reinterpret_cast(obj); + } +}; + +} + +#endif // _include_jc_module_h_