abstract_interpreter_definitions.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. AbstractInterpreter.prototype.TYPE_INHERITANCE = {
  2. "Sequence": ["List", "Set", "Tuple", "Str"],
  3. "Num": ["Int", "Float"]
  4. }
  5. AbstractInterpreter.prototype.BUILTINS = {
  6. //
  7. 'KeyError': {"type": "Exception"},
  8. 'IOError': {"type": "Exception"},
  9. // Values
  10. 'True': {"type": "Bool"},
  11. 'False': {"type": "Bool"},
  12. 'None': {"type": 'None'},
  13. // Functions
  14. "print": {
  15. "type": "Function",
  16. "returns": {"type": "None"},
  17. "parameters": [
  18. {"type": "Any", "var": true}
  19. ]
  20. },
  21. "sum": {
  22. "type": "Function",
  23. "returns": {"type": "Num"},
  24. "parameters": [
  25. {"type": "Sequence"},
  26. {"type": "Num", "optional": true}
  27. ]
  28. },
  29. "max": {
  30. "type": "Function",
  31. "returns": {"type": "Num"},
  32. "parameters": [
  33. {"type": "Sequence"},
  34. ]
  35. },
  36. "min": {
  37. "type": "Function",
  38. "returns": {"type": "Num"},
  39. "parameters": [
  40. {"type": "Sequence"},
  41. ]
  42. },
  43. "open": {
  44. "type": "Function",
  45. "returns": {"type": "File"},
  46. "parameters": [
  47. {"type": "Str"},
  48. {"type": "Str", "name": "mode", "optional": true}
  49. ]
  50. },
  51. "round": {
  52. "type": "Function",
  53. "returns": {"type": "Num"},
  54. "parameters": [
  55. {"type": "Num"},
  56. {"type": "Num"}
  57. ]
  58. },
  59. "float": {
  60. "type": "Function",
  61. "returns": {"type": "Num"},
  62. "parameters": [
  63. {"type": ["Str", "Num", "Bool"]}
  64. ]
  65. },
  66. "range": {
  67. "type": "Function",
  68. "returns": {"type": "List", "subtype": {"type": "Num"}},
  69. "parameters": [
  70. {"type": "Num"},
  71. {"type": "Num", "optional": true}
  72. ]
  73. },
  74. "map": {
  75. "type": "Function",
  76. "returns": {"type": "List"},
  77. "parameters": [
  78. {"type": "Function"},
  79. {"type": "Sequence"}
  80. ]
  81. },
  82. "filter": {
  83. "type": "Function",
  84. "returns": {"type": "List"},
  85. "parameters": [
  86. {"type": "Function"},
  87. {"type": "Sequence"}
  88. ]
  89. },
  90. "sorted": {
  91. "type": "Function",
  92. "returns": {"type": "List"},
  93. "parameters": [
  94. {"type": "Sequence"},
  95. {"type": "Function", "optional": true},
  96. {"type": "Function", "optional": true}
  97. ]
  98. },
  99. "xrange": {
  100. "type": "Function",
  101. "returns": {"type": "List", "subtype": {"type": "Num"}},
  102. "parameters": [
  103. {"type": "Num"},
  104. {"type": "Num", "optional": true}
  105. ]
  106. },
  107. "str": {
  108. "type": "Function",
  109. "returns": {"type": "Str"},
  110. "parameters": [
  111. {"type": "Any"}
  112. ]
  113. },
  114. "set": {
  115. "type": "Function",
  116. "returns": {"type": "Set"},
  117. "parameters": [
  118. {"type": "Any"}
  119. ]
  120. },
  121. "list": {
  122. "type": "Function",
  123. "returns": {"type": "List"},
  124. "parameters": [
  125. {"type": "Any"}
  126. ]
  127. },
  128. "dict": {
  129. "type": "Function",
  130. "returns": {"type": "Dict"},
  131. "parameters": [
  132. {"type": "Any"}
  133. ]
  134. },
  135. "abs": {
  136. "type": "Function",
  137. "returns": {"type": "Num"},
  138. "parameters": [
  139. {"type": "Num"}
  140. ]
  141. },
  142. "int": {
  143. "type": "Function",
  144. "returns": {"type": "Num"},
  145. "parameters": [
  146. {"type": "Any"}
  147. ]
  148. },
  149. "len": {
  150. "type": "Function",
  151. "returns": {"type": "Num"},
  152. "parameters": [
  153. {"type": "Sequence"}
  154. ]
  155. },
  156. 'input': {"type": "Str"},
  157. 'reversed': {"type": "List"},
  158. 'type': {"type": "Any"},
  159. 'dir': {"type": "List"}
  160. };
  161. AbstractInterpreter.METHODS = {
  162. "List": {
  163. "append": {
  164. "type": "Function",
  165. "returns": {"type": "None"}
  166. }
  167. },
  168. "Str": {
  169. "strip": {
  170. "type": "Function",
  171. "returns": {"type": "Str"}
  172. }
  173. }
  174. }
  175. AbstractInterpreter.MODULES = {
  176. 'random': {
  177. 'randint': { "type": "Function", "returns": {"type": "Num"}},
  178. 'choice': { "type": "Function", "returns": {"type": "Any"}},
  179. 'shuffle': { "type": "Function", "returns": {"type": "None"}},
  180. },
  181. 'parking': {
  182. 'now': { 'type': 'ParkingTime'},
  183. 'Time': { 'type': 'ParkingTime'},
  184. 'Day': { 'type': 'ParkingDay'},
  185. 'today': { 'type': 'ParkingDay'}
  186. },
  187. 'weather': {
  188. 'get_temperature': {"type": 'Num'},
  189. 'get_forecasts': {"type": "List", "empty": false, "component": {"type": 'Num'}},
  190. 'get_report': {"type": "Dict", "all_strings": true,
  191. "keys": {"temperature": {"type": 'Num'},
  192. "humidity": {"type": "Num"},
  193. "wind": {"type": "Num"}}},
  194. 'get_forecasted_reports': [{"temperature": 'Num', "humidity": "Num", "wind": "Num"}],
  195. 'get_all_forecasted_temperatures': [{'city': 'str', 'forecasts': ['int']}],
  196. 'get_highs_lows': {'highs': ['Num'], 'lows': ['Num']}
  197. },
  198. 'image': {
  199. },
  200. 'stocks': {
  201. 'get_current': 'float',
  202. 'get_past': ['float'],
  203. },
  204. 'earthquakes': {
  205. 'get': ['float'],
  206. 'get_both': [{'magnitude': 'float', 'depth': 'float'}],
  207. 'get_all': [{'magnitude': 'float', 'distance': 'float', 'gap': 'int',
  208. 'id': 'str', 'significance': 'int', 'time': 'int',
  209. 'location': {'depth': 'float', 'latitude': 'float', 'longitude': 'float',
  210. 'location_description': 'str'}}]
  211. },
  212. 'crime': {
  213. 'get_property_crimes': ['float'],
  214. 'get_violent_crimes': ['float'],
  215. 'get_both_crimes': ['float'],
  216. 'get_by_year': [{'state': 'str', 'violent': 'float', 'property': 'float', 'population': 'int'}],
  217. 'get_all': {}
  218. },
  219. 'books': {
  220. 'get_all': [{'title': 'str', 'author': 'str', 'price': 'float', 'paperback': 'bool', 'page count': 'int'}]
  221. }
  222. }