tree_ir.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. # NOTE: NOP_LITERAL abuses a mechanic of the modelverse kernel. Specifically,
  2. # whenever the `ModelverseKernel.execute_yields` method returns `None`, then
  3. # the server built around it takes that as a hint that an instruction's phase
  4. # has been completed. The server interrupts the kernel's thread of execution
  5. # when it remarks that an instruction has completed a phase (i.e., when `None`
  6. # is returned by `ModelverseKernel.execute_yields`) and proceeds to check for
  7. # input and output.
  8. #
  9. # In assembly language, a nop is usually used as a point at which a thread of
  10. # execution can be terminated. It follows from the paragraph above that what
  11. # the interpreter does is more or less equivalent to placing nops after every
  12. # instruction. It is worthwhile to remark that JIT-compiled code cannot rely
  13. # on the kernel to interrupt the thread of execution automatically during a
  14. # jitted function's execution -- jitted functions are considered equivalent
  15. # to a single instruction as far as the kernel is concerned. A nop will be
  16. # inserted _after_ the function call (if it is called from interpreted code)
  17. # but that does not suffice for IO, which needs the input/output processing
  18. # to be performed during function execution.
  19. #
  20. # For this reason, the JIT must strategically interrupt the execution of the
  21. # functions it compiles. In other words, it must insert its own nops.
  22. # Here comes the interesting part: a nop is equivalent to `yield None`,
  23. # because that will persuade `ModelverseKernel.execute_yields` to relay the
  24. # `None` marker value to the server, without terminating the current
  25. # generator.
  26. NOP_LITERAL = None
  27. """A literal that results in a nop during which execution may be interrupted
  28. when yielded."""
  29. class Instruction(object):
  30. """A base class for instructions. An instruction is essentially a syntax
  31. node that must first be defined, and can only then be used."""
  32. def __init__(self):
  33. pass
  34. def has_result(self):
  35. """Tells if this instruction computes a result."""
  36. return True
  37. def has_definition(self):
  38. """Tells if this instruction requires a definition."""
  39. return True
  40. def get_result_name_override(self):
  41. """Gets a value that overrides the code generator's result name for this
  42. instruction if it is not None."""
  43. return None
  44. def generate_python_def(self, code_generator):
  45. """Generates a Python statement that executes this instruction.
  46. The statement is appended immediately to the code generator."""
  47. if self.has_definition():
  48. raise NotImplementedError()
  49. else:
  50. code_generator.append_line('pass')
  51. def generate_python_use(self, code_generator):
  52. """Generates a Python expression that retrieves this instruction's
  53. result. The expression is returned as a string."""
  54. if self.has_result():
  55. return code_generator.get_result_name(self)
  56. else:
  57. return 'None'
  58. def simplify(self):
  59. """Applies basic simplification to this instruction and its children."""
  60. return self
  61. def __str__(self):
  62. code_generator = PythonGenerator()
  63. self.generate_python_def(code_generator)
  64. return str(code_generator)
  65. class PythonGenerator(object):
  66. """Generates Python code from instructions."""
  67. def __init__(self):
  68. self.code = []
  69. self.indentation_string = ' ' * 4
  70. self.indentation = 0
  71. self.result_value_dict = {}
  72. def append(self, text):
  73. """Appends the given string to this code generator."""
  74. self.code.append(text)
  75. def append_indentation(self):
  76. """Appends indentation to the code generator."""
  77. self.append(self.indentation_string * self.indentation)
  78. def append_line(self, line=None):
  79. """Appends the indentation string followed by the given string (if any)
  80. and a newline to the code generator."""
  81. self.append_indentation()
  82. if line is not None:
  83. self.append(line)
  84. self.append('\n')
  85. def increase_indentation(self):
  86. """Increases the code generator's indentation by one indent."""
  87. self.indentation += 1
  88. def decrease_indentation(self):
  89. """Decreases the code generator's indentation by one indent."""
  90. self.indentation -= 1
  91. def get_result_name(self, instruction, advised_name=None):
  92. """Gets the name of the given instruction's result variable."""
  93. if instruction not in self.result_value_dict:
  94. override_name = instruction.get_result_name_override()
  95. if override_name is not None:
  96. self.result_value_dict[instruction] = override_name
  97. elif advised_name is not None:
  98. self.result_value_dict[instruction] = advised_name
  99. else:
  100. self.result_value_dict[instruction] = \
  101. 'tmp' + str(len(self.result_value_dict))
  102. return self.result_value_dict[instruction]
  103. def append_definition(self, lhs, rhs):
  104. """Defines the first instruction's result variable as the second
  105. instruction's result."""
  106. self.append_line(
  107. self.get_result_name(lhs) + ' = ' + rhs.generate_python_use(self))
  108. def append_move_definition(self, lhs, rhs):
  109. """First defines the second instruction, then defines the first
  110. instruction as the result of the second."""
  111. if rhs.has_definition():
  112. # Retrieve the result name for the lhs.
  113. lhs_result_name = self.get_result_name(lhs)
  114. # Encourage the rhs to take on the same result name as the lhs.
  115. rhs_result_name = self.get_result_name(rhs, lhs_result_name)
  116. # Generate the rhs' definition.
  117. rhs.generate_python_def(self)
  118. # Only perform an assignment if it's truly necessary.
  119. if lhs_result_name != rhs_result_name:
  120. self.append_definition(lhs, rhs)
  121. else:
  122. self.append_definition(lhs, rhs)
  123. def append_state_definition(self, lhs, opcode, args):
  124. """Appends a definition that queries the modelverse state."""
  125. self.append_line(
  126. "%s, = yield [('%s', [%s])]" % (
  127. self.get_result_name(lhs),
  128. opcode,
  129. ', '.join([arg_i.generate_python_use(self) for arg_i in args])))
  130. def __str__(self):
  131. return ''.join(self.code)
  132. class VoidInstruction(Instruction):
  133. """A base class for instructions that do not return a value."""
  134. def has_result(self):
  135. """Tells if this instruction computes a result."""
  136. return False
  137. class EmptyInstruction(VoidInstruction):
  138. """Represents the empty instruction, which does nothing."""
  139. def has_definition(self):
  140. """Tells if this instruction requires a definition."""
  141. return False
  142. class SelectInstruction(Instruction):
  143. """Represents a select-instruction: an instruction that defines one of two
  144. child instructions, and sets its result to the defined child's result."""
  145. def __init__(self, condition, if_clause, else_clause):
  146. Instruction.__init__(self)
  147. self.condition = condition
  148. self.if_clause = if_clause
  149. self.else_clause = else_clause
  150. def has_result(self):
  151. """Tells if this instruction computes a result."""
  152. return self.if_clause.has_result() or self.else_clause.has_result()
  153. def simplify(self):
  154. """Applies basic simplification to this instruction and its children."""
  155. simple_cond = self.condition.simplify()
  156. simple_if = self.if_clause.simplify()
  157. simple_else = self.else_clause.simplify()
  158. if isinstance(simple_cond, LiteralInstruction):
  159. return simple_if if simple_cond.literal else simple_else
  160. else:
  161. return SelectInstruction(simple_cond, simple_if, simple_else)
  162. def generate_python_def(self, code_generator):
  163. """Generates Python code for this instruction."""
  164. if_has_result = self.has_result()
  165. if self.condition.has_definition():
  166. self.condition.generate_python_def(code_generator)
  167. code_generator.append_line(
  168. 'if ' + self.condition.generate_python_use(code_generator) + ':')
  169. code_generator.increase_indentation()
  170. if if_has_result:
  171. code_generator.append_move_definition(self, self.if_clause)
  172. else:
  173. self.if_clause.generate_python_def(code_generator)
  174. code_generator.decrease_indentation()
  175. else_has_def = self.else_clause.has_definition()
  176. if else_has_def or if_has_result:
  177. code_generator.append_line('else:')
  178. code_generator.increase_indentation()
  179. if if_has_result:
  180. code_generator.append_move_definition(self, self.else_clause)
  181. else:
  182. self.else_clause.generate_python_def(code_generator)
  183. code_generator.decrease_indentation()
  184. class ReturnInstruction(VoidInstruction):
  185. """Represents a return-instruction."""
  186. def __init__(self, value):
  187. VoidInstruction.__init__(self)
  188. self.value = value
  189. def simplify(self):
  190. """Applies basic simplification to this instruction and its children."""
  191. return ReturnInstruction(self.value.simplify())
  192. def generate_python_def(self, code_generator):
  193. """Generates Python code for this instruction."""
  194. if self.value.has_definition():
  195. self.value.generate_python_def(code_generator)
  196. code_generator.append_line(
  197. 'raise PrimitiveFinished(' +
  198. self.value.generate_python_use(code_generator) +
  199. ')')
  200. class RaiseInstruction(VoidInstruction):
  201. """An instruction that raises an error."""
  202. def __init__(self, value):
  203. VoidInstruction.__init__(self)
  204. self.value = value
  205. def simplify(self):
  206. """Applies basic simplification to this instruction and its children."""
  207. return RaiseInstruction(self.value.simplify())
  208. def generate_python_def(self, code_generator):
  209. """Generates Python code for this instruction."""
  210. self.value.generate_python_def(code_generator)
  211. code_generator.append_line(
  212. 'raise ' + self.value.generate_python_use(code_generator))
  213. class CallInstruction(Instruction):
  214. """An instruction that performs a simple call."""
  215. def __init__(self, target, argument_list):
  216. Instruction.__init__(self)
  217. self.target = target
  218. self.argument_list = argument_list
  219. def simplify(self):
  220. """Applies basic simplification to this instruction and its children."""
  221. return CallInstruction(
  222. self.target.simplify(),
  223. [arg.simplify() for arg in self.argument_list])
  224. def generate_python_def(self, code_generator):
  225. """Generates Python code for this instruction."""
  226. if self.target.has_definition():
  227. self.target.generate_python_def(code_generator)
  228. for arg in self.argument_list:
  229. if arg.has_definition():
  230. arg.generate_python_def(code_generator)
  231. code_generator.append_line(
  232. '%s = %s(%s) ' % (
  233. code_generator.get_result_name(self),
  234. self.target.generate_python_use(code_generator),
  235. ', '.join([arg.generate_python_use(code_generator) for arg in self.argument_list])))
  236. class BinaryInstruction(Instruction):
  237. """An instruction that performs a binary operation."""
  238. def __init__(self, lhs, operator, rhs):
  239. Instruction.__init__(self)
  240. self.lhs = lhs
  241. self.operator = operator
  242. self.rhs = rhs
  243. def has_definition(self):
  244. """Tells if this instruction requires a definition."""
  245. return self.lhs.has_definition() or self.rhs.has_definition()
  246. def simplify(self):
  247. """Applies basic simplification to this instruction and its children."""
  248. simple_lhs, simple_rhs = self.lhs.simplify(), self.rhs.simplify()
  249. return BinaryInstruction(simple_lhs, self.operator, simple_rhs)
  250. def generate_python_use(self, code_generator):
  251. """Generates a Python expression that retrieves this instruction's
  252. result. The expression is returned as a string."""
  253. return '%s %s %s' % (
  254. self.lhs.generate_python_use(code_generator),
  255. self.operator,
  256. self.rhs.generate_python_use(code_generator))
  257. def generate_python_def(self, code_generator):
  258. """Generates a Python statement that executes this instruction.
  259. The statement is appended immediately to the code generator."""
  260. if self.lhs.has_definition():
  261. self.lhs.generate_python_def(code_generator)
  262. if self.rhs.has_definition():
  263. self.rhs.generate_python_def(code_generator)
  264. elif self.rhs.has_definition():
  265. self.rhs.generate_python_def(code_generator)
  266. else:
  267. code_generator.append_line('pass')
  268. class LoopInstruction(VoidInstruction):
  269. """Represents a loop-instruction, which loops until broken."""
  270. def __init__(self, body):
  271. VoidInstruction.__init__(self)
  272. self.body = body
  273. def simplify(self):
  274. """Applies basic simplification to this instruction and its children."""
  275. return LoopInstruction(self.body.simplify())
  276. def generate_python_def(self, code_generator):
  277. """Generates Python code for this instruction."""
  278. code_generator.append_line('while 1:')
  279. code_generator.increase_indentation()
  280. self.body.generate_python_def(code_generator)
  281. code_generator.decrease_indentation()
  282. class BreakInstruction(VoidInstruction):
  283. """Represents a break-instruction."""
  284. def generate_python_def(self, code_generator):
  285. """Generates Python code for this instruction."""
  286. code_generator.append_line('break')
  287. class ContinueInstruction(VoidInstruction):
  288. """Represents a continue-instruction."""
  289. def generate_python_def(self, code_generator):
  290. """Generates Python code for this instruction."""
  291. code_generator.append_line('continue')
  292. class CompoundInstruction(Instruction):
  293. """Represents an instruction that evaluates two other instructions
  294. in order, and returns the second instruction's result."""
  295. def __init__(self, first, second):
  296. Instruction.__init__(self)
  297. self.first = first
  298. self.second = second
  299. def has_result(self):
  300. """Tells if this instruction has a result."""
  301. return self.second.has_result()
  302. def simplify(self):
  303. """Applies basic simplification to this instruction and its children."""
  304. simple_fst, simple_snd = self.first.simplify(), self.second.simplify()
  305. if not simple_fst.has_definition():
  306. return simple_snd
  307. elif (not simple_snd.has_definition()) and (not simple_snd.has_result()):
  308. return simple_fst
  309. else:
  310. return CompoundInstruction(simple_fst, simple_snd)
  311. def generate_python_def(self, code_generator):
  312. """Generates Python code for this instruction."""
  313. self.first.generate_python_def(code_generator)
  314. code_generator.append_move_definition(self, self.second)
  315. class LiteralInstruction(Instruction):
  316. """Represents an integer, floating-point, string or Boolean literal."""
  317. def __init__(self, literal):
  318. Instruction.__init__(self)
  319. self.literal = literal
  320. def has_definition(self):
  321. """Tells if this instruction requires a definition."""
  322. return False
  323. def generate_python_use(self, code_generator):
  324. """Generates a Python expression that retrieves this instruction's
  325. result. The expression is returned as a string."""
  326. return repr(self.literal)
  327. class StateInstruction(Instruction):
  328. """An instruction that accesses the modelverse state."""
  329. def get_opcode(self):
  330. """Gets the opcode for this state instruction."""
  331. raise NotImplementedError()
  332. def get_arguments(self):
  333. """Gets this state instruction's argument list."""
  334. raise NotImplementedError()
  335. def generate_python_def(self, code_generator):
  336. """Generates a Python statement that executes this instruction.
  337. The statement is appended immediately to the code generator."""
  338. args = self.get_arguments()
  339. for arg_i in args:
  340. if arg_i.has_definition():
  341. arg_i.generate_python_def(code_generator)
  342. code_generator.append_state_definition(self, self.get_opcode(), args)
  343. class LocalInstruction(Instruction):
  344. """A base class for instructions that access local variables."""
  345. def __init__(self, name):
  346. Instruction.__init__(self)
  347. self.name = name
  348. def get_result_name_override(self):
  349. """Gets a value that overrides the code generator's result name for this
  350. instruction if it is not None."""
  351. return self.name
  352. def create_load(self):
  353. """Creates an instruction that loads the variable referenced by this instruction."""
  354. return LoadLocalInstruction(self.name)
  355. def create_store(self, value):
  356. """Creates an instruction that stores the given value in the variable referenced
  357. by this instruction."""
  358. return StoreLocalInstruction(self.name, value)
  359. def generate_python_use(self, code_generator):
  360. """Generates a Python expression that retrieves this instruction's
  361. result. The expression is returned as a string."""
  362. return self.name
  363. class StoreLocalInstruction(LocalInstruction):
  364. """An instruction that stores a value in a local variable."""
  365. def __init__(self, name, value):
  366. LocalInstruction.__init__(self, name)
  367. self.value = value
  368. def simplify(self):
  369. """Applies basic simplification to this instruction and its children."""
  370. return StoreLocalInstruction(self.name, self.value.simplify())
  371. def generate_python_def(self, code_generator):
  372. """Generates a Python statement that executes this instruction.
  373. The statement is appended immediately to the code generator."""
  374. code_generator.append_move_definition(self, self.value)
  375. class LoadLocalInstruction(LocalInstruction):
  376. """An instruction that loads a value from a local variable."""
  377. def has_definition(self):
  378. """Tells if this instruction requires a definition."""
  379. return False
  380. class DefineFunctionInstruction(LocalInstruction):
  381. """An instruction that defines a function."""
  382. def __init__(self, name, parameter_list, body):
  383. LocalInstruction.__init__(self, name)
  384. self.parameter_list = parameter_list
  385. self.body = body
  386. def generate_python_def(self, code_generator):
  387. """Generates a Python statement that executes this instruction.
  388. The statement is appended immediately to the code generator."""
  389. code_generator.append_line('def %s(%s):' % (self.name, ', '.join(self.parameter_list)))
  390. code_generator.increase_indentation()
  391. self.body.generate_python_def(code_generator)
  392. code_generator.decrease_indentation()
  393. class LocalExistsInstruction(LocalInstruction):
  394. """An instruction that checks if a local variable exists."""
  395. def has_definition(self):
  396. """Tells if this instruction requires a definition."""
  397. return False
  398. def generate_python_use(self, code_generator):
  399. """Generates a Python expression that retrieves this instruction's
  400. result. The expression is returned as a string."""
  401. return "'%s' in locals()" % self.name
  402. class LoadIndexInstruction(Instruction):
  403. """An instruction that produces a value by indexing a specified expression with
  404. a given key."""
  405. def __init__(self, indexed, key):
  406. Instruction.__init__(self)
  407. self.indexed = indexed
  408. self.key = key
  409. def has_definition(self):
  410. """Tells if this instruction requires a definition."""
  411. return False
  412. def generate_python_use(self, code_generator):
  413. """Generates a Python expression that retrieves this instruction's
  414. result. The expression is returned as a string."""
  415. if self.indexed.has_definition():
  416. self.indexed.generate_python_def(code_generator)
  417. if self.key.has_definition():
  418. self.key.generate_python_def(code_generator)
  419. return "%s[%s]" % (
  420. self.indexed.generate_python_use(code_generator),
  421. self.key.generate_python_use(code_generator))
  422. class NopInstruction(Instruction):
  423. """A nop instruction, which allows for the kernel's thread of execution to be interrupted."""
  424. def has_result(self):
  425. """Tells if this instruction computes a result."""
  426. return False
  427. def generate_python_def(self, code_generator):
  428. """Generates a Python statement that executes this instruction.
  429. The statement is appended immediately to the code generator."""
  430. code_generator.append_line('yield %s' % repr(NOP_LITERAL))
  431. class ReadValueInstruction(StateInstruction):
  432. """An instruction that reads a value from a node."""
  433. def __init__(self, node_id):
  434. StateInstruction.__init__(self)
  435. self.node_id = node_id
  436. def simplify(self):
  437. """Applies basic simplification to this instruction and its children."""
  438. return ReadValueInstruction(self.node_id.simplify())
  439. def get_opcode(self):
  440. """Gets the opcode for this state instruction."""
  441. return "RV"
  442. def get_arguments(self):
  443. """Gets this state instruction's argument list."""
  444. return [self.node_id]
  445. class ReadDictionaryValueInstruction(StateInstruction):
  446. """An instruction that reads a dictionary value."""
  447. def __init__(self, node_id, key):
  448. StateInstruction.__init__(self)
  449. self.node_id = node_id
  450. self.key = key
  451. def simplify(self):
  452. """Applies basic simplification to this instruction and its children."""
  453. return ReadDictionaryValueInstruction(
  454. self.node_id.simplify(),
  455. self.key.simplify())
  456. def get_opcode(self):
  457. """Gets the opcode for this state instruction."""
  458. return "RD"
  459. def get_arguments(self):
  460. """Gets this state instruction's argument list."""
  461. return [self.node_id, self.key]
  462. class ReadDictionaryEdgeInstruction(StateInstruction):
  463. """An instruction that reads a dictionary edge."""
  464. def __init__(self, node_id, key):
  465. StateInstruction.__init__(self)
  466. self.node_id = node_id
  467. self.key = key
  468. def simplify(self):
  469. """Applies basic simplification to this instruction and its children."""
  470. return ReadDictionaryEdgeInstruction(
  471. self.node_id.simplify(),
  472. self.key.simplify())
  473. def get_opcode(self):
  474. """Gets the opcode for this state instruction."""
  475. return "RDE"
  476. def get_arguments(self):
  477. """Gets this state instruction's argument list."""
  478. return [self.node_id, self.key]
  479. class CreateNodeInstruction(StateInstruction):
  480. """An instruction that creates an empty node."""
  481. def get_opcode(self):
  482. """Gets the opcode for this state instruction."""
  483. return "CN"
  484. def get_arguments(self):
  485. """Gets this state instruction's argument list."""
  486. return []
  487. class CreateDictionaryEdgeInstruction(StateInstruction):
  488. """An instruction that creates a dictionary edge."""
  489. def __init__(self, source_id, key, target_id):
  490. StateInstruction.__init__(self)
  491. self.source_id = source_id
  492. self.key = key
  493. self.target_id = target_id
  494. def simplify(self):
  495. """Applies basic simplification to this instruction and its children."""
  496. return CreateDictionaryEdgeInstruction(
  497. self.source_id.simplify(),
  498. self.key.simplify(),
  499. self.target_id.simplify())
  500. def get_opcode(self):
  501. """Gets the opcode for this state instruction."""
  502. return "CD"
  503. def get_arguments(self):
  504. """Gets this state instruction's argument list."""
  505. return [self.source_id, self.key, self.target_id]
  506. class DeleteNodeInstruction(StateInstruction):
  507. """An instruction that deletes a node."""
  508. def __init__(self, node_id):
  509. StateInstruction.__init__(self)
  510. self.node_id = node_id
  511. def simplify(self):
  512. """Applies basic simplification to this instruction and its children."""
  513. return DeleteNodeInstruction(self.node_id.simplify())
  514. def has_result(self):
  515. """Tells if this instruction computes a result."""
  516. return False
  517. def get_opcode(self):
  518. """Gets the opcode for this state instruction."""
  519. return "DN"
  520. def get_arguments(self):
  521. """Gets this state instruction's argument list."""
  522. return [self.node_id]
  523. class DeleteEdgeInstruction(StateInstruction):
  524. """An instruction that deletes an edge."""
  525. def __init__(self, edge_id):
  526. StateInstruction.__init__(self)
  527. self.edge_id = edge_id
  528. def simplify(self):
  529. """Applies basic simplification to this instruction and its children."""
  530. return DeleteEdgeInstruction(self.edge_id.simplify())
  531. def has_result(self):
  532. """Tells if this instruction computes a result."""
  533. return False
  534. def get_opcode(self):
  535. """Gets the opcode for this state instruction."""
  536. return "DE"
  537. def get_arguments(self):
  538. """Gets this state instruction's argument list."""
  539. return [self.edge_id]
  540. def create_block(*statements):
  541. """Creates a block-statement from the given list of statements."""
  542. length = len(statements)
  543. if length == 0:
  544. return EmptyInstruction()
  545. elif length == 1:
  546. return statements[0]
  547. else:
  548. return CompoundInstruction(
  549. statements[0],
  550. create_block(*statements[1:]))
  551. if __name__ == "__main__":
  552. example_tree = SelectInstruction(
  553. LiteralInstruction(True),
  554. LoopInstruction(
  555. CompoundInstruction(
  556. BreakInstruction(),
  557. CompoundInstruction(
  558. EmptyInstruction(),
  559. ContinueInstruction()
  560. )
  561. )
  562. ),
  563. ReturnInstruction(
  564. EmptyInstruction()))
  565. print(example_tree.simplify())