From fe6562e020e9e4af79dd0659b7ffb56209088181 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 27 Aug 2024 00:33:11 -0400 Subject: [PATCH] making progress on MCL linker and compiler, still many bugs --- mocha-common/compilers/yaml2mcl/Program.py | 16 +++++ .../editormini/dataformats/McxDataFormat.py | 22 ------ .../library/manager/MochaLibraryManager.py | 16 ++++- .../library/{editormini => mcx}/DataFormat.py | 0 .../library/mcx/dataformats/McxDataFormat.py | 72 +++++++++++++++++++ .../mocha/library/mcx/dataformats/__init__.py | 1 + .../mcx/objectmodels/McxObjectModel.py | 3 + .../library/mcx/objectmodels/McxSection.py | 3 + .../003-Classes/00009-OMS.yaml | 2 +- ...066-GetAttributeBySystemRoutineMethod.yaml | 17 +++++ .../00070-SystemAttributeRoutine.yaml | 5 ++ 11 files changed, 133 insertions(+), 24 deletions(-) delete mode 100644 mocha-common/compilers/yaml2mcl/mocha/library/editormini/dataformats/McxDataFormat.py rename mocha-common/compilers/yaml2mcl/mocha/library/{editormini => mcx}/DataFormat.py (100%) create mode 100644 mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/McxDataFormat.py create mode 100644 mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/__init__.py create mode 100644 mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxObjectModel.py create mode 100644 mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxSection.py diff --git a/mocha-common/compilers/yaml2mcl/Program.py b/mocha-common/compilers/yaml2mcl/Program.py index 48b0483..3d06cb3 100644 --- a/mocha-common/compilers/yaml2mcl/Program.py +++ b/mocha-common/compilers/yaml2mcl/Program.py @@ -31,6 +31,8 @@ class Yaml2Mcl: args = sys.argv[1:] # args = [ '-o', '/tmp/net.alcetech.Mocha.System.mcl', '/home/beckermj/Documents/Projects/mochapowered/mocha-dotnet/mocha-common/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System' ] + # !! FIXME !! the instance key is probably not in the cache because the 'class' template is not loaded from the YAML so it doesn't know what to do + filenames = [ ] outputFileName = "" exportEntitiesFileName = None @@ -69,6 +71,20 @@ class Yaml2Mcl: manager = MemoryLibraryManager() yl = YAMLLibraryParser(manager) + # before we load any files, load entity definitions from referenced libraries + for libraryRef in libraryReferences: + print ("loading entity definitions from library reference '" + libraryRef + "'") + + from mocha.library.mcx.dataformats import McxDataFormat + df = McxDataFormat() + f = open(libraryRef, 'rb') + df.load_internal(f) + f.close() + + for (k, v) in df.defs: + manager.register_entity_reference(k, v, libraryRef, True) + + for filename in filenames: if not os.path.isdir(filename): print ("not a directory: '" + filename + "'") diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/editormini/dataformats/McxDataFormat.py b/mocha-common/compilers/yaml2mcl/mocha/library/editormini/dataformats/McxDataFormat.py deleted file mode 100644 index 3da29f6..0000000 --- a/mocha-common/compilers/yaml2mcl/mocha/library/editormini/dataformats/McxDataFormat.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) 2024 Michael Becker -# -# This file is part of yaml2mcl. -# -# yaml2mcl 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. -# -# yaml2mcl 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 yaml2mcl. If not, see . - -class McxDataFormat (DataFormat): - - def load_internal(self, stream): - - r = Reader(stream) \ No newline at end of file diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/manager/MochaLibraryManager.py b/mocha-common/compilers/yaml2mcl/mocha/library/manager/MochaLibraryManager.py index 24c826b..dc304eb 100644 --- a/mocha-common/compilers/yaml2mcl/mocha/library/manager/MochaLibraryManager.py +++ b/mocha-common/compilers/yaml2mcl/mocha/library/manager/MochaLibraryManager.py @@ -25,6 +25,7 @@ class MochaLibraryManager: def __init__(self): self.entityReferences = dict() self.entityReferenceFileNames = dict() + self.entityReferencesExternal = dict() self.db = None self._instances = [] self._attOps = [] @@ -206,6 +207,9 @@ class MochaLibraryManager: print ("preparing debug information (use --no-debug or undefine DEBUG or etc. [NOT IMPLEMENTED] to turn off)") for key in self.entityReferences: + if self.is_entity_reference_external(key): + continue + val = self.entityReferences[key] gidEntityDefinition = Guid.create() @@ -427,9 +431,13 @@ class MochaLibraryManager: def exists_entity_reference(self, name): return name in self.entityReferences - def register_entity_reference(self, name, value, filename = None): + def register_entity_reference(self, name, value, filename = None, externalReference = False): self.entityReferences[name] = value self.entityReferenceFileNames[name] = filename + self.entityReferencesExternal[name] = externalReference + + def is_entity_reference_external(self, name): + return self.entityReferencesExternal[name] def define_entity_reference(self, name): return self.entityReferences[name] @@ -475,6 +483,9 @@ class MochaLibraryManager: print("public static class KnownInstances", file=f) print("{", file=f) for name in self.entityReferences: + if self.is_entity_reference_external(name): + continue + if name.startswith("IDC_") or name.startswith("IDA_") or name.startswith("IDI_"): shortname = name if name.startswith("ID") and "_" in name: @@ -491,6 +502,9 @@ class MochaLibraryManager: print("class KnownInstances:", file=f) print("", file=f) for name in self.entityReferences: + if self.is_entity_reference_external(name): + continue + if name.startswith("IDC_") or name.startswith("IDA_") or name.startswith("IDI_"): shortname = name if name.startswith("ID") and "_" in name: diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/editormini/DataFormat.py b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/DataFormat.py similarity index 100% rename from mocha-common/compilers/yaml2mcl/mocha/library/editormini/DataFormat.py rename to mocha-common/compilers/yaml2mcl/mocha/library/mcx/DataFormat.py diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/McxDataFormat.py b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/McxDataFormat.py new file mode 100644 index 0000000..a3c24b9 --- /dev/null +++ b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/McxDataFormat.py @@ -0,0 +1,72 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of yaml2mcl. +# +# yaml2mcl 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. +# +# yaml2mcl 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 yaml2mcl. If not, see . + +from editor.core import DataFormat, InvalidDataFormatException +from editor.core.io import Reader + +from io import FileIO + +class McxDataFormat (DataFormat): + + def __init__(self): + self.defs = [ ] + + def get_signature(self) -> str: + return "MCX!" + + def load_internal(self, stream : FileIO): + + r = Reader(stream) + + # SectionFile header + signature = r.read_fixedstring(4) + if signature != self.get_signature(): + raise InvalidDataFormatException + + version = r.read_single() + if version != 2.0: + raise InvalidDataFormatException + + flags = r.read_int32() + section_count = r.read_int32() + guid = r.read_guid() + + sections = [ ] + + for i in range(0, section_count): + section_name = r.read_fixedstring(16).strip(' \0') + offset = r.read_int32() + length = r.read_int32() + length2 = r.read_int32() + itemcount = r.read_int32() + + print(' '+section_name) + sections.append((section_name, offset, length, length2, itemcount)) + + for (section_name, offset, length, length2, itemcount) in sections: + if section_name == "Defs": + + r.get_stream().seek(offset) + for j in range(0, itemcount): + key = r.read_terminatedstring() + value = r.read_terminatedstring() + self.defs.append((key, value)) + + + def save_internal(self, stream : FileIO): + + pass \ No newline at end of file diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/__init__.py b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/__init__.py new file mode 100644 index 0000000..15ed30a --- /dev/null +++ b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/dataformats/__init__.py @@ -0,0 +1 @@ +from .McxDataFormat import McxDataFormat diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxObjectModel.py b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxObjectModel.py new file mode 100644 index 0000000..6fcbc97 --- /dev/null +++ b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxObjectModel.py @@ -0,0 +1,3 @@ +class McxObjectModel : + + pass \ No newline at end of file diff --git a/mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxSection.py b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxSection.py new file mode 100644 index 0000000..029034f --- /dev/null +++ b/mocha-common/compilers/yaml2mcl/mocha/library/mcx/objectmodels/McxSection.py @@ -0,0 +1,3 @@ +class McxSection : + + pass \ No newline at end of file diff --git a/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00009-OMS.yaml b/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00009-OMS.yaml index d6db5b9..a5ea896 100644 --- a/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00009-OMS.yaml +++ b/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00009-OMS.yaml @@ -8,4 +8,4 @@ - relationship: '&IDR_Class__has_title__Translation;' values: - languageInstanceId: '&IDI_Language_English;' - value: 'OMS' + value: 'OMS' \ No newline at end of file diff --git a/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00066-GetAttributeBySystemRoutineMethod.yaml b/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00066-GetAttributeBySystemRoutineMethod.yaml index dc4920d..8b923e9 100644 --- a/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00066-GetAttributeBySystemRoutineMethod.yaml +++ b/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00066-GetAttributeBySystemRoutineMethod.yaml @@ -1,4 +1,8 @@ --- +- entityDefinitions: + - IDM_OMS__get__Runtime_Version: '{58835bd3-21e2-43bb-a069-7f8befe9bf5d}' + - IDMB_OMS__get__Runtime_Version: '{d5b09408-b000-4f45-9d97-df610ee15506}' + - library: '&IDL_MochaBaseSystem;' instances: - class: '&IDC_GetAttributeBySystemRoutineMethod;' @@ -73,3 +77,16 @@ destinationClassId: '&IDC_GetAttributeBySystemRoutineMethod;' siblingRelationshipId: '&IDR_Get_Attribute_by_System_Routine_Method__uses__System_Attribute_Routine;' singular: no + + + - getAttributeBySystemRoutineMethod: '&IDM_OMS__get__Runtime_Version;' + forClassId: '&IDC_OMS;' + verb: 'get' + name: 'Runtime Version' + accessModifierId: '&IDI_AccessModifier_Public;' + returnsAttributeId: '&IDA_Version;' + systemAttributeRoutineId: '&IDI_SystemAttributeRoutine_GetRuntimeVersion;' + moduleId: '&IDI_Module_MochaBaseSystem;' + + - returnAttributeMethodBinding: '&IDMB_OMS__get__Runtime_Version;' + executesMethod: '&IDM_OMS__get__Runtime_Version;' \ No newline at end of file diff --git a/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00070-SystemAttributeRoutine.yaml b/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00070-SystemAttributeRoutine.yaml index 0415efb..ee8a5c8 100644 --- a/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00070-SystemAttributeRoutine.yaml +++ b/mocha-common/data/libraries/yaml/net.alcetech.Mocha.System/003-Classes/00070-SystemAttributeRoutine.yaml @@ -1,4 +1,7 @@ --- +- entityDefinitions: + - IDI_SystemAttributeRoutine_GetRuntimeVersion: '{dc4e6c8d-936d-457f-90e9-af47e229b80c}' # {5d13d326-bbf2-4421-b1f0-4fa43892bcf5} + - library: '&IDL_MochaBaseSystem;' instances: - class: '&IDC_SystemAttributeRoutine;' @@ -11,4 +14,6 @@ - instance: '&IDI_SystemAttributeRoutine_GetGlobalIdentifier;' name: 'Get Global Identifier for Instance Parm' - instance: '&IDI_SystemAttributeRoutine_GetInstanceText;' + name: 'Get Instance Text for Instance Parm' + - instance: '&IDI_SystemAttributeRoutine_GetRuntimeVersion;' name: 'Get Instance Text for Instance Parm' \ No newline at end of file