mm_design.od 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Block:Class {
  2. abstract = True;
  3. }
  4. InPort:Class {
  5. # abstract = True;
  6. }
  7. OutPort:Class {
  8. # abstract = True;
  9. }
  10. hasInPort:Association (Block -> InPort) {
  11. # Every Port contained by exactly one Block:
  12. source_lower_cardinality = 1;
  13. source_upper_cardinality = 1;
  14. }
  15. hasOutPort:Association (Block -> OutPort) {
  16. # Every Port contained by exactly one Block:
  17. source_lower_cardinality = 1;
  18. source_upper_cardinality = 1;
  19. }
  20. link:Association (OutPort -> InPort) {
  21. #abstract = True;
  22. # Every InPort connected to exactly one OutPort
  23. source_lower_cardinality = 1;
  24. source_upper_cardinality = 1;
  25. }
  26. # In- and Out-Ports are labeled:
  27. # hasInPort_label:AttributeLink (hasInPort -> String) {
  28. # name = "label";
  29. # optional = False;
  30. # }
  31. # hasOutPort_label:AttributeLink (hasOutPort -> String) {
  32. # name = "label";
  33. # optional = False;
  34. # }
  35. # Function Block: pure function that computes outputs based on inputs
  36. Function:Class
  37. :Inheritance (Function -> Block)
  38. Function_func:AttributeLink (Function -> ActionCode) {
  39. name = "func";
  40. optional = False;
  41. }
  42. DetailedFunction:Class
  43. :Inheritance (DetailedFunction -> Function)
  44. VeryDetailedFunction:Class
  45. :Inheritance (VeryDetailedFunction -> DetailedFunction)
  46. # Delay Block
  47. Delay:Class {
  48. constraint = ```
  49. errors = []
  50. num_inports = len(get_outgoing(this, "hasInPort"))
  51. num_outports = len(get_outgoing(this, "hasOutPort"))
  52. if num_inports != 1:
  53. errors.append(f"Delay block must have one inport, instead got {num_inports}")
  54. in_type = None
  55. else:
  56. in_type = get_type_name(get_target(get_outgoing(this, "hasInPort")[0]))
  57. if num_outports != 1:
  58. errors.append(f"Delay block must have one inport, instead got {num_outports}")
  59. out_type = None
  60. else:
  61. out_type = get_type_name(get_target(get_outgoing(this, "hasOutPort")[0]))
  62. # if in_type != None and out_type != None and in_type[0:3] != out_type[0:3]:
  63. # errors.append(f"Inport type ({in_type}) differs from outport type ({out_type})")
  64. errors
  65. ```;
  66. }
  67. :Inheritance (Delay -> Block)
  68. # Object Diagrams are statically typed, so we must create in/out-ports, and MemorySlots for all primitive types:
  69. # # Port types
  70. # BoolInPort:Class
  71. # IntInPort:Class
  72. # StrInPort:Class
  73. # BoolOutPort:Class
  74. # IntOutPort:Class
  75. # StrOutPort:Class
  76. # :Inheritance (BoolInPort -> InPort)
  77. # :Inheritance (IntInPort -> InPort)
  78. # :Inheritance (StrInPort -> InPort)
  79. # :Inheritance (BoolOutPort -> OutPort)
  80. # :Inheritance (IntOutPort -> OutPort)
  81. # :Inheritance (StrOutPort -> OutPort)
  82. # # Link types
  83. # boolLink:Association (BoolOutPort -> BoolInPort)
  84. # intLink:Association (IntOutPort -> IntInPort)
  85. # strLink:Association (StrOutPort -> StrInPort)
  86. # :Inheritance (boolLink -> link)
  87. # :Inheritance (intLink -> link)
  88. # :Inheritance (strLink -> link)
  89. # # Delay block types
  90. # BoolDelay:Class
  91. # IntDelay:Class
  92. # StrDelay:Class
  93. # :Inheritance (BoolDelay -> Delay)
  94. # :Inheritance (IntDelay -> Delay)
  95. # :Inheritance (StrDelay -> Delay)