My project which can be found at The Medusa Project aims at running Python much faster by compiling it to Dart and running it on the Dart Virtual Machine. All's fine and I'm achieving up to 1500% speed boosts over the the usual CPython implementation.
My next objective is to provide a error reporting mechanism to the project. When the Python code gets compiled to a optimized and compressed Dart code, all the line numbers and related debugging info is lost. So during run time, if something goes wrong somewhere the error arises from the Dart VM and as expected, the VM reports errors in the Line:Column in the generated Dart file. What I want is a way to point out the error in the corresponding line of the Python file.
Currently I'm translating The Python code to Dart using the NodeVisitor class provided by the ast module. I visit each node in the AST and generate the Drat code for the node. I'm in a fix how to maintain the line numbers of where i got the Python code. Should I go for Debugging Symbol table like implementation which C/C++ compilers use for debugging purposes or should I go for a hand written parser?
Sample Translation:
Python code:
a = input("Enter a number: ")
b = input("Enter another number: ")
print a + b
print a - b
print a * b
print a / b
Corresponding Dart Code:
import'file:///C:/Users/Rahul/.medusa/lib/inbuilts.dart';import'dart:io';var a,b;main(){a=input(str('Enter a number: '));b=input(str('Enter another number: '));stdout.writeln((a+b));stdout.writeln((a-b));stdout.writeln((a*b));stdout.writeln((a/b));}
Suppose if b is 0 here, I want the error to show that if happened at line 7 of the Python file not at 1:245 of the Dart file.
Thanks!