pytunia 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (417) hide show
  1. pytunia-0.1/LICENSE.txt +45 -0
  2. pytunia-0.1/MANIFEST.in +3 -0
  3. pytunia-0.1/PKG-INFO +276 -0
  4. pytunia-0.1/README.md +245 -0
  5. pytunia-0.1/pyproject.toml +45 -0
  6. pytunia-0.1/pytunia/__init__.py +34 -0
  7. pytunia-0.1/pytunia/__main__.py +7 -0
  8. pytunia-0.1/pytunia/api.py +106 -0
  9. pytunia-0.1/pytunia/classfile.py +911 -0
  10. pytunia-0.1/pytunia/diagnostics.py +61 -0
  11. pytunia-0.1/pytunia/insninfo.py +266 -0
  12. pytunia-0.1/pytunia/jas/__init__.py +79 -0
  13. pytunia-0.1/pytunia/jas/annotation.py +325 -0
  14. pytunia-0.1/pytunia/jas/attributes.py +225 -0
  15. pytunia-0.1/pytunia/jas/classenv.py +334 -0
  16. pytunia-0.1/pytunia/jas/code.py +281 -0
  17. pytunia-0.1/pytunia/jas/constants.py +328 -0
  18. pytunia-0.1/pytunia/jas/cp.py +208 -0
  19. pytunia-0.1/pytunia/jas/errors.py +26 -0
  20. pytunia-0.1/pytunia/jas/insn.py +520 -0
  21. pytunia-0.1/pytunia/jas/stackmap.py +293 -0
  22. pytunia-0.1/pytunia/javacompat.py +830 -0
  23. pytunia-0.1/pytunia/main.py +273 -0
  24. pytunia-0.1/pytunia/parser.py +612 -0
  25. pytunia-0.1/pytunia/parser_tables.py +2321 -0
  26. pytunia-0.1/pytunia/scanner.py +513 -0
  27. pytunia-0.1/pytunia/sym.py +153 -0
  28. pytunia-0.1/pytunia.egg-info/PKG-INFO +276 -0
  29. pytunia-0.1/pytunia.egg-info/SOURCES.txt +415 -0
  30. pytunia-0.1/pytunia.egg-info/dependency_links.txt +1 -0
  31. pytunia-0.1/pytunia.egg-info/top_level.txt +1 -0
  32. pytunia-0.1/setup.cfg +4 -0
  33. pytunia-0.1/tests/cases/Annotations.j +93 -0
  34. pytunia-0.1/tests/cases/AutoLines.j +25 -0
  35. pytunia-0.1/tests/cases/Constants.j +48 -0
  36. pytunia-0.1/tests/cases/Crlf.j +10 -0
  37. pytunia-0.1/tests/cases/Debug.j +35 -0
  38. pytunia-0.1/tests/cases/DebugG.j +35 -0
  39. pytunia-0.1/tests/cases/Enclosing.j +4 -0
  40. pytunia-0.1/tests/cases/ErrAnnFloatNeg.j +5 -0
  41. pytunia-0.1/tests/cases/ErrAnnNotClosed.j +6 -0
  42. pytunia-0.1/tests/cases/ErrAnnParam.j +6 -0
  43. pytunia-0.1/tests/cases/ErrAnnRange.j +5 -0
  44. pytunia-0.1/tests/cases/ErrAnnSig.j +5 -0
  45. pytunia-0.1/tests/cases/ErrAnnTooMany.j +5 -0
  46. pytunia-0.1/tests/cases/ErrAnnValue.j +5 -0
  47. pytunia-0.1/tests/cases/ErrArrayType.j +8 -0
  48. pytunia-0.1/tests/cases/ErrAttrFile.j +3 -0
  49. pytunia-0.1/tests/cases/ErrBadArgs.j +8 -0
  50. pytunia-0.1/tests/cases/ErrBadArgs2.j +8 -0
  51. pytunia-0.1/tests/cases/ErrBadArgs3.j +8 -0
  52. pytunia-0.1/tests/cases/ErrBadArgs4.j +8 -0
  53. pytunia-0.1/tests/cases/ErrBadEscape.j +8 -0
  54. pytunia-0.1/tests/cases/ErrBadNumber.j +8 -0
  55. pytunia-0.1/tests/cases/ErrBadNumber2.j +8 -0
  56. pytunia-0.1/tests/cases/ErrBadNumber3.j +8 -0
  57. pytunia-0.1/tests/cases/ErrBadNumber4.j +8 -0
  58. pytunia-0.1/tests/cases/ErrBadUEscape.j +8 -0
  59. pytunia-0.1/tests/cases/ErrBipush.j +8 -0
  60. pytunia-0.1/tests/cases/ErrBytecodeDouble.j +3 -0
  61. pytunia-0.1/tests/cases/ErrBytecodeExp.j +3 -0
  62. pytunia-0.1/tests/cases/ErrBytecodeInt.j +3 -0
  63. pytunia-0.1/tests/cases/ErrBytecodeLong.j +3 -0
  64. pytunia-0.1/tests/cases/ErrCatchMixed.j +8 -0
  65. pytunia-0.1/tests/cases/ErrDirectiveNumber.j +3 -0
  66. pytunia-0.1/tests/cases/ErrDollar.j +8 -0
  67. pytunia-0.1/tests/cases/ErrDollarBad.j +8 -0
  68. pytunia-0.1/tests/cases/ErrDoubleClass.j +4 -0
  69. pytunia-0.1/tests/cases/ErrDupLabelOk.j +11 -0
  70. pytunia-0.1/tests/cases/ErrEmpty.j +0 -0
  71. pytunia-0.1/tests/cases/ErrEmptyName.j +8 -0
  72. pytunia-0.1/tests/cases/ErrEndField.j +3 -0
  73. pytunia-0.1/tests/cases/ErrFarJump.j +33009 -0
  74. pytunia-0.1/tests/cases/ErrFieldNoClass.j +8 -0
  75. pytunia-0.1/tests/cases/ErrFieldValue.j +3 -0
  76. pytunia-0.1/tests/cases/ErrGloups.j +8 -0
  77. pytunia-0.1/tests/cases/ErrInterfaceNargs.j +8 -0
  78. pytunia-0.1/tests/cases/ErrLabelSyntax.j +9 -0
  79. pytunia-0.1/tests/cases/ErrLimit.j +6 -0
  80. pytunia-0.1/tests/cases/ErrLimitWord.j +6 -0
  81. pytunia-0.1/tests/cases/ErrMalformedSig.j +8 -0
  82. pytunia-0.1/tests/cases/ErrManyErrors.j +10 -0
  83. pytunia-0.1/tests/cases/ErrMetho.j +3 -0
  84. pytunia-0.1/tests/cases/ErrMissingArgs.j +8 -0
  85. pytunia-0.1/tests/cases/ErrNameEscape.j +8 -0
  86. pytunia-0.1/tests/cases/ErrNameNoSep.j +8 -0
  87. pytunia-0.1/tests/cases/ErrNewarrayInt.j +8 -0
  88. pytunia-0.1/tests/cases/ErrNoEndMethod.j +4 -0
  89. pytunia-0.1/tests/cases/ErrNoNewlineAtEnd.j +4 -0
  90. pytunia-0.1/tests/cases/ErrNoSuper.j +4 -0
  91. pytunia-0.1/tests/cases/ErrOnlyComments.j +3 -0
  92. pytunia-0.1/tests/cases/ErrRecovery.j +13 -0
  93. pytunia-0.1/tests/cases/ErrSet.j +10 -0
  94. pytunia-0.1/tests/cases/ErrSignatureOutside.j +4 -0
  95. pytunia-0.1/tests/cases/ErrSipush.j +8 -0
  96. pytunia-0.1/tests/cases/ErrStackOffset2.j +9 -0
  97. pytunia-0.1/tests/cases/ErrStackType.j +10 -0
  98. pytunia-0.1/tests/cases/ErrStackUse.j +7 -0
  99. pytunia-0.1/tests/cases/ErrStackUse0.j +7 -0
  100. pytunia-0.1/tests/cases/ErrTableHigh.j +12 -0
  101. pytunia-0.1/tests/cases/ErrTabs.j +5 -0
  102. pytunia-0.1/tests/cases/ErrUndefinedLabel.j +8 -0
  103. pytunia-0.1/tests/cases/ErrUnknownDirective.j +3 -0
  104. pytunia-0.1/tests/cases/ErrUntermName.j +8 -0
  105. pytunia-0.1/tests/cases/ErrUntermString.j +9 -0
  106. pytunia-0.1/tests/cases/ErrUntermStringEOF.j +4 -0
  107. pytunia-0.1/tests/cases/ErrVar.j +8 -0
  108. pytunia-0.1/tests/cases/FarJumpW.j +33009 -0
  109. pytunia-0.1/tests/cases/Fields.j +50 -0
  110. pytunia-0.1/tests/cases/Header.j +34 -0
  111. pytunia-0.1/tests/cases/Iface.j +15 -0
  112. pytunia-0.1/tests/cases/Instructions.j +253 -0
  113. pytunia-0.1/tests/cases/Latin1.j +4 -0
  114. pytunia-0.1/tests/cases/ManyConstants.j +2070 -0
  115. pytunia-0.1/tests/cases/Names.j +19 -0
  116. pytunia-0.1/tests/cases/NumLabels.j +29 -0
  117. pytunia-0.1/tests/cases/NumLabelsG.j +29 -0
  118. pytunia-0.1/tests/cases/StackMapOld.j +17 -0
  119. pytunia-0.1/tests/cases/StackMapTable.j +137 -0
  120. pytunia-0.1/tests/cases/Switches.j +94 -0
  121. pytunia-0.1/tests/cases/Unicode.j +11 -0
  122. pytunia-0.1/tests/cases/attr.bin +0 -0
  123. pytunia-0.1/tests/cases/empty.bin +0 -0
  124. pytunia-0.1/tests/expected/Annotations/classes/Annotations.class +0 -0
  125. pytunia-0.1/tests/expected/Annotations/status.txt +1 -0
  126. pytunia-0.1/tests/expected/Annotations/stderr.txt +0 -0
  127. pytunia-0.1/tests/expected/Annotations/stdout.txt +1 -0
  128. pytunia-0.1/tests/expected/AutoLines/classes/AutoLines.class +0 -0
  129. pytunia-0.1/tests/expected/AutoLines/status.txt +1 -0
  130. pytunia-0.1/tests/expected/AutoLines/stderr.txt +0 -0
  131. pytunia-0.1/tests/expected/AutoLines/stdout.txt +1 -0
  132. pytunia-0.1/tests/expected/Constants/classes/Constants.class +0 -0
  133. pytunia-0.1/tests/expected/Constants/status.txt +1 -0
  134. pytunia-0.1/tests/expected/Constants/stderr.txt +0 -0
  135. pytunia-0.1/tests/expected/Constants/stdout.txt +1 -0
  136. pytunia-0.1/tests/expected/Crlf/classes/Crlf.class +0 -0
  137. pytunia-0.1/tests/expected/Crlf/status.txt +1 -0
  138. pytunia-0.1/tests/expected/Crlf/stderr.txt +0 -0
  139. pytunia-0.1/tests/expected/Crlf/stdout.txt +1 -0
  140. pytunia-0.1/tests/expected/Debug/classes/Debug.class +0 -0
  141. pytunia-0.1/tests/expected/Debug/status.txt +1 -0
  142. pytunia-0.1/tests/expected/Debug/stderr.txt +0 -0
  143. pytunia-0.1/tests/expected/Debug/stdout.txt +1 -0
  144. pytunia-0.1/tests/expected/DebugG/classes/DebugG.class +0 -0
  145. pytunia-0.1/tests/expected/DebugG/status.txt +1 -0
  146. pytunia-0.1/tests/expected/DebugG/stderr.txt +0 -0
  147. pytunia-0.1/tests/expected/DebugG/stdout.txt +1 -0
  148. pytunia-0.1/tests/expected/Enclosing/classes/Enclosing$1.class +0 -0
  149. pytunia-0.1/tests/expected/Enclosing/status.txt +1 -0
  150. pytunia-0.1/tests/expected/Enclosing/stderr.txt +0 -0
  151. pytunia-0.1/tests/expected/Enclosing/stdout.txt +1 -0
  152. pytunia-0.1/tests/expected/ErrAnnFloatNeg/status.txt +1 -0
  153. pytunia-0.1/tests/expected/ErrAnnFloatNeg/stderr.txt +4 -0
  154. pytunia-0.1/tests/expected/ErrAnnFloatNeg/stdout.txt +0 -0
  155. pytunia-0.1/tests/expected/ErrAnnNotClosed/status.txt +1 -0
  156. pytunia-0.1/tests/expected/ErrAnnNotClosed/stderr.txt +7 -0
  157. pytunia-0.1/tests/expected/ErrAnnNotClosed/stdout.txt +0 -0
  158. pytunia-0.1/tests/expected/ErrAnnParam/status.txt +1 -0
  159. pytunia-0.1/tests/expected/ErrAnnParam/stderr.txt +4 -0
  160. pytunia-0.1/tests/expected/ErrAnnParam/stdout.txt +0 -0
  161. pytunia-0.1/tests/expected/ErrAnnRange/status.txt +1 -0
  162. pytunia-0.1/tests/expected/ErrAnnRange/stderr.txt +4 -0
  163. pytunia-0.1/tests/expected/ErrAnnRange/stdout.txt +0 -0
  164. pytunia-0.1/tests/expected/ErrAnnSig/status.txt +1 -0
  165. pytunia-0.1/tests/expected/ErrAnnSig/stderr.txt +4 -0
  166. pytunia-0.1/tests/expected/ErrAnnSig/stdout.txt +0 -0
  167. pytunia-0.1/tests/expected/ErrAnnTooMany/status.txt +1 -0
  168. pytunia-0.1/tests/expected/ErrAnnTooMany/stderr.txt +4 -0
  169. pytunia-0.1/tests/expected/ErrAnnTooMany/stdout.txt +0 -0
  170. pytunia-0.1/tests/expected/ErrAnnValue/status.txt +1 -0
  171. pytunia-0.1/tests/expected/ErrAnnValue/stderr.txt +4 -0
  172. pytunia-0.1/tests/expected/ErrAnnValue/stdout.txt +0 -0
  173. pytunia-0.1/tests/expected/ErrArrayType/status.txt +1 -0
  174. pytunia-0.1/tests/expected/ErrArrayType/stderr.txt +4 -0
  175. pytunia-0.1/tests/expected/ErrArrayType/stdout.txt +0 -0
  176. pytunia-0.1/tests/expected/ErrAttrFile/status.txt +1 -0
  177. pytunia-0.1/tests/expected/ErrAttrFile/stderr.txt +2 -0
  178. pytunia-0.1/tests/expected/ErrAttrFile/stdout.txt +0 -0
  179. pytunia-0.1/tests/expected/ErrBadArgs/status.txt +1 -0
  180. pytunia-0.1/tests/expected/ErrBadArgs/stderr.txt +5 -0
  181. pytunia-0.1/tests/expected/ErrBadArgs/stdout.txt +0 -0
  182. pytunia-0.1/tests/expected/ErrBadArgs2/status.txt +1 -0
  183. pytunia-0.1/tests/expected/ErrBadArgs2/stderr.txt +4 -0
  184. pytunia-0.1/tests/expected/ErrBadArgs2/stdout.txt +0 -0
  185. pytunia-0.1/tests/expected/ErrBadArgs3/status.txt +1 -0
  186. pytunia-0.1/tests/expected/ErrBadArgs3/stderr.txt +4 -0
  187. pytunia-0.1/tests/expected/ErrBadArgs3/stdout.txt +0 -0
  188. pytunia-0.1/tests/expected/ErrBadArgs4/status.txt +1 -0
  189. pytunia-0.1/tests/expected/ErrBadArgs4/stderr.txt +4 -0
  190. pytunia-0.1/tests/expected/ErrBadArgs4/stdout.txt +0 -0
  191. pytunia-0.1/tests/expected/ErrBadEscape/status.txt +1 -0
  192. pytunia-0.1/tests/expected/ErrBadEscape/stderr.txt +4 -0
  193. pytunia-0.1/tests/expected/ErrBadEscape/stdout.txt +0 -0
  194. pytunia-0.1/tests/expected/ErrBadNumber/status.txt +1 -0
  195. pytunia-0.1/tests/expected/ErrBadNumber/stderr.txt +4 -0
  196. pytunia-0.1/tests/expected/ErrBadNumber/stdout.txt +0 -0
  197. pytunia-0.1/tests/expected/ErrBadNumber2/status.txt +1 -0
  198. pytunia-0.1/tests/expected/ErrBadNumber2/stderr.txt +4 -0
  199. pytunia-0.1/tests/expected/ErrBadNumber2/stdout.txt +0 -0
  200. pytunia-0.1/tests/expected/ErrBadNumber3/status.txt +1 -0
  201. pytunia-0.1/tests/expected/ErrBadNumber3/stderr.txt +4 -0
  202. pytunia-0.1/tests/expected/ErrBadNumber3/stdout.txt +0 -0
  203. pytunia-0.1/tests/expected/ErrBadNumber4/status.txt +1 -0
  204. pytunia-0.1/tests/expected/ErrBadNumber4/stderr.txt +4 -0
  205. pytunia-0.1/tests/expected/ErrBadNumber4/stdout.txt +0 -0
  206. pytunia-0.1/tests/expected/ErrBadUEscape/status.txt +1 -0
  207. pytunia-0.1/tests/expected/ErrBadUEscape/stderr.txt +4 -0
  208. pytunia-0.1/tests/expected/ErrBadUEscape/stdout.txt +0 -0
  209. pytunia-0.1/tests/expected/ErrBipush/status.txt +1 -0
  210. pytunia-0.1/tests/expected/ErrBipush/stderr.txt +4 -0
  211. pytunia-0.1/tests/expected/ErrBipush/stdout.txt +0 -0
  212. pytunia-0.1/tests/expected/ErrBytecodeDouble/status.txt +1 -0
  213. pytunia-0.1/tests/expected/ErrBytecodeDouble/stderr.txt +4 -0
  214. pytunia-0.1/tests/expected/ErrBytecodeDouble/stdout.txt +0 -0
  215. pytunia-0.1/tests/expected/ErrBytecodeExp/status.txt +1 -0
  216. pytunia-0.1/tests/expected/ErrBytecodeExp/stderr.txt +4 -0
  217. pytunia-0.1/tests/expected/ErrBytecodeExp/stdout.txt +0 -0
  218. pytunia-0.1/tests/expected/ErrBytecodeInt/status.txt +1 -0
  219. pytunia-0.1/tests/expected/ErrBytecodeInt/stderr.txt +7 -0
  220. pytunia-0.1/tests/expected/ErrBytecodeInt/stdout.txt +0 -0
  221. pytunia-0.1/tests/expected/ErrBytecodeLong/status.txt +1 -0
  222. pytunia-0.1/tests/expected/ErrBytecodeLong/stderr.txt +7 -0
  223. pytunia-0.1/tests/expected/ErrBytecodeLong/stdout.txt +0 -0
  224. pytunia-0.1/tests/expected/ErrCatchMixed/status.txt +1 -0
  225. pytunia-0.1/tests/expected/ErrCatchMixed/stderr.txt +4 -0
  226. pytunia-0.1/tests/expected/ErrCatchMixed/stdout.txt +0 -0
  227. pytunia-0.1/tests/expected/ErrDirectiveNumber/status.txt +1 -0
  228. pytunia-0.1/tests/expected/ErrDirectiveNumber/stderr.txt +4 -0
  229. pytunia-0.1/tests/expected/ErrDirectiveNumber/stdout.txt +0 -0
  230. pytunia-0.1/tests/expected/ErrDollar/status.txt +1 -0
  231. pytunia-0.1/tests/expected/ErrDollar/stderr.txt +4 -0
  232. pytunia-0.1/tests/expected/ErrDollar/stdout.txt +0 -0
  233. pytunia-0.1/tests/expected/ErrDollarBad/status.txt +1 -0
  234. pytunia-0.1/tests/expected/ErrDollarBad/stderr.txt +4 -0
  235. pytunia-0.1/tests/expected/ErrDollarBad/stdout.txt +0 -0
  236. pytunia-0.1/tests/expected/ErrDoubleClass/status.txt +1 -0
  237. pytunia-0.1/tests/expected/ErrDoubleClass/stderr.txt +7 -0
  238. pytunia-0.1/tests/expected/ErrDoubleClass/stdout.txt +0 -0
  239. pytunia-0.1/tests/expected/ErrDupLabelOk/classes/DupLabel.class +0 -0
  240. pytunia-0.1/tests/expected/ErrDupLabelOk/status.txt +1 -0
  241. pytunia-0.1/tests/expected/ErrDupLabelOk/stderr.txt +0 -0
  242. pytunia-0.1/tests/expected/ErrDupLabelOk/stdout.txt +1 -0
  243. pytunia-0.1/tests/expected/ErrEmpty/status.txt +1 -0
  244. pytunia-0.1/tests/expected/ErrEmpty/stderr.txt +2 -0
  245. pytunia-0.1/tests/expected/ErrEmpty/stdout.txt +0 -0
  246. pytunia-0.1/tests/expected/ErrEmptyName/status.txt +1 -0
  247. pytunia-0.1/tests/expected/ErrEmptyName/stderr.txt +4 -0
  248. pytunia-0.1/tests/expected/ErrEmptyName/stdout.txt +0 -0
  249. pytunia-0.1/tests/expected/ErrEndField/status.txt +1 -0
  250. pytunia-0.1/tests/expected/ErrEndField/stderr.txt +7 -0
  251. pytunia-0.1/tests/expected/ErrEndField/stdout.txt +0 -0
  252. pytunia-0.1/tests/expected/ErrFarJump/status.txt +1 -0
  253. pytunia-0.1/tests/expected/ErrFarJump/stderr.txt +2 -0
  254. pytunia-0.1/tests/expected/ErrFarJump/stdout.txt +0 -0
  255. pytunia-0.1/tests/expected/ErrFieldNoClass/status.txt +1 -0
  256. pytunia-0.1/tests/expected/ErrFieldNoClass/stderr.txt +4 -0
  257. pytunia-0.1/tests/expected/ErrFieldNoClass/stdout.txt +0 -0
  258. pytunia-0.1/tests/expected/ErrFieldValue/status.txt +1 -0
  259. pytunia-0.1/tests/expected/ErrFieldValue/stderr.txt +7 -0
  260. pytunia-0.1/tests/expected/ErrFieldValue/stdout.txt +0 -0
  261. pytunia-0.1/tests/expected/ErrGloups/status.txt +1 -0
  262. pytunia-0.1/tests/expected/ErrGloups/stderr.txt +4 -0
  263. pytunia-0.1/tests/expected/ErrGloups/stdout.txt +0 -0
  264. pytunia-0.1/tests/expected/ErrInterfaceNargs/status.txt +1 -0
  265. pytunia-0.1/tests/expected/ErrInterfaceNargs/stderr.txt +4 -0
  266. pytunia-0.1/tests/expected/ErrInterfaceNargs/stdout.txt +0 -0
  267. pytunia-0.1/tests/expected/ErrLabelSyntax/status.txt +1 -0
  268. pytunia-0.1/tests/expected/ErrLabelSyntax/stderr.txt +5 -0
  269. pytunia-0.1/tests/expected/ErrLabelSyntax/stdout.txt +0 -0
  270. pytunia-0.1/tests/expected/ErrLimit/status.txt +1 -0
  271. pytunia-0.1/tests/expected/ErrLimit/stderr.txt +4 -0
  272. pytunia-0.1/tests/expected/ErrLimit/stdout.txt +0 -0
  273. pytunia-0.1/tests/expected/ErrLimitWord/status.txt +1 -0
  274. pytunia-0.1/tests/expected/ErrLimitWord/stderr.txt +4 -0
  275. pytunia-0.1/tests/expected/ErrLimitWord/stdout.txt +0 -0
  276. pytunia-0.1/tests/expected/ErrMalformedSig/status.txt +1 -0
  277. pytunia-0.1/tests/expected/ErrMalformedSig/stderr.txt +4 -0
  278. pytunia-0.1/tests/expected/ErrMalformedSig/stdout.txt +0 -0
  279. pytunia-0.1/tests/expected/ErrManyErrors/status.txt +1 -0
  280. pytunia-0.1/tests/expected/ErrManyErrors/stderr.txt +4 -0
  281. pytunia-0.1/tests/expected/ErrManyErrors/stdout.txt +0 -0
  282. pytunia-0.1/tests/expected/ErrMetho/status.txt +1 -0
  283. pytunia-0.1/tests/expected/ErrMetho/stderr.txt +4 -0
  284. pytunia-0.1/tests/expected/ErrMetho/stdout.txt +0 -0
  285. pytunia-0.1/tests/expected/ErrMissingArgs/status.txt +1 -0
  286. pytunia-0.1/tests/expected/ErrMissingArgs/stderr.txt +4 -0
  287. pytunia-0.1/tests/expected/ErrMissingArgs/stdout.txt +0 -0
  288. pytunia-0.1/tests/expected/ErrNameEscape/status.txt +1 -0
  289. pytunia-0.1/tests/expected/ErrNameEscape/stderr.txt +4 -0
  290. pytunia-0.1/tests/expected/ErrNameEscape/stdout.txt +0 -0
  291. pytunia-0.1/tests/expected/ErrNameNoSep/status.txt +1 -0
  292. pytunia-0.1/tests/expected/ErrNameNoSep/stderr.txt +4 -0
  293. pytunia-0.1/tests/expected/ErrNameNoSep/stdout.txt +0 -0
  294. pytunia-0.1/tests/expected/ErrNewarrayInt/status.txt +1 -0
  295. pytunia-0.1/tests/expected/ErrNewarrayInt/stderr.txt +4 -0
  296. pytunia-0.1/tests/expected/ErrNewarrayInt/stdout.txt +0 -0
  297. pytunia-0.1/tests/expected/ErrNoEndMethod/status.txt +1 -0
  298. pytunia-0.1/tests/expected/ErrNoEndMethod/stderr.txt +3 -0
  299. pytunia-0.1/tests/expected/ErrNoEndMethod/stdout.txt +0 -0
  300. pytunia-0.1/tests/expected/ErrNoNewlineAtEnd/status.txt +1 -0
  301. pytunia-0.1/tests/expected/ErrNoNewlineAtEnd/stderr.txt +2 -0
  302. pytunia-0.1/tests/expected/ErrNoNewlineAtEnd/stdout.txt +0 -0
  303. pytunia-0.1/tests/expected/ErrNoSuper/status.txt +1 -0
  304. pytunia-0.1/tests/expected/ErrNoSuper/stderr.txt +7 -0
  305. pytunia-0.1/tests/expected/ErrNoSuper/stdout.txt +0 -0
  306. pytunia-0.1/tests/expected/ErrOnlyComments/status.txt +1 -0
  307. pytunia-0.1/tests/expected/ErrOnlyComments/stderr.txt +2 -0
  308. pytunia-0.1/tests/expected/ErrOnlyComments/stdout.txt +0 -0
  309. pytunia-0.1/tests/expected/ErrRecovery/status.txt +1 -0
  310. pytunia-0.1/tests/expected/ErrRecovery/stderr.txt +4 -0
  311. pytunia-0.1/tests/expected/ErrRecovery/stdout.txt +0 -0
  312. pytunia-0.1/tests/expected/ErrSet/status.txt +1 -0
  313. pytunia-0.1/tests/expected/ErrSet/stderr.txt +7 -0
  314. pytunia-0.1/tests/expected/ErrSet/stdout.txt +0 -0
  315. pytunia-0.1/tests/expected/ErrSignatureOutside/status.txt +1 -0
  316. pytunia-0.1/tests/expected/ErrSignatureOutside/stderr.txt +3 -0
  317. pytunia-0.1/tests/expected/ErrSignatureOutside/stdout.txt +0 -0
  318. pytunia-0.1/tests/expected/ErrSipush/status.txt +1 -0
  319. pytunia-0.1/tests/expected/ErrSipush/stderr.txt +4 -0
  320. pytunia-0.1/tests/expected/ErrSipush/stdout.txt +0 -0
  321. pytunia-0.1/tests/expected/ErrStackOffset2/status.txt +1 -0
  322. pytunia-0.1/tests/expected/ErrStackOffset2/stderr.txt +4 -0
  323. pytunia-0.1/tests/expected/ErrStackOffset2/stdout.txt +0 -0
  324. pytunia-0.1/tests/expected/ErrStackType/status.txt +1 -0
  325. pytunia-0.1/tests/expected/ErrStackType/stderr.txt +10 -0
  326. pytunia-0.1/tests/expected/ErrStackType/stdout.txt +0 -0
  327. pytunia-0.1/tests/expected/ErrStackUse/classes/X.class +0 -0
  328. pytunia-0.1/tests/expected/ErrStackUse/status.txt +1 -0
  329. pytunia-0.1/tests/expected/ErrStackUse/stderr.txt +0 -0
  330. pytunia-0.1/tests/expected/ErrStackUse/stdout.txt +1 -0
  331. pytunia-0.1/tests/expected/ErrStackUse0/status.txt +1 -0
  332. pytunia-0.1/tests/expected/ErrStackUse0/stderr.txt +4 -0
  333. pytunia-0.1/tests/expected/ErrStackUse0/stdout.txt +0 -0
  334. pytunia-0.1/tests/expected/ErrTableHigh/status.txt +1 -0
  335. pytunia-0.1/tests/expected/ErrTableHigh/stderr.txt +4 -0
  336. pytunia-0.1/tests/expected/ErrTableHigh/stdout.txt +0 -0
  337. pytunia-0.1/tests/expected/ErrTabs/status.txt +1 -0
  338. pytunia-0.1/tests/expected/ErrTabs/stderr.txt +4 -0
  339. pytunia-0.1/tests/expected/ErrTabs/stdout.txt +0 -0
  340. pytunia-0.1/tests/expected/ErrUndefinedLabel/status.txt +1 -0
  341. pytunia-0.1/tests/expected/ErrUndefinedLabel/stderr.txt +2 -0
  342. pytunia-0.1/tests/expected/ErrUndefinedLabel/stdout.txt +0 -0
  343. pytunia-0.1/tests/expected/ErrUnknownDirective/status.txt +1 -0
  344. pytunia-0.1/tests/expected/ErrUnknownDirective/stderr.txt +4 -0
  345. pytunia-0.1/tests/expected/ErrUnknownDirective/stdout.txt +0 -0
  346. pytunia-0.1/tests/expected/ErrUntermName/status.txt +1 -0
  347. pytunia-0.1/tests/expected/ErrUntermName/stderr.txt +4 -0
  348. pytunia-0.1/tests/expected/ErrUntermName/stdout.txt +0 -0
  349. pytunia-0.1/tests/expected/ErrUntermString/status.txt +1 -0
  350. pytunia-0.1/tests/expected/ErrUntermString/stderr.txt +2 -0
  351. pytunia-0.1/tests/expected/ErrUntermString/stdout.txt +0 -0
  352. pytunia-0.1/tests/expected/ErrUntermStringEOF/status.txt +1 -0
  353. pytunia-0.1/tests/expected/ErrUntermStringEOF/stderr.txt +2 -0
  354. pytunia-0.1/tests/expected/ErrUntermStringEOF/stdout.txt +0 -0
  355. pytunia-0.1/tests/expected/ErrVar/status.txt +1 -0
  356. pytunia-0.1/tests/expected/ErrVar/stderr.txt +8 -0
  357. pytunia-0.1/tests/expected/ErrVar/stdout.txt +0 -0
  358. pytunia-0.1/tests/expected/FarJumpW/classes/FarJumpW.class +0 -0
  359. pytunia-0.1/tests/expected/FarJumpW/status.txt +1 -0
  360. pytunia-0.1/tests/expected/FarJumpW/stderr.txt +0 -0
  361. pytunia-0.1/tests/expected/FarJumpW/stdout.txt +1 -0
  362. pytunia-0.1/tests/expected/Fields/classes/Fields.class +0 -0
  363. pytunia-0.1/tests/expected/Fields/status.txt +1 -0
  364. pytunia-0.1/tests/expected/Fields/stderr.txt +0 -0
  365. pytunia-0.1/tests/expected/Fields/stdout.txt +1 -0
  366. pytunia-0.1/tests/expected/Header/classes/Outer$Inner.class +0 -0
  367. pytunia-0.1/tests/expected/Header/status.txt +1 -0
  368. pytunia-0.1/tests/expected/Header/stderr.txt +0 -0
  369. pytunia-0.1/tests/expected/Header/stdout.txt +1 -0
  370. pytunia-0.1/tests/expected/Iface/classes/pkg/sub/Iface.class +0 -0
  371. pytunia-0.1/tests/expected/Iface/status.txt +1 -0
  372. pytunia-0.1/tests/expected/Iface/stderr.txt +0 -0
  373. pytunia-0.1/tests/expected/Iface/stdout.txt +1 -0
  374. pytunia-0.1/tests/expected/Instructions/classes/Instructions.class +0 -0
  375. pytunia-0.1/tests/expected/Instructions/status.txt +1 -0
  376. pytunia-0.1/tests/expected/Instructions/stderr.txt +0 -0
  377. pytunia-0.1/tests/expected/Instructions/stdout.txt +1 -0
  378. pytunia-0.1/tests/expected/Latin1/classes/Latin1.class +0 -0
  379. pytunia-0.1/tests/expected/Latin1/status.txt +1 -0
  380. pytunia-0.1/tests/expected/Latin1/stderr.txt +0 -0
  381. pytunia-0.1/tests/expected/Latin1/stdout.txt +1 -0
  382. pytunia-0.1/tests/expected/ManyConstants/classes/ManyConstants.class +0 -0
  383. pytunia-0.1/tests/expected/ManyConstants/status.txt +1 -0
  384. pytunia-0.1/tests/expected/ManyConstants/stderr.txt +0 -0
  385. pytunia-0.1/tests/expected/ManyConstants/stdout.txt +1 -0
  386. pytunia-0.1/tests/expected/Names/classes/class.class +0 -0
  387. pytunia-0.1/tests/expected/Names/status.txt +1 -0
  388. pytunia-0.1/tests/expected/Names/stderr.txt +0 -0
  389. pytunia-0.1/tests/expected/Names/stdout.txt +1 -0
  390. pytunia-0.1/tests/expected/NumLabels/classes/NumLabels.class +0 -0
  391. pytunia-0.1/tests/expected/NumLabels/status.txt +1 -0
  392. pytunia-0.1/tests/expected/NumLabels/stderr.txt +0 -0
  393. pytunia-0.1/tests/expected/NumLabels/stdout.txt +1 -0
  394. pytunia-0.1/tests/expected/NumLabelsG/classes/NumLabelsG.class +0 -0
  395. pytunia-0.1/tests/expected/NumLabelsG/status.txt +1 -0
  396. pytunia-0.1/tests/expected/NumLabelsG/stderr.txt +0 -0
  397. pytunia-0.1/tests/expected/NumLabelsG/stdout.txt +1 -0
  398. pytunia-0.1/tests/expected/StackMapOld/classes/StackMapOld.class +0 -0
  399. pytunia-0.1/tests/expected/StackMapOld/status.txt +1 -0
  400. pytunia-0.1/tests/expected/StackMapOld/stderr.txt +0 -0
  401. pytunia-0.1/tests/expected/StackMapOld/stdout.txt +1 -0
  402. pytunia-0.1/tests/expected/StackMapTable/classes/StackMapTable.class +0 -0
  403. pytunia-0.1/tests/expected/StackMapTable/status.txt +1 -0
  404. pytunia-0.1/tests/expected/StackMapTable/stderr.txt +0 -0
  405. pytunia-0.1/tests/expected/StackMapTable/stdout.txt +1 -0
  406. pytunia-0.1/tests/expected/Switches/classes/Switches.class +0 -0
  407. pytunia-0.1/tests/expected/Switches/status.txt +1 -0
  408. pytunia-0.1/tests/expected/Switches/stderr.txt +0 -0
  409. pytunia-0.1/tests/expected/Switches/stdout.txt +1 -0
  410. pytunia-0.1/tests/expected/Unicode/classes/Unicode.class +0 -0
  411. pytunia-0.1/tests/expected/Unicode/status.txt +1 -0
  412. pytunia-0.1/tests/expected/Unicode/stderr.txt +0 -0
  413. pytunia-0.1/tests/expected/Unicode/stdout.txt +1 -0
  414. pytunia-0.1/tests/expected/numbers.txt +10067 -0
  415. pytunia-0.1/tests/make_expected.py +205 -0
  416. pytunia-0.1/tests/test_api.py +225 -0
  417. pytunia-0.1/tests/test_cli.py +158 -0
