modelling.alc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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_fast(new_model, "model", create_node())
  21. dict_add_fast(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_fast(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_fast(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. return ""!
  54. new_edge = create_edge(model["model"][source], model["model"][destination])
  55. actual_name = instantiated_name(new_edge, name)
  56. dict_add_fast(model["model"], actual_name, new_edge)
  57. return actual_name!
  58. Void function retype_model(model : Element, metamodel : Element):
  59. // Remove the type mapping and add a new one for the specified metamodel
  60. dict_delete(model, "type_mapping")
  61. dict_add_fast(model, "type_mapping", create_node())
  62. dict_add_fast(model, "metamodel", metamodel)
  63. return!
  64. Void function retype(model : Element, element : String, type : String):
  65. // Retype a model, deleting any previous type the element had
  66. // The type string is evaluated in the metamodel previously specified
  67. if (dict_in(model["type_mapping"], element)):
  68. dict_delete(model["type_mapping"], element)
  69. dict_add_fast(model["type_mapping"], element, type)
  70. return!
  71. Element function instantiate_model(metamodel : Element):
  72. // Instantiate a model
  73. // Basically create an untyped model and retype it
  74. Element model
  75. model = instantiate_bottom()
  76. retype_model(model, metamodel)
  77. return model!
  78. String function reuse_element(model : Element, type_name : String, instance_name : String, element : Element):
  79. String actual_name
  80. if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
  81. log("ERROR: (instantiate_node) no such type in metamodel: " + type_name)
  82. log(" for " + instance_name)
  83. return ""!
  84. actual_name = instantiated_name(element, instance_name)
  85. dict_add_fast(model["model"], actual_name, element)
  86. dict_add_fast(model["type_mapping"], actual_name, type_name)
  87. return actual_name!
  88. String function instantiate_node(model : Element, type_name : String, instance_name : String):
  89. String actual_name
  90. if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
  91. log("ERROR: (instantiate_node) no such type in metamodel: " + type_name)
  92. log(" for " + instance_name)
  93. return ""!
  94. Element value
  95. value = create_node()
  96. actual_name = instantiated_name(value, instance_name)
  97. dict_add_fast(model["model"], actual_name, value)
  98. dict_add_fast(model["type_mapping"], actual_name, type_name)
  99. return actual_name!
  100. String function instantiate_value(model : Element, type_name : String, instance_name : String, value : Element):
  101. String actual_name
  102. if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
  103. log("ERROR: (instantiate_value) no such type in metamodel: " + type_name)
  104. log(" for " + instance_name)
  105. return ""!
  106. actual_name = instantiated_name(value, instance_name)
  107. dict_add_fast(model["model"], actual_name, value)
  108. dict_add_fast(model["type_mapping"], actual_name, type_name)
  109. return actual_name!
  110. String function find_attribute_type(model : Element, elem : String, name : String):
  111. String mm_elem
  112. String direct_type
  113. String result
  114. direct_type = read_type(model, elem)
  115. if (direct_type == ""):
  116. return ""!
  117. mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
  118. if (value_eq(mm_elem, "")):
  119. // Couldn't find element, so is not allowed!
  120. return ""!
  121. else:
  122. result = reverseKeyLookup(model["metamodel"]["model"], dict_read_edge(model["metamodel"]["model"][mm_elem], name))
  123. return result!
  124. Element function get_subclasses(model : Element, name : String):
  125. Element result
  126. Integer i
  127. Integer j
  128. Integer num_edges
  129. Element edge
  130. String elem
  131. Element nodes
  132. nodes = create_node()
  133. set_add(nodes, name)
  134. // Initialize empty set
  135. result = create_node()
  136. i = 0
  137. while (list_len(nodes) > 0):
  138. elem = set_pop(nodes)
  139. if (bool_not(set_in(result, elem))):
  140. create_edge(result, elem)
  141. // Read out all incoming edges
  142. num_edges = read_nr_in(model["model"][elem])
  143. j = 0
  144. while (j < num_edges):
  145. edge = read_in(model["model"][elem], j)
  146. if (value_eq(model["type_mapping"][reverseKeyLookup(model["model"], edge)], "Inheritance")):
  147. set_add(nodes, reverseKeyLookup(model["model"], read_edge_src(edge)))
  148. j = j + 1
  149. return result!
  150. Element function get_superclasses(model : Element, name : String):
  151. Element result
  152. Integer i
  153. Integer j
  154. Integer num_edges
  155. Element edge
  156. String elem
  157. Element nodes
  158. nodes = create_node()
  159. set_add(nodes, name)
  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 (type == ""):
  254. // Have to find the type ourselves, as it isn't defined
  255. Element out
  256. Element in
  257. Element options
  258. options = allowedAssociationsBetween(model, source, destination)
  259. if (read_nr_out(options) == 1):
  260. type = set_pop(options)
  261. elif (read_nr_out(options) == 0):
  262. log("ERROR: cannot find possible link between entries")
  263. log(" for " + source)
  264. log(" to " + destination)
  265. return ""!
  266. else:
  267. log("ERROR: too many possible links between entries")
  268. log(" options: " + set_to_string(options))
  269. return ""!
  270. if (bool_not(dict_in(model["metamodel"]["model"], type))):
  271. log("ERROR: (instantiate_link) no such type in metamodel: " + type)
  272. log(" for " + name)
  273. return ""!
  274. Element v
  275. v = create_edge(model["model"][source], model["model"][destination])
  276. actual_name = instantiated_name(v, name)
  277. dict_add_fast(model["model"], actual_name, v)
  278. dict_add_fast(model["type_mapping"], actual_name, type)
  279. return actual_name!
  280. Void function model_delete_element(model : Element, name : String):
  281. // Remove the link
  282. // 1) from the type mapping
  283. dict_delete(model["type_mapping"], name)
  284. // 2) from the model
  285. delete_element(model["model"][name])
  286. return!
  287. String function model_define_attribute(model : Element, elem : String, name : String, optional : Boolean, type : String):
  288. // Create the necessary links to make it an attribute
  289. String edge_name
  290. edge_name = (elem + "_") + name
  291. while (dict_in(model["model"], edge_name)):
  292. // Already exists, so make random name
  293. edge_name = edge_name + cast_id2s(model["model"][elem])
  294. log("Name clash detected for attribute: try new name: " + edge_name)
  295. edge_name = instantiate_link(model, "AttributeLink", edge_name, elem, type)
  296. instantiate_attribute(model, edge_name, "name", name)
  297. instantiate_attribute(model, edge_name, "optional", optional)
  298. return edge_name!
  299. Element function read_attribute(model : Element, element : String, attribute : String):
  300. if (dict_in(model["model"], element)):
  301. Integer i
  302. Integer count
  303. Element edge
  304. Element edge_type
  305. Element elem
  306. Element typing
  307. Element name
  308. elem = model["model"][element]
  309. typing = model["type_mapping"]
  310. count = read_nr_out(elem)
  311. i = 0
  312. while (i < count):
  313. edge = read_out(elem, i)
  314. name = reverseKeyLookup(model["model"], edge)
  315. if (dict_in(typing, name)):
  316. edge_type = model["metamodel"]["model"][typing[name]]
  317. if (element_eq(edge_type, dict_read_edge(read_edge_src(edge_type), attribute))):
  318. return read_edge_dst(edge)!
  319. i = i + 1
  320. else:
  321. log("Element does not exist: " + element)
  322. // Not found: either element doesn't exist, or we couldn't find it
  323. return read_root()!
  324. Void function unset_attribute(model : Element, element : String, attribute : String):
  325. // Removes an attribute if it exists
  326. String attr_type
  327. Element attr_links
  328. String attr_link
  329. attr_type = find_attribute_type(model, element, attribute)
  330. attr_links = allOutgoingAssociationInstances(model, element, attr_type)
  331. while (list_len(attr_links) > 0):
  332. attr_link = set_pop(attr_links)
  333. dict_delete(model["type_mapping"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
  334. dict_delete(model["type_mapping"], attr_link)
  335. dict_delete_node(model["model"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
  336. delete_element(model["model"][attr_link])
  337. return!
  338. Void function add_AL_links(model : Element, list : Element, element : Element, type: String, linkname : String, expected_type : String):
  339. if (bool_not(dict_in(element, linkname))):
  340. return!
  341. Element link
  342. String link_name
  343. link = dict_read_edge(element, linkname)
  344. link_name = "__" + cast_id2s(link)
  345. // The link
  346. dict_add_fast(model["model"], link_name, link)
  347. dict_add_fast(model["type_mapping"], link_name, (type + "_") + linkname)
  348. // The name link
  349. link = read_out(link, 0)
  350. link_name = "__" + cast_id2s(link)
  351. dict_add_fast(model["model"], link_name, link)
  352. dict_add_fast(model["type_mapping"], link_name, "dict_link_name")
  353. // The name node
  354. link = read_edge_dst(link)
  355. link_name = "__" + cast_id2s(link)
  356. if (bool_not(set_in_node(model["model"], link))):
  357. dict_add_fast(model["model"], link_name, link)
  358. dict_add_fast(model["type_mapping"], link_name, "StringAttr")
  359. // Now add the destination to the worker list
  360. set_add(list, create_tuple(element[linkname], expected_type))
  361. return!
  362. String function add_AL(model : Element, element : Element):
  363. Element todo
  364. Element node
  365. Element work_node
  366. Element elem
  367. String type
  368. String elem_name
  369. todo = create_node()
  370. set_add(todo, create_tuple(element, "funcdef"))
  371. while (0 < dict_len(todo)):
  372. work_node = set_pop(todo)
  373. elem = list_read(work_node, 0)
  374. type = list_read(work_node, 1)
  375. if (bool_not(set_in_node(model["model"], elem))):
  376. // Determine the type if we don't know it
  377. if (type == ""):
  378. if (is_physical_action(elem)):
  379. type = cast_a2s(elem)
  380. else:
  381. type = "Element"
  382. // Add the node itself
  383. elem_name = "__" + cast_id2s(elem)
  384. dict_add_fast(model["model"], elem_name, elem)
  385. dict_add_fast(model["type_mapping"], elem_name, type)
  386. // Now add its edges
  387. if (type == "if"):
  388. add_AL_links(model, todo, elem, type, "cond", "")
  389. add_AL_links(model, todo, elem, type, "then", "")
  390. add_AL_links(model, todo, elem, type, "else", "")
  391. add_AL_links(model, todo, elem, type, "next", "")
  392. elif (type == "while"):
  393. add_AL_links(model, todo, elem, type, "cond", "")
  394. add_AL_links(model, todo, elem, type, "body", "")
  395. add_AL_links(model, todo, elem, type, "next", "")
  396. elif (type == "assign"):
  397. add_AL_links(model, todo, elem, type, "var", "resolve")
  398. add_AL_links(model, todo, elem, type, "value", "")
  399. add_AL_links(model, todo, elem, type, "next", "")
  400. elif (type == "break"):
  401. add_AL_links(model, todo, elem, type, "while", "while")
  402. elif (type == "continue"):
  403. add_AL_links(model, todo, elem, type, "while", "while")
  404. elif (type == "return"):
  405. add_AL_links(model, todo, elem, type, "value", "")
  406. elif (type == "resolve"):
  407. add_AL_links(model, todo, elem, type, "var", "")
  408. elif (type == "access"):
  409. add_AL_links(model, todo, elem, type, "var", "resolve")
  410. elif (type == "constant"):
  411. add_AL_links(model, todo, elem, type, "node", "")
  412. elif (type == "output"):
  413. add_AL_links(model, todo, elem, type, "node", "")
  414. add_AL_links(model, todo, elem, type, "next", "")
  415. elif (type == "global"):
  416. add_AL_links(model, todo, elem, type, "var", "String")
  417. add_AL_links(model, todo, elem, type, "next", "")
  418. elif (type == "param"):
  419. add_AL_links(model, todo, elem, type, "name", "String")
  420. add_AL_links(model, todo, elem, type, "value", "")
  421. add_AL_links(model, todo, elem, type, "next_param", "param")
  422. elif (type == "funcdef"):
  423. add_AL_links(model, todo, elem, type, "body", "")
  424. // TODO this should be added, but is not the same as "param"
  425. //add_AL_links(model, todo, elem, type, "params", "")
  426. add_AL_links(model, todo, elem, type, "next", "")
  427. elif (type == "call"):
  428. add_AL_links(model, todo, elem, type, "func", "")
  429. add_AL_links(model, todo, elem, type, "params", "param")
  430. add_AL_links(model, todo, elem, type, "last_param", "param")
  431. add_AL_links(model, todo, elem, type, "next", "")
  432. // Mark the node as first
  433. String initial
  434. initial = instantiate_node(model, "Initial", "")
  435. instantiate_link(model, "initial_funcdef", "", initial, reverseKeyLookup(model["model"], element))
  436. return reverseKeyLookup(model["model"], element)!
  437. Void function construct_model():
  438. String command
  439. while (True):
  440. command = input()
  441. if (command == "instantiate_bottom"):
  442. Element m
  443. m = instantiate_bottom()
  444. dict_add_fast(global_models, input(), m)
  445. elif (command == "add_node"):
  446. model_add_node(global_models[input()], input())
  447. elif (command == "add_value"):
  448. model_add_value(global_models[input()], input(), input())
  449. elif (command == "add_edge"):
  450. model_add_edge(global_models[input()], input(), input(), input())
  451. elif (command == "exit"):
  452. return!
  453. elif (command == "retype_model"):
  454. retype_model(global_models[input()], global_models[input()])
  455. elif (command == "retype"):
  456. retype(global_models[input()], input(), input())
  457. elif (command == "instantiate_model"):
  458. Element m
  459. m = instantiate_model(global_models[input()])
  460. dict_add_fast(global_models, input(), m)
  461. elif (command == "instantiate_node"):
  462. instantiate_node(global_models[input()], input(), input())
  463. elif (command == "instantiate_attribute"):
  464. instantiate_attribute(global_models[input()], input(), input(), input())
  465. elif (command == "instantiate_attribute_ref"):
  466. instantiate_attribute_ref(global_models[input()], input(), input(), input())
  467. elif (command == "instantiate_attribute_code"):
  468. instantiate_attribute_code(global_models[input()], input(), input(), construct_function())
  469. elif (command == "instantiate_link"):
  470. instantiate_link(global_models[input()], input(), input(), input(), input())
  471. elif (command == "model_define_attribute"):
  472. model_define_attribute(global_models[input()], input(), input(), input(), input())
  473. elif (command == "initialize_bottom"):
  474. initialize_bottom(input())
  475. elif (command == "export_node"):
  476. String local_name
  477. String location
  478. local_name = input()
  479. location = input()
  480. export_node(location, global_models[local_name])
  481. elif (command == "import_node"):
  482. Element m
  483. command = input()
  484. m = import_node(command)
  485. if (element_eq(m, read_root())):
  486. log("Error: import not found for " + command)
  487. else:
  488. dict_add_fast(global_models, input(), m)
  489. elif (command == "add_code_model"):
  490. add_code_model(global_models[input()], input(), construct_function())
  491. else:
  492. log("Modelling error: did not understand command " + command)
  493. Element function construct_model_raw(metamodel : Element):
  494. String command
  495. Element model
  496. model = instantiate_model(metamodel)
  497. while (True):
  498. command = input()
  499. if (command == "add_node"):
  500. input()
  501. model_add_node(model, input())
  502. elif (command == "add_value"):
  503. input()
  504. model_add_value(model, input(), input())
  505. elif (command == "add_edge"):
  506. input()
  507. model_add_edge(model, input(), input(), input())
  508. elif (command == "exit"):
  509. return model!
  510. elif (command == "instantiate_node"):
  511. input()
  512. instantiate_node(model, input(), input())
  513. elif (command == "model_define_attribute"):
  514. input()
  515. model_define_attribute(model, input(), input(), input(), input())
  516. elif (command == "instantiate_attribute"):
  517. input()
  518. instantiate_attribute(model, input(), input(), input())
  519. elif (command == "instantiate_attribute_ref"):
  520. input()
  521. instantiate_attribute_ref(model, input(), input(), input())
  522. elif (command == "instantiate_attribute_code"):
  523. input()
  524. instantiate_attribute_code(model, input(), input(), construct_function())
  525. elif (command == "instantiate_link"):
  526. input()
  527. instantiate_link(model, input(), input(), input(), input())
  528. elif (command == "import_node"):
  529. input()
  530. input()
  531. elif (command == "export_node"):
  532. input()
  533. input()
  534. elif (command == "instantiate_model"):
  535. input()
  536. input()
  537. elif (command == "add_code_model"):
  538. input()
  539. add_code_model(model, input(), construct_function())
  540. else:
  541. log("Modelling error: did not understand command " + command)
  542. Element function get_func_AL_model(al_model : Element):
  543. Element result
  544. Element initial_function
  545. // Find the initial function
  546. initial_function = allInstances(al_model, "Initial")
  547. if (read_nr_out(initial_function) == 0):
  548. log("Could not find function to execute in this model!")
  549. return create_node()!
  550. elif (read_nr_out(initial_function) > 1):
  551. log("Too many functions to execute in this model!")
  552. return create_node()!
  553. else:
  554. initial_function = al_model["model"][set_pop(allAssociationDestinations(al_model, set_pop(initial_function), "initial_funcdef"))]
  555. return initial_function!