1

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!

Seki
  • 11,135
  • 7
  • 46
  • 70
Rahul De
  • 393
  • 3
  • 14

2 Answers2

2

JavaScript has adopted source maps for exactly this reason: html5rocks

It's not a perfect format, but it would probably do the job here.

Sidenote: the Dart VM doesn't support source maps yet. So you would need to parse stack traces (have a look at the stack_trace package for code that does this), and then map the locations back.

Florian Loitsch
  • 7,698
  • 25
  • 30
0

Maintaining line numbers will be very difficult because there might be additional statements or statements that can be written better in Dart and thus would change the line number so using the Dart lines doesnt help you.

First of all, why are you translating the code into one single dart line?

I'd personally would catch errors and rethrow errors with corresponding line numbers from python.

Regards Robert

Robert
  • 5,484
  • 1
  • 22
  • 35
  • The dart code is made into a single line to minify it as much as possible an allow for a faster parse by the VM. Also I am caching the generated code in a persistent SQLite storage and smaller the code the better. – Rahul De May 30 '14 at 08:53