modelling.alc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. include "primitives.alh"
  2. include "io.alh"
  3. include "object_operations.alh"
  4. include "constructors.alh"
  5. include "metamodels.alh"
  6. include "library.alh"
  7. Element global_models = ?
  8. String function instantiated_name(element : Element, original : String):
  9. if (original == ""):
  10. return "__" + cast_id2s(element)!
  11. else:
  12. return original!
  13. Element function instantiate_bottom():
  14. // Just create a new node that serves as the basis for everything
  15. // We don't know anything about the model yet, so just create an empty one
  16. Element new_model
  17. // The actual root node of the model
  18. new_model = create_node()
  19. // Add an empty model and empty type mapping
  20. dict_add(new_model, "model", create_node())
  21. dict_add(new_model, "type_mapping", create_node())
  22. // Return the created model
  23. return new_model!
  24. String function model_add_node(model : Element, name : String):
  25. // Adds a new node to the specified model with the desired name
  26. // This is a bottom operation, as it doesn't take any type
  27. Element new_node
  28. String actual_name
  29. new_node = create_node()
  30. actual_name = instantiated_name(new_node, name)
  31. dict_add(model["model"], actual_name, new_node)
  32. return actual_name!
  33. String function model_add_value(model : Element, name : String, value : Element):
  34. // Similar to model_add_node, but add a value as well
  35. String actual_name
  36. actual_name = instantiated_name(value, name)
  37. dict_add(model["model"], actual_name, value)
  38. return actual_name!
  39. String function model_add_edge(model : Element, name : String, source : String, destination : String):
  40. // Add an edge between the source and destination nodes
  41. // Nodes are specified using their string representation previously defined
  42. Element new_edge
  43. String actual_name
  44. if (bool_not(dict_in(model["model"], source))):
  45. log("In link " + name)
  46. log("ERROR: source of link unknown: " + source)
  47. log("Destination: " + destination)
  48. return ""!
  49. if (bool_not(dict_in(model["model"], destination))):
  50. log("In link " + name)
  51. log("ERROR: destination of link unknown: " + destination)
  52. log("Source: " + source)
  53. Integer i
  54. i = 1/0
  55. return ""!
  56. new_edge = create_edge(model["model"][source], model["model"][destination])
  57. actual_name = instantiated_name(new_edge, name)
  58. dict_add(model["model"], actual_name, new_edge)
  59. return actual_name!
  60. Void function retype_model(model : Element, metamodel : Element):
  61. // Remove the type mapping and add a new one for the specified metamodel
  62. dict_delete(model, "type_mapping")
  63. dict_add(model, "type_mapping", create_node())
  64. dict_add(model, "metamodel", metamodel)
  65. return!
  66. Void function retype(model : Element, element : String, type : String):
  67. // Retype a model, deleting any previous type the element had
  68. // The type string is evaluated in the metamodel previously specified
  69. if (dict_in(model["type_mapping"], element)):
  70. dict_delete(model["type_mapping"], element)
  71. dict_add(model["type_mapping"], element, type)
  72. return!
  73. Element function instantiate_model(metamodel : Element):
  74. // Instantiate a model
  75. // Basically create an untyped model and retype it
  76. Element model
  77. model = instantiate_bottom()
  78. retype_model(model, metamodel)
  79. return model!
  80. String function instantiate_node(model : Element, type_name : String, instance_name : String):
  81. // Create a node typed by a node from the metamodel
  82. // Basically create a node and type it immediately
  83. String actual_name
  84. if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
  85. log("ERROR: (instantiate_node) no such type in metamodel: " + type_name)
  86. log(" for " + instance_name)
  87. return ""!
  88. if (dict_in(model["model"], instance_name)):
  89. return ""!
  90. actual_name = model_add_node(model, instance_name)
  91. retype(model, actual_name, type_name)
  92. return actual_name!
  93. String function instantiate_value(model : Element, type_name : String, instance_name : String, value : Element):
  94. // Create a node typed by a node from the metamodel
  95. // Basically create a node and type it immediately
  96. String actual_name
  97. if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
  98. log("ERROR: (instantiate_value) no such type in metamodel: " + type_name)
  99. log(" for " + instance_name)
  100. return ""!
  101. if (dict_in(model["model"], instance_name)):
  102. return ""!
  103. actual_name = model_add_value(model, instance_name, value)
  104. retype(model, actual_name, type_name)
  105. return actual_name!
  106. String function find_attribute_type(model : Element, elem : String, name : String):
  107. String mm_elem
  108. String direct_type
  109. String result
  110. direct_type = read_type(model, elem)
  111. if (direct_type == ""):
  112. return ""!
  113. mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
  114. if (value_eq(mm_elem, "")):
  115. // Couldn't find element, so is not allowed!
  116. return ""!
  117. else:
  118. result = reverseKeyLookup(model["metamodel"]["model"], dict_read_edge(model["metamodel"]["model"][mm_elem], name))
  119. return result!
  120. Element function get_subclasses(model : Element, name : String):
  121. Element result
  122. Integer i
  123. Integer j
  124. Integer num_edges
  125. Element edge
  126. String elem
  127. Element nodes
  128. Element inheritance
  129. nodes = create_node()
  130. set_add(nodes, name)
  131. inheritance = "Inheritance"
  132. // Initialize empty set
  133. result = create_node()
  134. i = 0
  135. while (list_len(nodes) > 0):
  136. elem = set_pop(nodes)
  137. if (bool_not(set_in(result, elem))):
  138. create_edge(result, elem)
  139. // Read out all incoming edges
  140. num_edges = read_nr_in(model["model"][elem])
  141. j = 0
  142. while (j < num_edges):
  143. edge = read_in(model["model"][elem], j)
  144. if (value_eq(model["type_mapping"][reverseKeyLookup(model["model"], edge)], inheritance)):
  145. set_add(nodes, reverseKeyLookup(model["model"], read_edge_src(edge)))
  146. j = j + 1
  147. return result!
  148. Element function get_superclasses(model : Element, name : String):
  149. Element result
  150. Integer i
  151. Integer j
  152. Integer num_edges
  153. Element edge
  154. String elem
  155. Element nodes
  156. Element inheritance
  157. nodes = create_node()
  158. set_add(nodes, name)
  159. inheritance = "Inheritance"
  160. // Initialize empty set
  161. result = create_node()
  162. i = 0
  163. while (list_len(nodes) > 0):
  164. elem = set_pop(nodes)
  165. if (bool_not(set_in(result, elem))):
  166. create_edge(result, elem)
  167. // Read out all outgoing edges
  168. num_edges = read_nr_out(model["model"][elem])
  169. j = 0
  170. while (j < num_edges):
  171. edge = read_out(model["model"][elem], j)
  172. if (value_eq(model["type_mapping"][reverseKeyLookup(model["model"], edge)], inheritance)):
  173. set_add(nodes, reverseKeyLookup(model["model"], read_edge_dst(edge)))
  174. j = j + 1
  175. return result!
  176. String function find_attribute_definer(model : Element, elem_name : String, name : String):
  177. Element superclasses
  178. String current
  179. Integer nr_out
  180. Element out
  181. String name_attr
  182. superclasses = get_superclasses(model, elem_name)
  183. while (list_len(superclasses) > 0):
  184. current = set_pop(superclasses)
  185. nr_out = read_nr_out(model["model"][current])
  186. while (nr_out > 0):
  187. nr_out = nr_out - 1
  188. out = read_out(model["model"][current], nr_out)
  189. name_attr = read_attribute(model, reverseKeyLookup(model["model"], out), "name")
  190. if (name_attr == name):
  191. return current!
  192. return ""!
  193. Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : Element):
  194. // Instantiate an attribute of something that needs to be instantiated
  195. // Actually a bit more difficult than all the rest, as we need to find the attribute to instantiate
  196. String attr_type
  197. String attr_name
  198. if (element_neq(read_attribute(model, element, attribute_name), read_root())):
  199. unset_attribute(model, element, attribute_name)
  200. attr_type = find_attribute_type(model, element, attribute_name)
  201. if (attr_type == ""):
  202. log("Could not find attribute " + cast_v2s(attribute_name))
  203. log("For element " + element)
  204. log("Type: " + read_type(model, element))
  205. return!
  206. if (has_value(value)):
  207. value = create_value(value)
  208. attr_name = model_add_value(model, (element + ".") + attribute_name, value)
  209. retype(model, attr_name, reverseKeyLookup(model["metamodel"]["model"], read_edge_dst(model["metamodel"]["model"][attr_type])))
  210. instantiate_link(model, attr_type, "", element, attr_name)
  211. return!
  212. Void function instantiate_attribute_ref(model : Element, element : String, attribute_name : String, ref : String):
  213. // Instantiate an attribute of something that needs to be instantiated
  214. // Actually a bit more difficult than all the rest, as we need to find the attribute to instantiate
  215. String attr_type
  216. String attr_name
  217. attr_type = find_attribute_type(model, element, attribute_name)
  218. if (attr_type == ""):
  219. log("Could not find attribute " + cast_v2s(attribute_name))
  220. return!
  221. instantiate_link(model, attr_type, "", element, ref)
  222. return!
  223. Void function add_code_model(model : Element, export_name : String, code : Element):
  224. Element code_model
  225. code_model = instantiate_model(model)
  226. add_AL(code_model, code)
  227. export_node(export_name, code_model)
  228. return !
  229. Void function instantiate_attribute_code(model : Element, element : String, attribute_name : String, code : Element):
  230. // First create a new model for the AL part
  231. String location
  232. location = "code/" + cast_id2s(code)
  233. add_code_model(import_node("models/ActionLanguage"), location, code)
  234. // Now link it with a complex attribute
  235. instantiate_attribute(model, element, attribute_name, location)
  236. return!
  237. Void function instantiate_existing_attribute(model : Element, element : String, attribute_name : String, attr_ref : String):
  238. // Instantiate an attribute of something that needs to be instantiated
  239. // Actually a bit more difficult than all the rest, as we need to find the attribute to instantiate
  240. String attr_type
  241. String attr_name
  242. attr_type = find_attribute_type(model, element, attribute_name)
  243. if (attr_type == ""):
  244. log("Could not find attribute " + cast_v2s(attribute_name))
  245. return!
  246. // Make a copy of the value, as it is likely that this value is reused later on
  247. retype(model, attr_ref, reverseKeyLookup(model["metamodel"]["model"], read_edge_dst(model["metamodel"]["model"][attr_type])))
  248. instantiate_link(model, attr_type, "", element, attr_ref)
  249. return!
  250. String function instantiate_link(model : Element, type : String, name : String, source : String, destination : String):
  251. // Create a typed link between two nodes
  252. String actual_name
  253. if (dict_in(model["model"], name)):
  254. return ""!
  255. if (type == ""):
  256. // Have to find the type ourselves, as it isn't defined
  257. Element out
  258. Element in
  259. Element options
  260. options = allowedAssociationsBetween(model, source, destination)
  261. if (read_nr_out(options) == 1):
  262. type = set_pop(options)
  263. elif (read_nr_out(options) == 0):
  264. log("ERROR: cannot find possible link between entries")
  265. log(" for " + source)
  266. log(" to " + destination)
  267. return ""!
  268. else:
  269. log("ERROR: too many possible links between entries")
  270. log(" options: " + set_to_string(options))
  271. return ""!
  272. if (bool_not(dict_in(model["metamodel"]["model"], type))):
  273. log("ERROR: (instantiate_link) no such type in metamodel: " + type)
  274. log(" for " + name)
  275. return ""!
  276. actual_name = model_add_edge(model, name, source, destination)
  277. retype(model, actual_name, type)
  278. return actual_name!
  279. Void function model_delete_element(model : Element, name : String):
  280. // Remove the link
  281. // 1) from the type mapping
  282. dict_delete(model["type_mapping"], name)
  283. // 2) from the model
  284. delete_element(model["model"][name])
  285. return!
  286. String function model_define_attribute(model : Element, elem : String, name : String, optional : Boolean, type : String):
  287. // Create the necessary links to make it an attribute
  288. String edge_name
  289. edge_name = (elem + "_") + name
  290. while (dict_in(model["model"], edge_name)):
  291. // Already exists, so make random name
  292. edge_name = edge_name + cast_id2s(model["model"][elem])
  293. log("Name clash detected for attribute: try new name: " + edge_name)
  294. edge_name = instantiate_link(model, "AttributeLink", edge_name, elem, type)
  295. instantiate_attribute(model, edge_name, "name", name)
  296. instantiate_attribute(model, edge_name, "optional", optional)
  297. return edge_name!
  298. Element function read_attribute(model : Element, element : String, attribute : String):
  299. Integer i
  300. Integer count
  301. Element edge
  302. String edge_type_name
  303. Element elem
  304. Element typing
  305. Element name
  306. if (dict_in(model["model"], element)):
  307. elem = model["model"][element]
  308. typing = model["type_mapping"]
  309. count = read_nr_out(elem)
  310. i = 0
  311. while (i < count):
  312. edge = read_out(elem, i)
  313. name = reverseKeyLookup(model["model"], edge)
  314. if (dict_in(typing, name)):
  315. edge_type_name = typing[name]
  316. if (edge_type_name == reverseKeyLookup(model["metamodel"]["model"], dict_read_edge(read_edge_src(model["metamodel"]["model"][edge_type_name]), attribute))):
  317. return read_edge_dst(edge)!
  318. i = i + 1
  319. else:
  320. log("Element does not exist: " + element)
  321. // Not found: either element doesn't exist, or we couldn't find it
  322. return read_root()!
  323. Void function unset_attribute(model : Element, element : String, attribute : String):
  324. // Removes an attribute if it exists
  325. String attr_type
  326. Element attr_links
  327. String attr_link
  328. attr_type = find_attribute_type(model, element, attribute)
  329. attr_links = allOutgoingAssociationInstances(model, element, attr_type)
  330. while (list_len(attr_links) > 0):
  331. attr_link = set_pop(attr_links)
  332. dict_delete(model["type_mapping"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
  333. dict_delete(model["type_mapping"], attr_link)
  334. dict_delete_node(model["model"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
  335. delete_element(model["model"][attr_link])
  336. return!
  337. Void function add_AL_links(model : Element, list : Element, element : Element, type: String, linkname : String, expected_type : String):
  338. if (bool_not(dict_in(element, linkname))):
  339. return!
  340. Element link
  341. String link_name
  342. link = dict_read_edge(element, linkname)
  343. link_name = "__" + cast_id2s(link)
  344. // The link
  345. dict_add(model["model"], link_name, link)
  346. dict_add(model["type_mapping"], link_name, (type + "_") + linkname)
  347. // The name link
  348. link = read_out(link, 0)
  349. link_name = "__" + cast_id2s(link)
  350. dict_add(model["model"], link_name, link)
  351. dict_add(model["type_mapping"], link_name, "dict_link_name")
  352. // The name node
  353. link = read_edge_dst(link)
  354. link_name = "__" + cast_id2s(link)
  355. if (bool_not(set_in_node(model["model"], link))):
  356. dict_add(model["model"], link_name, link)
  357. dict_add(model["type_mapping"], link_name, "StringAttr")
  358. // Now add the destination to the worker list
  359. set_add(list, create_tuple(element[linkname], expected_type))
  360. return!
  361. String function add_AL(model : Element, element : Element):
  362. Element todo
  363. Element node
  364. Element work_node
  365. Element elem
  366. String type
  367. String elem_name
  368. todo = create_node()
  369. node = create_node()
  370. list_append(node, element)
  371. list_append(node, "funcdef")
  372. set_add(todo, node)
  373. while (0 < dict_len(todo)):
  374. work_node = set_pop(todo)
  375. elem = list_read(work_node, 0)
  376. type = list_read(work_node, 1)
  377. if (bool_not(set_in_node(model["model"], elem))):
  378. // Determine the type if we don't know it
  379. if (type == ""):
  380. if (is_physical_action(elem)):
  381. type = cast_a2s(elem)
  382. else:
  383. type = "Element"
  384. // Add the node itself
  385. elem_name = "__" + cast_id2s(elem)
  386. dict_add(model["model"], elem_name, elem)
  387. dict_add(model["type_mapping"], elem_name, type)
  388. // Now add its edges
  389. if (type == "if"):
  390. add_AL_links(model, todo, elem, type, "cond", "")
  391. add_AL_links(model, todo, elem, type, "then", "")
  392. add_AL_links(model, todo, elem, type, "else", "")
  393. add_AL_links(model, todo, elem, type, "next", "")
  394. elif (type == "while"):
  395. add_AL_links(model, todo, elem, type, "cond", "")
  396. add_AL_links(model, todo, elem, type, "body", "")
  397. add_AL_links(model, todo, elem, type, "next", "")
  398. elif (type == "assign"):
  399. add_AL_links(model, todo, elem, type, "var", "resolve")
  400. add_AL_links(model, todo, elem, type, "value", "")
  401. add_AL_links(model, todo, elem, type, "next", "")
  402. elif (type == "break"):
  403. add_AL_links(model, todo, elem, type, "while", "while")
  404. elif (type == "continue"):
  405. add_AL_links(model, todo, elem, type, "while", "while")
  406. elif (type == "return"):
  407. add_AL_links(model, todo, elem, type, "value", "")
  408. elif (type == "resolve"):
  409. add_AL_links(model, todo, elem, type, "var", "")
  410. elif (type == "access"):
  411. add_AL_links(model, todo, elem, type, "var", "resolve")
  412. elif (type == "constant"):
  413. add_AL_links(model, todo, elem, type, "node", "")
  414. elif (type == "output"):
  415. add_AL_links(model, todo, elem, type, "node", "")
  416. add_AL_links(model, todo, elem, type, "next", "")
  417. elif (type == "global"):
  418. add_AL_links(model, todo, elem, type, "var", "String")
  419. add_AL_links(model, todo, elem, type, "next", "")
  420. elif (type == "param"):
  421. add_AL_links(model, todo, elem, type, "name", "String")
  422. add_AL_links(model, todo, elem, type, "value", "")
  423. add_AL_links(model, todo, elem, type, "next_param", "param")
  424. elif (type == "funcdef"):
  425. add_AL_links(model, todo, elem, type, "body", "")
  426. // TODO this should be added, but is not the same as "param"
  427. //add_AL_links(model, todo, elem, type, "params", "")
  428. add_AL_links(model, todo, elem, type, "next", "")
  429. elif (type == "call"):
  430. add_AL_links(model, todo, elem, type, "func", "")
  431. add_AL_links(model, todo, elem, type, "params", "param")
  432. add_AL_links(model, todo, elem, type, "last_param", "param")
  433. add_AL_links(model, todo, elem, type, "next", "")
  434. // Mark the node as first
  435. String initial
  436. initial = instantiate_node(model, "Initial", "")
  437. instantiate_link(model, "initial_funcdef", "", initial, reverseKeyLookup(model["model"], element))
  438. return reverseKeyLookup(model["model"], element)!
  439. Void function construct_model():
  440. String command
  441. initialize_SCD("models/SimpleClassDiagrams")
  442. while (True):
  443. command = input()
  444. if (command == "instantiate_bottom"):
  445. Element m
  446. m = instantiate_bottom()
  447. dict_add(global_models, input(), m)
  448. elif (command == "add_node"):
  449. model_add_node(global_models[input()], input())
  450. elif (command == "add_value"):
  451. model_add_value(global_models[input()], input(), input())
  452. elif (command == "add_edge"):
  453. model_add_edge(global_models[input()], input(), input(), input())
  454. elif (command == "exit"):
  455. return!
  456. elif (command == "retype_model"):
  457. retype_model(global_models[input()], global_models[input()])
  458. elif (command == "retype"):
  459. retype(global_models[input()], input(), input())
  460. elif (command == "instantiate_model"):
  461. Element m
  462. m = instantiate_model(global_models[input()])
  463. dict_add(global_models, input(), m)
  464. elif (command == "instantiate_node"):
  465. instantiate_node(global_models[input()], input(), input())
  466. elif (command == "instantiate_attribute"):
  467. instantiate_attribute(global_models[input()], input(), input(), input())
  468. elif (command == "instantiate_attribute_ref"):
  469. instantiate_attribute_ref(global_models[input()], input(), input(), input())
  470. elif (command == "instantiate_attribute_code"):
  471. instantiate_attribute_code(global_models[input()], input(), input(), construct_function())
  472. elif (command == "instantiate_link"):
  473. instantiate_link(global_models[input()], input(), input(), input(), input())
  474. elif (command == "model_define_attribute"):
  475. model_define_attribute(global_models[input()], input(), input(), input(), input())
  476. elif (command == "initialize_SCD"):
  477. initialize_SCD(input())
  478. elif (command == "initialize_bottom"):
  479. initialize_bottom(input())
  480. elif (command == "export_node"):
  481. String local_name
  482. String location
  483. local_name = input()
  484. location = input()
  485. export_node(location, global_models[local_name])
  486. elif (command == "import_node"):
  487. Element m
  488. command = input()
  489. m = import_node(command)
  490. if (element_eq(m, read_root())):
  491. log("Error: import not found for " + command)
  492. else:
  493. dict_add(global_models, input(), m)
  494. elif (command == "add_code_model"):
  495. add_code_model(global_models[input()], input(), construct_function())
  496. else:
  497. log("Modelling error: did not understand command " + command)
  498. Element function construct_model_raw(metamodel : Element):
  499. String command
  500. Element model
  501. model = instantiate_model(metamodel)
  502. while (True):
  503. command = input()
  504. if (command == "add_node"):
  505. input()
  506. model_add_node(model, input())
  507. elif (command == "add_value"):
  508. input()
  509. model_add_value(model, input(), input())
  510. elif (command == "add_edge"):
  511. input()
  512. model_add_edge(model, input(), input(), input())
  513. elif (command == "exit"):
  514. return model!
  515. elif (command == "instantiate_node"):
  516. input()
  517. instantiate_node(model, input(), input())
  518. elif (command == "model_define_attribute"):
  519. input()
  520. model_define_attribute(model, input(), input(), input(), input())
  521. elif (command == "instantiate_attribute"):
  522. input()
  523. instantiate_attribute(model, input(), input(), input())
  524. elif (command == "instantiate_attribute_ref"):
  525. input()
  526. instantiate_attribute_ref(model, input(), input(), input())
  527. elif (command == "instantiate_attribute_code"):
  528. input()
  529. instantiate_attribute_code(model, input(), input(), construct_function())
  530. elif (command == "instantiate_link"):
  531. input()
  532. instantiate_link(model, input(), input(), input(), input())
  533. elif (command == "import_node"):
  534. input()
  535. input()
  536. elif (command == "export_node"):
  537. input()
  538. input()
  539. elif (command == "instantiate_model"):
  540. input()
  541. input()
  542. elif (command == "add_code_model"):
  543. input()
  544. add_code_model(model, input(), construct_function())
  545. else:
  546. log("Modelling error: did not understand command " + command)
  547. Element function get_func_AL_model(al_model : Element):
  548. Element result
  549. Element initial_function
  550. // Find the initial function
  551. initial_function = allInstances(al_model, "Initial")
  552. if (read_nr_out(initial_function) == 0):
  553. log("Could not find function to execute in this model!")
  554. return create_node()!
  555. elif (read_nr_out(initial_function) > 1):
  556. log("Too many functions to execute in this model!")
  557. return create_node()!
  558. else:
  559. initial_function = al_model["model"][set_pop(allAssociationDestinations(al_model, set_pop(initial_function), "initial_funcdef"))]
  560. return initial_function!