pocketpy_bindings_generated.dart 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086
  1. // ignore_for_file: always_specify_types
  2. // ignore_for_file: camel_case_types
  3. // ignore_for_file: non_constant_identifier_names
  4. // AUTO GENERATED FILE, DO NOT EDIT.
  5. //
  6. // Generated by `package:ffigen`.
  7. // ignore_for_file: type=lint
  8. import 'dart:ffi' as ffi;
  9. /// Bindings for `src/pocketpy.h`.
  10. ///
  11. /// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
  12. ///
  13. class PocketpyBindings {
  14. /// Holds the symbol lookup function.
  15. final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
  16. _lookup;
  17. /// The symbols are looked up in [dynamicLibrary].
  18. PocketpyBindings(ffi.DynamicLibrary dynamicLibrary)
  19. : _lookup = dynamicLibrary.lookup;
  20. /// The symbols are looked up with [lookup].
  21. PocketpyBindings.fromLookup(
  22. ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
  23. lookup)
  24. : _lookup = lookup;
  25. /// Initialize pocketpy and the default VM.
  26. void py_initialize() {
  27. return _py_initialize();
  28. }
  29. late final _py_initializePtr =
  30. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_initialize');
  31. late final _py_initialize = _py_initializePtr.asFunction<void Function()>();
  32. /// Finalize pocketpy and free all VMs.
  33. void py_finalize() {
  34. return _py_finalize();
  35. }
  36. late final _py_finalizePtr =
  37. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_finalize');
  38. late final _py_finalize = _py_finalizePtr.asFunction<void Function()>();
  39. /// Get the current VM index.
  40. int py_currentvm() {
  41. return _py_currentvm();
  42. }
  43. late final _py_currentvmPtr =
  44. _lookup<ffi.NativeFunction<ffi.Int Function()>>('py_currentvm');
  45. late final _py_currentvm = _py_currentvmPtr.asFunction<int Function()>();
  46. /// Switch to a VM.
  47. /// @param index index of the VM ranging from 0 to 16 (exclusive). `0` is the default VM.
  48. void py_switchvm(
  49. int index,
  50. ) {
  51. return _py_switchvm(
  52. index,
  53. );
  54. }
  55. late final _py_switchvmPtr =
  56. _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>('py_switchvm');
  57. late final _py_switchvm = _py_switchvmPtr.asFunction<void Function(int)>();
  58. /// Reset the current VM.
  59. void py_resetvm() {
  60. return _py_resetvm();
  61. }
  62. late final _py_resetvmPtr =
  63. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_resetvm');
  64. late final _py_resetvm = _py_resetvmPtr.asFunction<void Function()>();
  65. /// Get the current VM context. This is used for user-defined data.
  66. ffi.Pointer<ffi.Void> py_getvmctx() {
  67. return _py_getvmctx();
  68. }
  69. late final _py_getvmctxPtr =
  70. _lookup<ffi.NativeFunction<ffi.Pointer<ffi.Void> Function()>>(
  71. 'py_getvmctx');
  72. late final _py_getvmctx =
  73. _py_getvmctxPtr.asFunction<ffi.Pointer<ffi.Void> Function()>();
  74. /// Set the current VM context. This is used for user-defined data.
  75. void py_setvmctx(
  76. ffi.Pointer<ffi.Void> ctx,
  77. ) {
  78. return _py_setvmctx(
  79. ctx,
  80. );
  81. }
  82. late final _py_setvmctxPtr =
  83. _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>(
  84. 'py_setvmctx');
  85. late final _py_setvmctx =
  86. _py_setvmctxPtr.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
  87. /// Set `sys.argv`. Used for storing command-line arguments.
  88. void py_sys_setargv(
  89. int argc,
  90. ffi.Pointer<ffi.Pointer<ffi.Char>> argv,
  91. ) {
  92. return _py_sys_setargv(
  93. argc,
  94. argv,
  95. );
  96. }
  97. late final _py_sys_setargvPtr = _lookup<
  98. ffi.NativeFunction<
  99. ffi.Void Function(
  100. ffi.Int, ffi.Pointer<ffi.Pointer<ffi.Char>>)>>('py_sys_setargv');
  101. late final _py_sys_setargv = _py_sys_setargvPtr
  102. .asFunction<void Function(int, ffi.Pointer<ffi.Pointer<ffi.Char>>)>();
  103. /// Setup the callbacks for the current VM.
  104. ffi.Pointer<py_Callbacks> py_callbacks() {
  105. return _py_callbacks();
  106. }
  107. late final _py_callbacksPtr =
  108. _lookup<ffi.NativeFunction<ffi.Pointer<py_Callbacks> Function()>>(
  109. 'py_callbacks');
  110. late final _py_callbacks =
  111. _py_callbacksPtr.asFunction<ffi.Pointer<py_Callbacks> Function()>();
  112. /// Run a source string.
  113. /// @param source source string.
  114. /// @param filename filename (for error messages).
  115. /// @param mode compile mode. Use `EXEC_MODE` for statements `EVAL_MODE` for expressions.
  116. /// @param module target module. Use NULL for the main module.
  117. /// @return `true` if the execution is successful or `false` if an exception is raised.
  118. bool py_exec(
  119. ffi.Pointer<ffi.Char> source,
  120. ffi.Pointer<ffi.Char> filename,
  121. int mode,
  122. py_Ref module,
  123. ) {
  124. return _py_exec(
  125. source,
  126. filename,
  127. mode,
  128. module,
  129. );
  130. }
  131. late final _py_execPtr = _lookup<
  132. ffi.NativeFunction<
  133. ffi.Bool Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>,
  134. ffi.Int32, py_Ref)>>('py_exec');
  135. late final _py_exec = _py_execPtr.asFunction<
  136. bool Function(
  137. ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>, int, py_Ref)>();
  138. /// Evaluate a source string. Equivalent to `py_exec(source, "<string>", EVAL_MODE, module)`.
  139. bool py_eval(
  140. ffi.Pointer<ffi.Char> source,
  141. py_Ref module,
  142. ) {
  143. return _py_eval(
  144. source,
  145. module,
  146. );
  147. }
  148. late final _py_evalPtr = _lookup<
  149. ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Char>, py_Ref)>>(
  150. 'py_eval');
  151. late final _py_eval =
  152. _py_evalPtr.asFunction<bool Function(ffi.Pointer<ffi.Char>, py_Ref)>();
  153. /// Run a source string with smart interpretation.
  154. /// Example:
  155. /// `py_newstr(py_r0(), "abc");`
  156. /// `py_newint(py_r1(), 123);`
  157. /// `py_smartexec("print(_0, _1)", NULL, py_r0(), py_r1());`
  158. /// `// "abc 123" will be printed`.
  159. bool py_smartexec(
  160. ffi.Pointer<ffi.Char> source,
  161. py_Ref module,
  162. ) {
  163. return _py_smartexec(
  164. source,
  165. module,
  166. );
  167. }
  168. late final _py_smartexecPtr = _lookup<
  169. ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Char>, py_Ref)>>(
  170. 'py_smartexec');
  171. late final _py_smartexec = _py_smartexecPtr
  172. .asFunction<bool Function(ffi.Pointer<ffi.Char>, py_Ref)>();
  173. /// Evaluate a source string with smart interpretation.
  174. /// Example:
  175. /// `py_newstr(py_r0(), "abc");`
  176. /// `py_smarteval("len(_)", NULL, py_r0());`
  177. /// `int res = py_toint(py_retval());`
  178. /// `// res will be 3`.
  179. bool py_smarteval(
  180. ffi.Pointer<ffi.Char> source,
  181. py_Ref module,
  182. ) {
  183. return _py_smarteval(
  184. source,
  185. module,
  186. );
  187. }
  188. late final _py_smartevalPtr = _lookup<
  189. ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Char>, py_Ref)>>(
  190. 'py_smarteval');
  191. late final _py_smarteval = _py_smartevalPtr
  192. .asFunction<bool Function(ffi.Pointer<ffi.Char>, py_Ref)>();
  193. /// Compile a source string into a code object.
  194. /// Use python's `exec()` or `eval()` to execute it.
  195. bool py_compile(
  196. ffi.Pointer<ffi.Char> source,
  197. ffi.Pointer<ffi.Char> filename,
  198. int mode,
  199. bool is_dynamic,
  200. ) {
  201. return _py_compile(
  202. source,
  203. filename,
  204. mode,
  205. is_dynamic,
  206. );
  207. }
  208. late final _py_compilePtr = _lookup<
  209. ffi.NativeFunction<
  210. ffi.Bool Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>,
  211. ffi.Int32, ffi.Bool)>>('py_compile');
  212. late final _py_compile = _py_compilePtr.asFunction<
  213. bool Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>, int, bool)>();
  214. /// Python equivalent to `globals()`.
  215. void py_newglobals(
  216. py_OutRef arg0,
  217. ) {
  218. return _py_newglobals(
  219. arg0,
  220. );
  221. }
  222. late final _py_newglobalsPtr =
  223. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>(
  224. 'py_newglobals');
  225. late final _py_newglobals =
  226. _py_newglobalsPtr.asFunction<void Function(py_OutRef)>();
  227. /// Python equivalent to `locals()`.
  228. /// @return a temporary object, which expires on the associated function return.
  229. void py_newlocals(
  230. py_OutRef arg0,
  231. ) {
  232. return _py_newlocals(
  233. arg0,
  234. );
  235. }
  236. late final _py_newlocalsPtr =
  237. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>('py_newlocals');
  238. late final _py_newlocals =
  239. _py_newlocalsPtr.asFunction<void Function(py_OutRef)>();
  240. /// A shorthand for `True`.
  241. py_GlobalRef py_True() {
  242. return _py_True();
  243. }
  244. late final _py_TruePtr =
  245. _lookup<ffi.NativeFunction<py_GlobalRef Function()>>('py_True');
  246. late final _py_True = _py_TruePtr.asFunction<py_GlobalRef Function()>();
  247. /// A shorthand for `False`.
  248. py_GlobalRef py_False() {
  249. return _py_False();
  250. }
  251. late final _py_FalsePtr =
  252. _lookup<ffi.NativeFunction<py_GlobalRef Function()>>('py_False');
  253. late final _py_False = _py_FalsePtr.asFunction<py_GlobalRef Function()>();
  254. /// A shorthand for `None`.
  255. py_GlobalRef py_None() {
  256. return _py_None();
  257. }
  258. late final _py_NonePtr =
  259. _lookup<ffi.NativeFunction<py_GlobalRef Function()>>('py_None');
  260. late final _py_None = _py_NonePtr.asFunction<py_GlobalRef Function()>();
  261. /// A shorthand for `nil`. `nil` is not a valid python object.
  262. py_GlobalRef py_NIL() {
  263. return _py_NIL();
  264. }
  265. late final _py_NILPtr =
  266. _lookup<ffi.NativeFunction<py_GlobalRef Function()>>('py_NIL');
  267. late final _py_NIL = _py_NILPtr.asFunction<py_GlobalRef Function()>();
  268. /// Create an `int` object.
  269. void py_newint(
  270. py_OutRef arg0,
  271. int arg1,
  272. ) {
  273. return _py_newint(
  274. arg0,
  275. arg1,
  276. );
  277. }
  278. late final _py_newintPtr =
  279. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, py_i64)>>(
  280. 'py_newint');
  281. late final _py_newint =
  282. _py_newintPtr.asFunction<void Function(py_OutRef, int)>();
  283. /// Create a `float` object.
  284. void py_newfloat(
  285. py_OutRef arg0,
  286. double arg1,
  287. ) {
  288. return _py_newfloat(
  289. arg0,
  290. arg1,
  291. );
  292. }
  293. late final _py_newfloatPtr =
  294. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, py_f64)>>(
  295. 'py_newfloat');
  296. late final _py_newfloat =
  297. _py_newfloatPtr.asFunction<void Function(py_OutRef, double)>();
  298. /// Create a `bool` object.
  299. void py_newbool(
  300. py_OutRef arg0,
  301. bool arg1,
  302. ) {
  303. return _py_newbool(
  304. arg0,
  305. arg1,
  306. );
  307. }
  308. late final _py_newboolPtr =
  309. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, ffi.Bool)>>(
  310. 'py_newbool');
  311. late final _py_newbool =
  312. _py_newboolPtr.asFunction<void Function(py_OutRef, bool)>();
  313. /// Create a `str` object from a null-terminated string (utf-8).
  314. void py_newstr(
  315. py_OutRef arg0,
  316. ffi.Pointer<ffi.Char> arg1,
  317. ) {
  318. return _py_newstr(
  319. arg0,
  320. arg1,
  321. );
  322. }
  323. late final _py_newstrPtr = _lookup<
  324. ffi.NativeFunction<
  325. ffi.Void Function(py_OutRef, ffi.Pointer<ffi.Char>)>>('py_newstr');
  326. late final _py_newstr = _py_newstrPtr
  327. .asFunction<void Function(py_OutRef, ffi.Pointer<ffi.Char>)>();
  328. /// Create a `str` object with `n` UNINITIALIZED bytes plus `'\0'`.
  329. ffi.Pointer<ffi.Char> py_newstrn(
  330. py_OutRef arg0,
  331. int arg1,
  332. ) {
  333. return _py_newstrn(
  334. arg0,
  335. arg1,
  336. );
  337. }
  338. late final _py_newstrnPtr = _lookup<
  339. ffi.NativeFunction<
  340. ffi.Pointer<ffi.Char> Function(py_OutRef, ffi.Int)>>('py_newstrn');
  341. late final _py_newstrn = _py_newstrnPtr
  342. .asFunction<ffi.Pointer<ffi.Char> Function(py_OutRef, int)>();
  343. /// Create a `str` object from a `c11_sv`.
  344. void py_newstrv(
  345. py_OutRef arg0,
  346. c11_sv arg1,
  347. ) {
  348. return _py_newstrv(
  349. arg0,
  350. arg1,
  351. );
  352. }
  353. late final _py_newstrvPtr =
  354. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, c11_sv)>>(
  355. 'py_newstrv');
  356. late final _py_newstrv =
  357. _py_newstrvPtr.asFunction<void Function(py_OutRef, c11_sv)>();
  358. /// Create a `bytes` object with `n` UNINITIALIZED bytes.
  359. ffi.Pointer<ffi.UnsignedChar> py_newbytes(
  360. py_OutRef arg0,
  361. int n,
  362. ) {
  363. return _py_newbytes(
  364. arg0,
  365. n,
  366. );
  367. }
  368. late final _py_newbytesPtr = _lookup<
  369. ffi.NativeFunction<
  370. ffi.Pointer<ffi.UnsignedChar> Function(
  371. py_OutRef, ffi.Int)>>('py_newbytes');
  372. late final _py_newbytes = _py_newbytesPtr
  373. .asFunction<ffi.Pointer<ffi.UnsignedChar> Function(py_OutRef, int)>();
  374. /// Create a `None` object.
  375. void py_newnone(
  376. py_OutRef arg0,
  377. ) {
  378. return _py_newnone(
  379. arg0,
  380. );
  381. }
  382. late final _py_newnonePtr =
  383. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>('py_newnone');
  384. late final _py_newnone =
  385. _py_newnonePtr.asFunction<void Function(py_OutRef)>();
  386. /// Create a `NotImplemented` object.
  387. void py_newnotimplemented(
  388. py_OutRef arg0,
  389. ) {
  390. return _py_newnotimplemented(
  391. arg0,
  392. );
  393. }
  394. late final _py_newnotimplementedPtr =
  395. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>(
  396. 'py_newnotimplemented');
  397. late final _py_newnotimplemented =
  398. _py_newnotimplementedPtr.asFunction<void Function(py_OutRef)>();
  399. /// Create a `...` object.
  400. void py_newellipsis(
  401. py_OutRef arg0,
  402. ) {
  403. return _py_newellipsis(
  404. arg0,
  405. );
  406. }
  407. late final _py_newellipsisPtr =
  408. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>(
  409. 'py_newellipsis');
  410. late final _py_newellipsis =
  411. _py_newellipsisPtr.asFunction<void Function(py_OutRef)>();
  412. /// Create a `nil` object. `nil` is an invalid representation of an object.
  413. /// Don't use it unless you know what you are doing.
  414. void py_newnil(
  415. py_OutRef arg0,
  416. ) {
  417. return _py_newnil(
  418. arg0,
  419. );
  420. }
  421. late final _py_newnilPtr =
  422. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>('py_newnil');
  423. late final _py_newnil = _py_newnilPtr.asFunction<void Function(py_OutRef)>();
  424. /// Create a `tuple` with `n` UNINITIALIZED elements.
  425. /// You should initialize all elements before using it.
  426. void py_newtuple(
  427. py_OutRef arg0,
  428. int n,
  429. ) {
  430. return _py_newtuple(
  431. arg0,
  432. n,
  433. );
  434. }
  435. late final _py_newtuplePtr =
  436. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, ffi.Int)>>(
  437. 'py_newtuple');
  438. late final _py_newtuple =
  439. _py_newtuplePtr.asFunction<void Function(py_OutRef, int)>();
  440. /// Create an empty `list`.
  441. void py_newlist(
  442. py_OutRef arg0,
  443. ) {
  444. return _py_newlist(
  445. arg0,
  446. );
  447. }
  448. late final _py_newlistPtr =
  449. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>('py_newlist');
  450. late final _py_newlist =
  451. _py_newlistPtr.asFunction<void Function(py_OutRef)>();
  452. /// Create a `list` with `n` UNINITIALIZED elements.
  453. /// You should initialize all elements before using it.
  454. void py_newlistn(
  455. py_OutRef arg0,
  456. int n,
  457. ) {
  458. return _py_newlistn(
  459. arg0,
  460. n,
  461. );
  462. }
  463. late final _py_newlistnPtr =
  464. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, ffi.Int)>>(
  465. 'py_newlistn');
  466. late final _py_newlistn =
  467. _py_newlistnPtr.asFunction<void Function(py_OutRef, int)>();
  468. /// Create an empty `dict`.
  469. void py_newdict(
  470. py_OutRef arg0,
  471. ) {
  472. return _py_newdict(
  473. arg0,
  474. );
  475. }
  476. late final _py_newdictPtr =
  477. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>('py_newdict');
  478. late final _py_newdict =
  479. _py_newdictPtr.asFunction<void Function(py_OutRef)>();
  480. /// Create an UNINITIALIZED `slice` object.
  481. /// You should use `py_setslot()` to set `start`, `stop`, and `step`.
  482. void py_newslice(
  483. py_OutRef arg0,
  484. ) {
  485. return _py_newslice(
  486. arg0,
  487. );
  488. }
  489. late final _py_newslicePtr =
  490. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef)>>('py_newslice');
  491. late final _py_newslice =
  492. _py_newslicePtr.asFunction<void Function(py_OutRef)>();
  493. /// Create a `nativefunc` object.
  494. void py_newnativefunc(
  495. py_OutRef arg0,
  496. py_CFunction arg1,
  497. ) {
  498. return _py_newnativefunc(
  499. arg0,
  500. arg1,
  501. );
  502. }
  503. late final _py_newnativefuncPtr =
  504. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, py_CFunction)>>(
  505. 'py_newnativefunc');
  506. late final _py_newnativefunc =
  507. _py_newnativefuncPtr.asFunction<void Function(py_OutRef, py_CFunction)>();
  508. /// Create a `function` object.
  509. int py_newfunction(
  510. py_OutRef out,
  511. ffi.Pointer<ffi.Char> sig,
  512. py_CFunction f,
  513. ffi.Pointer<ffi.Char> docstring,
  514. int slots,
  515. ) {
  516. return _py_newfunction(
  517. out,
  518. sig,
  519. f,
  520. docstring,
  521. slots,
  522. );
  523. }
  524. late final _py_newfunctionPtr = _lookup<
  525. ffi.NativeFunction<
  526. py_Name Function(py_OutRef, ffi.Pointer<ffi.Char>, py_CFunction,
  527. ffi.Pointer<ffi.Char>, ffi.Int)>>('py_newfunction');
  528. late final _py_newfunction = _py_newfunctionPtr.asFunction<
  529. int Function(py_OutRef, ffi.Pointer<ffi.Char>, py_CFunction,
  530. ffi.Pointer<ffi.Char>, int)>();
  531. /// Create a `boundmethod` object.
  532. void py_newboundmethod(
  533. py_OutRef out,
  534. py_Ref self,
  535. py_Ref func,
  536. ) {
  537. return _py_newboundmethod(
  538. out,
  539. self,
  540. func,
  541. );
  542. }
  543. late final _py_newboundmethodPtr =
  544. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, py_Ref, py_Ref)>>(
  545. 'py_newboundmethod');
  546. late final _py_newboundmethod = _py_newboundmethodPtr
  547. .asFunction<void Function(py_OutRef, py_Ref, py_Ref)>();
  548. /// Convert a null-terminated string to a name.
  549. int py_name(
  550. ffi.Pointer<ffi.Char> arg0,
  551. ) {
  552. return _py_name(
  553. arg0,
  554. );
  555. }
  556. late final _py_namePtr =
  557. _lookup<ffi.NativeFunction<py_Name Function(ffi.Pointer<ffi.Char>)>>(
  558. 'py_name');
  559. late final _py_name =
  560. _py_namePtr.asFunction<int Function(ffi.Pointer<ffi.Char>)>();
  561. /// Convert a name to a null-terminated string.
  562. ffi.Pointer<ffi.Char> py_name2str(
  563. int arg0,
  564. ) {
  565. return _py_name2str(
  566. arg0,
  567. );
  568. }
  569. late final _py_name2strPtr =
  570. _lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function(py_Name)>>(
  571. 'py_name2str');
  572. late final _py_name2str =
  573. _py_name2strPtr.asFunction<ffi.Pointer<ffi.Char> Function(int)>();
  574. /// Convert a `c11_sv` to a name.
  575. int py_namev(
  576. c11_sv arg0,
  577. ) {
  578. return _py_namev(
  579. arg0,
  580. );
  581. }
  582. late final _py_namevPtr =
  583. _lookup<ffi.NativeFunction<py_Name Function(c11_sv)>>('py_namev');
  584. late final _py_namev = _py_namevPtr.asFunction<int Function(c11_sv)>();
  585. /// Convert a name to a `c11_sv`.
  586. c11_sv py_name2sv(
  587. int arg0,
  588. ) {
  589. return _py_name2sv(
  590. arg0,
  591. );
  592. }
  593. late final _py_name2svPtr =
  594. _lookup<ffi.NativeFunction<c11_sv Function(py_Name)>>('py_name2sv');
  595. late final _py_name2sv = _py_name2svPtr.asFunction<c11_sv Function(int)>();
  596. /// Create a new type.
  597. /// @param name name of the type.
  598. /// @param base base type.
  599. /// @param module module where the type is defined. Use `NULL` for built-in types.
  600. /// @param dtor destructor function. Use `NULL` if not needed.
  601. int py_newtype(
  602. ffi.Pointer<ffi.Char> name,
  603. int base,
  604. py_GlobalRef module,
  605. py_Dtor dtor,
  606. ) {
  607. return _py_newtype(
  608. name,
  609. base,
  610. module,
  611. dtor,
  612. );
  613. }
  614. late final _py_newtypePtr = _lookup<
  615. ffi.NativeFunction<
  616. py_Type Function(ffi.Pointer<ffi.Char>, py_Type, py_GlobalRef,
  617. py_Dtor)>>('py_newtype');
  618. late final _py_newtype = _py_newtypePtr.asFunction<
  619. int Function(ffi.Pointer<ffi.Char>, int, py_GlobalRef, py_Dtor)>();
  620. /// Create a new object.
  621. /// @param out output reference.
  622. /// @param type type of the object.
  623. /// @param slots number of slots. Use `-1` to create a `__dict__`.
  624. /// @param udsize size of your userdata.
  625. /// @return pointer to the userdata.
  626. ffi.Pointer<ffi.Void> py_newobject(
  627. py_OutRef out,
  628. int type,
  629. int slots,
  630. int udsize,
  631. ) {
  632. return _py_newobject(
  633. out,
  634. type,
  635. slots,
  636. udsize,
  637. );
  638. }
  639. late final _py_newobjectPtr = _lookup<
  640. ffi.NativeFunction<
  641. ffi.Pointer<ffi.Void> Function(
  642. py_OutRef, py_Type, ffi.Int, ffi.Int)>>('py_newobject');
  643. late final _py_newobject = _py_newobjectPtr
  644. .asFunction<ffi.Pointer<ffi.Void> Function(py_OutRef, int, int, int)>();
  645. /// Convert an `int` object in python to `int64_t`.
  646. int py_toint(
  647. py_Ref arg0,
  648. ) {
  649. return _py_toint(
  650. arg0,
  651. );
  652. }
  653. late final _py_tointPtr =
  654. _lookup<ffi.NativeFunction<py_i64 Function(py_Ref)>>('py_toint');
  655. late final _py_toint = _py_tointPtr.asFunction<int Function(py_Ref)>();
  656. /// Convert a `float` object in python to `double`.
  657. double py_tofloat(
  658. py_Ref arg0,
  659. ) {
  660. return _py_tofloat(
  661. arg0,
  662. );
  663. }
  664. late final _py_tofloatPtr =
  665. _lookup<ffi.NativeFunction<py_f64 Function(py_Ref)>>('py_tofloat');
  666. late final _py_tofloat = _py_tofloatPtr.asFunction<double Function(py_Ref)>();
  667. /// Cast a `int` or `float` object in python to `double`.
  668. /// If successful, return true and set the value to `out`.
  669. /// Otherwise, return false and raise `TypeError`.
  670. bool py_castfloat(
  671. py_Ref arg0,
  672. ffi.Pointer<py_f64> out,
  673. ) {
  674. return _py_castfloat(
  675. arg0,
  676. out,
  677. );
  678. }
  679. late final _py_castfloatPtr = _lookup<
  680. ffi.NativeFunction<ffi.Bool Function(py_Ref, ffi.Pointer<py_f64>)>>(
  681. 'py_castfloat');
  682. late final _py_castfloat =
  683. _py_castfloatPtr.asFunction<bool Function(py_Ref, ffi.Pointer<py_f64>)>();
  684. /// 32-bit version of `py_castfloat`.
  685. bool py_castfloat32(
  686. py_Ref arg0,
  687. ffi.Pointer<ffi.Float> out,
  688. ) {
  689. return _py_castfloat32(
  690. arg0,
  691. out,
  692. );
  693. }
  694. late final _py_castfloat32Ptr = _lookup<
  695. ffi.NativeFunction<
  696. ffi.Bool Function(py_Ref, ffi.Pointer<ffi.Float>)>>('py_castfloat32');
  697. late final _py_castfloat32 = _py_castfloat32Ptr
  698. .asFunction<bool Function(py_Ref, ffi.Pointer<ffi.Float>)>();
  699. /// Cast a `int` object in python to `int64_t`.
  700. bool py_castint(
  701. py_Ref arg0,
  702. ffi.Pointer<py_i64> out,
  703. ) {
  704. return _py_castint(
  705. arg0,
  706. out,
  707. );
  708. }
  709. late final _py_castintPtr = _lookup<
  710. ffi.NativeFunction<ffi.Bool Function(py_Ref, ffi.Pointer<py_i64>)>>(
  711. 'py_castint');
  712. late final _py_castint =
  713. _py_castintPtr.asFunction<bool Function(py_Ref, ffi.Pointer<py_i64>)>();
  714. /// Convert a `bool` object in python to `bool`.
  715. bool py_tobool(
  716. py_Ref arg0,
  717. ) {
  718. return _py_tobool(
  719. arg0,
  720. );
  721. }
  722. late final _py_toboolPtr =
  723. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_tobool');
  724. late final _py_tobool = _py_toboolPtr.asFunction<bool Function(py_Ref)>();
  725. /// Convert a `type` object in python to `py_Type`.
  726. int py_totype(
  727. py_Ref arg0,
  728. ) {
  729. return _py_totype(
  730. arg0,
  731. );
  732. }
  733. late final _py_totypePtr =
  734. _lookup<ffi.NativeFunction<py_Type Function(py_Ref)>>('py_totype');
  735. late final _py_totype = _py_totypePtr.asFunction<int Function(py_Ref)>();
  736. /// Convert a `str` object in python to null-terminated string.
  737. ffi.Pointer<ffi.Char> py_tostr(
  738. py_Ref arg0,
  739. ) {
  740. return _py_tostr(
  741. arg0,
  742. );
  743. }
  744. late final _py_tostrPtr =
  745. _lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function(py_Ref)>>(
  746. 'py_tostr');
  747. late final _py_tostr =
  748. _py_tostrPtr.asFunction<ffi.Pointer<ffi.Char> Function(py_Ref)>();
  749. /// Convert a `str` object in python to char array.
  750. ffi.Pointer<ffi.Char> py_tostrn(
  751. py_Ref arg0,
  752. ffi.Pointer<ffi.Int> size,
  753. ) {
  754. return _py_tostrn(
  755. arg0,
  756. size,
  757. );
  758. }
  759. late final _py_tostrnPtr = _lookup<
  760. ffi.NativeFunction<
  761. ffi.Pointer<ffi.Char> Function(
  762. py_Ref, ffi.Pointer<ffi.Int>)>>('py_tostrn');
  763. late final _py_tostrn = _py_tostrnPtr.asFunction<
  764. ffi.Pointer<ffi.Char> Function(py_Ref, ffi.Pointer<ffi.Int>)>();
  765. /// Convert a `str` object in python to `c11_sv`.
  766. c11_sv py_tosv(
  767. py_Ref arg0,
  768. ) {
  769. return _py_tosv(
  770. arg0,
  771. );
  772. }
  773. late final _py_tosvPtr =
  774. _lookup<ffi.NativeFunction<c11_sv Function(py_Ref)>>('py_tosv');
  775. late final _py_tosv = _py_tosvPtr.asFunction<c11_sv Function(py_Ref)>();
  776. /// Convert a `bytes` object in python to char array.
  777. ffi.Pointer<ffi.UnsignedChar> py_tobytes(
  778. py_Ref arg0,
  779. ffi.Pointer<ffi.Int> size,
  780. ) {
  781. return _py_tobytes(
  782. arg0,
  783. size,
  784. );
  785. }
  786. late final _py_tobytesPtr = _lookup<
  787. ffi.NativeFunction<
  788. ffi.Pointer<ffi.UnsignedChar> Function(
  789. py_Ref, ffi.Pointer<ffi.Int>)>>('py_tobytes');
  790. late final _py_tobytes = _py_tobytesPtr.asFunction<
  791. ffi.Pointer<ffi.UnsignedChar> Function(py_Ref, ffi.Pointer<ffi.Int>)>();
  792. /// Convert a user-defined object to its userdata.
  793. ffi.Pointer<ffi.Void> py_touserdata(
  794. py_Ref arg0,
  795. ) {
  796. return _py_touserdata(
  797. arg0,
  798. );
  799. }
  800. late final _py_touserdataPtr =
  801. _lookup<ffi.NativeFunction<ffi.Pointer<ffi.Void> Function(py_Ref)>>(
  802. 'py_touserdata');
  803. late final _py_touserdata =
  804. _py_touserdataPtr.asFunction<ffi.Pointer<ffi.Void> Function(py_Ref)>();
  805. /// Get the type of the object.
  806. int py_typeof(
  807. py_Ref self,
  808. ) {
  809. return _py_typeof(
  810. self,
  811. );
  812. }
  813. late final _py_typeofPtr =
  814. _lookup<ffi.NativeFunction<py_Type Function(py_Ref)>>('py_typeof');
  815. late final _py_typeof = _py_typeofPtr.asFunction<int Function(py_Ref)>();
  816. /// Get type by module and name. e.g. `py_gettype("time", py_name("struct_time"))`.
  817. /// Return `0` if not found.
  818. int py_gettype(
  819. ffi.Pointer<ffi.Char> module,
  820. int name,
  821. ) {
  822. return _py_gettype(
  823. module,
  824. name,
  825. );
  826. }
  827. late final _py_gettypePtr = _lookup<
  828. ffi.NativeFunction<py_Type Function(ffi.Pointer<ffi.Char>, py_Name)>>(
  829. 'py_gettype');
  830. late final _py_gettype =
  831. _py_gettypePtr.asFunction<int Function(ffi.Pointer<ffi.Char>, int)>();
  832. /// Check if the object is exactly the given type.
  833. bool py_istype(
  834. py_Ref arg0,
  835. int arg1,
  836. ) {
  837. return _py_istype(
  838. arg0,
  839. arg1,
  840. );
  841. }
  842. late final _py_istypePtr =
  843. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Type)>>(
  844. 'py_istype');
  845. late final _py_istype =
  846. _py_istypePtr.asFunction<bool Function(py_Ref, int)>();
  847. /// Check if the object is an instance of the given type.
  848. bool py_isinstance(
  849. py_Ref obj,
  850. int type,
  851. ) {
  852. return _py_isinstance(
  853. obj,
  854. type,
  855. );
  856. }
  857. late final _py_isinstancePtr =
  858. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Type)>>(
  859. 'py_isinstance');
  860. late final _py_isinstance =
  861. _py_isinstancePtr.asFunction<bool Function(py_Ref, int)>();
  862. /// Check if the derived type is a subclass of the base type.
  863. bool py_issubclass(
  864. int derived,
  865. int base,
  866. ) {
  867. return _py_issubclass(
  868. derived,
  869. base,
  870. );
  871. }
  872. late final _py_issubclassPtr =
  873. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Type, py_Type)>>(
  874. 'py_issubclass');
  875. late final _py_issubclass =
  876. _py_issubclassPtr.asFunction<bool Function(int, int)>();
  877. /// Get the magic method from the given type only.
  878. /// The returned reference is always valid. However, its value may be `nil`.
  879. py_GlobalRef py_tpgetmagic(
  880. int type,
  881. int name,
  882. ) {
  883. return _py_tpgetmagic(
  884. type,
  885. name,
  886. );
  887. }
  888. late final _py_tpgetmagicPtr =
  889. _lookup<ffi.NativeFunction<py_GlobalRef Function(py_Type, py_Name)>>(
  890. 'py_tpgetmagic');
  891. late final _py_tpgetmagic =
  892. _py_tpgetmagicPtr.asFunction<py_GlobalRef Function(int, int)>();
  893. /// Search the magic method from the given type to the base type.
  894. /// Return `NULL` if not found.
  895. py_GlobalRef py_tpfindmagic(
  896. int arg0,
  897. int name,
  898. ) {
  899. return _py_tpfindmagic(
  900. arg0,
  901. name,
  902. );
  903. }
  904. late final _py_tpfindmagicPtr =
  905. _lookup<ffi.NativeFunction<py_GlobalRef Function(py_Type, py_Name)>>(
  906. 'py_tpfindmagic');
  907. late final _py_tpfindmagic =
  908. _py_tpfindmagicPtr.asFunction<py_GlobalRef Function(int, int)>();
  909. /// Search the name from the given type to the base type.
  910. /// Return `NULL` if not found.
  911. py_ItemRef py_tpfindname(
  912. int arg0,
  913. int name,
  914. ) {
  915. return _py_tpfindname(
  916. arg0,
  917. name,
  918. );
  919. }
  920. late final _py_tpfindnamePtr =
  921. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Type, py_Name)>>(
  922. 'py_tpfindname');
  923. late final _py_tpfindname =
  924. _py_tpfindnamePtr.asFunction<py_ItemRef Function(int, int)>();
  925. /// Get the type object of the given type.
  926. py_GlobalRef py_tpobject(
  927. int type,
  928. ) {
  929. return _py_tpobject(
  930. type,
  931. );
  932. }
  933. late final _py_tpobjectPtr =
  934. _lookup<ffi.NativeFunction<py_GlobalRef Function(py_Type)>>(
  935. 'py_tpobject');
  936. late final _py_tpobject =
  937. _py_tpobjectPtr.asFunction<py_GlobalRef Function(int)>();
  938. /// Get the type name.
  939. ffi.Pointer<ffi.Char> py_tpname(
  940. int type,
  941. ) {
  942. return _py_tpname(
  943. type,
  944. );
  945. }
  946. late final _py_tpnamePtr =
  947. _lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function(py_Type)>>(
  948. 'py_tpname');
  949. late final _py_tpname =
  950. _py_tpnamePtr.asFunction<ffi.Pointer<ffi.Char> Function(int)>();
  951. /// Call a type to create a new instance.
  952. bool py_tpcall(
  953. int type,
  954. int argc,
  955. py_Ref argv,
  956. ) {
  957. return _py_tpcall(
  958. type,
  959. argc,
  960. argv,
  961. );
  962. }
  963. late final _py_tpcallPtr =
  964. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Type, ffi.Int, py_Ref)>>(
  965. 'py_tpcall');
  966. late final _py_tpcall =
  967. _py_tpcallPtr.asFunction<bool Function(int, int, py_Ref)>();
  968. /// Check if the object is an instance of the given type.
  969. /// Raise `TypeError` if the check fails.
  970. bool py_checktype(
  971. py_Ref self,
  972. int type,
  973. ) {
  974. return _py_checktype(
  975. self,
  976. type,
  977. );
  978. }
  979. late final _py_checktypePtr =
  980. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Type)>>(
  981. 'py_checktype');
  982. late final _py_checktype =
  983. _py_checktypePtr.asFunction<bool Function(py_Ref, int)>();
  984. /// Get the i-th register.
  985. /// All registers are located in a contiguous memory.
  986. py_GlobalRef py_getreg(
  987. int i,
  988. ) {
  989. return _py_getreg(
  990. i,
  991. );
  992. }
  993. late final _py_getregPtr =
  994. _lookup<ffi.NativeFunction<py_GlobalRef Function(ffi.Int)>>('py_getreg');
  995. late final _py_getreg =
  996. _py_getregPtr.asFunction<py_GlobalRef Function(int)>();
  997. /// Set the i-th register.
  998. void py_setreg(
  999. int i,
  1000. py_Ref val,
  1001. ) {
  1002. return _py_setreg(
  1003. i,
  1004. val,
  1005. );
  1006. }
  1007. late final _py_setregPtr =
  1008. _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int, py_Ref)>>(
  1009. 'py_setreg');
  1010. late final _py_setreg =
  1011. _py_setregPtr.asFunction<void Function(int, py_Ref)>();
  1012. /// Get variable in the `__main__` module.
  1013. py_ItemRef py_getglobal(
  1014. int name,
  1015. ) {
  1016. return _py_getglobal(
  1017. name,
  1018. );
  1019. }
  1020. late final _py_getglobalPtr =
  1021. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Name)>>('py_getglobal');
  1022. late final _py_getglobal =
  1023. _py_getglobalPtr.asFunction<py_ItemRef Function(int)>();
  1024. /// Set variable in the `__main__` module.
  1025. void py_setglobal(
  1026. int name,
  1027. py_Ref val,
  1028. ) {
  1029. return _py_setglobal(
  1030. name,
  1031. val,
  1032. );
  1033. }
  1034. late final _py_setglobalPtr =
  1035. _lookup<ffi.NativeFunction<ffi.Void Function(py_Name, py_Ref)>>(
  1036. 'py_setglobal');
  1037. late final _py_setglobal =
  1038. _py_setglobalPtr.asFunction<void Function(int, py_Ref)>();
  1039. /// Get variable in the `builtins` module.
  1040. py_ItemRef py_getbuiltin(
  1041. int name,
  1042. ) {
  1043. return _py_getbuiltin(
  1044. name,
  1045. );
  1046. }
  1047. late final _py_getbuiltinPtr =
  1048. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Name)>>(
  1049. 'py_getbuiltin');
  1050. late final _py_getbuiltin =
  1051. _py_getbuiltinPtr.asFunction<py_ItemRef Function(int)>();
  1052. /// Equivalent to `*dst = *src`.
  1053. void py_assign(
  1054. py_Ref dst,
  1055. py_Ref src,
  1056. ) {
  1057. return _py_assign(
  1058. dst,
  1059. src,
  1060. );
  1061. }
  1062. late final _py_assignPtr =
  1063. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, py_Ref)>>(
  1064. 'py_assign');
  1065. late final _py_assign =
  1066. _py_assignPtr.asFunction<void Function(py_Ref, py_Ref)>();
  1067. /// Get the last return value.
  1068. py_GlobalRef py_retval() {
  1069. return _py_retval();
  1070. }
  1071. late final _py_retvalPtr =
  1072. _lookup<ffi.NativeFunction<py_GlobalRef Function()>>('py_retval');
  1073. late final _py_retval = _py_retvalPtr.asFunction<py_GlobalRef Function()>();
  1074. /// Get an item from the object's `__dict__`.
  1075. /// Return `NULL` if not found.
  1076. py_ItemRef py_getdict(
  1077. py_Ref self,
  1078. int name,
  1079. ) {
  1080. return _py_getdict(
  1081. self,
  1082. name,
  1083. );
  1084. }
  1085. late final _py_getdictPtr =
  1086. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Ref, py_Name)>>(
  1087. 'py_getdict');
  1088. late final _py_getdict =
  1089. _py_getdictPtr.asFunction<py_ItemRef Function(py_Ref, int)>();
  1090. /// Set an item to the object's `__dict__`.
  1091. void py_setdict(
  1092. py_Ref self,
  1093. int name,
  1094. py_Ref val,
  1095. ) {
  1096. return _py_setdict(
  1097. self,
  1098. name,
  1099. val,
  1100. );
  1101. }
  1102. late final _py_setdictPtr =
  1103. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, py_Name, py_Ref)>>(
  1104. 'py_setdict');
  1105. late final _py_setdict =
  1106. _py_setdictPtr.asFunction<void Function(py_Ref, int, py_Ref)>();
  1107. /// Delete an item from the object's `__dict__`.
  1108. /// Return `true` if the deletion is successful.
  1109. bool py_deldict(
  1110. py_Ref self,
  1111. int name,
  1112. ) {
  1113. return _py_deldict(
  1114. self,
  1115. name,
  1116. );
  1117. }
  1118. late final _py_deldictPtr =
  1119. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Name)>>(
  1120. 'py_deldict');
  1121. late final _py_deldict =
  1122. _py_deldictPtr.asFunction<bool Function(py_Ref, int)>();
  1123. /// Prepare an insertion to the object's `__dict__`.
  1124. py_ItemRef py_emplacedict(
  1125. py_Ref self,
  1126. int name,
  1127. ) {
  1128. return _py_emplacedict(
  1129. self,
  1130. name,
  1131. );
  1132. }
  1133. late final _py_emplacedictPtr =
  1134. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Ref, py_Name)>>(
  1135. 'py_emplacedict');
  1136. late final _py_emplacedict =
  1137. _py_emplacedictPtr.asFunction<py_ItemRef Function(py_Ref, int)>();
  1138. /// Apply a function to all items in the object's `__dict__`.
  1139. /// Return `true` if the function is successful for all items.
  1140. /// NOTE: Be careful if `f` modifies the object's `__dict__`.
  1141. bool py_applydict(
  1142. py_Ref self,
  1143. ffi.Pointer<
  1144. ffi.NativeFunction<
  1145. ffi.Bool Function(
  1146. py_Name name, py_Ref val, ffi.Pointer<ffi.Void> ctx)>>
  1147. f,
  1148. ffi.Pointer<ffi.Void> ctx,
  1149. ) {
  1150. return _py_applydict(
  1151. self,
  1152. f,
  1153. ctx,
  1154. );
  1155. }
  1156. late final _py_applydictPtr = _lookup<
  1157. ffi.NativeFunction<
  1158. ffi.Bool Function(
  1159. py_Ref,
  1160. ffi.Pointer<
  1161. ffi.NativeFunction<
  1162. ffi.Bool Function(py_Name name, py_Ref val,
  1163. ffi.Pointer<ffi.Void> ctx)>>,
  1164. ffi.Pointer<ffi.Void>)>>('py_applydict');
  1165. late final _py_applydict = _py_applydictPtr.asFunction<
  1166. bool Function(
  1167. py_Ref,
  1168. ffi.Pointer<
  1169. ffi.NativeFunction<
  1170. ffi.Bool Function(
  1171. py_Name name, py_Ref val, ffi.Pointer<ffi.Void> ctx)>>,
  1172. ffi.Pointer<ffi.Void>)>();
  1173. /// Get the i-th slot of the object.
  1174. /// The object must have slots and `i` must be in valid range.
  1175. py_ObjectRef py_getslot(
  1176. py_Ref self,
  1177. int i,
  1178. ) {
  1179. return _py_getslot(
  1180. self,
  1181. i,
  1182. );
  1183. }
  1184. late final _py_getslotPtr =
  1185. _lookup<ffi.NativeFunction<py_ObjectRef Function(py_Ref, ffi.Int)>>(
  1186. 'py_getslot');
  1187. late final _py_getslot =
  1188. _py_getslotPtr.asFunction<py_ObjectRef Function(py_Ref, int)>();
  1189. /// Set the i-th slot of the object.
  1190. void py_setslot(
  1191. py_Ref self,
  1192. int i,
  1193. py_Ref val,
  1194. ) {
  1195. return _py_setslot(
  1196. self,
  1197. i,
  1198. val,
  1199. );
  1200. }
  1201. late final _py_setslotPtr =
  1202. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, ffi.Int, py_Ref)>>(
  1203. 'py_setslot');
  1204. late final _py_setslot =
  1205. _py_setslotPtr.asFunction<void Function(py_Ref, int, py_Ref)>();
  1206. /// Get the current `function` object on the stack.
  1207. /// Return `NULL` if not available.
  1208. /// NOTE: This function should be placed at the beginning of your decl-based bindings.
  1209. py_StackRef py_inspect_currentfunction() {
  1210. return _py_inspect_currentfunction();
  1211. }
  1212. late final _py_inspect_currentfunctionPtr =
  1213. _lookup<ffi.NativeFunction<py_StackRef Function()>>(
  1214. 'py_inspect_currentfunction');
  1215. late final _py_inspect_currentfunction =
  1216. _py_inspect_currentfunctionPtr.asFunction<py_StackRef Function()>();
  1217. /// Get the current `module` object where the code is executed.
  1218. /// Return `NULL` if not available.
  1219. py_GlobalRef py_inspect_currentmodule() {
  1220. return _py_inspect_currentmodule();
  1221. }
  1222. late final _py_inspect_currentmodulePtr =
  1223. _lookup<ffi.NativeFunction<py_GlobalRef Function()>>(
  1224. 'py_inspect_currentmodule');
  1225. late final _py_inspect_currentmodule =
  1226. _py_inspect_currentmodulePtr.asFunction<py_GlobalRef Function()>();
  1227. /// Bind a function to the object via "decl-based" style.
  1228. /// @param obj the target object.
  1229. /// @param sig signature of the function. e.g. `add(x, y)`.
  1230. /// @param f function to bind.
  1231. void py_bind(
  1232. py_Ref obj,
  1233. ffi.Pointer<ffi.Char> sig,
  1234. py_CFunction f,
  1235. ) {
  1236. return _py_bind(
  1237. obj,
  1238. sig,
  1239. f,
  1240. );
  1241. }
  1242. late final _py_bindPtr = _lookup<
  1243. ffi.NativeFunction<
  1244. ffi.Void Function(
  1245. py_Ref, ffi.Pointer<ffi.Char>, py_CFunction)>>('py_bind');
  1246. late final _py_bind = _py_bindPtr
  1247. .asFunction<void Function(py_Ref, ffi.Pointer<ffi.Char>, py_CFunction)>();
  1248. /// Bind a method to type via "argc-based" style.
  1249. /// @param type the target type.
  1250. /// @param name name of the method.
  1251. /// @param f function to bind.
  1252. void py_bindmethod(
  1253. int type,
  1254. ffi.Pointer<ffi.Char> name,
  1255. py_CFunction f,
  1256. ) {
  1257. return _py_bindmethod(
  1258. type,
  1259. name,
  1260. f,
  1261. );
  1262. }
  1263. late final _py_bindmethodPtr = _lookup<
  1264. ffi.NativeFunction<
  1265. ffi.Void Function(
  1266. py_Type, ffi.Pointer<ffi.Char>, py_CFunction)>>('py_bindmethod');
  1267. late final _py_bindmethod = _py_bindmethodPtr
  1268. .asFunction<void Function(int, ffi.Pointer<ffi.Char>, py_CFunction)>();
  1269. /// Bind a function to the object via "argc-based" style.
  1270. /// @param obj the target object.
  1271. /// @param name name of the function.
  1272. /// @param f function to bind.
  1273. void py_bindfunc(
  1274. py_Ref obj,
  1275. ffi.Pointer<ffi.Char> name,
  1276. py_CFunction f,
  1277. ) {
  1278. return _py_bindfunc(
  1279. obj,
  1280. name,
  1281. f,
  1282. );
  1283. }
  1284. late final _py_bindfuncPtr = _lookup<
  1285. ffi.NativeFunction<
  1286. ffi.Void Function(
  1287. py_Ref, ffi.Pointer<ffi.Char>, py_CFunction)>>('py_bindfunc');
  1288. late final _py_bindfunc = _py_bindfuncPtr
  1289. .asFunction<void Function(py_Ref, ffi.Pointer<ffi.Char>, py_CFunction)>();
  1290. /// Bind a property to type.
  1291. /// @param type the target type.
  1292. /// @param name name of the property.
  1293. /// @param getter getter function.
  1294. /// @param setter setter function. Use `NULL` if not needed.
  1295. void py_bindproperty(
  1296. int type,
  1297. ffi.Pointer<ffi.Char> name,
  1298. py_CFunction getter,
  1299. py_CFunction setter,
  1300. ) {
  1301. return _py_bindproperty(
  1302. type,
  1303. name,
  1304. getter,
  1305. setter,
  1306. );
  1307. }
  1308. late final _py_bindpropertyPtr = _lookup<
  1309. ffi.NativeFunction<
  1310. ffi.Void Function(py_Type, ffi.Pointer<ffi.Char>, py_CFunction,
  1311. py_CFunction)>>('py_bindproperty');
  1312. late final _py_bindproperty = _py_bindpropertyPtr.asFunction<
  1313. void Function(int, ffi.Pointer<ffi.Char>, py_CFunction, py_CFunction)>();
  1314. /// Python equivalent to `getattr(self, name)`.
  1315. bool py_getattr(
  1316. py_Ref self,
  1317. int name,
  1318. ) {
  1319. return _py_getattr(
  1320. self,
  1321. name,
  1322. );
  1323. }
  1324. late final _py_getattrPtr =
  1325. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Name)>>(
  1326. 'py_getattr');
  1327. late final _py_getattr =
  1328. _py_getattrPtr.asFunction<bool Function(py_Ref, int)>();
  1329. /// Python equivalent to `setattr(self, name, val)`.
  1330. bool py_setattr(
  1331. py_Ref self,
  1332. int name,
  1333. py_Ref val,
  1334. ) {
  1335. return _py_setattr(
  1336. self,
  1337. name,
  1338. val,
  1339. );
  1340. }
  1341. late final _py_setattrPtr =
  1342. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Name, py_Ref)>>(
  1343. 'py_setattr');
  1344. late final _py_setattr =
  1345. _py_setattrPtr.asFunction<bool Function(py_Ref, int, py_Ref)>();
  1346. /// Python equivalent to `delattr(self, name)`.
  1347. bool py_delattr(
  1348. py_Ref self,
  1349. int name,
  1350. ) {
  1351. return _py_delattr(
  1352. self,
  1353. name,
  1354. );
  1355. }
  1356. late final _py_delattrPtr =
  1357. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Name)>>(
  1358. 'py_delattr');
  1359. late final _py_delattr =
  1360. _py_delattrPtr.asFunction<bool Function(py_Ref, int)>();
  1361. /// Python equivalent to `self[key]`.
  1362. bool py_getitem(
  1363. py_Ref self,
  1364. py_Ref key,
  1365. ) {
  1366. return _py_getitem(
  1367. self,
  1368. key,
  1369. );
  1370. }
  1371. late final _py_getitemPtr =
  1372. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Ref)>>(
  1373. 'py_getitem');
  1374. late final _py_getitem =
  1375. _py_getitemPtr.asFunction<bool Function(py_Ref, py_Ref)>();
  1376. /// Python equivalent to `self[key] = val`.
  1377. bool py_setitem(
  1378. py_Ref self,
  1379. py_Ref key,
  1380. py_Ref val,
  1381. ) {
  1382. return _py_setitem(
  1383. self,
  1384. key,
  1385. val,
  1386. );
  1387. }
  1388. late final _py_setitemPtr =
  1389. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Ref, py_Ref)>>(
  1390. 'py_setitem');
  1391. late final _py_setitem =
  1392. _py_setitemPtr.asFunction<bool Function(py_Ref, py_Ref, py_Ref)>();
  1393. /// Python equivalent to `del self[key]`.
  1394. bool py_delitem(
  1395. py_Ref self,
  1396. py_Ref key,
  1397. ) {
  1398. return _py_delitem(
  1399. self,
  1400. key,
  1401. );
  1402. }
  1403. late final _py_delitemPtr =
  1404. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Ref)>>(
  1405. 'py_delitem');
  1406. late final _py_delitem =
  1407. _py_delitemPtr.asFunction<bool Function(py_Ref, py_Ref)>();
  1408. /// Perform a binary operation.
  1409. /// The result will be set to `py_retval()`.
  1410. /// The stack remains unchanged after the operation.
  1411. bool py_binaryop(
  1412. py_Ref lhs,
  1413. py_Ref rhs,
  1414. int op,
  1415. int rop,
  1416. ) {
  1417. return _py_binaryop(
  1418. lhs,
  1419. rhs,
  1420. op,
  1421. rop,
  1422. );
  1423. }
  1424. late final _py_binaryopPtr = _lookup<
  1425. ffi.NativeFunction<
  1426. ffi.Bool Function(py_Ref, py_Ref, py_Name, py_Name)>>('py_binaryop');
  1427. late final _py_binaryop =
  1428. _py_binaryopPtr.asFunction<bool Function(py_Ref, py_Ref, int, int)>();
  1429. /// Get the i-th object from the top of the stack.
  1430. /// `i` should be negative, e.g. (-1) means TOS.
  1431. py_StackRef py_peek(
  1432. int i,
  1433. ) {
  1434. return _py_peek(
  1435. i,
  1436. );
  1437. }
  1438. late final _py_peekPtr =
  1439. _lookup<ffi.NativeFunction<py_StackRef Function(ffi.Int)>>('py_peek');
  1440. late final _py_peek = _py_peekPtr.asFunction<py_StackRef Function(int)>();
  1441. /// Push the object to the stack.
  1442. void py_push(
  1443. py_Ref src,
  1444. ) {
  1445. return _py_push(
  1446. src,
  1447. );
  1448. }
  1449. late final _py_pushPtr =
  1450. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref)>>('py_push');
  1451. late final _py_push = _py_pushPtr.asFunction<void Function(py_Ref)>();
  1452. /// Push a `nil` object to the stack.
  1453. void py_pushnil() {
  1454. return _py_pushnil();
  1455. }
  1456. late final _py_pushnilPtr =
  1457. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_pushnil');
  1458. late final _py_pushnil = _py_pushnilPtr.asFunction<void Function()>();
  1459. /// Push a `None` object to the stack.
  1460. void py_pushnone() {
  1461. return _py_pushnone();
  1462. }
  1463. late final _py_pushnonePtr =
  1464. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_pushnone');
  1465. late final _py_pushnone = _py_pushnonePtr.asFunction<void Function()>();
  1466. /// Push a `py_Name` to the stack. This is used for keyword arguments.
  1467. void py_pushname(
  1468. int name,
  1469. ) {
  1470. return _py_pushname(
  1471. name,
  1472. );
  1473. }
  1474. late final _py_pushnamePtr =
  1475. _lookup<ffi.NativeFunction<ffi.Void Function(py_Name)>>('py_pushname');
  1476. late final _py_pushname = _py_pushnamePtr.asFunction<void Function(int)>();
  1477. /// Pop an object from the stack.
  1478. void py_pop() {
  1479. return _py_pop();
  1480. }
  1481. late final _py_popPtr =
  1482. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_pop');
  1483. late final _py_pop = _py_popPtr.asFunction<void Function()>();
  1484. /// Shrink the stack by n.
  1485. void py_shrink(
  1486. int n,
  1487. ) {
  1488. return _py_shrink(
  1489. n,
  1490. );
  1491. }
  1492. late final _py_shrinkPtr =
  1493. _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>('py_shrink');
  1494. late final _py_shrink = _py_shrinkPtr.asFunction<void Function(int)>();
  1495. /// Get a temporary variable from the stack.
  1496. py_StackRef py_pushtmp() {
  1497. return _py_pushtmp();
  1498. }
  1499. late final _py_pushtmpPtr =
  1500. _lookup<ffi.NativeFunction<py_StackRef Function()>>('py_pushtmp');
  1501. late final _py_pushtmp = _py_pushtmpPtr.asFunction<py_StackRef Function()>();
  1502. /// Get the unbound method of the object.
  1503. /// Assume the object is located at the top of the stack.
  1504. /// If return true: `[self] -> [unbound, self]`.
  1505. /// If return false: `[self] -> [self]` (no change).
  1506. bool py_pushmethod(
  1507. int name,
  1508. ) {
  1509. return _py_pushmethod(
  1510. name,
  1511. );
  1512. }
  1513. late final _py_pushmethodPtr =
  1514. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Name)>>('py_pushmethod');
  1515. late final _py_pushmethod =
  1516. _py_pushmethodPtr.asFunction<bool Function(int)>();
  1517. /// Call a callable object via pocketpy's calling convention.
  1518. /// You need to prepare the stack using this form: `callable, self/nil, arg1, arg2, ..., k1, v1, k2, v2, ...`
  1519. /// `argc` is the number of positional arguments excluding `self`.
  1520. /// `kwargc` is the number of keyword arguments, i.e. the number of key-value pairs.
  1521. /// The result will be set to `py_retval()`.
  1522. /// The stack size will be reduced by `argc + kwargc`.
  1523. bool py_vectorcall(
  1524. int argc,
  1525. int kwargc,
  1526. ) {
  1527. return _py_vectorcall(
  1528. argc,
  1529. kwargc,
  1530. );
  1531. }
  1532. late final _py_vectorcallPtr =
  1533. _lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Uint16, ffi.Uint16)>>(
  1534. 'py_vectorcall');
  1535. late final _py_vectorcall =
  1536. _py_vectorcallPtr.asFunction<bool Function(int, int)>();
  1537. /// Evaluate an expression and push the result to the stack.
  1538. /// This function is used for testing.
  1539. bool py_pusheval(
  1540. ffi.Pointer<ffi.Char> expr,
  1541. py_GlobalRef module,
  1542. ) {
  1543. return _py_pusheval(
  1544. expr,
  1545. module,
  1546. );
  1547. }
  1548. late final _py_pushevalPtr = _lookup<
  1549. ffi.NativeFunction<
  1550. ffi.Bool Function(
  1551. ffi.Pointer<ffi.Char>, py_GlobalRef)>>('py_pusheval');
  1552. late final _py_pusheval = _py_pushevalPtr
  1553. .asFunction<bool Function(ffi.Pointer<ffi.Char>, py_GlobalRef)>();
  1554. /// Create a new module.
  1555. py_GlobalRef py_newmodule(
  1556. ffi.Pointer<ffi.Char> path,
  1557. ) {
  1558. return _py_newmodule(
  1559. path,
  1560. );
  1561. }
  1562. late final _py_newmodulePtr =
  1563. _lookup<ffi.NativeFunction<py_GlobalRef Function(ffi.Pointer<ffi.Char>)>>(
  1564. 'py_newmodule');
  1565. late final _py_newmodule = _py_newmodulePtr
  1566. .asFunction<py_GlobalRef Function(ffi.Pointer<ffi.Char>)>();
  1567. /// Get a module by path.
  1568. py_GlobalRef py_getmodule(
  1569. ffi.Pointer<ffi.Char> path,
  1570. ) {
  1571. return _py_getmodule(
  1572. path,
  1573. );
  1574. }
  1575. late final _py_getmodulePtr =
  1576. _lookup<ffi.NativeFunction<py_GlobalRef Function(ffi.Pointer<ffi.Char>)>>(
  1577. 'py_getmodule');
  1578. late final _py_getmodule = _py_getmodulePtr
  1579. .asFunction<py_GlobalRef Function(ffi.Pointer<ffi.Char>)>();
  1580. /// Import a module.
  1581. /// The result will be set to `py_retval()`.
  1582. /// -1: error, 0: not found, 1: success
  1583. int py_import(
  1584. ffi.Pointer<ffi.Char> path,
  1585. ) {
  1586. return _py_import(
  1587. path,
  1588. );
  1589. }
  1590. late final _py_importPtr =
  1591. _lookup<ffi.NativeFunction<ffi.Int Function(ffi.Pointer<ffi.Char>)>>(
  1592. 'py_import');
  1593. late final _py_import =
  1594. _py_importPtr.asFunction<int Function(ffi.Pointer<ffi.Char>)>();
  1595. /// Raise an exception by type and message. Always return false.
  1596. bool py_exception(
  1597. int type,
  1598. ffi.Pointer<ffi.Char> fmt,
  1599. ) {
  1600. return _py_exception(
  1601. type,
  1602. fmt,
  1603. );
  1604. }
  1605. late final _py_exceptionPtr = _lookup<
  1606. ffi.NativeFunction<
  1607. ffi.Bool Function(py_Type, ffi.Pointer<ffi.Char>)>>('py_exception');
  1608. late final _py_exception =
  1609. _py_exceptionPtr.asFunction<bool Function(int, ffi.Pointer<ffi.Char>)>();
  1610. /// Raise an expection object. Always return false.
  1611. bool py_raise(
  1612. py_Ref arg0,
  1613. ) {
  1614. return _py_raise(
  1615. arg0,
  1616. );
  1617. }
  1618. late final _py_raisePtr =
  1619. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_raise');
  1620. late final _py_raise = _py_raisePtr.asFunction<bool Function(py_Ref)>();
  1621. /// Print the current exception.
  1622. /// The exception will be set as handled.
  1623. void py_printexc() {
  1624. return _py_printexc();
  1625. }
  1626. late final _py_printexcPtr =
  1627. _lookup<ffi.NativeFunction<ffi.Void Function()>>('py_printexc');
  1628. late final _py_printexc = _py_printexcPtr.asFunction<void Function()>();
  1629. /// Format the current exception and return a null-terminated string.
  1630. /// The result should be freed by the caller.
  1631. /// The exception will be set as handled.
  1632. ffi.Pointer<ffi.Char> py_formatexc() {
  1633. return _py_formatexc();
  1634. }
  1635. late final _py_formatexcPtr =
  1636. _lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function()>>(
  1637. 'py_formatexc');
  1638. late final _py_formatexc =
  1639. _py_formatexcPtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
  1640. /// Check if an exception is raised.
  1641. bool py_checkexc(
  1642. bool ignore_handled,
  1643. ) {
  1644. return _py_checkexc(
  1645. ignore_handled,
  1646. );
  1647. }
  1648. late final _py_checkexcPtr =
  1649. _lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Bool)>>('py_checkexc');
  1650. late final _py_checkexc = _py_checkexcPtr.asFunction<bool Function(bool)>();
  1651. /// Check if the exception is an instance of the given type.
  1652. /// This function is roughly equivalent to python's `except <T> as e:` block.
  1653. /// If match, the exception will be stored in `py_retval()` as handled.
  1654. bool py_matchexc(
  1655. int type,
  1656. ) {
  1657. return _py_matchexc(
  1658. type,
  1659. );
  1660. }
  1661. late final _py_matchexcPtr =
  1662. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Type)>>('py_matchexc');
  1663. late final _py_matchexc = _py_matchexcPtr.asFunction<bool Function(int)>();
  1664. /// Clear the current exception.
  1665. /// @param p0 the unwinding point. Use `NULL` if not needed.
  1666. void py_clearexc(
  1667. py_StackRef p0,
  1668. ) {
  1669. return _py_clearexc(
  1670. p0,
  1671. );
  1672. }
  1673. late final _py_clearexcPtr =
  1674. _lookup<ffi.NativeFunction<ffi.Void Function(py_StackRef)>>(
  1675. 'py_clearexc');
  1676. late final _py_clearexc =
  1677. _py_clearexcPtr.asFunction<void Function(py_StackRef)>();
  1678. bool StopIteration() {
  1679. return _StopIteration();
  1680. }
  1681. late final _StopIterationPtr =
  1682. _lookup<ffi.NativeFunction<ffi.Bool Function()>>('StopIteration');
  1683. late final _StopIteration = _StopIterationPtr.asFunction<bool Function()>();
  1684. bool KeyError(
  1685. py_Ref key,
  1686. ) {
  1687. return _KeyError(
  1688. key,
  1689. );
  1690. }
  1691. late final _KeyErrorPtr =
  1692. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('KeyError');
  1693. late final _KeyError = _KeyErrorPtr.asFunction<bool Function(py_Ref)>();
  1694. /// Python equivalent to `bool(val)`.
  1695. /// 1: true, 0: false, -1: error
  1696. int py_bool(
  1697. py_Ref val,
  1698. ) {
  1699. return _py_bool(
  1700. val,
  1701. );
  1702. }
  1703. late final _py_boolPtr =
  1704. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref)>>('py_bool');
  1705. late final _py_bool = _py_boolPtr.asFunction<int Function(py_Ref)>();
  1706. /// Compare two objects.
  1707. /// 1: lhs == rhs, 0: lhs != rhs, -1: error
  1708. int py_equal(
  1709. py_Ref lhs,
  1710. py_Ref rhs,
  1711. ) {
  1712. return _py_equal(
  1713. lhs,
  1714. rhs,
  1715. );
  1716. }
  1717. late final _py_equalPtr =
  1718. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref, py_Ref)>>('py_equal');
  1719. late final _py_equal =
  1720. _py_equalPtr.asFunction<int Function(py_Ref, py_Ref)>();
  1721. /// Compare two objects.
  1722. /// 1: lhs < rhs, 0: lhs >= rhs, -1: error
  1723. int py_less(
  1724. py_Ref lhs,
  1725. py_Ref rhs,
  1726. ) {
  1727. return _py_less(
  1728. lhs,
  1729. rhs,
  1730. );
  1731. }
  1732. late final _py_lessPtr =
  1733. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref, py_Ref)>>('py_less');
  1734. late final _py_less = _py_lessPtr.asFunction<int Function(py_Ref, py_Ref)>();
  1735. /// Python equivalent to `callable(val)`.
  1736. bool py_callable(
  1737. py_Ref val,
  1738. ) {
  1739. return _py_callable(
  1740. val,
  1741. );
  1742. }
  1743. late final _py_callablePtr =
  1744. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_callable');
  1745. late final _py_callable = _py_callablePtr.asFunction<bool Function(py_Ref)>();
  1746. /// Get the hash value of the object.
  1747. bool py_hash(
  1748. py_Ref arg0,
  1749. ffi.Pointer<py_i64> out,
  1750. ) {
  1751. return _py_hash(
  1752. arg0,
  1753. out,
  1754. );
  1755. }
  1756. late final _py_hashPtr = _lookup<
  1757. ffi.NativeFunction<ffi.Bool Function(py_Ref, ffi.Pointer<py_i64>)>>(
  1758. 'py_hash');
  1759. late final _py_hash =
  1760. _py_hashPtr.asFunction<bool Function(py_Ref, ffi.Pointer<py_i64>)>();
  1761. /// Get the iterator of the object.
  1762. bool py_iter(
  1763. py_Ref arg0,
  1764. ) {
  1765. return _py_iter(
  1766. arg0,
  1767. );
  1768. }
  1769. late final _py_iterPtr =
  1770. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_iter');
  1771. late final _py_iter = _py_iterPtr.asFunction<bool Function(py_Ref)>();
  1772. /// Get the next element from the iterator.
  1773. /// 1: success, 0: StopIteration, -1: error
  1774. int py_next(
  1775. py_Ref arg0,
  1776. ) {
  1777. return _py_next(
  1778. arg0,
  1779. );
  1780. }
  1781. late final _py_nextPtr =
  1782. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref)>>('py_next');
  1783. late final _py_next = _py_nextPtr.asFunction<int Function(py_Ref)>();
  1784. /// Python equivalent to `lhs is rhs`.
  1785. bool py_isidentical(
  1786. py_Ref arg0,
  1787. py_Ref arg1,
  1788. ) {
  1789. return _py_isidentical(
  1790. arg0,
  1791. arg1,
  1792. );
  1793. }
  1794. late final _py_isidenticalPtr =
  1795. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Ref)>>(
  1796. 'py_isidentical');
  1797. late final _py_isidentical =
  1798. _py_isidenticalPtr.asFunction<bool Function(py_Ref, py_Ref)>();
  1799. /// Call a function.
  1800. /// It prepares the stack and then performs a `vectorcall(argc, 0, false)`.
  1801. /// The result will be set to `py_retval()`.
  1802. /// The stack remains unchanged after the operation.
  1803. bool py_call(
  1804. py_Ref f,
  1805. int argc,
  1806. py_Ref argv,
  1807. ) {
  1808. return _py_call(
  1809. f,
  1810. argc,
  1811. argv,
  1812. );
  1813. }
  1814. late final _py_callPtr =
  1815. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, ffi.Int, py_Ref)>>(
  1816. 'py_call');
  1817. late final _py_call =
  1818. _py_callPtr.asFunction<bool Function(py_Ref, int, py_Ref)>();
  1819. /// Call a `py_CFunction` in a safe way.
  1820. /// This function does extra checks to help you debug `py_CFunction`.
  1821. bool py_callcfunc(
  1822. py_CFunction f,
  1823. int argc,
  1824. py_Ref argv,
  1825. ) {
  1826. return _py_callcfunc(
  1827. f,
  1828. argc,
  1829. argv,
  1830. );
  1831. }
  1832. late final _py_callcfuncPtr = _lookup<
  1833. ffi.NativeFunction<ffi.Bool Function(py_CFunction, ffi.Int, py_Ref)>>(
  1834. 'py_callcfunc');
  1835. late final _py_callcfunc =
  1836. _py_callcfuncPtr.asFunction<bool Function(py_CFunction, int, py_Ref)>();
  1837. /// Python equivalent to `str(val)`.
  1838. bool py_str(
  1839. py_Ref val,
  1840. ) {
  1841. return _py_str(
  1842. val,
  1843. );
  1844. }
  1845. late final _py_strPtr =
  1846. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_str');
  1847. late final _py_str = _py_strPtr.asFunction<bool Function(py_Ref)>();
  1848. /// Python equivalent to `repr(val)`.
  1849. bool py_repr(
  1850. py_Ref val,
  1851. ) {
  1852. return _py_repr(
  1853. val,
  1854. );
  1855. }
  1856. late final _py_reprPtr =
  1857. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_repr');
  1858. late final _py_repr = _py_reprPtr.asFunction<bool Function(py_Ref)>();
  1859. /// Python equivalent to `len(val)`.
  1860. bool py_len(
  1861. py_Ref val,
  1862. ) {
  1863. return _py_len(
  1864. val,
  1865. );
  1866. }
  1867. late final _py_lenPtr =
  1868. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_len');
  1869. late final _py_len = _py_lenPtr.asFunction<bool Function(py_Ref)>();
  1870. /// Python equivalent to `json.dumps(val)`.
  1871. bool py_json_dumps(
  1872. py_Ref val,
  1873. ) {
  1874. return _py_json_dumps(
  1875. val,
  1876. );
  1877. }
  1878. late final _py_json_dumpsPtr =
  1879. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref)>>('py_json_dumps');
  1880. late final _py_json_dumps =
  1881. _py_json_dumpsPtr.asFunction<bool Function(py_Ref)>();
  1882. /// Python equivalent to `json.loads(val)`.
  1883. bool py_json_loads(
  1884. ffi.Pointer<ffi.Char> source,
  1885. ) {
  1886. return _py_json_loads(
  1887. source,
  1888. );
  1889. }
  1890. late final _py_json_loadsPtr =
  1891. _lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Char>)>>(
  1892. 'py_json_loads');
  1893. late final _py_json_loads =
  1894. _py_json_loadsPtr.asFunction<bool Function(ffi.Pointer<ffi.Char>)>();
  1895. /// Unchecked Functions
  1896. py_ObjectRef py_tuple_data(
  1897. py_Ref self,
  1898. ) {
  1899. return _py_tuple_data(
  1900. self,
  1901. );
  1902. }
  1903. late final _py_tuple_dataPtr =
  1904. _lookup<ffi.NativeFunction<py_ObjectRef Function(py_Ref)>>(
  1905. 'py_tuple_data');
  1906. late final _py_tuple_data =
  1907. _py_tuple_dataPtr.asFunction<py_ObjectRef Function(py_Ref)>();
  1908. py_ObjectRef py_tuple_getitem(
  1909. py_Ref self,
  1910. int i,
  1911. ) {
  1912. return _py_tuple_getitem(
  1913. self,
  1914. i,
  1915. );
  1916. }
  1917. late final _py_tuple_getitemPtr =
  1918. _lookup<ffi.NativeFunction<py_ObjectRef Function(py_Ref, ffi.Int)>>(
  1919. 'py_tuple_getitem');
  1920. late final _py_tuple_getitem =
  1921. _py_tuple_getitemPtr.asFunction<py_ObjectRef Function(py_Ref, int)>();
  1922. void py_tuple_setitem(
  1923. py_Ref self,
  1924. int i,
  1925. py_Ref val,
  1926. ) {
  1927. return _py_tuple_setitem(
  1928. self,
  1929. i,
  1930. val,
  1931. );
  1932. }
  1933. late final _py_tuple_setitemPtr =
  1934. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, ffi.Int, py_Ref)>>(
  1935. 'py_tuple_setitem');
  1936. late final _py_tuple_setitem =
  1937. _py_tuple_setitemPtr.asFunction<void Function(py_Ref, int, py_Ref)>();
  1938. int py_tuple_len(
  1939. py_Ref self,
  1940. ) {
  1941. return _py_tuple_len(
  1942. self,
  1943. );
  1944. }
  1945. late final _py_tuple_lenPtr =
  1946. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref)>>('py_tuple_len');
  1947. late final _py_tuple_len =
  1948. _py_tuple_lenPtr.asFunction<int Function(py_Ref)>();
  1949. py_ItemRef py_list_data(
  1950. py_Ref self,
  1951. ) {
  1952. return _py_list_data(
  1953. self,
  1954. );
  1955. }
  1956. late final _py_list_dataPtr =
  1957. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Ref)>>('py_list_data');
  1958. late final _py_list_data =
  1959. _py_list_dataPtr.asFunction<py_ItemRef Function(py_Ref)>();
  1960. py_ItemRef py_list_getitem(
  1961. py_Ref self,
  1962. int i,
  1963. ) {
  1964. return _py_list_getitem(
  1965. self,
  1966. i,
  1967. );
  1968. }
  1969. late final _py_list_getitemPtr =
  1970. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Ref, ffi.Int)>>(
  1971. 'py_list_getitem');
  1972. late final _py_list_getitem =
  1973. _py_list_getitemPtr.asFunction<py_ItemRef Function(py_Ref, int)>();
  1974. void py_list_setitem(
  1975. py_Ref self,
  1976. int i,
  1977. py_Ref val,
  1978. ) {
  1979. return _py_list_setitem(
  1980. self,
  1981. i,
  1982. val,
  1983. );
  1984. }
  1985. late final _py_list_setitemPtr =
  1986. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, ffi.Int, py_Ref)>>(
  1987. 'py_list_setitem');
  1988. late final _py_list_setitem =
  1989. _py_list_setitemPtr.asFunction<void Function(py_Ref, int, py_Ref)>();
  1990. void py_list_delitem(
  1991. py_Ref self,
  1992. int i,
  1993. ) {
  1994. return _py_list_delitem(
  1995. self,
  1996. i,
  1997. );
  1998. }
  1999. late final _py_list_delitemPtr =
  2000. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, ffi.Int)>>(
  2001. 'py_list_delitem');
  2002. late final _py_list_delitem =
  2003. _py_list_delitemPtr.asFunction<void Function(py_Ref, int)>();
  2004. int py_list_len(
  2005. py_Ref self,
  2006. ) {
  2007. return _py_list_len(
  2008. self,
  2009. );
  2010. }
  2011. late final _py_list_lenPtr =
  2012. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref)>>('py_list_len');
  2013. late final _py_list_len = _py_list_lenPtr.asFunction<int Function(py_Ref)>();
  2014. void py_list_swap(
  2015. py_Ref self,
  2016. int i,
  2017. int j,
  2018. ) {
  2019. return _py_list_swap(
  2020. self,
  2021. i,
  2022. j,
  2023. );
  2024. }
  2025. late final _py_list_swapPtr =
  2026. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, ffi.Int, ffi.Int)>>(
  2027. 'py_list_swap');
  2028. late final _py_list_swap =
  2029. _py_list_swapPtr.asFunction<void Function(py_Ref, int, int)>();
  2030. void py_list_append(
  2031. py_Ref self,
  2032. py_Ref val,
  2033. ) {
  2034. return _py_list_append(
  2035. self,
  2036. val,
  2037. );
  2038. }
  2039. late final _py_list_appendPtr =
  2040. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, py_Ref)>>(
  2041. 'py_list_append');
  2042. late final _py_list_append =
  2043. _py_list_appendPtr.asFunction<void Function(py_Ref, py_Ref)>();
  2044. py_ItemRef py_list_emplace(
  2045. py_Ref self,
  2046. ) {
  2047. return _py_list_emplace(
  2048. self,
  2049. );
  2050. }
  2051. late final _py_list_emplacePtr =
  2052. _lookup<ffi.NativeFunction<py_ItemRef Function(py_Ref)>>(
  2053. 'py_list_emplace');
  2054. late final _py_list_emplace =
  2055. _py_list_emplacePtr.asFunction<py_ItemRef Function(py_Ref)>();
  2056. void py_list_clear(
  2057. py_Ref self,
  2058. ) {
  2059. return _py_list_clear(
  2060. self,
  2061. );
  2062. }
  2063. late final _py_list_clearPtr =
  2064. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref)>>('py_list_clear');
  2065. late final _py_list_clear =
  2066. _py_list_clearPtr.asFunction<void Function(py_Ref)>();
  2067. void py_list_insert(
  2068. py_Ref self,
  2069. int i,
  2070. py_Ref val,
  2071. ) {
  2072. return _py_list_insert(
  2073. self,
  2074. i,
  2075. val,
  2076. );
  2077. }
  2078. late final _py_list_insertPtr =
  2079. _lookup<ffi.NativeFunction<ffi.Void Function(py_Ref, ffi.Int, py_Ref)>>(
  2080. 'py_list_insert');
  2081. late final _py_list_insert =
  2082. _py_list_insertPtr.asFunction<void Function(py_Ref, int, py_Ref)>();
  2083. /// -1: error, 0: not found, 1: found
  2084. int py_dict_getitem(
  2085. py_Ref self,
  2086. py_Ref key,
  2087. ) {
  2088. return _py_dict_getitem(
  2089. self,
  2090. key,
  2091. );
  2092. }
  2093. late final _py_dict_getitemPtr =
  2094. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref, py_Ref)>>(
  2095. 'py_dict_getitem');
  2096. late final _py_dict_getitem =
  2097. _py_dict_getitemPtr.asFunction<int Function(py_Ref, py_Ref)>();
  2098. /// true: success, false: error
  2099. bool py_dict_setitem(
  2100. py_Ref self,
  2101. py_Ref key,
  2102. py_Ref val,
  2103. ) {
  2104. return _py_dict_setitem(
  2105. self,
  2106. key,
  2107. val,
  2108. );
  2109. }
  2110. late final _py_dict_setitemPtr =
  2111. _lookup<ffi.NativeFunction<ffi.Bool Function(py_Ref, py_Ref, py_Ref)>>(
  2112. 'py_dict_setitem');
  2113. late final _py_dict_setitem =
  2114. _py_dict_setitemPtr.asFunction<bool Function(py_Ref, py_Ref, py_Ref)>();
  2115. /// -1: error, 0: not found, 1: found (and deleted)
  2116. int py_dict_delitem(
  2117. py_Ref self,
  2118. py_Ref key,
  2119. ) {
  2120. return _py_dict_delitem(
  2121. self,
  2122. key,
  2123. );
  2124. }
  2125. late final _py_dict_delitemPtr =
  2126. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref, py_Ref)>>(
  2127. 'py_dict_delitem');
  2128. late final _py_dict_delitem =
  2129. _py_dict_delitemPtr.asFunction<int Function(py_Ref, py_Ref)>();
  2130. /// -1: error, 0: not found, 1: found
  2131. int py_dict_getitem_by_str(
  2132. py_Ref self,
  2133. ffi.Pointer<ffi.Char> key,
  2134. ) {
  2135. return _py_dict_getitem_by_str(
  2136. self,
  2137. key,
  2138. );
  2139. }
  2140. late final _py_dict_getitem_by_strPtr = _lookup<
  2141. ffi.NativeFunction<ffi.Int Function(py_Ref, ffi.Pointer<ffi.Char>)>>(
  2142. 'py_dict_getitem_by_str');
  2143. late final _py_dict_getitem_by_str = _py_dict_getitem_by_strPtr
  2144. .asFunction<int Function(py_Ref, ffi.Pointer<ffi.Char>)>();
  2145. /// true: success, false: error
  2146. bool py_dict_setitem_by_str(
  2147. py_Ref self,
  2148. ffi.Pointer<ffi.Char> key,
  2149. py_Ref val,
  2150. ) {
  2151. return _py_dict_setitem_by_str(
  2152. self,
  2153. key,
  2154. val,
  2155. );
  2156. }
  2157. late final _py_dict_setitem_by_strPtr = _lookup<
  2158. ffi.NativeFunction<
  2159. ffi.Bool Function(py_Ref, ffi.Pointer<ffi.Char>,
  2160. py_Ref)>>('py_dict_setitem_by_str');
  2161. late final _py_dict_setitem_by_str = _py_dict_setitem_by_strPtr
  2162. .asFunction<bool Function(py_Ref, ffi.Pointer<ffi.Char>, py_Ref)>();
  2163. /// -1: error, 0: not found, 1: found (and deleted)
  2164. int py_dict_delitem_by_str(
  2165. py_Ref self,
  2166. ffi.Pointer<ffi.Char> key,
  2167. ) {
  2168. return _py_dict_delitem_by_str(
  2169. self,
  2170. key,
  2171. );
  2172. }
  2173. late final _py_dict_delitem_by_strPtr = _lookup<
  2174. ffi.NativeFunction<ffi.Int Function(py_Ref, ffi.Pointer<ffi.Char>)>>(
  2175. 'py_dict_delitem_by_str');
  2176. late final _py_dict_delitem_by_str = _py_dict_delitem_by_strPtr
  2177. .asFunction<int Function(py_Ref, ffi.Pointer<ffi.Char>)>();
  2178. /// true: success, false: error
  2179. bool py_dict_apply(
  2180. py_Ref self,
  2181. ffi.Pointer<
  2182. ffi.NativeFunction<
  2183. ffi.Bool Function(
  2184. py_Ref key, py_Ref val, ffi.Pointer<ffi.Void> ctx)>>
  2185. f,
  2186. ffi.Pointer<ffi.Void> ctx,
  2187. ) {
  2188. return _py_dict_apply(
  2189. self,
  2190. f,
  2191. ctx,
  2192. );
  2193. }
  2194. late final _py_dict_applyPtr = _lookup<
  2195. ffi.NativeFunction<
  2196. ffi.Bool Function(
  2197. py_Ref,
  2198. ffi.Pointer<
  2199. ffi.NativeFunction<
  2200. ffi.Bool Function(
  2201. py_Ref key, py_Ref val, ffi.Pointer<ffi.Void> ctx)>>,
  2202. ffi.Pointer<ffi.Void>)>>('py_dict_apply');
  2203. late final _py_dict_apply = _py_dict_applyPtr.asFunction<
  2204. bool Function(
  2205. py_Ref,
  2206. ffi.Pointer<
  2207. ffi.NativeFunction<
  2208. ffi.Bool Function(
  2209. py_Ref key, py_Ref val, ffi.Pointer<ffi.Void> ctx)>>,
  2210. ffi.Pointer<ffi.Void>)>();
  2211. /// noexcept
  2212. int py_dict_len(
  2213. py_Ref self,
  2214. ) {
  2215. return _py_dict_len(
  2216. self,
  2217. );
  2218. }
  2219. late final _py_dict_lenPtr =
  2220. _lookup<ffi.NativeFunction<ffi.Int Function(py_Ref)>>('py_dict_len');
  2221. late final _py_dict_len = _py_dict_lenPtr.asFunction<int Function(py_Ref)>();
  2222. /// linalg module
  2223. void py_newvec2(
  2224. py_OutRef out,
  2225. c11_vec2 arg1,
  2226. ) {
  2227. return _py_newvec2(
  2228. out,
  2229. arg1,
  2230. );
  2231. }
  2232. late final _py_newvec2Ptr =
  2233. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, c11_vec2)>>(
  2234. 'py_newvec2');
  2235. late final _py_newvec2 =
  2236. _py_newvec2Ptr.asFunction<void Function(py_OutRef, c11_vec2)>();
  2237. void py_newvec3(
  2238. py_OutRef out,
  2239. c11_vec3 arg1,
  2240. ) {
  2241. return _py_newvec3(
  2242. out,
  2243. arg1,
  2244. );
  2245. }
  2246. late final _py_newvec3Ptr =
  2247. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, c11_vec3)>>(
  2248. 'py_newvec3');
  2249. late final _py_newvec3 =
  2250. _py_newvec3Ptr.asFunction<void Function(py_OutRef, c11_vec3)>();
  2251. void py_newvec2i(
  2252. py_OutRef out,
  2253. c11_vec2i arg1,
  2254. ) {
  2255. return _py_newvec2i(
  2256. out,
  2257. arg1,
  2258. );
  2259. }
  2260. late final _py_newvec2iPtr =
  2261. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, c11_vec2i)>>(
  2262. 'py_newvec2i');
  2263. late final _py_newvec2i =
  2264. _py_newvec2iPtr.asFunction<void Function(py_OutRef, c11_vec2i)>();
  2265. void py_newvec3i(
  2266. py_OutRef out,
  2267. c11_vec3i arg1,
  2268. ) {
  2269. return _py_newvec3i(
  2270. out,
  2271. arg1,
  2272. );
  2273. }
  2274. late final _py_newvec3iPtr =
  2275. _lookup<ffi.NativeFunction<ffi.Void Function(py_OutRef, c11_vec3i)>>(
  2276. 'py_newvec3i');
  2277. late final _py_newvec3i =
  2278. _py_newvec3iPtr.asFunction<void Function(py_OutRef, c11_vec3i)>();
  2279. ffi.Pointer<c11_mat3x3> py_newmat3x3(
  2280. py_OutRef out,
  2281. ) {
  2282. return _py_newmat3x3(
  2283. out,
  2284. );
  2285. }
  2286. late final _py_newmat3x3Ptr =
  2287. _lookup<ffi.NativeFunction<ffi.Pointer<c11_mat3x3> Function(py_OutRef)>>(
  2288. 'py_newmat3x3');
  2289. late final _py_newmat3x3 = _py_newmat3x3Ptr
  2290. .asFunction<ffi.Pointer<c11_mat3x3> Function(py_OutRef)>();
  2291. c11_vec2 py_tovec2(
  2292. py_Ref self,
  2293. ) {
  2294. return _py_tovec2(
  2295. self,
  2296. );
  2297. }
  2298. late final _py_tovec2Ptr =
  2299. _lookup<ffi.NativeFunction<c11_vec2 Function(py_Ref)>>('py_tovec2');
  2300. late final _py_tovec2 = _py_tovec2Ptr.asFunction<c11_vec2 Function(py_Ref)>();
  2301. c11_vec3 py_tovec3(
  2302. py_Ref self,
  2303. ) {
  2304. return _py_tovec3(
  2305. self,
  2306. );
  2307. }
  2308. late final _py_tovec3Ptr =
  2309. _lookup<ffi.NativeFunction<c11_vec3 Function(py_Ref)>>('py_tovec3');
  2310. late final _py_tovec3 = _py_tovec3Ptr.asFunction<c11_vec3 Function(py_Ref)>();
  2311. c11_vec2i py_tovec2i(
  2312. py_Ref self,
  2313. ) {
  2314. return _py_tovec2i(
  2315. self,
  2316. );
  2317. }
  2318. late final _py_tovec2iPtr =
  2319. _lookup<ffi.NativeFunction<c11_vec2i Function(py_Ref)>>('py_tovec2i');
  2320. late final _py_tovec2i =
  2321. _py_tovec2iPtr.asFunction<c11_vec2i Function(py_Ref)>();
  2322. c11_vec3i py_tovec3i(
  2323. py_Ref self,
  2324. ) {
  2325. return _py_tovec3i(
  2326. self,
  2327. );
  2328. }
  2329. late final _py_tovec3iPtr =
  2330. _lookup<ffi.NativeFunction<c11_vec3i Function(py_Ref)>>('py_tovec3i');
  2331. late final _py_tovec3i =
  2332. _py_tovec3iPtr.asFunction<c11_vec3i Function(py_Ref)>();
  2333. ffi.Pointer<c11_mat3x3> py_tomat3x3(
  2334. py_Ref self,
  2335. ) {
  2336. return _py_tomat3x3(
  2337. self,
  2338. );
  2339. }
  2340. late final _py_tomat3x3Ptr =
  2341. _lookup<ffi.NativeFunction<ffi.Pointer<c11_mat3x3> Function(py_Ref)>>(
  2342. 'py_tomat3x3');
  2343. late final _py_tomat3x3 =
  2344. _py_tomat3x3Ptr.asFunction<ffi.Pointer<c11_mat3x3> Function(py_Ref)>();
  2345. /// An utility function to read a line from stdin for REPL.
  2346. int py_replinput(
  2347. ffi.Pointer<ffi.Char> buf,
  2348. int max_size,
  2349. ) {
  2350. return _py_replinput(
  2351. buf,
  2352. max_size,
  2353. );
  2354. }
  2355. late final _py_replinputPtr = _lookup<
  2356. ffi.NativeFunction<ffi.Int Function(ffi.Pointer<ffi.Char>, ffi.Int)>>(
  2357. 'py_replinput');
  2358. late final _py_replinput =
  2359. _py_replinputPtr.asFunction<int Function(ffi.Pointer<ffi.Char>, int)>();
  2360. }
  2361. final class c11_vec2i extends ffi.Union {
  2362. external UnnamedStruct1 unnamed;
  2363. @ffi.Array.multi([2])
  2364. external ffi.Array<ffi.Int> data;
  2365. }
  2366. final class UnnamedStruct1 extends ffi.Struct {
  2367. @ffi.Int()
  2368. external int x;
  2369. @ffi.Int()
  2370. external int y;
  2371. }
  2372. final class c11_vec3i extends ffi.Union {
  2373. external UnnamedStruct2 unnamed;
  2374. @ffi.Array.multi([3])
  2375. external ffi.Array<ffi.Int> data;
  2376. }
  2377. final class UnnamedStruct2 extends ffi.Struct {
  2378. @ffi.Int()
  2379. external int x;
  2380. @ffi.Int()
  2381. external int y;
  2382. @ffi.Int()
  2383. external int z;
  2384. }
  2385. final class c11_vec2 extends ffi.Union {
  2386. external UnnamedStruct3 unnamed;
  2387. @ffi.Array.multi([2])
  2388. external ffi.Array<ffi.Float> data;
  2389. }
  2390. final class UnnamedStruct3 extends ffi.Struct {
  2391. @ffi.Float()
  2392. external double x;
  2393. @ffi.Float()
  2394. external double y;
  2395. }
  2396. final class c11_vec3 extends ffi.Union {
  2397. external UnnamedStruct4 unnamed;
  2398. @ffi.Array.multi([3])
  2399. external ffi.Array<ffi.Float> data;
  2400. }
  2401. final class UnnamedStruct4 extends ffi.Struct {
  2402. @ffi.Float()
  2403. external double x;
  2404. @ffi.Float()
  2405. external double y;
  2406. @ffi.Float()
  2407. external double z;
  2408. }
  2409. final class c11_mat3x3 extends ffi.Union {
  2410. external UnnamedStruct5 unnamed;
  2411. @ffi.Array.multi([3, 3])
  2412. external ffi.Array<ffi.Array<ffi.Float>> m;
  2413. @ffi.Array.multi([9])
  2414. external ffi.Array<ffi.Float> data;
  2415. }
  2416. final class UnnamedStruct5 extends ffi.Struct {
  2417. @ffi.Float()
  2418. external double _11;
  2419. @ffi.Float()
  2420. external double _12;
  2421. @ffi.Float()
  2422. external double _13;
  2423. @ffi.Float()
  2424. external double _21;
  2425. @ffi.Float()
  2426. external double _22;
  2427. @ffi.Float()
  2428. external double _23;
  2429. @ffi.Float()
  2430. external double _31;
  2431. @ffi.Float()
  2432. external double _32;
  2433. @ffi.Float()
  2434. external double _33;
  2435. }
  2436. final class py_TValue extends ffi.Opaque {}
  2437. /// A string view type. It is helpful for passing strings which are not null-terminated.
  2438. final class c11_sv extends ffi.Struct {
  2439. external ffi.Pointer<ffi.Char> data;
  2440. @ffi.Int()
  2441. external int size;
  2442. }
  2443. /// A struct contains the callbacks of the VM.
  2444. final class py_Callbacks extends ffi.Struct {
  2445. /// Used by `__import__` to load source code of a module.
  2446. external ffi.Pointer<
  2447. ffi.NativeFunction<
  2448. ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>> importfile;
  2449. /// Used by `print` to output a string.
  2450. external ffi
  2451. .Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Char>)>>
  2452. print;
  2453. }
  2454. /// Python compiler modes.
  2455. /// + `EXEC_MODE`: for statements.
  2456. /// + `EVAL_MODE`: for expressions.
  2457. /// + `SINGLE_MODE`: for REPL or jupyter notebook execution.
  2458. abstract class py_CompileMode {
  2459. static const int EXEC_MODE = 0;
  2460. static const int EVAL_MODE = 1;
  2461. static const int SINGLE_MODE = 2;
  2462. }
  2463. /// A generic reference to a python object.
  2464. typedef py_Ref = ffi.Pointer<py_TValue>;
  2465. /// An output reference for returning a value.
  2466. typedef py_OutRef = ffi.Pointer<py_TValue>;
  2467. /// A global reference which has the same lifespan as the VM.
  2468. typedef py_GlobalRef = ffi.Pointer<py_TValue>;
  2469. /// A 64-bit integer type. Corresponds to `int` in python.
  2470. typedef py_i64 = ffi.Int64;
  2471. /// A 64-bit floating-point type. Corresponds to `float` in python.
  2472. typedef py_f64 = ffi.Double;
  2473. /// Native function signature.
  2474. /// @param argc number of arguments.
  2475. /// @param argv array of arguments. Use `py_arg(i)` macro to get the i-th argument.
  2476. /// @return `true` if the function is successful or `false` if an exception is raised.
  2477. typedef py_CFunction = ffi.Pointer<
  2478. ffi.NativeFunction<ffi.Bool Function(ffi.Int argc, py_StackRef argv)>>;
  2479. /// A specific location in the value stack of the VM.
  2480. typedef py_StackRef = ffi.Pointer<py_TValue>;
  2481. /// An integer that represents a python identifier. This is to achieve string pooling and fast name
  2482. /// resolution.
  2483. typedef py_Name = ffi.Uint16;
  2484. /// An integer that represents a python type. `0` is invalid.
  2485. typedef py_Type = ffi.Int16;
  2486. /// A generic destructor function.
  2487. typedef py_Dtor
  2488. = ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>;
  2489. /// An item reference to a container object. It invalidates when the container is modified.
  2490. typedef py_ItemRef = ffi.Pointer<py_TValue>;
  2491. /// A reference which has the same lifespan as the python object.
  2492. typedef py_ObjectRef = ffi.Pointer<py_TValue>;
  2493. /// Python favored string formatting.
  2494. /// %d: int
  2495. /// %i: py_i64 (int64_t)
  2496. /// %f: py_f64 (double)
  2497. /// %s: const char*
  2498. /// %q: c11_sv
  2499. /// %v: c11_sv
  2500. /// %c: char
  2501. /// %p: void*
  2502. /// %t: py_Type
  2503. /// %n: py_Name
  2504. abstract class py_MagicNames {
  2505. /// 0 is reserved
  2506. static const int py_MagicNames__NULL = 0;
  2507. /// unary operators
  2508. static const int __repr__ = 1;
  2509. static const int __str__ = 2;
  2510. static const int __hash__ = 3;
  2511. static const int __len__ = 4;
  2512. static const int __iter__ = 5;
  2513. static const int __next__ = 6;
  2514. static const int __neg__ = 7;
  2515. static const int __invert__ = 8;
  2516. static const int __bool__ = 9;
  2517. /// logical operators
  2518. static const int __contains__ = 10;
  2519. /// //////////////////////////
  2520. static const int __eq__ = 11;
  2521. static const int __ne__ = 12;
  2522. static const int __lt__ = 13;
  2523. static const int __le__ = 14;
  2524. static const int __gt__ = 15;
  2525. static const int __ge__ = 16;
  2526. /// binary operators
  2527. static const int __add__ = 17;
  2528. static const int __radd__ = 18;
  2529. static const int __sub__ = 19;
  2530. static const int __rsub__ = 20;
  2531. static const int __mul__ = 21;
  2532. static const int __rmul__ = 22;
  2533. static const int __truediv__ = 23;
  2534. static const int __rtruediv__ = 24;
  2535. static const int __floordiv__ = 25;
  2536. static const int __rfloordiv__ = 26;
  2537. static const int __mod__ = 27;
  2538. static const int __rmod__ = 28;
  2539. static const int __pow__ = 29;
  2540. static const int __rpow__ = 30;
  2541. static const int __matmul__ = 31;
  2542. static const int __lshift__ = 32;
  2543. static const int __rshift__ = 33;
  2544. static const int __and__ = 34;
  2545. static const int __or__ = 35;
  2546. static const int __xor__ = 36;
  2547. /// //////////////////////////
  2548. /// indexer
  2549. static const int __getitem__ = 37;
  2550. static const int __setitem__ = 38;
  2551. static const int __delitem__ = 39;
  2552. /// specials
  2553. static const int __new__ = 40;
  2554. static const int __init__ = 41;
  2555. static const int __call__ = 42;
  2556. static const int __divmod__ = 43;
  2557. static const int __enter__ = 44;
  2558. static const int __exit__ = 45;
  2559. static const int __name__ = 46;
  2560. static const int __all__ = 47;
  2561. static const int __package__ = 48;
  2562. static const int __path__ = 49;
  2563. static const int __class__ = 50;
  2564. static const int __abs__ = 51;
  2565. static const int __getattr__ = 52;
  2566. static const int __missing__ = 53;
  2567. }
  2568. abstract class py_PredefinedTypes {
  2569. static const int tp_nil = 0;
  2570. static const int tp_object = 1;
  2571. /// py_Type
  2572. static const int tp_type = 2;
  2573. static const int tp_int = 3;
  2574. static const int tp_float = 4;
  2575. static const int tp_bool = 5;
  2576. static const int tp_str = 6;
  2577. static const int tp_str_iterator = 7;
  2578. /// c11_vector
  2579. static const int tp_list = 8;
  2580. /// N slots
  2581. static const int tp_tuple = 9;
  2582. static const int tp_array_iterator = 10;
  2583. /// 3 slots (start, stop, step)
  2584. static const int tp_slice = 11;
  2585. static const int tp_range = 12;
  2586. static const int tp_range_iterator = 13;
  2587. static const int tp_module = 14;
  2588. static const int tp_function = 15;
  2589. static const int tp_nativefunc = 16;
  2590. static const int tp_boundmethod = 17;
  2591. /// 1 slot + py_Type
  2592. static const int tp_super = 18;
  2593. /// 2 slots (arg + inner_exc)
  2594. static const int tp_BaseException = 19;
  2595. static const int tp_Exception = 20;
  2596. static const int tp_bytes = 21;
  2597. static const int tp_namedict = 22;
  2598. static const int tp_locals = 23;
  2599. static const int tp_code = 24;
  2600. static const int tp_dict = 25;
  2601. /// 1 slot
  2602. static const int tp_dict_items = 26;
  2603. /// 2 slots (getter + setter)
  2604. static const int tp_property = 27;
  2605. /// 1 slot + int level
  2606. static const int tp_star_wrapper = 28;
  2607. /// 1 slot
  2608. static const int tp_staticmethod = 29;
  2609. /// 1 slot
  2610. static const int tp_classmethod = 30;
  2611. static const int tp_NoneType = 31;
  2612. static const int tp_NotImplementedType = 32;
  2613. static const int tp_ellipsis = 33;
  2614. static const int tp_generator = 34;
  2615. /// builtin exceptions
  2616. static const int tp_SystemExit = 35;
  2617. static const int tp_KeyboardInterrupt = 36;
  2618. static const int tp_StopIteration = 37;
  2619. static const int tp_SyntaxError = 38;
  2620. static const int tp_StackOverflowError = 39;
  2621. static const int tp_IOError = 40;
  2622. static const int tp_OSError = 41;
  2623. static const int tp_NotImplementedError = 42;
  2624. static const int tp_TypeError = 43;
  2625. static const int tp_IndexError = 44;
  2626. static const int tp_ValueError = 45;
  2627. static const int tp_RuntimeError = 46;
  2628. static const int tp_ZeroDivisionError = 47;
  2629. static const int tp_NameError = 48;
  2630. static const int tp_UnboundLocalError = 49;
  2631. static const int tp_AttributeError = 50;
  2632. static const int tp_ImportError = 51;
  2633. static const int tp_AssertionError = 52;
  2634. static const int tp_KeyError = 53;
  2635. /// linalg
  2636. static const int tp_vec2 = 54;
  2637. static const int tp_vec3 = 55;
  2638. static const int tp_vec2i = 56;
  2639. static const int tp_vec3i = 57;
  2640. static const int tp_mat3x3 = 58;
  2641. /// array2d
  2642. static const int tp_array2d = 59;
  2643. static const int tp_array2d_iterator = 60;
  2644. }
  2645. const String PK_VERSION = '2.0.0';
  2646. const int PK_VERSION_MAJOR = 2;
  2647. const int PK_VERSION_MINOR = 0;
  2648. const int PK_VERSION_PATCH = 0;
  2649. const int PK_ENABLE_OS = 1;
  2650. const int PK_GC_MIN_THRESHOLD = 16384;
  2651. const int PK_DEBUG_CEVAL_STEP = 0;
  2652. const int PK_DEBUG_MEMORY_POOL = 0;
  2653. const int PK_DEBUG_NO_AUTO_GC = 0;
  2654. const int PK_DEBUG_GC_STATS = 0;
  2655. const int PK_DEBUG_COMPILER = 0;
  2656. const int PK_VM_STACK_SIZE = 16384;
  2657. const int PK_MAX_CO_VARNAMES = 64;
  2658. const int PK_PLATFORM_SEP = 47;
  2659. const int PY_SYS_PLATFORM = 3;
  2660. const String PY_SYS_PLATFORM_STRING = 'darwin';
  2661. const int PK_IS_DESKTOP_PLATFORM = 1;