apollovm 0.0.5 apollovm: ^0.0.5 copied to clipboard
ApolloVM is a portable VM (native, JS/Web, Flutter) that can parser, translate and run multiple languages, like Dart, Java, Kotlin and JavaScript.
ApolloVM #
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 title = args[0];
var a = args[1];
var b = args[2];
var c = args[3];
var sumAB = a + b ;
var sumABC = a + b + c;
print(title);
print(sumAB);
print(sumABC);
}
''',
'test');
var loadOK = await vm.loadCodeUnit(codeUnit);
if (!loadOK) {
throw StateError('Error parsing Dart code!');
}
var dartRunner = vm.getRunner('dart')!;
dartRunner.executeFunction('', 'main', [
['Sums:', 10, 20, 30]
]);
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) {
var title = args[0];
var a = args[1];
var b = args[2];
var c = args[3];
var sumAB = a + b ;
var sumABC = a + b + c;
print(title);
print(sumAB);
print(sumABC);
}
}
''',
'test');
var loadOK = await vm.loadCodeUnit(codeUnit);
if (!loadOK) {
throw StateError('Error parsing Java8 code!');
}
var java8Runner = vm.getRunner('java8')!;
java8Runner.executeClassMethod('', 'Foo', 'main', [
['Sums:', 10, 20, 30]
]);
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.
- PetitParser @ GitHub (a very nice project to build parsers).
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.