| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef LYTHON_OBJECT_VALUE_HEADER | ||
| 2 | #define LYTHON_OBJECT_VALUE_HEADER | ||
| 3 | |||
| 4 | // Actual method signature is WIP | ||
| 5 | // most mght become references | ||
| 6 | |||
| 7 | #include "ast/constant.h" | ||
| 8 | #include "dtypes.h" | ||
| 9 | #include "native.h" | ||
| 10 | |||
| 11 | namespace lython { | ||
| 12 | |||
| 13 | /* Compile time representation of an object | ||
| 14 | * This is just an array of attributes, methods were move out during SEMA | ||
| 15 | */ | ||
| 16 | struct Object: public NativeObject { | ||
| 17 | Array<struct Constant*> attributes; | ||
| 18 | // Methods belong in the class | ||
| 19 | // The object type is not known | ||
| 20 | // we rely on the SEMA to guarante the type | ||
| 21 | |||
| 22 | |||
| 23 | virtual bool is_native() const override { return false; } | ||
| 24 | }; | ||
| 25 | |||
| 26 | // Same as an object, but allocate a single block for all the attributes | ||
| 27 | // each attribute is a native value, avoids the ConstantValue overhead | ||
| 28 | // useful for POD types | ||
| 29 | struct PackedObject: public NativeObject { | ||
| 30 | int8* data; | ||
| 31 | |||
| 32 | template <typename T> | ||
| 33 | T& attribute(int offset) { | ||
| 34 | T* val = static_cast<T*>(data + offset); | ||
| 35 | return *val; | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | |||
| 39 | } // namespace lython | ||
| 40 | |||
| 41 | #endif | ||
| 42 |