From b530937393f7db6ef71158c59990f8705e52f7c6 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 27 May 2023 21:56:48 +0800 Subject: [PATCH] remove unused assets --- plugins/flutter/analysis_options.yaml | 4 - plugins/flutter/example/lib/main.dart | 97 +--------------- plugins/flutter/example/pubspec.lock | 127 +++------------------ plugins/flutter/example/pubspec.yaml | 8 -- plugins/flutter/lib/_ffi.dart | 76 ------------- plugins/flutter/lib/common.dart | 9 -- plugins/flutter/lib/no_web.dart | 152 -------------------------- plugins/flutter/lib/pocketpy.dart | 5 +- plugins/flutter/lib/web.dart | 92 ---------------- plugins/flutter/pubspec.yaml | 7 -- 10 files changed, 23 insertions(+), 554 deletions(-) delete mode 100644 plugins/flutter/analysis_options.yaml delete mode 100644 plugins/flutter/lib/_ffi.dart delete mode 100644 plugins/flutter/lib/common.dart delete mode 100644 plugins/flutter/lib/no_web.dart delete mode 100644 plugins/flutter/lib/web.dart diff --git a/plugins/flutter/analysis_options.yaml b/plugins/flutter/analysis_options.yaml deleted file mode 100644 index a5744c1c..00000000 --- a/plugins/flutter/analysis_options.yaml +++ /dev/null @@ -1,4 +0,0 @@ -include: package:flutter_lints/flutter.yaml - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/plugins/flutter/example/lib/main.dart b/plugins/flutter/example/lib/main.dart index 2cb338ff..24a77197 100644 --- a/plugins/flutter/example/lib/main.dart +++ b/plugins/flutter/example/lib/main.dart @@ -1,7 +1,5 @@ -import 'dart:io'; - import 'package:flutter/material.dart'; -import 'package:pocketpy/pocketpy.dart' as pkpy; +import 'package:pocketpy/pocketpy.dart'; void main() { runApp(const MaterialApp(home: MyApp())); @@ -15,102 +13,17 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - late final pkpy.VM vm; - late final pkpy.REPL repl; - bool needMoreLines = false; - - final TextEditingController _controller = TextEditingController(); - final StringBuffer buffer = StringBuffer(); - @override void initState() { + test(); super.initState(); - - // create a pocketpy virtual machine - vm = pkpy.VM(); - - // create a REPL - repl = pkpy.REPL(vm); - - // create a binding - vm.bind("builtins", "add", (int x, int y) => x + y); - vm.bind("builtins", "test", (String x) => x.split(',').join('|')); - - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - refresh(); - }); - } - - void addMessage(String text) { - setState(() { - buffer.write(text); - }); - } - - void submitCode() { - var text = _controller.text; - _controller.clear(); - setState(() { - buffer.write(needMoreLines ? '... $text' : '>>> $text\n'); - }); - if (text == "exit()") exit(0); - needMoreLines = repl.input(text) == 0; - refresh(); - } - - void refresh() { - // ignore: no_leading_underscores_for_local_identifiers - var _o = vm.read_output(); - if (_o.stdout.isNotEmpty) buffer.write(_o.stdout); - if (_o.stderr.isNotEmpty) buffer.write(_o.stderr); - setState(() {}); } @override Widget build(BuildContext context) { - var style = const TextStyle(fontSize: 16); - return Scaffold( - appBar: AppBar( - title: const Text('Demo'), - ), - body: Padding( - padding: const EdgeInsets.all(8.0), - child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - child: SingleChildScrollView( - reverse: true, - child: Text( - buffer.toString(), - style: style, - textAlign: TextAlign.left, - ), - ), - ), - const SizedBox( - height: 16, - ), - SizedBox( - height: 50, - child: TextFormField( - controller: _controller, - style: style, - maxLines: 1, - decoration: const InputDecoration( - border: OutlineInputBorder(), - hintText: 'Enter Python code', - ), - ), - ), - Container( - height: 60, - alignment: Alignment.centerRight, - child: MaterialButton( - onPressed: submitCode, - color: Colors.blue, - textColor: Colors.white, - child: const Text('Run')), - ), - ]), + return const Scaffold( + body: Center( + child: Text("Hello World!"), ), ); } diff --git a/plugins/flutter/example/pubspec.lock b/plugins/flutter/example/pubspec.lock index c5a2f4fd..89cee798 100644 --- a/plugins/flutter/example/pubspec.lock +++ b/plugins/flutter/example/pubspec.lock @@ -1,107 +1,51 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.9.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" source: hosted version: "1.2.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" source: hosted - version: "1.16.0" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" - ffi: - dependency: transitive - description: - name: ffi - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" + version: "1.17.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" js: dependency: transitive description: name: js - url: "https://pub.dartlang.org" + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" source: hosted version: "0.6.5" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" source: hosted version: "1.8.0" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.2" pocketpy: dependency: "direct main" description: @@ -114,55 +58,14 @@ packages: description: flutter source: sdk version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.9.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.1" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.1" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.12" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" sdks: dart: ">=2.17.0 <3.0.0" flutter: ">=2.5.0" diff --git a/plugins/flutter/example/pubspec.yaml b/plugins/flutter/example/pubspec.yaml index 07417f62..2c49fcbb 100644 --- a/plugins/flutter/example/pubspec.yaml +++ b/plugins/flutter/example/pubspec.yaml @@ -40,14 +40,6 @@ dependencies: # the parent directory to use the current plugin's version. path: ../ - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 - -dev_dependencies: - flutter_test: - sdk: flutter - # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/plugins/flutter/lib/_ffi.dart b/plugins/flutter/lib/_ffi.dart deleted file mode 100644 index 81edf484..00000000 --- a/plugins/flutter/lib/_ffi.dart +++ /dev/null @@ -1,76 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -import 'dart:convert'; -import 'dart:ffi' as ffi; -import 'package:ffi/ffi.dart'; - -Map _mappings = {}; - -class StrWrapper { - static final Finalizer> finalizer = - Finalizer((p) => malloc.free(p)); - - late final ffi.Pointer _p; - StrWrapper(String s) { - _p = s.toNativeUtf8(); - finalizer.attach(this, _p); - } - - ffi.Pointer get p => _p; -} - -dynamic invoke_f_any(ffi.Pointer p) { - String s = p.toDartString(); - var parts = s.split(' '); - List args = []; - for (int i = 1; i < parts.length; i++) { - args.add(jsonDecode(parts[i])); - } - var f = _mappings[parts[0]]; - return Function.apply(f!, args); -} - -int invoke_f_int(ffi.Pointer p) => invoke_f_any(p); -double invoke_f_float(ffi.Pointer p) => invoke_f_any(p); -bool invoke_f_bool(ffi.Pointer p) => invoke_f_any(p); -ffi.Pointer invoke_f_str(ffi.Pointer p) => - StrWrapper(invoke_f_any(p)).p; -void invoke_f_None(ffi.Pointer p) => invoke_f_any(p); - -ffi.Pointer f_int() { - return ffi.Pointer.fromFunction)>( - invoke_f_int, 0); -} - -ffi.Pointer f_float() { - return ffi.Pointer.fromFunction)>( - invoke_f_float, 0.0); -} - -ffi.Pointer f_bool() { - return ffi.Pointer.fromFunction)>( - invoke_f_bool, false); -} - -ffi.Pointer f_str() { - return ffi.Pointer.fromFunction< - ffi.Pointer Function(ffi.Pointer)>(invoke_f_str); -} - -ffi.Pointer f_None() { - return ffi.Pointer.fromFunction)>( - invoke_f_None); -} - -void register(String? key, Function value) { - _mappings[key!] = value; -} - -int t_code() { - if (T == int) return 'i'.codeUnitAt(0); - if (T == double) return 'f'.codeUnitAt(0); - if (T == bool) return 'b'.codeUnitAt(0); - if (T == String) return 's'.codeUnitAt(0); - return 'N'.codeUnitAt(0); - // throw Exception("Type must be int/double/bool/String"); -} diff --git a/plugins/flutter/lib/common.dart b/plugins/flutter/lib/common.dart deleted file mode 100644 index 9ba4f628..00000000 --- a/plugins/flutter/lib/common.dart +++ /dev/null @@ -1,9 +0,0 @@ -class PyOutput { - final String stdout; - final String stderr; - PyOutput(this.stdout, this.stderr); - - PyOutput.fromJson(Map json) - : stdout = json['stdout'], - stderr = json['stderr']; -} diff --git a/plugins/flutter/lib/no_web.dart b/plugins/flutter/lib/no_web.dart deleted file mode 100644 index 30d835e6..00000000 --- a/plugins/flutter/lib/no_web.dart +++ /dev/null @@ -1,152 +0,0 @@ -// ignore_for_file: non_constant_identifier_names, prefer_typing_uninitialized_variables, constant_identifier_names, no_leading_underscores_for_local_identifiers - -import 'dart:convert' as cvt; -import 'dart:ffi' as ffi; -import 'dart:io'; -import 'package:ffi/ffi.dart'; -import '_ffi.dart'; -import 'common.dart'; - -class _Bindings { - static ffi.DynamicLibrary _load() { - String _libName = "pocketpy"; - if (Platform.isIOS) { - return ffi.DynamicLibrary.process(); - } - if (Platform.isAndroid || Platform.isLinux) { - return ffi.DynamicLibrary.open('lib$_libName.so'); - } - if (Platform.isWindows) { - return ffi.DynamicLibrary.open('$_libName.dll'); - } - throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); - } - - static final _lib = _load(); - - static final pkpy_delete = _lib.lookupFunction< - ffi.Void Function(ffi.Pointer p), - void Function(ffi.Pointer p)>("pkpy_delete"); - static final pkpy_setup_callbacks = _lib.lookupFunction< - ffi.Void Function(ffi.Pointer _f_int, ffi.Pointer _f_float, - ffi.Pointer _f_bool, ffi.Pointer _f_str, ffi.Pointer _f_None), - void Function( - ffi.Pointer _f_int, - ffi.Pointer _f_float, - ffi.Pointer _f_bool, - ffi.Pointer _f_str, - ffi.Pointer _f_None)>("pkpy_setup_callbacks"); - static final pkpy_new_repl = _lib.lookupFunction< - ffi.Pointer Function(ffi.Pointer vm), - ffi.Pointer Function(ffi.Pointer vm)>("pkpy_new_repl"); - static final pkpy_repl_input = _lib.lookupFunction< - ffi.Bool Function(ffi.Pointer r, ffi.Pointer line), - bool Function(ffi.Pointer r, ffi.Pointer line)>("pkpy_repl_input"); - static final pkpy_new_vm = _lib.lookupFunction< - ffi.Pointer Function(ffi.Bool use_stdio), - ffi.Pointer Function(bool use_stdio)>("pkpy_new_vm"); - static final pkpy_vm_add_module = _lib.lookupFunction< - ffi.Void Function( - ffi.Pointer vm, ffi.Pointer name, ffi.Pointer source), - void Function(ffi.Pointer vm, ffi.Pointer name, - ffi.Pointer source)>("pkpy_vm_add_module"); - static final pkpy_vm_bind = _lib.lookupFunction< - ffi.Pointer Function(ffi.Pointer vm, ffi.Pointer mod, - ffi.Pointer name, ffi.Int32 ret_code), - ffi.Pointer Function(ffi.Pointer vm, ffi.Pointer mod, - ffi.Pointer name, int ret_code)>("pkpy_vm_bind"); - static final pkpy_vm_eval = _lib.lookupFunction< - ffi.Pointer Function(ffi.Pointer vm, ffi.Pointer source), - ffi.Pointer Function( - ffi.Pointer vm, ffi.Pointer source)>("pkpy_vm_eval"); - static final pkpy_vm_exec = _lib.lookupFunction< - ffi.Void Function(ffi.Pointer vm, ffi.Pointer source), - void Function(ffi.Pointer vm, ffi.Pointer source)>("pkpy_vm_exec"); - static final pkpy_vm_get_global = _lib.lookupFunction< - ffi.Pointer Function(ffi.Pointer vm, ffi.Pointer name), - ffi.Pointer Function( - ffi.Pointer vm, ffi.Pointer name)>("pkpy_vm_get_global"); - static final pkpy_vm_read_output = _lib.lookupFunction< - ffi.Pointer Function(ffi.Pointer vm), - ffi.Pointer Function(ffi.Pointer vm)>("pkpy_vm_read_output"); -} - -class VM { - late final pointer = _Bindings.pkpy_new_vm(false); - static bool _firstNew = true; - - VM() { - if (!_firstNew) return; - _firstNew = false; - _Bindings.pkpy_setup_callbacks( - f_int(), f_float(), f_bool(), f_str(), f_None()); - } - - void dispose() { - _Bindings.pkpy_delete(pointer); - } - - PyOutput read_output() { - var _o = _Bindings.pkpy_vm_read_output(pointer); - String _j = _o.toDartString(); - var ret = PyOutput.fromJson(cvt.jsonDecode(_j)); - _Bindings.pkpy_delete(_o); - return ret; - } - - /// Add a source module into a virtual machine. - void add_module(String name, String source) { - _Bindings.pkpy_vm_add_module( - pointer, StrWrapper(name).p, StrWrapper(source).p); - } - - /// Evaluate an expression. Return `__repr__` of the result. If there is any error, return `nullptr`. - String? eval(String source) { - var ret = _Bindings.pkpy_vm_eval(pointer, StrWrapper(source).p); - if (ret == ffi.nullptr) return null; - String s = ret.toDartString(); - _Bindings.pkpy_delete(ret); - return s; - } - - /// Run a given source on a virtual machine. - void exec(String source) { - _Bindings.pkpy_vm_exec(pointer, StrWrapper(source).p); - } - - /// Get a global variable of a virtual machine. Return `__repr__` of the result. If the variable is not found, return `nullptr`. - String? get_global(String name) { - var ret = _Bindings.pkpy_vm_get_global(pointer, StrWrapper(name).p); - if (ret == ffi.nullptr) return null; - String s = ret.toDartString(); - _Bindings.pkpy_delete(ret); - return s; - } - - void bind(String mod, String name, Function f) { - ffi.Pointer p = _Bindings.pkpy_vm_bind( - pointer, StrWrapper(mod).p, StrWrapper(name).p, t_code()); - if (p == ffi.nullptr) throw Exception("vm.bind() failed"); - String s = p.toDartString(); - _Bindings.pkpy_delete(p); - register(s, f); - } -} - -class REPL { - late final dynamic pointer; - - REPL(VM vm) { - pointer = _Bindings.pkpy_new_repl(vm.pointer); - } - - void dispose() { - _Bindings.pkpy_delete(pointer); - } - - /// Input a source line to an interactive console. Return true if need more lines. - bool input(String line) { - var ret = _Bindings.pkpy_repl_input(pointer, StrWrapper(line).p); - return ret; - } -} diff --git a/plugins/flutter/lib/pocketpy.dart b/plugins/flutter/lib/pocketpy.dart index fc64c546..89a5d7a2 100644 --- a/plugins/flutter/lib/pocketpy.dart +++ b/plugins/flutter/lib/pocketpy.dart @@ -1,4 +1,5 @@ library pocketpy; -export 'common.dart'; -export 'no_web.dart' if (dart.library.html) 'web.dart'; +void test(){ + print("Hello World!"); +} \ No newline at end of file diff --git a/plugins/flutter/lib/web.dart b/plugins/flutter/lib/web.dart deleted file mode 100644 index 39f024ec..00000000 --- a/plugins/flutter/lib/web.dart +++ /dev/null @@ -1,92 +0,0 @@ -// ignore_for_file: prefer_function_declarations_over_variables, non_constant_identifier_names, no_leading_underscores_for_local_identifiers -import 'dart:convert' as cvt; -import 'package:js/js.dart'; -import 'common.dart'; - -@JS("Module.ccall") -external dynamic ccall( - String name, String? returnType, List argTypes, List args); - -class _Bindings { - static final pkpy_delete = - (dynamic p) => ccall("pkpy_delete", null, ["number"], [p]); - static final pkpy_new_repl = - (dynamic vm) => ccall("pkpy_new_repl", "number", ["number"], [vm]); - static final pkpy_repl_input = (dynamic r, String line) => - ccall("pkpy_repl_input", "boolean", ["number", "string"], [r, line]); - static final pkpy_new_vm = (bool use_stdio) => - ccall("pkpy_new_vm", "number", ["boolean"], [use_stdio]); - static final pkpy_vm_add_module = (dynamic vm, String name, String source) => - ccall("pkpy_vm_add_module", null, ["number", "string", "string"], - [vm, name, source]); - static final pkpy_vm_eval = (dynamic vm, String source) => - ccall("pkpy_vm_eval", "string", ["number", "string"], [vm, source]); - static final pkpy_vm_exec = (dynamic vm, String source) => - ccall("pkpy_vm_exec", null, ["number", "string"], [vm, source]); - static final pkpy_vm_get_global = (dynamic vm, String name) => - ccall("pkpy_vm_get_global", "string", ["number", "string"], [vm, name]); - static final pkpy_vm_read_output = - (dynamic vm) => ccall("pkpy_vm_read_output", "string", ["number"], [vm]); -} - -class VM { - late final pointer = _Bindings.pkpy_new_vm(false); - static bool _firstNew = true; - - VM() { - if (!_firstNew) return; - _firstNew = false; - } - - void dispose() { - _Bindings.pkpy_delete(pointer); - } - - PyOutput read_output() { - var _o = _Bindings.pkpy_vm_read_output(pointer); - String _j = _o; - var ret = PyOutput.fromJson(cvt.jsonDecode(_j)); - - return ret; - } - - /// Add a source module into a virtual machine. - void add_module(String name, String source) { - _Bindings.pkpy_vm_add_module(pointer, name, source); - } - - /// Evaluate an expression. Return `__repr__` of the result. If there is any error, return `nullptr`. - String? eval(String source) { - var ret = _Bindings.pkpy_vm_eval(pointer, source); - return ret; - } - - /// Run a given source on a virtual machine. - void exec(String source) { - _Bindings.pkpy_vm_exec(pointer, source); - } - - /// Get a global variable of a virtual machine. Return `__repr__` of the result. If the variable is not found, return `nullptr`. - String? get_global(String name) { - var ret = _Bindings.pkpy_vm_get_global(pointer, name); - return ret; - } -} - -class REPL { - late final dynamic pointer; - - REPL(VM vm) { - pointer = _Bindings.pkpy_new_repl(vm.pointer); - } - - void dispose() { - _Bindings.pkpy_delete(pointer); - } - - /// Input a source line to an interactive console. Return true if need more lines. - bool input(String line) { - var ret = _Bindings.pkpy_repl_input(pointer, line); - return ret; - } -} diff --git a/plugins/flutter/pubspec.yaml b/plugins/flutter/pubspec.yaml index 26b7edfc..41a90cf5 100644 --- a/plugins/flutter/pubspec.yaml +++ b/plugins/flutter/pubspec.yaml @@ -11,13 +11,6 @@ environment: dependencies: flutter: sdk: flutter - ffi: ^2.0.1 - js: ^0.6.4 - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.0 flutter: plugin: