changeset 71:5351594349b0

Moved error to core
author windel
date Fri, 02 Nov 2012 14:05:00 +0100
parents 35286e8abd03
children b01311fb3be7
files python/libs/compiler/core/__init__.py python/libs/compiler/core/errors.py python/libs/compiler/core/instruction.py python/libs/compiler/errors.py
diffstat 4 files changed, 52 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/python/libs/compiler/core/__init__.py	Mon Oct 29 20:24:29 2012 +0100
+++ b/python/libs/compiler/core/__init__.py	Fri Nov 02 14:05:00 2012 +0100
@@ -1,4 +1,5 @@
-from instruction import *
-from function import *
-from value import *
+from .instruction import *
+from .function import *
+from .value import *
+from .bitreader import BitReader
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/libs/compiler/core/errors.py	Fri Nov 02 14:05:00 2012 +0100
@@ -0,0 +1,47 @@
+""" Error handling routines """
+
+class CompilerException(Exception):
+  def __init__(self, msg, row=0, col=0, filename=None):
+    self.msg = msg
+    self.row = row
+    self.col = col
+    self.filename = filename
+  def __repr__(self):
+     return self.msg
+  def __str__(self):
+     return self.msg
+
+class ErrorNode:
+   def __init__(self, row, col, msg):
+      self.row, self.col = row,col
+      self.msg = msg
+
+def Error(msg, node=None):
+   if node is None:
+      raise CompilerException(msg)
+   else:
+      raise CompilerException(msg, node.row, node.col)
+
+def printError(source, e):
+     def printLine(row, txt):
+        print(str(row)+':'+txt)
+     if e.row == 0:
+        print('Error: {0}'.format(e.msg))
+     else:
+        lines = source.split('\n')
+        prerow = e.row - 3
+        if prerow < 1:
+           prerow = 1
+        afterrow = e.row + 3
+        if afterrow > len(lines):
+           afterrow = len(lines)
+
+        # print preceding source lines:
+        for r in range(prerow, e.row):
+           printLine(r, lines[r-1])
+        # print source line containing error:
+        printLine(e.row, lines[e.row-1])
+        print(' '*(len(str(e.row)+':')+e.col-1) + '^ Error: {0}'.format(e.msg))
+        # print trailing source line:
+        for r in range(e.row+1, afterrow+1):
+          printLine(r, lines[r-1])
--- a/python/libs/compiler/core/instruction.py	Mon Oct 29 20:24:29 2012 +0100
+++ b/python/libs/compiler/core/instruction.py	Fri Nov 02 14:05:00 2012 +0100
@@ -1,3 +1,4 @@
+from .value import Value
 
 class Instruction(Value):
    pass
--- a/python/libs/compiler/errors.py	Mon Oct 29 20:24:29 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-""" Error handling routines """
-
-class CompilerException(Exception):
-  def __init__(self, msg, row=0, col=0, filename=None):
-    self.msg = msg
-    self.row = row
-    self.col = col
-    self.filename = filename
-  def __repr__(self):
-     return self.msg
-  def __str__(self):
-     return self.msg
-
-class ErrorNode:
-   def __init__(self, row, col, msg):
-      self.row, self.col = row,col
-      self.msg = msg
-
-def Error(msg, node=None):
-   if node is None:
-      raise CompilerException(msg)
-   else:
-      raise CompilerException(msg, node.row, node.col)
-
-def printError(source, e):
-     def printLine(row, txt):
-        print(str(row)+':'+txt)
-     if e.row == 0:
-        print('Error: {0}'.format(e.msg))
-     else:
-        lines = source.split('\n')
-        prerow = e.row - 3
-        if prerow < 1:
-           prerow = 1
-        afterrow = e.row + 3
-        if afterrow > len(lines):
-           afterrow = len(lines)
-
-        # print preceding source lines:
-        for r in range(prerow, e.row):
-           printLine(r, lines[r-1])
-        # print source line containing error:
-        printLine(e.row, lines[e.row-1])
-        print(' '*(len(str(e.row)+':')+e.col-1) + '^ Error: {0}'.format(e.msg))
-        # print trailing source line:
-        for r in range(e.row+1, afterrow+1):
-          printLine(r, lines[r-1])