apollovm 0.0.3 copy "apollovm: ^0.0.3" to clipboard
apollovm: ^0.0.3 copied to clipboard

outdated

ApolloVM is a portable VM (native, JS/Web, Flutter) that can parser, translate and run multiple languages, like Dart, Java, Kotlin and JavaScript.

ApolloVM #

pub package Null Safety

CI GitHub Tag New Commits Last Commits Pull Requests Code size License

ApolloVM is a portable VM (native, JS/Web, Flutter) that can parser, translate and run multiple languages, like Dart, Java, Kotlin and JavaScript.

Usage #

The ApolloVM is still in alpha stage. Below, we can see simple usage examples in Dart and Java.

Language: Dart #

import 'package:apollovm/apollovm.dart';

void main() async {
  var vm = ApolloVM();

  var codeUnit = CodeUnit(
          'dart',
          r'''
            void main(List<String> args) {
              var s = args[0] ;
              print(s);
            }
          ''',
          'test');

  var loadOK = await vm.loadCodeUnit(codeUnit);

  if (!loadOK) {
    throw StateError('Error parsing Dart code!');
  }

  var dartRunner = vm.getRunner('dart')!;
  dartRunner.executeFunction('', 'main', [
    ['foo!', 'abc']
  ]);

  print('---------------------------------------');
  // Regenerate code:
  var codeStorageDart = vm.generateAllCodeIn('dart');
  var allSourcesDart = codeStorageDart.writeAllSources().toString();
  print(allSourcesDart);
  
}

Note: the parsed function print was mapped as an external function.

Language: Java8 #

import 'package:apollovm/apollovm.dart';

void main() async {

  var vm = ApolloVM();

  var codeUnit = CodeUnit(
          'java8',
          r'''
            class Foo {
               static public void main(String[] args) {
                 String s = args[0] ;
                 print(s);
               }
            }
          ''',
          'test');

  var loadOK = await vm.loadCodeUnit(codeUnit);

  if (!loadOK) {
    throw StateError('Error parsing Java8 code!');
  }

  var java8Runner = vm.getRunner('java8')!;
  java8Runner.executeClassMethod('', 'Foo', 'main', [
    ['foo!', 'abc']
  ]);

  print('---------------------------------------');
  // Regenerate code:
  var codeStorageDart = vm.generateAllCodeIn('dart');
  var allSourcesDart = codeStorageDart.writeAllSources().toString();
  print(allSourcesDart);

  print('---------------------------------------');
  // Regenerate code:
  var codeStorageJava8 = vm.generateAllCodeIn('java8');
  var allSourcesJava8 = codeStorageJava8.writeAllSources().toString();
  print(allSourcesJava8);
  
}

Note: the parsed function print was mapped as an external function.

See Also #

ApolloVM uses PetitParser for Dart to define the grammars of the languages and to analyze the source codes.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Contribution #

Any help from open-source community is always welcome and needed:

  • Found an issue?
    • Fill a bug with details.
  • Which a feature?
    • Open a feature request.
  • Are you using and liking the project?
    • Promote the project: create an article, post or make a donation.
  • Are you a developer?
    • Fix a bug and send a pull request.
    • Implement a new feature.
    • Implement/improve a language support.
    • Added support for another language.
  • Have you already helped in any way?
    • Many thanks from me, the contributors and everybody that uses this project!

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Apache License - Version 2.0

42
likes
0
pub points
31%
popularity

Publisher

unverified uploader

ApolloVM is a portable VM (native, JS/Web, Flutter) that can parser, translate and run multiple languages, like Dart, Java, Kotlin and JavaScript.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, petitparser, swiss_knife

More

Packages that depend on apollovm