diff --git a/amalgamate.py b/amalgamate.py index 9facee36..1688d558 100644 --- a/amalgamate.py +++ b/amalgamate.py @@ -154,6 +154,3 @@ if sys.platform in ['linux', 'darwin']: print("Test build success!") print("amalgamated/pocketpy.h") - -shutil.copy("amalgamated/pocketpy.h", "plugins/flutter/pocketpy/src/pocketpy.h") -shutil.copy("amalgamated/pocketpy.c", "plugins/flutter/pocketpy/src/pocketpy.c") \ No newline at end of file diff --git a/plugins/flutter/pocketpy/.gitignore b/plugins/flutter/pocketpy/.gitignore index 193c997e..ac5aa989 100644 --- a/plugins/flutter/pocketpy/.gitignore +++ b/plugins/flutter/pocketpy/.gitignore @@ -27,6 +27,3 @@ migrate_working_dir/ **/doc/api/ .dart_tool/ build/ - -src/pocketpy.h -src/pocketpy.c \ No newline at end of file diff --git a/plugins/flutter/pocketpy/example/.gitignore b/plugins/flutter/pocketpy/example/.gitignore index 29a3a501..79c113f9 100644 --- a/plugins/flutter/pocketpy/example/.gitignore +++ b/plugins/flutter/pocketpy/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/plugins/flutter/pocketpy/example/macos/Podfile.lock b/plugins/flutter/pocketpy/example/macos/Podfile.lock index 90513f54..b180369c 100644 --- a/plugins/flutter/pocketpy/example/macos/Podfile.lock +++ b/plugins/flutter/pocketpy/example/macos/Podfile.lock @@ -1,6 +1,6 @@ PODS: - FlutterMacOS (1.0.0) - - pocketpy (0.0.1): + - pocketpy (2.0.0): - FlutterMacOS DEPENDENCIES: @@ -15,7 +15,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 - pocketpy: aad616a188d342ec739a5ce7634f508d59b5cba1 + pocketpy: 99ce4fe9fc8cccfda3633f5599c2d8f802c6d5e8 PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 diff --git a/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/project.pbxproj b/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/project.pbxproj index 0a32042c..936d66f8 100644 --- a/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/project.pbxproj +++ b/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/project.pbxproj @@ -240,7 +240,6 @@ 33CC10EB2044A3C60003C045 /* Resources */, 33CC110E2044A8840003C045 /* Bundle Framework */, 3399D490228B24CF009A79C7 /* ShellScript */, - 8490AAF1431D28E951B5B8F7 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -383,23 +382,6 @@ shellPath = /bin/sh; shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; }; - 8490AAF1431D28E951B5B8F7 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; 887088EC4CE137E3DE87B445 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 0cf50e72..bcf1412c 100644 --- a/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/plugins/flutter/pocketpy/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -59,6 +59,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> diff --git a/plugins/flutter/pocketpy/example/macos/Runner/AppDelegate.swift b/plugins/flutter/pocketpy/example/macos/Runner/AppDelegate.swift index d53ef643..b3c17614 100644 --- a/plugins/flutter/pocketpy/example/macos/Runner/AppDelegate.swift +++ b/plugins/flutter/pocketpy/example/macos/Runner/AppDelegate.swift @@ -1,9 +1,13 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/plugins/flutter/pocketpy/example/pubspec.lock b/plugins/flutter/pocketpy/example/pubspec.lock index 4b068409..87345c15 100644 --- a/plugins/flutter/pocketpy/example/pubspec.lock +++ b/plugins/flutter/pocketpy/example/pubspec.lock @@ -5,42 +5,42 @@ packages: dependency: transitive description: name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 url: "https://pub.flutter-io.cn" source: hosted - version: "2.11.0" + version: "2.12.0" boolean_selector: dependency: transitive description: name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.1" + version: "2.1.2" characters: dependency: transitive description: name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0" + version: "1.4.0" clock: dependency: transitive description: name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.1" + version: "1.1.2" collection: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" url: "https://pub.flutter-io.cn" source: hosted - version: "1.18.0" + version: "1.19.1" cupertino_icons: dependency: "direct main" description: @@ -53,10 +53,10 @@ packages: dependency: transitive description: name: fake_async - sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc" url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.1" + version: "1.3.2" ffi: dependency: "direct main" description: @@ -87,18 +87,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec url: "https://pub.flutter-io.cn" source: hosted - version: "10.0.5" + version: "10.0.8" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573 url: "https://pub.flutter-io.cn" source: hosted - version: "3.0.5" + version: "3.0.9" leak_tracker_testing: dependency: transitive description: @@ -119,10 +119,10 @@ packages: dependency: transitive description: name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.16+1" + version: "0.12.17" material_color_utilities: dependency: transitive description: @@ -135,18 +135,18 @@ packages: dependency: transitive description: name: meta - sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.flutter-io.cn" source: hosted - version: "1.15.0" + version: "1.16.0" path: dependency: transitive description: name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.0" + version: "1.9.1" plugin_platform_interface: dependency: transitive description: @@ -161,60 +161,60 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "2.1.3" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" url: "https://pub.flutter-io.cn" source: hosted - version: "1.10.0" + version: "1.10.1" stack_trace: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" url: "https://pub.flutter-io.cn" source: hosted - version: "1.11.1" + version: "1.12.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.2" + version: "2.1.4" string_scanner: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0" + version: "1.4.1" term_glyph: dependency: transitive description: name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.2.2" test_api: dependency: transitive description: name: test_api - sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd url: "https://pub.flutter-io.cn" source: hosted - version: "0.7.2" + version: "0.7.4" vector_math: dependency: transitive description: @@ -227,10 +227,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14" url: "https://pub.flutter-io.cn" source: hosted - version: "14.2.5" + version: "14.3.1" sdks: - dart: ">=3.3.0 <4.0.0" + dart: ">=3.7.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/plugins/flutter/pocketpy/ffigen.yaml b/plugins/flutter/pocketpy/ffigen.yaml index ee177ae0..4d44d2f0 100644 --- a/plugins/flutter/pocketpy/ffigen.yaml +++ b/plugins/flutter/pocketpy/ffigen.yaml @@ -7,9 +7,9 @@ description: | output: 'lib/pocketpy_bindings_generated.dart' headers: entry-points: - - 'src/pocketpy.h' + - '../../../include/pocketpy.h' include-directives: - - 'src/pocketpy.h' + - '../../../include/pocketpy/*.h' preamble: | // ignore_for_file: always_specify_types // ignore_for_file: camel_case_types @@ -17,3 +17,6 @@ preamble: | comments: style: any length: full +compiler-opts: + - '-I../../../include' + - '-std=c11' diff --git a/plugins/flutter/pocketpy/ios/pocketpy.podspec b/plugins/flutter/pocketpy/ios/pocketpy.podspec index ce4fbd3b..79d327ef 100644 --- a/plugins/flutter/pocketpy/ios/pocketpy.podspec +++ b/plugins/flutter/pocketpy/ios/pocketpy.podspec @@ -4,14 +4,14 @@ # Pod::Spec.new do |s| s.name = 'pocketpy' - s.version = '0.0.1' + s.version = '2.0.0' s.summary = 'A new Flutter FFI plugin project.' s.description = <<-DESC A new Flutter FFI plugin project. DESC - s.homepage = 'http://example.com' + s.homepage = 'https://pocketpy.dev' s.license = { :file => '../LICENSE' } - s.author = { 'Your Company' => 'email@example.com' } + s.author = { 'blueloveTH' => 'blueloveth@foxmail.com' } # This will ensure the source files in Classes/ are included in the native # builds of apps using this FFI plugin. Podspec does not support relative @@ -20,7 +20,7 @@ A new Flutter FFI plugin project. s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.platform = :ios, '11.0' + s.platform = :ios, '13.0' # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } diff --git a/plugins/flutter/pocketpy/lib/pocketpy_bindings_generated.dart b/plugins/flutter/pocketpy/lib/pocketpy_bindings_generated.dart index f7c65960..c5b1ea93 100644 --- a/plugins/flutter/pocketpy/lib/pocketpy_bindings_generated.dart +++ b/plugins/flutter/pocketpy/lib/pocketpy_bindings_generated.dart @@ -113,6 +113,28 @@ class PocketpyBindings { late final _py_setvmctx = _py_setvmctxPtr.asFunction)>(); + /// Setup the callbacks for the current VM. + ffi.Pointer py_callbacks() { + return _py_callbacks(); + } + + late final _py_callbacksPtr = + _lookup Function()>>( + 'py_callbacks'); + late final _py_callbacks = + _py_callbacksPtr.asFunction Function()>(); + + /// Setup the application callbacks + ffi.Pointer py_appcallbacks() { + return _py_appcallbacks(); + } + + late final _py_appcallbacksPtr = + _lookup Function()>>( + 'py_appcallbacks'); + late final _py_appcallbacks = + _py_appcallbacksPtr.asFunction Function()>(); + /// Set `sys.argv`. Used for storing command-line arguments. void py_sys_setargv( int argc, @@ -157,17 +179,6 @@ class PocketpyBindings { _lookup>('py_gc_collect'); late final _py_gc_collect = _py_gc_collectPtr.asFunction(); - /// Setup the callbacks for the current VM. - ffi.Pointer py_callbacks() { - return _py_callbacks(); - } - - late final _py_callbacksPtr = - _lookup Function()>>( - 'py_callbacks'); - late final _py_callbacks = - _py_callbacksPtr.asFunction Function()>(); - /// Wrapper for `PK_MALLOC(size)`. ffi.Pointer py_malloc( int size, @@ -216,65 +227,41 @@ class PocketpyBindings { late final _py_free = _py_freePtr.asFunction)>(); - /// Begin the watchdog with `timeout` in milliseconds. - /// `PK_ENABLE_WATCHDOG` must be defined to `1` to use this feature. - /// You need to call `py_watchdog_end()` later. - /// If `timeout` is reached, `TimeoutError` will be raised. - void py_watchdog_begin( - int timeout, - ) { - return _py_watchdog_begin( - timeout, - ); + /// A shorthand for `True`. + py_GlobalRef py_True() { + return _py_True(); } - late final _py_watchdog_beginPtr = - _lookup>( - 'py_watchdog_begin'); - late final _py_watchdog_begin = - _py_watchdog_beginPtr.asFunction(); + late final _py_TruePtr = + _lookup>('py_True'); + late final _py_True = _py_TruePtr.asFunction(); - /// Reset the watchdog. - void py_watchdog_end() { - return _py_watchdog_end(); + /// A shorthand for `False`. + py_GlobalRef py_False() { + return _py_False(); } - late final _py_watchdog_endPtr = - _lookup>('py_watchdog_end'); - late final _py_watchdog_end = - _py_watchdog_endPtr.asFunction(); + late final _py_FalsePtr = + _lookup>('py_False'); + late final _py_False = _py_FalsePtr.asFunction(); - /// Bind a compile-time function via "decl-based" style. - void py_macrobind( - ffi.Pointer sig, - py_CFunction f, - ) { - return _py_macrobind( - sig, - f, - ); + /// A shorthand for `None`. + py_GlobalRef py_None() { + return _py_None(); } - late final _py_macrobindPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, py_CFunction)>>('py_macrobind'); - late final _py_macrobind = _py_macrobindPtr - .asFunction, py_CFunction)>(); + late final _py_NonePtr = + _lookup>('py_None'); + late final _py_None = _py_NonePtr.asFunction(); - /// Get a compile-time function by name. - py_ItemRef py_macroget( - py_Name name, - ) { - return _py_macroget( - name, - ); + /// A shorthand for `nil`. `nil` is not a valid python object. + py_GlobalRef py_NIL() { + return _py_NIL(); } - late final _py_macrogetPtr = - _lookup>('py_macroget'); - late final _py_macroget = - _py_macrogetPtr.asFunction(); + late final _py_NILPtr = + _lookup>('py_NIL'); + late final _py_NIL = _py_NILPtr.asFunction(); /// Get the current source location of the frame. ffi.Pointer py_Frame_sourceloc( @@ -347,6 +334,29 @@ class PocketpyBindings { late final _py_Frame_function = _py_Frame_functionPtr .asFunction)>(); + /// Compile a source string into a code object. + /// Use python's `exec()` or `eval()` to execute it. + bool py_compile( + ffi.Pointer source, + ffi.Pointer filename, + int mode, + bool is_dynamic, + ) { + return _py_compile( + source, + filename, + mode, + is_dynamic, + ); + } + + late final _py_compilePtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(ffi.Pointer, ffi.Pointer, + ffi.Int32, ffi.Bool)>>('py_compile'); + late final _py_compile = _py_compilePtr.asFunction< + bool Function(ffi.Pointer, ffi.Pointer, int, bool)>(); + /// Run a source string. /// @param source source string. /// @param filename filename (for error messages). @@ -436,94 +446,6 @@ class PocketpyBindings { late final _py_smarteval = _py_smartevalPtr .asFunction, py_Ref)>(); - /// Compile a source string into a code object. - /// Use python's `exec()` or `eval()` to execute it. - bool py_compile( - ffi.Pointer source, - ffi.Pointer filename, - int mode, - bool is_dynamic, - ) { - return _py_compile( - source, - filename, - mode, - is_dynamic, - ); - } - - late final _py_compilePtr = _lookup< - ffi.NativeFunction< - ffi.Bool Function(ffi.Pointer, ffi.Pointer, - ffi.Int32, ffi.Bool)>>('py_compile'); - late final _py_compile = _py_compilePtr.asFunction< - bool Function(ffi.Pointer, ffi.Pointer, int, bool)>(); - - /// Python equivalent to `globals()`. - void py_newglobals( - py_OutRef arg0, - ) { - return _py_newglobals( - arg0, - ); - } - - late final _py_newglobalsPtr = - _lookup>( - 'py_newglobals'); - late final _py_newglobals = - _py_newglobalsPtr.asFunction(); - - /// Python equivalent to `locals()`. - void py_newlocals( - py_OutRef arg0, - ) { - return _py_newlocals( - arg0, - ); - } - - late final _py_newlocalsPtr = - _lookup>('py_newlocals'); - late final _py_newlocals = - _py_newlocalsPtr.asFunction(); - - /// A shorthand for `True`. - py_GlobalRef py_True() { - return _py_True(); - } - - late final _py_TruePtr = - _lookup>('py_True'); - late final _py_True = _py_TruePtr.asFunction(); - - /// A shorthand for `False`. - py_GlobalRef py_False() { - return _py_False(); - } - - late final _py_FalsePtr = - _lookup>('py_False'); - late final _py_False = _py_FalsePtr.asFunction(); - - /// A shorthand for `None`. - py_GlobalRef py_None() { - return _py_None(); - } - - late final _py_NonePtr = - _lookup>('py_None'); - late final _py_None = _py_NonePtr.asFunction(); - - /// A shorthand for `nil`. `nil` is not a valid python object. - py_GlobalRef py_NIL() { - return _py_NIL(); - } - - late final _py_NILPtr = - _lookup>('py_NIL'); - late final _py_NIL = _py_NILPtr.asFunction(); - /// Create an `int` object. void py_newint( py_OutRef arg0, @@ -741,85 +663,6 @@ class PocketpyBindings { _lookup>('py_newnil'); late final _py_newnil = _py_newnilPtr.asFunction(); - /// Create a `tuple` with `n` UNINITIALIZED elements. - /// You should initialize all elements before using it. - py_ObjectRef py_newtuple( - py_OutRef arg0, - int n, - ) { - return _py_newtuple( - arg0, - n, - ); - } - - late final _py_newtuplePtr = - _lookup>( - 'py_newtuple'); - late final _py_newtuple = - _py_newtuplePtr.asFunction(); - - /// Create an empty `list`. - void py_newlist( - py_OutRef arg0, - ) { - return _py_newlist( - arg0, - ); - } - - late final _py_newlistPtr = - _lookup>('py_newlist'); - late final _py_newlist = - _py_newlistPtr.asFunction(); - - /// Create a `list` with `n` UNINITIALIZED elements. - /// You should initialize all elements before using it. - void py_newlistn( - py_OutRef arg0, - int n, - ) { - return _py_newlistn( - arg0, - n, - ); - } - - late final _py_newlistnPtr = - _lookup>( - 'py_newlistn'); - late final _py_newlistn = - _py_newlistnPtr.asFunction(); - - /// Create an empty `dict`. - void py_newdict( - py_OutRef arg0, - ) { - return _py_newdict( - arg0, - ); - } - - late final _py_newdictPtr = - _lookup>('py_newdict'); - late final _py_newdict = - _py_newdictPtr.asFunction(); - - /// Create an UNINITIALIZED `slice` object. - /// You should use `py_setslot()` to set `start`, `stop`, and `step`. - void py_newslice( - py_OutRef arg0, - ) { - return _py_newslice( - arg0, - ); - } - - late final _py_newslicePtr = - _lookup>('py_newslice'); - late final _py_newslice = - _py_newslicePtr.asFunction(); - /// Create a `nativefunc` object. void py_newnativefunc( py_OutRef arg0, @@ -881,6 +724,33 @@ class PocketpyBindings { late final _py_newboundmethod = _py_newboundmethodPtr .asFunction(); + /// Create a new object. + /// @param out output reference. + /// @param type type of the object. + /// @param slots number of slots. Use `-1` to create a `__dict__`. + /// @param udsize size of your userdata. + /// @return pointer to the userdata. + ffi.Pointer py_newobject( + py_OutRef out, + int type, + int slots, + int udsize, + ) { + return _py_newobject( + out, + type, + slots, + udsize, + ); + } + + late final _py_newobjectPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + py_OutRef, py_Type, ffi.Int, ffi.Int)>>('py_newobject'); + late final _py_newobject = _py_newobjectPtr + .asFunction Function(py_OutRef, int, int, int)>(); + /// Convert a null-terminated string to a name. py_Name py_name( ffi.Pointer arg0, @@ -953,58 +823,174 @@ class PocketpyBindings { late final _py_name2sv = _py_name2svPtr.asFunction(); - /// Create a new type. - /// @param name name of the type. - /// @param base base type. - /// @param module module where the type is defined. Use `NULL` for built-in types. - /// @param dtor destructor function. Use `NULL` if not needed. - int py_newtype( - ffi.Pointer name, - int base, - py_GlobalRef module, - py_Dtor dtor, + /// Bind a function to the object via "decl-based" style. + /// @param obj the target object. + /// @param sig signature of the function. e.g. `add(x, y)`. + /// @param f function to bind. + void py_bind( + py_Ref obj, + ffi.Pointer sig, + py_CFunction f, ) { - return _py_newtype( - name, - base, - module, - dtor, + return _py_bind( + obj, + sig, + f, ); } - late final _py_newtypePtr = _lookup< + late final _py_bindPtr = _lookup< ffi.NativeFunction< - py_Type Function(ffi.Pointer, py_Type, py_GlobalRef, - py_Dtor)>>('py_newtype'); - late final _py_newtype = _py_newtypePtr.asFunction< - int Function(ffi.Pointer, int, py_GlobalRef, py_Dtor)>(); + ffi.Void Function( + py_Ref, ffi.Pointer, py_CFunction)>>('py_bind'); + late final _py_bind = _py_bindPtr + .asFunction, py_CFunction)>(); - /// Create a new object. - /// @param out output reference. - /// @param type type of the object. - /// @param slots number of slots. Use `-1` to create a `__dict__`. - /// @param udsize size of your userdata. - /// @return pointer to the userdata. - ffi.Pointer py_newobject( - py_OutRef out, + /// Bind a method to type via "argc-based" style. + /// @param type the target type. + /// @param name name of the method. + /// @param f function to bind. + void py_bindmethod( int type, - int slots, - int udsize, + ffi.Pointer name, + py_CFunction f, ) { - return _py_newobject( - out, + return _py_bindmethod( type, - slots, - udsize, + name, + f, ); } - late final _py_newobjectPtr = _lookup< + late final _py_bindmethodPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function( - py_OutRef, py_Type, ffi.Int, ffi.Int)>>('py_newobject'); - late final _py_newobject = _py_newobjectPtr - .asFunction Function(py_OutRef, int, int, int)>(); + ffi.Void Function( + py_Type, ffi.Pointer, py_CFunction)>>('py_bindmethod'); + late final _py_bindmethod = _py_bindmethodPtr + .asFunction, py_CFunction)>(); + + /// Bind a static method to type via "argc-based" style. + /// @param type the target type. + /// @param name name of the method. + /// @param f function to bind. + void py_bindstaticmethod( + int type, + ffi.Pointer name, + py_CFunction f, + ) { + return _py_bindstaticmethod( + type, + name, + f, + ); + } + + late final _py_bindstaticmethodPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(py_Type, ffi.Pointer, + py_CFunction)>>('py_bindstaticmethod'); + late final _py_bindstaticmethod = _py_bindstaticmethodPtr + .asFunction, py_CFunction)>(); + + /// Bind a function to the object via "argc-based" style. + /// @param obj the target object. + /// @param name name of the function. + /// @param f function to bind. + void py_bindfunc( + py_Ref obj, + ffi.Pointer name, + py_CFunction f, + ) { + return _py_bindfunc( + obj, + name, + f, + ); + } + + late final _py_bindfuncPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + py_Ref, ffi.Pointer, py_CFunction)>>('py_bindfunc'); + late final _py_bindfunc = _py_bindfuncPtr + .asFunction, py_CFunction)>(); + + /// Bind a property to type. + /// @param type the target type. + /// @param name name of the property. + /// @param getter getter function. + /// @param setter setter function. Use `NULL` if not needed. + void py_bindproperty( + int type, + ffi.Pointer name, + py_CFunction getter, + py_CFunction setter, + ) { + return _py_bindproperty( + type, + name, + getter, + setter, + ); + } + + late final _py_bindpropertyPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(py_Type, ffi.Pointer, py_CFunction, + py_CFunction)>>('py_bindproperty'); + late final _py_bindproperty = _py_bindpropertyPtr.asFunction< + void Function(int, ffi.Pointer, py_CFunction, py_CFunction)>(); + + /// Bind a magic method to type. + void py_bindmagic( + int type, + py_Name name, + py_CFunction f, + ) { + return _py_bindmagic( + type, + name, + f, + ); + } + + late final _py_bindmagicPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function(py_Type, py_Name, py_CFunction)>>('py_bindmagic'); + late final _py_bindmagic = + _py_bindmagicPtr.asFunction(); + + /// Bind a compile-time function via "decl-based" style. + void py_macrobind( + ffi.Pointer sig, + py_CFunction f, + ) { + return _py_macrobind( + sig, + f, + ); + } + + late final _py_macrobindPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, py_CFunction)>>('py_macrobind'); + late final _py_macrobind = _py_macrobindPtr + .asFunction, py_CFunction)>(); + + /// Get a compile-time function by name. + py_ItemRef py_macroget( + py_Name name, + ) { + return _py_macroget( + name, + ); + } + + late final _py_macrogetPtr = + _lookup>('py_macroget'); + late final _py_macroget = + _py_macrogetPtr.asFunction(); /// Convert an `int` object in python to `int64_t`. int py_toint( @@ -1019,7 +1005,7 @@ class PocketpyBindings { _lookup>('py_toint'); late final _py_toint = _py_tointPtr.asFunction(); - /// Get the address of the trivial value object. + /// Get the address of the trivial value object (16 bytes). ffi.Pointer py_totrivial( py_Ref arg0, ) { @@ -1126,6 +1112,21 @@ class PocketpyBindings { _lookup>('py_totype'); late final _py_totype = _py_totypePtr.asFunction(); + /// Convert a user-defined object to its userdata. + ffi.Pointer py_touserdata( + py_Ref arg0, + ) { + return _py_touserdata( + arg0, + ); + } + + late final _py_touserdataPtr = + _lookup Function(py_Ref)>>( + 'py_touserdata'); + late final _py_touserdata = + _py_touserdataPtr.asFunction Function(py_Ref)>(); + /// Convert a `str` object in python to null-terminated string. ffi.Pointer py_tostr( py_Ref arg0, @@ -1207,51 +1208,31 @@ class PocketpyBindings { late final _py_bytes_resize = _py_bytes_resizePtr.asFunction(); - /// Convert a user-defined object to its userdata. - ffi.Pointer py_touserdata( - py_Ref arg0, + /// Create a new type. + /// @param name name of the type. + /// @param base base type. + /// @param module module where the type is defined. Use `NULL` for built-in types. + /// @param dtor destructor function. Use `NULL` if not needed. + int py_newtype( + ffi.Pointer name, + int base, + py_GlobalRef module, + py_Dtor dtor, ) { - return _py_touserdata( - arg0, - ); - } - - late final _py_touserdataPtr = - _lookup Function(py_Ref)>>( - 'py_touserdata'); - late final _py_touserdata = - _py_touserdataPtr.asFunction Function(py_Ref)>(); - - /// Get the type of the object. - int py_typeof( - py_Ref self, - ) { - return _py_typeof( - self, - ); - } - - late final _py_typeofPtr = - _lookup>('py_typeof'); - late final _py_typeof = _py_typeofPtr.asFunction(); - - /// Get type by module and name. e.g. `py_gettype("time", py_name("struct_time"))`. - /// Return `0` if not found. - int py_gettype( - ffi.Pointer module, - py_Name name, - ) { - return _py_gettype( - module, + return _py_newtype( name, + base, + module, + dtor, ); } - late final _py_gettypePtr = _lookup< - ffi.NativeFunction, py_Name)>>( - 'py_gettype'); - late final _py_gettype = - _py_gettypePtr.asFunction, py_Name)>(); + late final _py_newtypePtr = _lookup< + ffi.NativeFunction< + py_Type Function(ffi.Pointer, py_Type, py_GlobalRef, + py_Dtor)>>('py_newtype'); + late final _py_newtype = _py_newtypePtr.asFunction< + int Function(ffi.Pointer, int, py_GlobalRef, py_Dtor)>(); /// Check if the object is exactly the given type. bool py_istype( @@ -1270,6 +1251,19 @@ class PocketpyBindings { late final _py_istype = _py_istypePtr.asFunction(); + /// Get the type of the object. + int py_typeof( + py_Ref self, + ) { + return _py_typeof( + self, + ); + } + + late final _py_typeofPtr = + _lookup>('py_typeof'); + late final _py_typeof = _py_typeofPtr.asFunction(); + /// Check if the object is an instance of the given type. bool py_isinstance( py_Ref obj, @@ -1304,6 +1298,60 @@ class PocketpyBindings { late final _py_issubclass = _py_issubclassPtr.asFunction(); + /// Get type by module and name. e.g. `py_gettype("time", py_name("struct_time"))`. + /// Return `0` if not found. + int py_gettype( + ffi.Pointer module, + py_Name name, + ) { + return _py_gettype( + module, + name, + ); + } + + late final _py_gettypePtr = _lookup< + ffi.NativeFunction, py_Name)>>( + 'py_gettype'); + late final _py_gettype = + _py_gettypePtr.asFunction, py_Name)>(); + + /// Check if the object is an instance of the given type exactly. + /// Raise `TypeError` if the check fails. + bool py_checktype( + py_Ref self, + int type, + ) { + return _py_checktype( + self, + type, + ); + } + + late final _py_checktypePtr = + _lookup>( + 'py_checktype'); + late final _py_checktype = + _py_checktypePtr.asFunction(); + + /// Check if the object is an instance of the given type or its subclass. + /// Raise `TypeError` if the check fails. + bool py_checkinstance( + py_Ref self, + int type, + ) { + return _py_checkinstance( + self, + type, + ); + } + + late final _py_checkinstancePtr = + _lookup>( + 'py_checkinstance'); + late final _py_checkinstance = + _py_checkinstancePtr.asFunction(); + /// Get the magic method from the given type only. /// Return `nil` if not found. py_GlobalRef py_tpgetmagic( @@ -1401,25 +1449,6 @@ class PocketpyBindings { late final _py_tpname = _py_tpnamePtr.asFunction Function(int)>(); - /// Call a type to create a new instance. - bool py_tpcall( - int type, - int argc, - py_Ref argv, - ) { - return _py_tpcall( - type, - argc, - argv, - ); - } - - late final _py_tpcallPtr = - _lookup>( - 'py_tpcall'); - late final _py_tpcall = - _py_tpcallPtr.asFunction(); - /// Disable the type for subclassing. void py_tpsetfinal( int type, @@ -1492,41 +1521,71 @@ class PocketpyBindings { ffi.NativeFunction< ffi.Bool Function(py_Ref self, py_Name name)>>)>(); - /// Check if the object is an instance of the given type exactly. - /// Raise `TypeError` if the check fails. - bool py_checktype( - py_Ref self, - int type, + /// Get the current `function` object on the stack. + /// Return `NULL` if not available. + /// NOTE: This function should be placed at the beginning of your decl-based bindings. + py_StackRef py_inspect_currentfunction() { + return _py_inspect_currentfunction(); + } + + late final _py_inspect_currentfunctionPtr = + _lookup>( + 'py_inspect_currentfunction'); + late final _py_inspect_currentfunction = + _py_inspect_currentfunctionPtr.asFunction(); + + /// Get the current `module` object where the code is executed. + /// Return `NULL` if not available. + py_GlobalRef py_inspect_currentmodule() { + return _py_inspect_currentmodule(); + } + + late final _py_inspect_currentmodulePtr = + _lookup>( + 'py_inspect_currentmodule'); + late final _py_inspect_currentmodule = + _py_inspect_currentmodulePtr.asFunction(); + + /// Get the current frame object. + /// Return `NULL` if not available. + ffi.Pointer py_inspect_currentframe() { + return _py_inspect_currentframe(); + } + + late final _py_inspect_currentframePtr = + _lookup Function()>>( + 'py_inspect_currentframe'); + late final _py_inspect_currentframe = _py_inspect_currentframePtr + .asFunction Function()>(); + + /// Python equivalent to `globals()`. + void py_newglobals( + py_OutRef arg0, ) { - return _py_checktype( - self, - type, + return _py_newglobals( + arg0, ); } - late final _py_checktypePtr = - _lookup>( - 'py_checktype'); - late final _py_checktype = - _py_checktypePtr.asFunction(); + late final _py_newglobalsPtr = + _lookup>( + 'py_newglobals'); + late final _py_newglobals = + _py_newglobalsPtr.asFunction(); - /// Check if the object is an instance of the given type or its subclass. - /// Raise `TypeError` if the check fails. - bool py_checkinstance( - py_Ref self, - int type, + /// Python equivalent to `locals()`. + void py_newlocals( + py_OutRef arg0, ) { - return _py_checkinstance( - self, - type, + return _py_newlocals( + arg0, ); } - late final _py_checkinstancePtr = - _lookup>( - 'py_checkinstance'); - late final _py_checkinstance = - _py_checkinstancePtr.asFunction(); + late final _py_newlocalsPtr = + _lookup>('py_newlocals'); + late final _py_newlocals = + _py_newlocalsPtr.asFunction(); /// Get the i-th register. /// All registers are located in a contiguous memory. @@ -1560,52 +1619,6 @@ class PocketpyBindings { late final _py_setreg = _py_setregPtr.asFunction(); - /// Get variable in the `__main__` module. - py_ItemRef py_getglobal( - py_Name name, - ) { - return _py_getglobal( - name, - ); - } - - late final _py_getglobalPtr = - _lookup>('py_getglobal'); - late final _py_getglobal = - _py_getglobalPtr.asFunction(); - - /// Set variable in the `__main__` module. - void py_setglobal( - py_Name name, - py_Ref val, - ) { - return _py_setglobal( - name, - val, - ); - } - - late final _py_setglobalPtr = - _lookup>( - 'py_setglobal'); - late final _py_setglobal = - _py_setglobalPtr.asFunction(); - - /// Get variable in the `builtins` module. - py_ItemRef py_getbuiltin( - py_Name name, - ) { - return _py_getbuiltin( - name, - ); - } - - late final _py_getbuiltinPtr = - _lookup>( - 'py_getbuiltin'); - late final _py_getbuiltin = - _py_getbuiltinPtr.asFunction(); - /// Get the last return value. /// Please note that `py_retval()` cannot be used as input argument. py_GlobalRef py_retval() { @@ -1776,285 +1789,261 @@ class PocketpyBindings { late final _py_setslot = _py_setslotPtr.asFunction(); - /// Get the current `function` object on the stack. - /// Return `NULL` if not available. - /// NOTE: This function should be placed at the beginning of your decl-based bindings. - py_StackRef py_inspect_currentfunction() { - return _py_inspect_currentfunction(); - } - - late final _py_inspect_currentfunctionPtr = - _lookup>( - 'py_inspect_currentfunction'); - late final _py_inspect_currentfunction = - _py_inspect_currentfunctionPtr.asFunction(); - - /// Get the current `module` object where the code is executed. - /// Return `NULL` if not available. - py_GlobalRef py_inspect_currentmodule() { - return _py_inspect_currentmodule(); - } - - late final _py_inspect_currentmodulePtr = - _lookup>( - 'py_inspect_currentmodule'); - late final _py_inspect_currentmodule = - _py_inspect_currentmodulePtr.asFunction(); - - /// Get the current frame object. - /// Return `NULL` if not available. - ffi.Pointer py_inspect_currentframe() { - return _py_inspect_currentframe(); - } - - late final _py_inspect_currentframePtr = - _lookup Function()>>( - 'py_inspect_currentframe'); - late final _py_inspect_currentframe = _py_inspect_currentframePtr - .asFunction Function()>(); - - /// Bind a function to the object via "decl-based" style. - /// @param obj the target object. - /// @param sig signature of the function. e.g. `add(x, y)`. - /// @param f function to bind. - void py_bind( - py_Ref obj, - ffi.Pointer sig, - py_CFunction f, - ) { - return _py_bind( - obj, - sig, - f, - ); - } - - late final _py_bindPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - py_Ref, ffi.Pointer, py_CFunction)>>('py_bind'); - late final _py_bind = _py_bindPtr - .asFunction, py_CFunction)>(); - - /// Bind a method to type via "argc-based" style. - /// @param type the target type. - /// @param name name of the method. - /// @param f function to bind. - void py_bindmethod( - int type, - ffi.Pointer name, - py_CFunction f, - ) { - return _py_bindmethod( - type, - name, - f, - ); - } - - late final _py_bindmethodPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - py_Type, ffi.Pointer, py_CFunction)>>('py_bindmethod'); - late final _py_bindmethod = _py_bindmethodPtr - .asFunction, py_CFunction)>(); - - /// Bind a static method to type via "argc-based" style. - /// @param type the target type. - /// @param name name of the method. - /// @param f function to bind. - void py_bindstaticmethod( - int type, - ffi.Pointer name, - py_CFunction f, - ) { - return _py_bindstaticmethod( - type, - name, - f, - ); - } - - late final _py_bindstaticmethodPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(py_Type, ffi.Pointer, - py_CFunction)>>('py_bindstaticmethod'); - late final _py_bindstaticmethod = _py_bindstaticmethodPtr - .asFunction, py_CFunction)>(); - - /// Bind a function to the object via "argc-based" style. - /// @param obj the target object. - /// @param name name of the function. - /// @param f function to bind. - void py_bindfunc( - py_Ref obj, - ffi.Pointer name, - py_CFunction f, - ) { - return _py_bindfunc( - obj, - name, - f, - ); - } - - late final _py_bindfuncPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - py_Ref, ffi.Pointer, py_CFunction)>>('py_bindfunc'); - late final _py_bindfunc = _py_bindfuncPtr - .asFunction, py_CFunction)>(); - - /// Bind a property to type. - /// @param type the target type. - /// @param name name of the property. - /// @param getter getter function. - /// @param setter setter function. Use `NULL` if not needed. - void py_bindproperty( - int type, - ffi.Pointer name, - py_CFunction getter, - py_CFunction setter, - ) { - return _py_bindproperty( - type, - name, - getter, - setter, - ); - } - - late final _py_bindpropertyPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(py_Type, ffi.Pointer, py_CFunction, - py_CFunction)>>('py_bindproperty'); - late final _py_bindproperty = _py_bindpropertyPtr.asFunction< - void Function(int, ffi.Pointer, py_CFunction, py_CFunction)>(); - - /// Bind a magic method to type. - void py_bindmagic( - int type, - py_Name name, - py_CFunction f, - ) { - return _py_bindmagic( - type, - name, - f, - ); - } - - late final _py_bindmagicPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(py_Type, py_Name, py_CFunction)>>('py_bindmagic'); - late final _py_bindmagic = - _py_bindmagicPtr.asFunction(); - - /// Python equivalent to `getattr(self, name)`. - bool py_getattr( - py_Ref self, + /// Get variable in the `builtins` module. + py_ItemRef py_getbuiltin( py_Name name, ) { - return _py_getattr( - self, + return _py_getbuiltin( name, ); } - late final _py_getattrPtr = - _lookup>( - 'py_getattr'); - late final _py_getattr = - _py_getattrPtr.asFunction(); + late final _py_getbuiltinPtr = + _lookup>( + 'py_getbuiltin'); + late final _py_getbuiltin = + _py_getbuiltinPtr.asFunction(); - /// Python equivalent to `setattr(self, name, val)`. - bool py_setattr( - py_Ref self, + /// Get variable in the `__main__` module. + py_ItemRef py_getglobal( + py_Name name, + ) { + return _py_getglobal( + name, + ); + } + + late final _py_getglobalPtr = + _lookup>('py_getglobal'); + late final _py_getglobal = + _py_getglobalPtr.asFunction(); + + /// Set variable in the `__main__` module. + void py_setglobal( py_Name name, py_Ref val, ) { - return _py_setattr( - self, + return _py_setglobal( name, val, ); } - late final _py_setattrPtr = - _lookup>( - 'py_setattr'); - late final _py_setattr = - _py_setattrPtr.asFunction(); + late final _py_setglobalPtr = + _lookup>( + 'py_setglobal'); + late final _py_setglobal = + _py_setglobalPtr.asFunction(); - /// Python equivalent to `delattr(self, name)`. - bool py_delattr( - py_Ref self, + /// Get the i-th object from the top of the stack. + /// `i` should be negative, e.g. (-1) means TOS. + py_StackRef py_peek( + int i, + ) { + return _py_peek( + i, + ); + } + + late final _py_peekPtr = + _lookup>('py_peek'); + late final _py_peek = _py_peekPtr.asFunction(); + + /// Push the object to the stack. + void py_push( + py_Ref src, + ) { + return _py_push( + src, + ); + } + + late final _py_pushPtr = + _lookup>('py_push'); + late final _py_push = _py_pushPtr.asFunction(); + + /// Push a `nil` object to the stack. + void py_pushnil() { + return _py_pushnil(); + } + + late final _py_pushnilPtr = + _lookup>('py_pushnil'); + late final _py_pushnil = _py_pushnilPtr.asFunction(); + + /// Push a `None` object to the stack. + void py_pushnone() { + return _py_pushnone(); + } + + late final _py_pushnonePtr = + _lookup>('py_pushnone'); + late final _py_pushnone = _py_pushnonePtr.asFunction(); + + /// Push a `py_Name` to the stack. This is used for keyword arguments. + void py_pushname( py_Name name, ) { - return _py_delattr( - self, + return _py_pushname( name, ); } - late final _py_delattrPtr = - _lookup>( - 'py_delattr'); - late final _py_delattr = - _py_delattrPtr.asFunction(); + late final _py_pushnamePtr = + _lookup>('py_pushname'); + late final _py_pushname = + _py_pushnamePtr.asFunction(); - /// Python equivalent to `self[key]`. - bool py_getitem( - py_Ref self, - py_Ref key, + /// Pop an object from the stack. + void py_pop() { + return _py_pop(); + } + + late final _py_popPtr = + _lookup>('py_pop'); + late final _py_pop = _py_popPtr.asFunction(); + + /// Shrink the stack by n. + void py_shrink( + int n, ) { - return _py_getitem( - self, - key, + return _py_shrink( + n, ); } - late final _py_getitemPtr = - _lookup>( - 'py_getitem'); - late final _py_getitem = - _py_getitemPtr.asFunction(); + late final _py_shrinkPtr = + _lookup>('py_shrink'); + late final _py_shrink = _py_shrinkPtr.asFunction(); - /// Python equivalent to `self[key] = val`. - bool py_setitem( - py_Ref self, - py_Ref key, - py_Ref val, + /// Get a temporary variable from the stack. + py_StackRef py_pushtmp() { + return _py_pushtmp(); + } + + late final _py_pushtmpPtr = + _lookup>('py_pushtmp'); + late final _py_pushtmp = _py_pushtmpPtr.asFunction(); + + /// Get the unbound method of the object. + /// Assume the object is located at the top of the stack. + /// If return true: `[self] -> [unbound, self]`. + /// If return false: `[self] -> [self]` (no change). + bool py_pushmethod( + py_Name name, ) { - return _py_setitem( - self, - key, - val, + return _py_pushmethod( + name, ); } - late final _py_setitemPtr = - _lookup>( - 'py_setitem'); - late final _py_setitem = - _py_setitemPtr.asFunction(); + late final _py_pushmethodPtr = + _lookup>('py_pushmethod'); + late final _py_pushmethod = + _py_pushmethodPtr.asFunction(); - /// Python equivalent to `del self[key]`. - bool py_delitem( - py_Ref self, - py_Ref key, + /// Evaluate an expression and push the result to the stack. + /// This function is used for testing. + bool py_pusheval( + ffi.Pointer expr, + py_GlobalRef module, ) { - return _py_delitem( - self, - key, + return _py_pusheval( + expr, + module, ); } - late final _py_delitemPtr = - _lookup>( - 'py_delitem'); - late final _py_delitem = - _py_delitemPtr.asFunction(); + late final _py_pushevalPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function( + ffi.Pointer, py_GlobalRef)>>('py_pusheval'); + late final _py_pusheval = _py_pushevalPtr + .asFunction, py_GlobalRef)>(); + + /// Call a callable object via pocketpy's calling convention. + /// You need to prepare the stack using the following format: + /// `callable, self/nil, arg1, arg2, ..., k1, v1, k2, v2, ...`. + /// `argc` is the number of positional arguments excluding `self`. + /// `kwargc` is the number of keyword arguments. + /// The result will be set to `py_retval()`. + /// The stack size will be reduced by `2 + argc + kwargc * 2`. + bool py_vectorcall( + int argc, + int kwargc, + ) { + return _py_vectorcall( + argc, + kwargc, + ); + } + + late final _py_vectorcallPtr = + _lookup>( + 'py_vectorcall'); + late final _py_vectorcall = + _py_vectorcallPtr.asFunction(); + + /// Call a function. + /// It prepares the stack and then performs a `vectorcall(argc, 0, false)`. + /// The result will be set to `py_retval()`. + /// The stack remains unchanged if successful. + bool py_call( + py_Ref f, + int argc, + py_Ref argv, + ) { + return _py_call( + f, + argc, + argv, + ); + } + + late final _py_callPtr = + _lookup>( + 'py_call'); + late final _py_call = + _py_callPtr.asFunction(); + + /// Call a type to create a new instance. + bool py_tpcall( + int type, + int argc, + py_Ref argv, + ) { + return _py_tpcall( + type, + argc, + argv, + ); + } + + late final _py_tpcallPtr = + _lookup>( + 'py_tpcall'); + late final _py_tpcall = + _py_tpcallPtr.asFunction(); + + /// Call a `py_CFunction` in a safe way. + /// This function does extra checks to help you debug `py_CFunction`. + bool py_callcfunc( + py_CFunction f, + int argc, + py_Ref argv, + ) { + return _py_callcfunc( + f, + argc, + argv, + ); + } + + late final _py_callcfuncPtr = _lookup< + ffi.NativeFunction>( + 'py_callcfunc'); + late final _py_callcfunc = + _py_callcfuncPtr.asFunction(); /// Perform a binary operation. /// The result will be set to `py_retval()`. @@ -2300,381 +2289,6 @@ class PocketpyBindings { late final _py_binarymatmul = _py_binarymatmulPtr.asFunction(); - /// Get the i-th object from the top of the stack. - /// `i` should be negative, e.g. (-1) means TOS. - py_StackRef py_peek( - int i, - ) { - return _py_peek( - i, - ); - } - - late final _py_peekPtr = - _lookup>('py_peek'); - late final _py_peek = _py_peekPtr.asFunction(); - - /// Push the object to the stack. - void py_push( - py_Ref src, - ) { - return _py_push( - src, - ); - } - - late final _py_pushPtr = - _lookup>('py_push'); - late final _py_push = _py_pushPtr.asFunction(); - - /// Push a `nil` object to the stack. - void py_pushnil() { - return _py_pushnil(); - } - - late final _py_pushnilPtr = - _lookup>('py_pushnil'); - late final _py_pushnil = _py_pushnilPtr.asFunction(); - - /// Push a `None` object to the stack. - void py_pushnone() { - return _py_pushnone(); - } - - late final _py_pushnonePtr = - _lookup>('py_pushnone'); - late final _py_pushnone = _py_pushnonePtr.asFunction(); - - /// Push a `py_Name` to the stack. This is used for keyword arguments. - void py_pushname( - py_Name name, - ) { - return _py_pushname( - name, - ); - } - - late final _py_pushnamePtr = - _lookup>('py_pushname'); - late final _py_pushname = - _py_pushnamePtr.asFunction(); - - /// Pop an object from the stack. - void py_pop() { - return _py_pop(); - } - - late final _py_popPtr = - _lookup>('py_pop'); - late final _py_pop = _py_popPtr.asFunction(); - - /// Shrink the stack by n. - void py_shrink( - int n, - ) { - return _py_shrink( - n, - ); - } - - late final _py_shrinkPtr = - _lookup>('py_shrink'); - late final _py_shrink = _py_shrinkPtr.asFunction(); - - /// Get a temporary variable from the stack. - py_StackRef py_pushtmp() { - return _py_pushtmp(); - } - - late final _py_pushtmpPtr = - _lookup>('py_pushtmp'); - late final _py_pushtmp = _py_pushtmpPtr.asFunction(); - - /// Get the unbound method of the object. - /// Assume the object is located at the top of the stack. - /// If return true: `[self] -> [unbound, self]`. - /// If return false: `[self] -> [self]` (no change). - bool py_pushmethod( - py_Name name, - ) { - return _py_pushmethod( - name, - ); - } - - late final _py_pushmethodPtr = - _lookup>('py_pushmethod'); - late final _py_pushmethod = - _py_pushmethodPtr.asFunction(); - - /// Call a callable object via pocketpy's calling convention. - /// You need to prepare the stack using the following format: - /// `callable, self/nil, arg1, arg2, ..., k1, v1, k2, v2, ...`. - /// `argc` is the number of positional arguments excluding `self`. - /// `kwargc` is the number of keyword arguments. - /// The result will be set to `py_retval()`. - /// The stack size will be reduced by `2 + argc + kwargc * 2`. - bool py_vectorcall( - int argc, - int kwargc, - ) { - return _py_vectorcall( - argc, - kwargc, - ); - } - - late final _py_vectorcallPtr = - _lookup>( - 'py_vectorcall'); - late final _py_vectorcall = - _py_vectorcallPtr.asFunction(); - - /// Evaluate an expression and push the result to the stack. - /// This function is used for testing. - bool py_pusheval( - ffi.Pointer expr, - py_GlobalRef module, - ) { - return _py_pusheval( - expr, - module, - ); - } - - late final _py_pushevalPtr = _lookup< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer, py_GlobalRef)>>('py_pusheval'); - late final _py_pusheval = _py_pushevalPtr - .asFunction, py_GlobalRef)>(); - - /// Create a new module. - py_GlobalRef py_newmodule( - ffi.Pointer path, - ) { - return _py_newmodule( - path, - ); - } - - late final _py_newmodulePtr = - _lookup)>>( - 'py_newmodule'); - late final _py_newmodule = _py_newmodulePtr - .asFunction)>(); - - /// Get a module by path. - py_GlobalRef py_getmodule( - ffi.Pointer path, - ) { - return _py_getmodule( - path, - ); - } - - late final _py_getmodulePtr = - _lookup)>>( - 'py_getmodule'); - late final _py_getmodule = _py_getmodulePtr - .asFunction)>(); - - /// Reload an existing module. - bool py_importlib_reload( - py_Ref module, - ) { - return _py_importlib_reload( - module, - ); - } - - late final _py_importlib_reloadPtr = - _lookup>( - 'py_importlib_reload'); - late final _py_importlib_reload = - _py_importlib_reloadPtr.asFunction(); - - /// Import a module. - /// The result will be set to `py_retval()`. - /// -1: error, 0: not found, 1: success - int py_import( - ffi.Pointer path, - ) { - return _py_import( - path, - ); - } - - late final _py_importPtr = - _lookup)>>( - 'py_import'); - late final _py_import = - _py_importPtr.asFunction)>(); - - /// Raise an exception by type and message. Always return false. - bool py_exception( - int type, - ffi.Pointer fmt, - ) { - return _py_exception( - type, - fmt, - ); - } - - late final _py_exceptionPtr = _lookup< - ffi.NativeFunction< - ffi.Bool Function(py_Type, ffi.Pointer)>>('py_exception'); - late final _py_exception = - _py_exceptionPtr.asFunction)>(); - - /// Raise an exception object. Always return false. - bool py_raise( - py_Ref arg0, - ) { - return _py_raise( - arg0, - ); - } - - late final _py_raisePtr = - _lookup>('py_raise'); - late final _py_raise = _py_raisePtr.asFunction(); - - /// Print the current exception. - /// The exception will be set as handled. - void py_printexc() { - return _py_printexc(); - } - - late final _py_printexcPtr = - _lookup>('py_printexc'); - late final _py_printexc = _py_printexcPtr.asFunction(); - - /// Format the current exception and return a null-terminated string. - /// The result should be freed by the caller. - /// The exception will be set as handled. - ffi.Pointer py_formatexc() { - return _py_formatexc(); - } - - late final _py_formatexcPtr = - _lookup Function()>>( - 'py_formatexc'); - late final _py_formatexc = - _py_formatexcPtr.asFunction Function()>(); - - /// Check if an exception is raised. - bool py_checkexc( - bool ignore_handled, - ) { - return _py_checkexc( - ignore_handled, - ); - } - - late final _py_checkexcPtr = - _lookup>('py_checkexc'); - late final _py_checkexc = _py_checkexcPtr.asFunction(); - - /// Check if the exception is an instance of the given type. - /// This function is roughly equivalent to python's `except as e:` block. - /// If match, the exception will be stored in `py_retval()` as handled. - bool py_matchexc( - int type, - ) { - return _py_matchexc( - type, - ); - } - - late final _py_matchexcPtr = - _lookup>('py_matchexc'); - late final _py_matchexc = _py_matchexcPtr.asFunction(); - - /// Clear the current exception. - /// @param p0 the unwinding point. Use `NULL` if not needed. - void py_clearexc( - py_StackRef p0, - ) { - return _py_clearexc( - p0, - ); - } - - late final _py_clearexcPtr = - _lookup>( - 'py_clearexc'); - late final _py_clearexc = - _py_clearexcPtr.asFunction(); - - bool StopIteration() { - return _StopIteration(); - } - - late final _StopIterationPtr = - _lookup>('StopIteration'); - late final _StopIteration = _StopIterationPtr.asFunction(); - - bool KeyError( - py_Ref key, - ) { - return _KeyError( - key, - ); - } - - late final _KeyErrorPtr = - _lookup>('KeyError'); - late final _KeyError = _KeyErrorPtr.asFunction(); - - /// Python equivalent to `bool(val)`. - /// 1: true, 0: false, -1: error - int py_bool( - py_Ref val, - ) { - return _py_bool( - val, - ); - } - - late final _py_boolPtr = - _lookup>('py_bool'); - late final _py_bool = _py_boolPtr.asFunction(); - - /// Compare two objects. - /// 1: lhs == rhs, 0: lhs != rhs, -1: error - int py_equal( - py_Ref lhs, - py_Ref rhs, - ) { - return _py_equal( - lhs, - rhs, - ); - } - - late final _py_equalPtr = - _lookup>('py_equal'); - late final _py_equal = - _py_equalPtr.asFunction(); - - /// Compare two objects. - /// 1: lhs < rhs, 0: lhs >= rhs, -1: error - int py_less( - py_Ref lhs, - py_Ref rhs, - ) { - return _py_less( - lhs, - rhs, - ); - } - - late final _py_lessPtr = - _lookup>('py_less'); - late final _py_less = _py_lessPtr.asFunction(); - /// lhs == rhs bool py_eq( py_Ref lhs, @@ -2765,6 +2379,70 @@ class PocketpyBindings { _lookup>('py_ge'); late final _py_ge = _py_gePtr.asFunction(); + /// Python equivalent to `lhs is rhs`. + bool py_isidentical( + py_Ref arg0, + py_Ref arg1, + ) { + return _py_isidentical( + arg0, + arg1, + ); + } + + late final _py_isidenticalPtr = + _lookup>( + 'py_isidentical'); + late final _py_isidentical = + _py_isidenticalPtr.asFunction(); + + /// Python equivalent to `bool(val)`. + /// 1: true, 0: false, -1: error + int py_bool( + py_Ref val, + ) { + return _py_bool( + val, + ); + } + + late final _py_boolPtr = + _lookup>('py_bool'); + late final _py_bool = _py_boolPtr.asFunction(); + + /// Compare two objects. + /// 1: lhs == rhs, 0: lhs != rhs, -1: error + int py_equal( + py_Ref lhs, + py_Ref rhs, + ) { + return _py_equal( + lhs, + rhs, + ); + } + + late final _py_equalPtr = + _lookup>('py_equal'); + late final _py_equal = + _py_equalPtr.asFunction(); + + /// Compare two objects. + /// 1: lhs < rhs, 0: lhs >= rhs, -1: error + int py_less( + py_Ref lhs, + py_Ref rhs, + ) { + return _py_less( + lhs, + rhs, + ); + } + + late final _py_lessPtr = + _lookup>('py_less'); + late final _py_less = _py_lessPtr.asFunction(); + /// Python equivalent to `callable(val)`. bool py_callable( py_Ref val, @@ -2822,65 +2500,6 @@ class PocketpyBindings { _lookup>('py_next'); late final _py_next = _py_nextPtr.asFunction(); - /// Python equivalent to `lhs is rhs`. - bool py_isidentical( - py_Ref arg0, - py_Ref arg1, - ) { - return _py_isidentical( - arg0, - arg1, - ); - } - - late final _py_isidenticalPtr = - _lookup>( - 'py_isidentical'); - late final _py_isidentical = - _py_isidenticalPtr.asFunction(); - - /// Call a function. - /// It prepares the stack and then performs a `vectorcall(argc, 0, false)`. - /// The result will be set to `py_retval()`. - /// The stack remains unchanged if successful. - bool py_call( - py_Ref f, - int argc, - py_Ref argv, - ) { - return _py_call( - f, - argc, - argv, - ); - } - - late final _py_callPtr = - _lookup>( - 'py_call'); - late final _py_call = - _py_callPtr.asFunction(); - - /// Call a `py_CFunction` in a safe way. - /// This function does extra checks to help you debug `py_CFunction`. - bool py_callcfunc( - py_CFunction f, - int argc, - py_Ref argv, - ) { - return _py_callcfunc( - f, - argc, - argv, - ); - } - - late final _py_callcfuncPtr = _lookup< - ffi.NativeFunction>( - 'py_callcfunc'); - late final _py_callcfunc = - _py_callcfuncPtr.asFunction(); - /// Python equivalent to `str(val)`. bool py_str( py_Ref val, @@ -2920,109 +2539,284 @@ class PocketpyBindings { _lookup>('py_len'); late final _py_len = _py_lenPtr.asFunction(); - /// Python equivalent to `json.dumps(val)`. - bool py_json_dumps( - py_Ref val, - int indent, + /// Python equivalent to `getattr(self, name)`. + bool py_getattr( + py_Ref self, + py_Name name, ) { - return _py_json_dumps( - val, - indent, + return _py_getattr( + self, + name, ); } - late final _py_json_dumpsPtr = - _lookup>( - 'py_json_dumps'); - late final _py_json_dumps = - _py_json_dumpsPtr.asFunction(); + late final _py_getattrPtr = + _lookup>( + 'py_getattr'); + late final _py_getattr = + _py_getattrPtr.asFunction(); - /// Python equivalent to `json.loads(val)`. - bool py_json_loads( - ffi.Pointer source, - ) { - return _py_json_loads( - source, - ); - } - - late final _py_json_loadsPtr = - _lookup)>>( - 'py_json_loads'); - late final _py_json_loads = - _py_json_loadsPtr.asFunction)>(); - - /// Python equivalent to `pickle.dumps(val)`. - bool py_pickle_dumps( + /// Python equivalent to `setattr(self, name, val)`. + bool py_setattr( + py_Ref self, + py_Name name, py_Ref val, ) { - return _py_pickle_dumps( + return _py_setattr( + self, + name, val, ); } - late final _py_pickle_dumpsPtr = - _lookup>('py_pickle_dumps'); - late final _py_pickle_dumps = - _py_pickle_dumpsPtr.asFunction(); + late final _py_setattrPtr = + _lookup>( + 'py_setattr'); + late final _py_setattr = + _py_setattrPtr.asFunction(); - /// Python equivalent to `pickle.loads(val)`. - bool py_pickle_loads( - ffi.Pointer data, - int size, + /// Python equivalent to `delattr(self, name)`. + bool py_delattr( + py_Ref self, + py_Name name, ) { - return _py_pickle_loads( - data, - size, + return _py_delattr( + self, + name, ); } - late final _py_pickle_loadsPtr = _lookup< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer, ffi.Int)>>('py_pickle_loads'); - late final _py_pickle_loads = _py_pickle_loadsPtr - .asFunction, int)>(); + late final _py_delattrPtr = + _lookup>( + 'py_delattr'); + late final _py_delattr = + _py_delattrPtr.asFunction(); - /// Profiler - void py_profiler_begin() { - return _py_profiler_begin(); + /// Python equivalent to `self[key]`. + bool py_getitem( + py_Ref self, + py_Ref key, + ) { + return _py_getitem( + self, + key, + ); } - late final _py_profiler_beginPtr = - _lookup>('py_profiler_begin'); - late final _py_profiler_begin = - _py_profiler_beginPtr.asFunction(); + late final _py_getitemPtr = + _lookup>( + 'py_getitem'); + late final _py_getitem = + _py_getitemPtr.asFunction(); - void py_profiler_end() { - return _py_profiler_end(); + /// Python equivalent to `self[key] = val`. + bool py_setitem( + py_Ref self, + py_Ref key, + py_Ref val, + ) { + return _py_setitem( + self, + key, + val, + ); } - late final _py_profiler_endPtr = - _lookup>('py_profiler_end'); - late final _py_profiler_end = - _py_profiler_endPtr.asFunction(); + late final _py_setitemPtr = + _lookup>( + 'py_setitem'); + late final _py_setitem = + _py_setitemPtr.asFunction(); - void py_profiler_reset() { - return _py_profiler_reset(); + /// Python equivalent to `del self[key]`. + bool py_delitem( + py_Ref self, + py_Ref key, + ) { + return _py_delitem( + self, + key, + ); } - late final _py_profiler_resetPtr = - _lookup>('py_profiler_reset'); - late final _py_profiler_reset = - _py_profiler_resetPtr.asFunction(); + late final _py_delitemPtr = + _lookup>( + 'py_delitem'); + late final _py_delitem = + _py_delitemPtr.asFunction(); - ffi.Pointer py_profiler_report() { - return _py_profiler_report(); + /// Get a module by path. + py_GlobalRef py_getmodule( + ffi.Pointer path, + ) { + return _py_getmodule( + path, + ); } - late final _py_profiler_reportPtr = + late final _py_getmodulePtr = + _lookup)>>( + 'py_getmodule'); + late final _py_getmodule = _py_getmodulePtr + .asFunction)>(); + + /// Create a new module. + py_GlobalRef py_newmodule( + ffi.Pointer path, + ) { + return _py_newmodule( + path, + ); + } + + late final _py_newmodulePtr = + _lookup)>>( + 'py_newmodule'); + late final _py_newmodule = _py_newmodulePtr + .asFunction)>(); + + /// Reload an existing module. + bool py_importlib_reload( + py_Ref module, + ) { + return _py_importlib_reload( + module, + ); + } + + late final _py_importlib_reloadPtr = + _lookup>( + 'py_importlib_reload'); + late final _py_importlib_reload = + _py_importlib_reloadPtr.asFunction(); + + /// Import a module. + /// The result will be set to `py_retval()`. + /// -1: error, 0: not found, 1: success + int py_import( + ffi.Pointer path, + ) { + return _py_import( + path, + ); + } + + late final _py_importPtr = + _lookup)>>( + 'py_import'); + late final _py_import = + _py_importPtr.asFunction)>(); + + /// Check if there is an unhandled exception. + bool py_checkexc() { + return _py_checkexc(); + } + + late final _py_checkexcPtr = + _lookup>('py_checkexc'); + late final _py_checkexc = _py_checkexcPtr.asFunction(); + + /// Check if the unhandled exception is an instance of the given type. + /// If match, the exception will be stored in `py_retval()`. + bool py_matchexc( + int type, + ) { + return _py_matchexc( + type, + ); + } + + late final _py_matchexcPtr = + _lookup>('py_matchexc'); + late final _py_matchexc = _py_matchexcPtr.asFunction(); + + /// Clear the unhandled exception. + /// @param p0 the unwinding point. Use `NULL` if not needed. + void py_clearexc( + py_StackRef p0, + ) { + return _py_clearexc( + p0, + ); + } + + late final _py_clearexcPtr = + _lookup>( + 'py_clearexc'); + late final _py_clearexc = + _py_clearexcPtr.asFunction(); + + /// Print the unhandled exception. + void py_printexc() { + return _py_printexc(); + } + + late final _py_printexcPtr = + _lookup>('py_printexc'); + late final _py_printexc = _py_printexcPtr.asFunction(); + + /// Format the unhandled exception and return a null-terminated string. + /// The returned string should be freed by the caller. + ffi.Pointer py_formatexc() { + return _py_formatexc(); + } + + late final _py_formatexcPtr = _lookup Function()>>( - 'py_profiler_report'); - late final _py_profiler_report = - _py_profiler_reportPtr.asFunction Function()>(); + 'py_formatexc'); + late final _py_formatexc = + _py_formatexcPtr.asFunction Function()>(); + + /// Raise an exception by type and message. Always return false. + bool py_exception( + int type, + ffi.Pointer fmt, + ) { + return _py_exception( + type, + fmt, + ); + } + + late final _py_exceptionPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function(py_Type, ffi.Pointer)>>('py_exception'); + late final _py_exception = + _py_exceptionPtr.asFunction)>(); + + /// Raise an exception object. Always return false. + bool py_raise( + py_Ref arg0, + ) { + return _py_raise( + arg0, + ); + } + + late final _py_raisePtr = + _lookup>('py_raise'); + late final _py_raise = _py_raisePtr.asFunction(); + + bool KeyError( + py_Ref key, + ) { + return _KeyError( + key, + ); + } + + late final _KeyErrorPtr = + _lookup>('KeyError'); + late final _KeyError = _KeyErrorPtr.asFunction(); + + bool StopIteration() { + return _StopIteration(); + } + + late final _StopIterationPtr = + _lookup>('StopIteration'); + late final _StopIteration = _StopIterationPtr.asFunction(); - /// DAP void py_debugger_waitforattach( ffi.Pointer hostname, int port, @@ -3040,15 +2834,14 @@ class PocketpyBindings { late final _py_debugger_waitforattach = _py_debugger_waitforattachPtr .asFunction, int)>(); - bool py_debugger_isattached() { - return _py_debugger_isattached(); + int py_debugger_status() { + return _py_debugger_status(); } - late final _py_debugger_isattachedPtr = - _lookup>( - 'py_debugger_isattached'); - late final _py_debugger_isattached = - _py_debugger_isattachedPtr.asFunction(); + late final _py_debugger_statusPtr = + _lookup>('py_debugger_status'); + late final _py_debugger_status = + _py_debugger_statusPtr.asFunction(); void py_debugger_exceptionbreakpoint( py_Ref exc, @@ -3065,10 +2858,10 @@ class PocketpyBindings { _py_debugger_exceptionbreakpointPtr.asFunction(); void py_debugger_exit( - int exitCode, + int code, ) { return _py_debugger_exit( - exitCode, + code, ); } @@ -3078,7 +2871,24 @@ class PocketpyBindings { late final _py_debugger_exit = _py_debugger_exitPtr.asFunction(); - /// Unchecked Functions + /// Create a `tuple` with `n` UNINITIALIZED elements. + /// You should initialize all elements before using it. + py_ObjectRef py_newtuple( + py_OutRef arg0, + int n, + ) { + return _py_newtuple( + arg0, + n, + ); + } + + late final _py_newtuplePtr = + _lookup>( + 'py_newtuple'); + late final _py_newtuple = + _py_newtuplePtr.asFunction(); + py_ObjectRef py_tuple_data( py_Ref self, ) { @@ -3140,6 +2950,38 @@ class PocketpyBindings { late final _py_tuple_len = _py_tuple_lenPtr.asFunction(); + /// Create an empty `list`. + void py_newlist( + py_OutRef arg0, + ) { + return _py_newlist( + arg0, + ); + } + + late final _py_newlistPtr = + _lookup>('py_newlist'); + late final _py_newlist = + _py_newlistPtr.asFunction(); + + /// Create a `list` with `n` UNINITIALIZED elements. + /// You should initialize all elements before using it. + void py_newlistn( + py_OutRef arg0, + int n, + ) { + return _py_newlistn( + arg0, + n, + ); + } + + late final _py_newlistnPtr = + _lookup>( + 'py_newlistn'); + late final _py_newlistn = + _py_newlistnPtr.asFunction(); + py_ItemRef py_list_data( py_Ref self, ) { @@ -3294,6 +3136,20 @@ class PocketpyBindings { late final _py_list_insert = _py_list_insertPtr.asFunction(); + /// Create an empty `dict`. + void py_newdict( + py_OutRef arg0, + ) { + return _py_newdict( + arg0, + ); + } + + late final _py_newdictPtr = + _lookup>('py_newdict'); + late final _py_newdict = + _py_newdictPtr.asFunction(); + /// -1: error, 0: not found, 1: found int py_dict_getitem( py_Ref self, @@ -3502,6 +3358,44 @@ class PocketpyBindings { _lookup>('py_dict_len'); late final _py_dict_len = _py_dict_lenPtr.asFunction(); + /// Create an UNINITIALIZED `slice` object. + /// You should use `py_setslot()` to set `start`, `stop`, and `step`. + py_ObjectRef py_newslice( + py_OutRef arg0, + ) { + return _py_newslice( + arg0, + ); + } + + late final _py_newslicePtr = + _lookup>( + 'py_newslice'); + late final _py_newslice = + _py_newslicePtr.asFunction(); + + /// Create a `slice` object from 3 integers. + void py_newsliceint( + py_OutRef out, + int start, + int stop, + int step, + ) { + return _py_newsliceint( + out, + start, + stop, + step, + ); + } + + late final _py_newsliceintPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + py_OutRef, py_i64, py_i64, py_i64)>>('py_newsliceint'); + late final _py_newsliceint = + _py_newsliceintPtr.asFunction(); + /// random module void py_newRandom( py_OutRef out, @@ -3839,6 +3733,138 @@ class PocketpyBindings { late final _py_tocolor32 = _py_tocolor32Ptr.asFunction(); + /// json module *************/ + /// /// Python equivalent to `json.dumps(val)`. + bool py_json_dumps( + py_Ref val, + int indent, + ) { + return _py_json_dumps( + val, + indent, + ); + } + + late final _py_json_dumpsPtr = + _lookup>( + 'py_json_dumps'); + late final _py_json_dumps = + _py_json_dumpsPtr.asFunction(); + + /// Python equivalent to `json.loads(val)`. + bool py_json_loads( + ffi.Pointer source, + ) { + return _py_json_loads( + source, + ); + } + + late final _py_json_loadsPtr = + _lookup)>>( + 'py_json_loads'); + late final _py_json_loads = + _py_json_loadsPtr.asFunction)>(); + + /// pickle module *************/ + /// /// Python equivalent to `pickle.dumps(val)`. + bool py_pickle_dumps( + py_Ref val, + ) { + return _py_pickle_dumps( + val, + ); + } + + late final _py_pickle_dumpsPtr = + _lookup>('py_pickle_dumps'); + late final _py_pickle_dumps = + _py_pickle_dumpsPtr.asFunction(); + + /// Python equivalent to `pickle.loads(val)`. + bool py_pickle_loads( + ffi.Pointer data, + int size, + ) { + return _py_pickle_loads( + data, + size, + ); + } + + late final _py_pickle_loadsPtr = _lookup< + ffi.NativeFunction< + ffi.Bool Function( + ffi.Pointer, ffi.Int)>>('py_pickle_loads'); + late final _py_pickle_loads = _py_pickle_loadsPtr + .asFunction, int)>(); + + /// pkpy module *************/ + /// /// Begin the watchdog with `timeout` in milliseconds. + /// /// `PK_ENABLE_WATCHDOG` must be defined to `1` to use this feature. + /// /// You need to call `py_watchdog_end()` later. + /// /// If `timeout` is reached, `TimeoutError` will be raised. + void py_watchdog_begin( + int timeout, + ) { + return _py_watchdog_begin( + timeout, + ); + } + + late final _py_watchdog_beginPtr = + _lookup>( + 'py_watchdog_begin'); + late final _py_watchdog_begin = + _py_watchdog_beginPtr.asFunction(); + + /// Reset the watchdog. + void py_watchdog_end() { + return _py_watchdog_end(); + } + + late final _py_watchdog_endPtr = + _lookup>('py_watchdog_end'); + late final _py_watchdog_end = + _py_watchdog_endPtr.asFunction(); + + void py_profiler_begin() { + return _py_profiler_begin(); + } + + late final _py_profiler_beginPtr = + _lookup>('py_profiler_begin'); + late final _py_profiler_begin = + _py_profiler_beginPtr.asFunction(); + + void py_profiler_end() { + return _py_profiler_end(); + } + + late final _py_profiler_endPtr = + _lookup>('py_profiler_end'); + late final _py_profiler_end = + _py_profiler_endPtr.asFunction(); + + void py_profiler_reset() { + return _py_profiler_reset(); + } + + late final _py_profiler_resetPtr = + _lookup>('py_profiler_reset'); + late final _py_profiler_reset = + _py_profiler_resetPtr.asFunction(); + + ffi.Pointer py_profiler_report() { + return _py_profiler_report(); + } + + late final _py_profiler_reportPtr = + _lookup Function()>>( + 'py_profiler_report'); + late final _py_profiler_report = + _py_profiler_reportPtr.asFunction Function()>(); + /// An utility function to read a line from stdin for REPL. int py_replinput( ffi.Pointer buf, @@ -3857,138 +3883,31 @@ class PocketpyBindings { _py_replinputPtr.asFunction, int)>(); } -final class c11_vec2i extends ffi.Union { - external UnnamedStruct1 unnamed; - - @ffi.Array.multi([2]) - external ffi.Array data; - - @ffi.Int64() - external int _i64; -} - -final class UnnamedStruct1 extends ffi.Struct { - @ffi.Int() - external int x; - - @ffi.Int() - external int y; -} - -final class c11_vec3i extends ffi.Union { - external UnnamedStruct2 unnamed; - - @ffi.Array.multi([3]) - external ffi.Array data; -} - -final class UnnamedStruct2 extends ffi.Struct { - @ffi.Int() - external int x; - - @ffi.Int() - external int y; - - @ffi.Int() - external int z; -} - -final class c11_vec2 extends ffi.Union { - external UnnamedStruct3 unnamed; - - @ffi.Array.multi([2]) - external ffi.Array data; -} - -final class UnnamedStruct3 extends ffi.Struct { - @ffi.Float() - external double x; - - @ffi.Float() - external double y; -} - -final class c11_vec3 extends ffi.Union { - external UnnamedStruct4 unnamed; - - @ffi.Array.multi([3]) - external ffi.Array data; -} - -final class UnnamedStruct4 extends ffi.Struct { - @ffi.Float() - external double x; - - @ffi.Float() - external double y; - - @ffi.Float() - external double z; -} - -final class c11_mat3x3 extends ffi.Union { - external UnnamedStruct5 unnamed; - - @ffi.Array.multi([3, 3]) - external ffi.Array> m; - - @ffi.Array.multi([9]) - external ffi.Array data; -} - -final class UnnamedStruct5 extends ffi.Struct { - @ffi.Float() - external double _11; - - @ffi.Float() - external double _12; - - @ffi.Float() - external double _13; - - @ffi.Float() - external double _21; - - @ffi.Float() - external double _22; - - @ffi.Float() - external double _23; - - @ffi.Float() - external double _31; - - @ffi.Float() - external double _32; - - @ffi.Float() - external double _33; -} - -final class c11_color32 extends ffi.Union { - external UnnamedStruct6 unnamed; - - @ffi.Array.multi([4]) - external ffi.Array data; -} - -final class UnnamedStruct6 extends ffi.Struct { - @ffi.UnsignedChar() - external int r; - - @ffi.UnsignedChar() - external int g; - - @ffi.UnsignedChar() - external int b; - - @ffi.UnsignedChar() - external int a; -} - final class py_OpaqueName extends ffi.Opaque {} -final class py_TValue extends ffi.Opaque {} +final class py_TValue extends ffi.Struct { + @py_Type() + external int type; + + @ffi.Bool() + external bool is_ptr; + + @ffi.Int() + external int extra; + + external UnnamedUnion1 unnamed; +} + +/// An integer that represents a python type. `0` is invalid. +typedef py_Type = ffi.Int16; + +final class UnnamedUnion1 extends ffi.Union { + @ffi.Int64() + external int _i64; + + @ffi.Array.multi([16]) + external ffi.Array _chars; +} /// A string view type. It is helpful for passing strings which are not null-terminated. final class c11_sv extends ffi.Struct { @@ -4048,6 +3967,15 @@ typedef py_GlobalRef = ffi.Pointer; /// A generic reference to a python object. typedef py_Ref = ffi.Pointer; +/// A struct contains the application-level callbacks. +final class py_AppCallbacks extends ffi.Struct { + external ffi.Pointer> + on_vm_ctor; + + external ffi.Pointer> + on_vm_dtor; +} + /// Python compiler modes. /// + `EXEC_MODE`: for statements. /// + `EVAL_MODE`: for expressions. @@ -4063,9 +3991,18 @@ abstract class py_CompileMode { typedef py_TraceFunc = ffi.Pointer< ffi.NativeFunction, ffi.Int32)>>; +/// An output reference for returning a value. Only use this for function arguments. +typedef py_OutRef = ffi.Pointer; + +/// A specific location in the value stack of the VM. +typedef py_StackRef = ffi.Pointer; + /// A 64-bit integer type. Corresponds to `int` in python. typedef py_i64 = ffi.Int64; +/// A 64-bit floating-point type. Corresponds to `float` in python. +typedef py_f64 = ffi.Double; + /// Native function signature. /// @param argc number of arguments. /// @param argv array of arguments. Use `py_arg(i)` macro to get the i-th argument. @@ -4073,30 +4010,147 @@ typedef py_i64 = ffi.Int64; typedef py_CFunction = ffi.Pointer< ffi.NativeFunction>; -/// A specific location in the value stack of the VM. -typedef py_StackRef = ffi.Pointer; +/// A pointer that represents a python identifier. For fast name resolution. +typedef py_Name = ffi.Pointer; /// An item reference to a container object. It invalidates when the container is modified. typedef py_ItemRef = ffi.Pointer; -/// A pointer that represents a python identifier. For fast name resolution. -typedef py_Name = ffi.Pointer; - -/// An output reference for returning a value. Only use this for function arguments. -typedef py_OutRef = ffi.Pointer; - -/// An integer that represents a python type. `0` is invalid. -typedef py_Type = ffi.Int16; - -/// A 64-bit floating-point type. Corresponds to `float` in python. -typedef py_f64 = ffi.Double; +/// A generic destructor function. +typedef py_Dtor + = ffi.Pointer)>>; /// A reference which has the same lifespan as the python object. typedef py_ObjectRef = ffi.Pointer; -/// A generic destructor function. -typedef py_Dtor - = ffi.Pointer)>>; +final class c11_vec2 extends ffi.Union { + external UnnamedStruct1 unnamed; + + @ffi.Array.multi([2]) + external ffi.Array data; +} + +final class UnnamedStruct1 extends ffi.Struct { + @ffi.Float() + external double x; + + @ffi.Float() + external double y; +} + +final class c11_vec3 extends ffi.Union { + external UnnamedStruct2 unnamed; + + @ffi.Array.multi([3]) + external ffi.Array data; +} + +final class UnnamedStruct2 extends ffi.Struct { + @ffi.Float() + external double x; + + @ffi.Float() + external double y; + + @ffi.Float() + external double z; +} + +final class c11_vec2i extends ffi.Union { + external UnnamedStruct3 unnamed; + + @ffi.Array.multi([2]) + external ffi.Array data; + + @ffi.Int64() + external int _i64; +} + +final class UnnamedStruct3 extends ffi.Struct { + @ffi.Int() + external int x; + + @ffi.Int() + external int y; +} + +final class c11_vec3i extends ffi.Union { + external UnnamedStruct4 unnamed; + + @ffi.Array.multi([3]) + external ffi.Array data; +} + +final class UnnamedStruct4 extends ffi.Struct { + @ffi.Int() + external int x; + + @ffi.Int() + external int y; + + @ffi.Int() + external int z; +} + +final class c11_color32 extends ffi.Union { + external UnnamedStruct5 unnamed; + + @ffi.Array.multi([4]) + external ffi.Array data; +} + +final class UnnamedStruct5 extends ffi.Struct { + @ffi.UnsignedChar() + external int r; + + @ffi.UnsignedChar() + external int g; + + @ffi.UnsignedChar() + external int b; + + @ffi.UnsignedChar() + external int a; +} + +final class c11_mat3x3 extends ffi.Union { + external UnnamedStruct6 unnamed; + + @ffi.Array.multi([3, 3]) + external ffi.Array> m; + + @ffi.Array.multi([9]) + external ffi.Array data; +} + +final class UnnamedStruct6 extends ffi.Struct { + @ffi.Float() + external double _11; + + @ffi.Float() + external double _12; + + @ffi.Float() + external double _13; + + @ffi.Float() + external double _21; + + @ffi.Float() + external double _22; + + @ffi.Float() + external double _23; + + @ffi.Float() + external double _31; + + @ffi.Float() + external double _32; + + @ffi.Float() + external double _33; +} /// Python favored string formatting. /// %d: int @@ -4209,51 +4263,3 @@ abstract class py_PredefinedType { static const int tp_array2d_view = 64; static const int tp_chunked_array2d = 65; } - -const String PK_VERSION = '2.1.1'; - -const int PK_VERSION_MAJOR = 2; - -const int PK_VERSION_MINOR = 1; - -const int PK_VERSION_PATCH = 1; - -const int PK_ENABLE_OS = 1; - -const int PK_ENABLE_THREADS = 1; - -const int PK_ENABLE_DETERMINISM = 0; - -const int PK_ENABLE_WATCHDOG = 0; - -const int PK_ENABLE_CUSTOM_SNAME = 0; - -const int PK_ENABLE_MIMALLOC = 0; - -const int PK_GC_MIN_THRESHOLD = 32768; - -const int PK_VM_STACK_SIZE = 16384; - -const int PK_MAX_CO_VARNAMES = 64; - -const int PK_MAX_MODULE_PATH_LEN = 63; - -const double PK_M_PI = 3.141592653589793; - -const double PK_M_E = 2.718281828459045; - -const double PK_M_DEG2RAD = 0.017453292519943295; - -const double PK_M_RAD2DEG = 57.29577951308232; - -const double PK_INST_ATTR_LOAD_FACTOR = 0.6700000166893005; - -const double PK_TYPE_ATTR_LOAD_FACTOR = 0.5; - -const int PK_PLATFORM_SEP = 47; - -const int PY_SYS_PLATFORM = 3; - -const String PY_SYS_PLATFORM_STRING = 'darwin'; - -const int PK_IS_DESKTOP_PLATFORM = 1; diff --git a/plugins/flutter/pocketpy/macos/pocketpy.podspec b/plugins/flutter/pocketpy/macos/pocketpy.podspec index b6e0d812..7d46558d 100644 --- a/plugins/flutter/pocketpy/macos/pocketpy.podspec +++ b/plugins/flutter/pocketpy/macos/pocketpy.podspec @@ -4,14 +4,14 @@ # Pod::Spec.new do |s| s.name = 'pocketpy' - s.version = '0.0.1' + s.version = '2.0.0' s.summary = 'A new Flutter FFI plugin project.' s.description = <<-DESC A new Flutter FFI plugin project. DESC - s.homepage = 'http://example.com' + s.homepage = 'https://pocketpy.dev' s.license = { :file => '../LICENSE' } - s.author = { 'Your Company' => 'email@example.com' } + s.author = { 'blueloveTH' => 'blueloveth@foxmail.com' } # This will ensure the source files in Classes/ are included in the native # builds of apps using this FFI plugin. Podspec does not support relative diff --git a/plugins/flutter/pocketpy/pubspec.yaml b/plugins/flutter/pocketpy/pubspec.yaml index 670d247b..a44d2d09 100644 --- a/plugins/flutter/pocketpy/pubspec.yaml +++ b/plugins/flutter/pocketpy/pubspec.yaml @@ -1,6 +1,6 @@ name: pocketpy description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS. -version: 2.1.1 +version: 2.1.3 homepage: https://pocketpy.dev repository: https://github.com/pocketpy/pocketpy diff --git a/plugins/flutter/pocketpy/src/CMakeLists.txt b/plugins/flutter/pocketpy/src/CMakeLists.txt index 7de034e8..1100d4f8 100644 --- a/plugins/flutter/pocketpy/src/CMakeLists.txt +++ b/plugins/flutter/pocketpy/src/CMakeLists.txt @@ -7,17 +7,22 @@ project(pocketpy_library VERSION 0.0.1 LANGUAGES C) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) -add_library(pocketpy SHARED - "pocketpy.c" +include(FetchContent) + +FetchContent_Declare( + pocketpy + GIT_REPOSITORY https://github.com/pocketpy/pocketpy.git + GIT_TAG v2.1.3 ) -if(APPLE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shorten-64-to-32") -endif() +set(PK_ENABLE_OS OFF CACHE BOOL "" FORCE) +set(PK_ENABLE_DETERMINISM ON CACHE BOOL "" FORCE) +set(PK_BUILD_SHARED_LIB ON CACHE BOOL "" FORCE) set_target_properties(pocketpy PROPERTIES - PUBLIC_HEADER pocketpy.h + PUBLIC_HEADER ${pocketpy_SOURCE_DIR}/include/pocketpy.h OUTPUT_NAME "pocketpy" ) diff --git a/plugins/flutter/pocketpy/src/pocketpy.c b/plugins/flutter/pocketpy/src/pocketpy.c new file mode 100644 index 00000000..e9b6a44c --- /dev/null +++ b/plugins/flutter/pocketpy/src/pocketpy.c @@ -0,0 +1 @@ +// nothing