@@ -0,0 +1,45 @@
1
+ pytunia is a Python port of Jasmin 2.4 and of the JAS library it uses.
2
+ It is distributed under the same terms as the original Jasmin:
3
+
4
+ /*
5
+ * Copyright (c) 1996-2004, Jon Meyer
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
9
+ * that the following conditions are met:
10
+ *
11
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
12
+ * and the following disclaimer.
13
+ *
14
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
15
+ * and the following disclaimer in the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * Neither the name of the Jon Meyer nor the names of its contributors may be used to
19
+ * endorse or promote products derived from this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ *
30
+ * Jasmin was written by Jon Meyer, www.cybergrain.com
31
+ * The Jasmin website is jasmin.sourceforge.net.
32
+ */
33
+
34
+ Credits
35
+ -------
36
+
37
+ * Jasmin: Jonathan Meyer; extensions for Jasmin 2.x by Daniel Reynaud and
38
+ Iouri Kharon.
39
+ * JAS (the class file library, package pytunia.jas): K. B. Sriram. Its
40
+ README asks that users of derived code add the author to the list of
41
+ credits.
42
+ * The parse tables in pytunia/parser_tables.py were generated by
43
+ Java CUP 0.9 (Scott E. Hudson) from Jasmin's grammar, and the LR parser
44
+ driver in pytunia/parser.py is a port of the CUP runtime. Java CUP is
45
+ distributed under its own permissive license.
@@ -0,0 +1,3 @@
1
+ # include the complete test suite in the source distribution
2
+ graft tests
3
+ global-exclude __pycache__ *.py[cod]
pytunia-0.1/PKG-INFO ADDED
@@ -0,0 +1,276 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytunia
3
+ Version: 0.1
4
+ Summary: Jasmin, the assembler for the Java Virtual Machine, in Python
5
+ Author-email: Karl Stroetmann <karl.stroetmann@dhbw-mannheim.de>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/karlstroetmann/pytunia
8
+ Project-URL: Source, https://github.com/karlstroetmann/pytunia
9
+ Project-URL: Issues, https://github.com/karlstroetmann/pytunia/issues
10
+ Project-URL: Original Jasmin, https://jasmin.sourceforge.net/
11
+ Keywords: jasmin,assembler,jvm,java,bytecode,class file
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Java
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: 3.15
25
+ Classifier: Topic :: Software Development :: Assemblers
26
+ Classifier: Topic :: Software Development :: Compilers
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE.txt
30
+ Dynamic: license-file
31
+
32
+ # pytunia
33
+
34
+ **Jasmin, the assembler for the Java Virtual Machine, in Python.**
35
+
36
+ pytunia is a Python port of [Jasmin 2.4](https://jasmin.sourceforge.net/).
37
+ It translates assembly code for the Java Virtual Machine (`.j` files) into
38
+ Java class files, and it produces **byte-for-byte the same class files** as
39
+ the original `jasmin.jar`. Its error messages are identical, too.
40
+
41
+ pytunia is a library written in pure Python, with no dependencies. It needs
42
+ Python 3.9 or newer.
43
+
44
+ ## Installation
45
+
46
+ ```
47
+ pip install pytunia
48
+ ```
49
+
50
+ The latest development version can be installed from GitHub:
51
+
52
+ ```
53
+ pip install git+https://github.com/karlstroetmann/pytunia
54
+ ```
55
+
56
+ ## Example
57
+
58
+ `HelloWorld.j`:
59
+
60
+ ```
61
+ .class public HelloWorld
62
+ .super java/lang/Object
63
+
64
+ .method public static main([Ljava/lang/String;)V
65
+ .limit stack 2
66
+ getstatic java/lang/System/out Ljava/io/PrintStream;
67
+ ldc "Hello, World!"
68
+ invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
69
+ return
70
+ .end method
71
+ ```
72
+
73
+ ```python
74
+ import pytunia
75
+
76
+ pytunia.assemble("HelloWorld.j") # writes HelloWorld.class
77
+ ```
78
+
79
+ ```
80
+ $ java HelloWorld
81
+ Hello, World!
82
+ ```
83
+
84
+ ## Usage
85
+
86
+ ```python
87
+ import pytunia
88
+
89
+ # assemble a file and write the class file; returns its path
90
+ path = pytunia.assemble("Count.j") # examples/Count.class
91
+ path = pytunia.assemble("Count.j", output_dir="build") # build/examples/Count.class
92
+
93
+ # assemble source text in memory; nothing is written to disk
94
+ class_name, data = pytunia.assemble_string(source) # ("examples/Count", b"\xca\xfe...")
95
+ ```
96
+
97
+ (Here `Count.j` defines the class `examples.Count`.)
98
+
99
+ `assemble(source_file, output_dir=None, *, line_numbers=False, encoding="utf-8")`
100
+
101
+ * Places the class file below `output_dir` (default: the current directory)
102
+ in subdirectories for its package, as Jasmin does. `output_dir` can
103
+ therefore be used directly as a class path:
104
+ `java -cp build examples.Count`. Missing directories are created.
105
+ * `line_numbers=True` generates a line number table that refers to the lines
106
+ of the assembly source (option `-g` of Jasmin), so that Java stack traces
107
+ show the line numbers of the `.j` file.
108
+ * Returns the path of the class file as a `pathlib.Path`.
109
+
110
+ `assemble_string(source, name=None, *, line_numbers=False)`
111
+
112
+ * Returns the class name (in the internal form of the JVM, e.g.
113
+ `"examples/Count"`) and the class file as `bytes`.
114
+ * `name` is the file name used in error messages and for the class file's
115
+ `SourceFile` attribute. Without it, error messages show `<string>` and
116
+ the attribute is `<class name>.j`.
117
+
118
+ ### Errors
119
+
120
+ If the source contains errors, both functions raise `pytunia.AssemblyError`.
121
+ Its attribute `errors` is a list of `pytunia.Diagnostic` objects, each with
122
+ `filename`, `line`, `message`, `source_line` and `column`. `str(error)` is
123
+ exactly the error output of `jasmin.jar`:
124
+
125
+ ```python
126
+ try:
127
+ pytunia.assemble("Bad.j")
128
+ except pytunia.AssemblyError as e:
129
+ print(e)
130
+ ```
131
+
132
+ ```
133
+ Bad.j:4: JAS Error: bipush value exceed size of byte.
134
+ bipush 300
135
+ ^
136
+ Bad.j: Found 1 errors
137
+ ```
138
+
139
+ A file that cannot be read or written raises the usual `OSError`, for
140
+ example `FileNotFoundError`. The functions print nothing, and they can be
141
+ called from several threads at once.
142
+
143
+ ### Command line
144
+
145
+ For debugging, the command line of the Java version is available. It is not
146
+ installed as a command:
147
+
148
+ ```
149
+ python3 -m pytunia [-d <outpath>] [-g] [-e <encoding>] <file> [<file> ...]
150
+ ```
151
+
152
+ ### Low-level interface
153
+
154
+ `pytunia.ClassFile` has the methods of the Java class `jasmin.ClassFile`
155
+ (`read_jasmin`, `error_count`, `get_class_name`, `write`). Errors are
156
+ collected in its list `diagnostics`.
157
+
158
+ ## Compatibility with Jasmin
159
+
160
+ ### Why the output is identical
161
+
162
+ These details of the Java version had to be reproduced exactly:
163
+
164
+ * **Parsing.** Jasmin's parser is an LALR(1) parser generated by Java CUP.
165
+ pytunia uses the very same parse tables, extracted from the generated
166
+ `parser.java`, and a port of the CUP runtime, including its error
167
+ recovery. It therefore accepts the same language and reports syntax errors
168
+ at the same places.
169
+ * **Constant pool order.** Jasmin stores constant pool entries in a
170
+ `java.util.Hashtable` keyed by strings and writes them in the table's
171
+ enumeration order. pytunia reproduces this order (`String.hashCode`, bucket
172
+ layout, rehashing).
173
+ * **Number formatting.** Some of these keys contain numbers formatted with
174
+ `Float.toString` and `Double.toString`. These are not always the shortest
175
+ representation, so the JDK 8 algorithm (`sun.misc.FloatingDecimal`) is
176
+ ported as well.
177
+ * **Java strings and number types.** Strings are handled as UTF-16 code
178
+ units, and constants are written in modified UTF-8. Numbers keep their
179
+ Java type (Integer, Long, Float, Double), since Jasmin's behaviour depends
180
+ on it. Number parsing follows Java's rules.
181
+
182
+ Quirks of Jasmin 2.4 are kept on purpose, because changing them would
183
+ change the output. For example:
184
+
185
+ * `iinc` gets a `wide` prefix unless the increment is exactly 127 (a typo in
186
+ Jasmin's `jas.IincOperand`).
187
+ * Variable substitution with `.set name value` / `$name` does not work: the
188
+ substituted token is taken as `.method`.
189
+ * `ldc2_w 0.1` stores the *float* value 0.1f as a double. Write `0.1d` to
190
+ get the exact double.
191
+ * After a syntax error, the error recovery drops one token.
192
+
193
+ ### Known differences
194
+
195
+ * When `.stack` frames share an offset, Java prints a stack trace
196
+ (`UNEXPECTED JAS ERROR` …) before reporting the error. pytunia prints only
197
+ the first two lines of it. The result (error, no class file) is the same.
198
+ * The default source encoding is always UTF-8. Java up to version 17 uses
199
+ the platform encoding instead.
200
+ * Java keeps some state of the assembler in static fields. pytunia keeps it
201
+ in the objects of a single assembly instead, so assemblies can run in
202
+ parallel.
203
+
204
+ ## Development
205
+
206
+ ### How the code is organized
207
+
208
+ The structure follows the Java sources of Jasmin. Class names are kept, and
209
+ method names are converted to snake_case.
210
+
211
+ | Python module | Java original |
212
+ |---|---|
213
+ | `pytunia/api.py`, `pytunia/diagnostics.py` | the library interface (`assemble`, `assemble_string`, `AssemblyError`); new in pytunia |
214
+ | `pytunia/main.py` | `jasmin.Main`: command line handling |
215
+ | `pytunia/classfile.py` | `jasmin.ClassFile`: called by the parser to build the class |
216
+ | `pytunia/scanner.py` | `jasmin.Scanner`, `ScannerUtils`, `ReservedWords` |
217
+ | `pytunia/parser.py` | `jasmin.parser` (the CUP-generated parser) and the CUP runtime `java_cup.runtime.lr_parser` |
218
+ | `pytunia/parser_tables.py`, `pytunia/sym.py` | parse tables and symbol numbers (generated, see below) |
219
+ | `pytunia/insninfo.py` | `jasmin.InsnInfo`: instruction table |
220
+ | `pytunia/jas/` | the `jas` package that writes class files (constant pool, instructions, Code attribute, annotations, StackMap frames, ...) |
221
+ | `pytunia/javacompat.py` | emulation of the Java library behaviour that the output depends on |
222
+
223
+ ### Tests
224
+
225
+ ```
226
+ python3 -m unittest discover -s tests
227
+ ```
228
+
229
+ `tests/cases/` contains about 90 Jasmin files. They cover every instruction
230
+ form, all directives (fields with constant values, annotations, stack maps,
231
+ inner classes, debug information, ...), character encodings, and many kinds
232
+ of errors. `tests/expected/` holds the results of `jasmin.jar` for each case:
233
+ class files, standard output, standard error and exit status.
234
+
235
+ * `tests/test_api.py` assembles every case with `assemble()` and
236
+ `assemble_string()`. The class files must be identical to those of the
237
+ Java version, and for sources with errors `str(AssemblyError)` must be
238
+ identical to its error output.
239
+ * `tests/test_cli.py` runs the command line (`python3 -m pytunia`) on every
240
+ case and compares the class files, standard output, standard error and
241
+ exit status. It also checks the number formatting against Java for about
242
+ 10,000 values.
243
+
244
+ Running the tests needs neither Java nor Jasmin.
245
+
246
+ ### Comparing with the Java version
247
+
248
+ The following tools need the original Jasmin 2.4 (`jasmin-2.4.zip` from the
249
+ [Jasmin project on SourceForge](https://sourceforge.net/projects/jasmin/)).
250
+ By default they look for it in a directory `jasmin-2.4` next to the
251
+ repository.
252
+
253
+ To regenerate the expected test results (needs `java` and `javac`):
254
+
255
+ ```
256
+ python3 tests/make_expected.py ../jasmin-2.4/jasmin.jar
257
+ ```
258
+
259
+ `tools/fuzz_compare.py` runs randomly mutated Jasmin files through both
260
+ versions and reports any file where they differ:
261
+
262
+ ```
263
+ python3 tools/fuzz_compare.py --jar ../jasmin-2.4/jasmin.jar -n 20 tests/cases/*.j
264
+ ```
265
+
266
+ If Jasmin's grammar changes, rebuild its parser with CUP first and then
267
+ regenerate the parse tables from the generated Java sources:
268
+
269
+ ```
270
+ python3 tools/extract_tables.py ../jasmin-2.4/src/jasmin
271
+ ```
272
+
273
+ ## License
274
+
275
+ Jasmin is distributed under a BSD-style license, and pytunia keeps it; see
276
+ [LICENSE.txt](https://github.com/karlstroetmann/pytunia/blob/main/LICENSE.txt), which also lists the credits.
pytunia-0.1/README.md ADDED
@@ -0,0 +1,245 @@
1
+ # pytunia
2
+
3
+ **Jasmin, the assembler for the Java Virtual Machine, in Python.**
4
+
5
+ pytunia is a Python port of [Jasmin 2.4](https://jasmin.sourceforge.net/).
6
+ It translates assembly code for the Java Virtual Machine (`.j` files) into
7
+ Java class files, and it produces **byte-for-byte the same class files** as
8
+ the original `jasmin.jar`. Its error messages are identical, too.
9
+
10
+ pytunia is a library written in pure Python, with no dependencies. It needs
11
+ Python 3.9 or newer.
12
+
13
+ ## Installation
14
+
15
+ ```
16
+ pip install pytunia
17
+ ```
18
+
19
+ The latest development version can be installed from GitHub:
20
+
21
+ ```
22
+ pip install git+https://github.com/karlstroetmann/pytunia
23
+ ```
24
+
25
+ ## Example
26
+
27
+ `HelloWorld.j`:
28
+
29
+ ```
30
+ .class public HelloWorld
31
+ .super java/lang/Object
32
+
33
+ .method public static main([Ljava/lang/String;)V
34
+ .limit stack 2
35
+ getstatic java/lang/System/out Ljava/io/PrintStream;
36
+ ldc "Hello, World!"
37
+ invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
38
+ return
39
+ .end method
40
+ ```
41
+
42
+ ```python
43
+ import pytunia
44
+
45
+ pytunia.assemble("HelloWorld.j") # writes HelloWorld.class
46
+ ```
47
+
48
+ ```
49
+ $ java HelloWorld
50
+ Hello, World!
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+ import pytunia
57
+
58
+ # assemble a file and write the class file; returns its path
59
+ path = pytunia.assemble("Count.j") # examples/Count.class
60
+ path = pytunia.assemble("Count.j", output_dir="build") # build/examples/Count.class
61
+
62
+ # assemble source text in memory; nothing is written to disk
63
+ class_name, data = pytunia.assemble_string(source) # ("examples/Count", b"\xca\xfe...")
64
+ ```
65
+
66
+ (Here `Count.j` defines the class `examples.Count`.)
67
+
68
+ `assemble(source_file, output_dir=None, *, line_numbers=False, encoding="utf-8")`
69
+
70
+ * Places the class file below `output_dir` (default: the current directory)
71
+ in subdirectories for its package, as Jasmin does. `output_dir` can
72
+ therefore be used directly as a class path:
73
+ `java -cp build examples.Count`. Missing directories are created.
74
+ * `line_numbers=True` generates a line number table that refers to the lines
75
+ of the assembly source (option `-g` of Jasmin), so that Java stack traces
76
+ show the line numbers of the `.j` file.
77
+ * Returns the path of the class file as a `pathlib.Path`.
78
+
79
+ `assemble_string(source, name=None, *, line_numbers=False)`
80
+
81
+ * Returns the class name (in the internal form of the JVM, e.g.
82
+ `"examples/Count"`) and the class file as `bytes`.
83
+ * `name` is the file name used in error messages and for the class file's
84
+ `SourceFile` attribute. Without it, error messages show `<string>` and
85
+ the attribute is `<class name>.j`.
86
+
87
+ ### Errors
88
+
89
+ If the source contains errors, both functions raise `pytunia.AssemblyError`.
90
+ Its attribute `errors` is a list of `pytunia.Diagnostic` objects, each with
91
+ `filename`, `line`, `message`, `source_line` and `column`. `str(error)` is
92
+ exactly the error output of `jasmin.jar`:
93
+
94
+ ```python
95
+ try:
96
+ pytunia.assemble("Bad.j")
97
+ except pytunia.AssemblyError as e:
98
+ print(e)
99
+ ```
100
+
101
+ ```
102
+ Bad.j:4: JAS Error: bipush value exceed size of byte.
103
+ bipush 300
104
+ ^
105
+ Bad.j: Found 1 errors
106
+ ```
107
+
108
+ A file that cannot be read or written raises the usual `OSError`, for
109
+ example `FileNotFoundError`. The functions print nothing, and they can be
110
+ called from several threads at once.
111
+
112
+ ### Command line
113
+
114
+ For debugging, the command line of the Java version is available. It is not
115
+ installed as a command:
116
+
117
+ ```
118
+ python3 -m pytunia [-d <outpath>] [-g] [-e <encoding>] <file> [<file> ...]
119
+ ```
120
+
121
+ ### Low-level interface
122
+
123
+ `pytunia.ClassFile` has the methods of the Java class `jasmin.ClassFile`
124
+ (`read_jasmin`, `error_count`, `get_class_name`, `write`). Errors are
125
+ collected in its list `diagnostics`.
126
+
127
+ ## Compatibility with Jasmin
128
+
129
+ ### Why the output is identical
130
+
131
+ These details of the Java version had to be reproduced exactly:
132
+
133
+ * **Parsing.** Jasmin's parser is an LALR(1) parser generated by Java CUP.
134
+ pytunia uses the very same parse tables, extracted from the generated
135
+ `parser.java`, and a port of the CUP runtime, including its error
136
+ recovery. It therefore accepts the same language and reports syntax errors
137
+ at the same places.
138
+ * **Constant pool order.** Jasmin stores constant pool entries in a
139
+ `java.util.Hashtable` keyed by strings and writes them in the table's
140
+ enumeration order. pytunia reproduces this order (`String.hashCode`, bucket
141
+ layout, rehashing).
142
+ * **Number formatting.** Some of these keys contain numbers formatted with
143
+ `Float.toString` and `Double.toString`. These are not always the shortest
144
+ representation, so the JDK 8 algorithm (`sun.misc.FloatingDecimal`) is
145
+ ported as well.
146
+ * **Java strings and number types.** Strings are handled as UTF-16 code
147
+ units, and constants are written in modified UTF-8. Numbers keep their
148
+ Java type (Integer, Long, Float, Double), since Jasmin's behaviour depends
149
+ on it. Number parsing follows Java's rules.
150
+
151
+ Quirks of Jasmin 2.4 are kept on purpose, because changing them would
152
+ change the output. For example:
153
+
154
+ * `iinc` gets a `wide` prefix unless the increment is exactly 127 (a typo in
155
+ Jasmin's `jas.IincOperand`).
156
+ * Variable substitution with `.set name value` / `$name` does not work: the
157
+ substituted token is taken as `.method`.
158
+ * `ldc2_w 0.1` stores the *float* value 0.1f as a double. Write `0.1d` to
159
+ get the exact double.
160
+ * After a syntax error, the error recovery drops one token.
161
+
162
+ ### Known differences
163
+
164
+ * When `.stack` frames share an offset, Java prints a stack trace
165
+ (`UNEXPECTED JAS ERROR` …) before reporting the error. pytunia prints only
166
+ the first two lines of it. The result (error, no class file) is the same.
167
+ * The default source encoding is always UTF-8. Java up to version 17 uses
168
+ the platform encoding instead.
169
+ * Java keeps some state of the assembler in static fields. pytunia keeps it
170
+ in the objects of a single assembly instead, so assemblies can run in
171
+ parallel.
172
+
173
+ ## Development
174
+
175
+ ### How the code is organized
176
+
177
+ The structure follows the Java sources of Jasmin. Class names are kept, and
178
+ method names are converted to snake_case.
179
+
180
+ | Python module | Java original |
181
+ |---|---|
182
+ | `pytunia/api.py`, `pytunia/diagnostics.py` | the library interface (`assemble`, `assemble_string`, `AssemblyError`); new in pytunia |
183
+ | `pytunia/main.py` | `jasmin.Main`: command line handling |
184
+ | `pytunia/classfile.py` | `jasmin.ClassFile`: called by the parser to build the class |
185
+ | `pytunia/scanner.py` | `jasmin.Scanner`, `ScannerUtils`, `ReservedWords` |
186
+ | `pytunia/parser.py` | `jasmin.parser` (the CUP-generated parser) and the CUP runtime `java_cup.runtime.lr_parser` |
187
+ | `pytunia/parser_tables.py`, `pytunia/sym.py` | parse tables and symbol numbers (generated, see below) |
188
+ | `pytunia/insninfo.py` | `jasmin.InsnInfo`: instruction table |
189
+ | `pytunia/jas/` | the `jas` package that writes class files (constant pool, instructions, Code attribute, annotations, StackMap frames, ...) |
190
+ | `pytunia/javacompat.py` | emulation of the Java library behaviour that the output depends on |
191
+
192
+ ### Tests
193
+
194
+ ```
195
+ python3 -m unittest discover -s tests
196
+ ```
197
+
198
+ `tests/cases/` contains about 90 Jasmin files. They cover every instruction
199
+ form, all directives (fields with constant values, annotations, stack maps,
200
+ inner classes, debug information, ...), character encodings, and many kinds
201
+ of errors. `tests/expected/` holds the results of `jasmin.jar` for each case:
202
+ class files, standard output, standard error and exit status.
203
+
204
+ * `tests/test_api.py` assembles every case with `assemble()` and
205
+ `assemble_string()`. The class files must be identical to those of the
206
+ Java version, and for sources with errors `str(AssemblyError)` must be
207
+ identical to its error output.
208
+ * `tests/test_cli.py` runs the command line (`python3 -m pytunia`) on every
209
+ case and compares the class files, standard output, standard error and
210
+ exit status. It also checks the number formatting against Java for about
211
+ 10,000 values.
212
+
213
+ Running the tests needs neither Java nor Jasmin.
214
+
215
+ ### Comparing with the Java version
216
+
217
+ The following tools need the original Jasmin 2.4 (`jasmin-2.4.zip` from the
218
+ [Jasmin project on SourceForge](https://sourceforge.net/projects/jasmin/)).
219
+ By default they look for it in a directory `jasmin-2.4` next to the
220
+ repository.
221
+
222
+ To regenerate the expected test results (needs `java` and `javac`):
223
+
224
+ ```
225
+ python3 tests/make_expected.py ../jasmin-2.4/jasmin.jar
226
+ ```
227
+
228
+ `tools/fuzz_compare.py` runs randomly mutated Jasmin files through both
229
+ versions and reports any file where they differ:
230
+
231
+ ```
232
+ python3 tools/fuzz_compare.py --jar ../jasmin-2.4/jasmin.jar -n 20 tests/cases/*.j
233
+ ```
234
+
235
+ If Jasmin's grammar changes, rebuild its parser with CUP first and then
236
+ regenerate the parse tables from the generated Java sources:
237
+
238
+ ```
239
+ python3 tools/extract_tables.py ../jasmin-2.4/src/jasmin
240
+ ```
241
+
242
+ ## License
243
+
244
+ Jasmin is distributed under a BSD-style license, and pytunia keeps it; see
245
+ [LICENSE.txt](https://github.com/karlstroetmann/pytunia/blob/main/LICENSE.txt), which also lists the credits.
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pytunia"
7
+ dynamic = ["version"]
8
+ description = "Jasmin, the assembler for the Java Virtual Machine, in Python"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "BSD-3-Clause"
12
+ license-files = ["LICENSE.txt"]
13
+ authors = [
14
+ {name = "Karl Stroetmann", email = "karl.stroetmann@dhbw-mannheim.de"},
15
+ ]
16
+ keywords = ["jasmin", "assembler", "jvm", "java", "bytecode", "class file"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: Education",
21
+ "Operating System :: OS Independent",
22
+ "Programming Language :: Java",
23
+ "Programming Language :: Python :: 3 :: Only",
24
+ "Programming Language :: Python :: 3.9",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ "Programming Language :: Python :: 3.15",
31
+ "Topic :: Software Development :: Assemblers",
32
+ "Topic :: Software Development :: Compilers",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/karlstroetmann/pytunia"
37
+ Source = "https://github.com/karlstroetmann/pytunia"
38
+ Issues = "https://github.com/karlstroetmann/pytunia/issues"
39
+ "Original Jasmin" = "https://jasmin.sourceforge.net/"
40
+
41
+ [tool.setuptools]
42
+ packages = ["pytunia", "pytunia.jas"]
43
+
44
+ [tool.setuptools.dynamic]
45
+ version = {attr = "pytunia.__version__"}
@@ -0,0 +1,34 @@
1
+ """
2
+ pytunia - Jasmin, the assembler for the Java Virtual Machine, in Python.
3
+
4
+ This package is a port of Jasmin 2.4 (Jonathan Meyer, Daniel Reynaud,
5
+ Iouri Kharon) from Java to Python. It reads Jasmin assembly code and
6
+ produces Java class files that are byte-for-byte identical to those
7
+ produced by the Java version.
8
+
9
+ import pytunia
10
+
11
+ # assemble a file and write the class file (returns its path)
12
+ path = pytunia.assemble("Hello.j", output_dir="classes")
13
+
14
+ # assemble source text in memory
15
+ class_name, data = pytunia.assemble_string(source)
16
+
17
+ Errors raise pytunia.AssemblyError; its attribute ``errors`` is a list of
18
+ Diagnostic objects, and str(error) is the error output of Jasmin.
19
+
20
+ For debugging, the original command line interface is available as
21
+ ``python3 -m pytunia [-d <outpath>] [-g] [-e <encoding>] <file> ...``.
22
+ """
23
+
24
+ from .api import assemble, assemble_string
25
+ from .classfile import ClassFile
26
+ from .diagnostics import AssemblyError, Diagnostic
27
+ from .main import VERSION as JASMIN_VERSION
28
+
29
+ # the version of pytunia (JASMIN_VERSION is the version of Jasmin that
30
+ # pytunia reproduces)
31
+ __version__ = "0.1"
32
+
33
+ __all__ = ["assemble", "assemble_string", "AssemblyError", "Diagnostic",
34
+ "ClassFile", "JASMIN_VERSION"]
@@ -0,0 +1,7 @@
1
+ """Allows running Jasmin with ``python3 -m pytunia``."""
2
+
3
+ import sys
4
+
5
+ from .main import main
6
+
7
+ sys.exit(main())