diff --git a/Analyser/Static/Macintosh/Target.hpp b/Analyser/Static/Macintosh/Target.hpp index eac46acb7..5e7d4913e 100644 --- a/Analyser/Static/Macintosh/Target.hpp +++ b/Analyser/Static/Macintosh/Target.hpp @@ -10,24 +10,21 @@ #define Analyser_Static_Macintosh_Target_h #include "../../../Reflection/Enum.h" - +#include "../../../Reflection/Struct.h" namespace Analyser { namespace Static { namespace Macintosh { - -struct Target: public ::Analyser::Static::Target { - ReflectiveEnum(Model, int, Mac128k, Mac512k, Mac512ke, MacPlus); +struct Target: public ::Analyser::Static::Target, public Reflection::Struct { + ReflectableEnum(Model, int, Mac128k, Mac512k, Mac512ke, MacPlus); Target() { -// Model m; -// printf("%s\n", __declaration(m)); - printf("%zu\n", Reflection::Enum::size()); -// for(size_t c = 0; c < Reflection::Enum::size(); ++c) { -// const auto name = Reflection::Enum::toString(Model(c)); -// printf("%.*s\n", int(name.size()), name.data()); -// } + // Boilerplate for declaring fields and potential values. + if(needs_declare()) { + declare(&model, "model"); + declare_enum(&model, EnumDeclaration(Model)); + } } Model model = Model::MacPlus; @@ -37,5 +34,4 @@ struct Target: public ::Analyser::Static::Target { } } - #endif /* Analyser_Static_Macintosh_Target_h */ diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index b9ceedf4c..f8b1306c4 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -51,6 +51,9 @@ namespace { constexpr int CLOCK_RATE = 7833600; + +Analyser::Static::Macintosh::Target nothing; + } namespace Apple { diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 3f246ad8d..c7f57a85b 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1040,6 +1040,8 @@ 4B38F3471F2EC11D00D9235D /* AmstradCPC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AmstradCPC.hpp; path = AmstradCPC/AmstradCPC.hpp; sourceTree = ""; }; 4B3940E51DA83C8300427841 /* AsyncTaskQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AsyncTaskQueue.cpp; path = ../../Concurrency/AsyncTaskQueue.cpp; sourceTree = ""; }; 4B3940E61DA83C8300427841 /* AsyncTaskQueue.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AsyncTaskQueue.hpp; path = ../../Concurrency/AsyncTaskQueue.hpp; sourceTree = ""; }; + 4B3AF7D02413470E00873C0B /* Enum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enum.h; sourceTree = ""; }; + 4B3AF7D12413472200873C0B /* Struct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Struct.h; sourceTree = ""; }; 4B3BA0C21D318AEB005DD7A7 /* C1540Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C1540Tests.swift; sourceTree = ""; }; 4B3BA0C51D318B44005DD7A7 /* C1540Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = C1540Bridge.h; sourceTree = ""; }; 4B3BA0C61D318B44005DD7A7 /* C1540Bridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = C1540Bridge.mm; sourceTree = ""; }; @@ -1138,7 +1140,6 @@ 4B643F3C1D77AE5C00D431D6 /* CSMachine+Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CSMachine+Target.h"; sourceTree = ""; }; 4B643F3E1D77B88000D431D6 /* DocumentController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentController.swift; sourceTree = ""; }; 4B644ED023F0FB55006C0CC5 /* ScanSynchroniser.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ScanSynchroniser.hpp; sourceTree = ""; }; - 4B644ED123FAF162006C0CC5 /* Enum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Enum.h; path = ../../Reflection/Enum.h; sourceTree = ""; }; 4B65085F22F4CF8D009C1100 /* Keyboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Keyboard.cpp; sourceTree = ""; }; 4B670A832401CB8400D4E002 /* z80memptr.tap */ = {isa = PBXFileReference; lastKnownFileType = file; path = z80memptr.tap; sourceTree = ""; }; 4B670A852401CB8400D4E002 /* z80ccf.tap */ = {isa = PBXFileReference; lastKnownFileType = file; path = z80ccf.tap; sourceTree = ""; }; @@ -2195,6 +2196,16 @@ name = Concurrency; sourceTree = ""; }; + 4B3AF7CF2413470E00873C0B /* Reflection */ = { + isa = PBXGroup; + children = ( + 4B3AF7D02413470E00873C0B /* Enum.h */, + 4B3AF7D12413472200873C0B /* Struct.h */, + ); + name = Reflection; + path = ../../Reflection; + sourceTree = ""; + }; 4B3BA0C41D318B44005DD7A7 /* Bridges */ = { isa = PBXGroup; children = ( @@ -3247,7 +3258,6 @@ 4BB73E951B587A5100552FC2 = { isa = PBXGroup; children = ( - 4B644ED123FAF162006C0CC5 /* Enum.h */, 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */, 4B51F70820A521D700AFA2C1 /* Activity */, 4B8944E2201967B4007DE474 /* Analyser */, @@ -3265,6 +3275,7 @@ 4B366DFD1B5C165F0026627B /* Outputs */, 4BB73EDD1B587CA500552FC2 /* Processors */, 4BB73E9F1B587A5100552FC2 /* Products */, + 4B3AF7CF2413470E00873C0B /* Reflection */, 4B055A7B1FAE84A50060FFFF /* SDL */, 4B2409591C45DF85004DA684 /* SignalProcessing */, 4B69FB391C4D908A00B5F0AA /* Storage */, diff --git a/Reflection/Enum.h b/Reflection/Enum.h index 49359c271..781c91468 100644 --- a/Reflection/Enum.h +++ b/Reflection/Enum.h @@ -10,9 +10,17 @@ #define Enum_h #include +#include namespace Reflection { +#define ReflectableEnum(Name, Type, ...) \ + enum class Name: Type { Mac128k, Mac512k, Mac512ke, MacPlus }; \ + constexpr static const char *__declaration##Name = #__VA_ARGS__; + +#define EnumDeclaration(Name) __declaration##Name + + template struct Enum { static size_t size() { return members().size(); @@ -69,8 +77,16 @@ template struct Enum { Enum members must take default values, and this enum must be in the global scope. */ -#define ReflectiveEnum(Name, Type, ...) \ - enum class Name: Type { __VA_ARGS__ }; \ - constexpr const char *__declaration(Name) { return #__VA_ARGS__; } +//#define DefX #define X + +//#define ForwardDeclareReflectiveEnum(Namespace, Name, ...) \ +// #define HAT + +// DeclName(m) m(__VA_ARGS__) + +// constexpr const char *__declaration(Namespace::Name) { return __VA_ARGS__; } + +//#define DefineReflectiveEnum(Name, Type) \ +// enum class Name: Type { Mac128k, Mac512k, Mac512ke, MacPlus }; #endif /* Enum_h */ diff --git a/Reflection/Struct.h b/Reflection/Struct.h index 0f6e83f19..7e55d702a 100644 --- a/Reflection/Struct.h +++ b/Reflection/Struct.h @@ -57,6 +57,10 @@ template class Struct { to determine whether a class of this type has already established the reflective fields. */ + + /*! + Exposes the field pointed to by @c t for reflection as @c name. + */ template void declare(Type *t, const std::string &name) { contents_.emplace( std::make_pair( @@ -65,6 +69,14 @@ template class Struct { )); } + /*! + Provides the original declaration of an enum. + */ + template void declare_enum(Type *t, const char *declaration) { + // TODO: something. + printf("%s\n", declaration); + } + /*! @returns @c true if this */