# HG changeset patch # User Windel Bouwman # Date 1375031271 -7200 # Node ID f5fba5b554d7f526ae0705b58cd873a4a3242b3c # Parent e41e4109adddcead67d07ee24ea6187f5ccb3596 Removal of obsolete editor diff -r e41e4109addd -r f5fba5b554d7 python/codeedit.py --- a/python/codeedit.py Fri Jul 26 20:26:05 2013 +0200 +++ b/python/codeedit.py Sun Jul 28 19:07:51 2013 +0200 @@ -30,10 +30,11 @@ # Initial values: self.setSource('') self.CursorPosition = 0 - t = QTimer(self) - t.timeout.connect(self.updateCursor) - t.setInterval(500) - t.start() + self.t = QTimer(self) + self.t.timeout.connect(self.updateCursor) + self.t.setInterval(500) + self.t.start() + def updateCursor(self): self.blinkcursor = not self.blinkcursor self.update() @@ -147,7 +148,7 @@ curRow = self.CursorRow ydt = -chh + self.charDescent for row in range(row1, row2 + 1): - if curRow == row: + if curRow == row and self.hasFocus(): painter.fillRect(self.xposTXT, ypos + ydt, er.width(), chh, Qt.yellow) # cursor if self.blinkcursor: diff -r e41e4109addd -r f5fba5b554d7 python/codeeditor.py --- a/python/codeeditor.py Fri Jul 26 20:26:05 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -from PyQt4.QtCore import * -from PyQt4.QtGui import * -#import compiler.lexer -import os.path - -class MySyntaxHighlighter(QSyntaxHighlighter): - def __init__(self, parent=None): - super(MySyntaxHighlighter, self).__init__(parent) - # Syntax highlighting: - self.rules = [] - fmt = QTextCharFormat() - fmt.setForeground(Qt.darkBlue) - fmt.setFontWeight(QFont.Bold) - #for kw in compiler.lexer.keywords: - # pattern = '\\b'+kw+'\\b' - # self.rules.append( (pattern, fmt) ) - - # Comments: - fmt = QTextCharFormat() - fmt.setForeground(Qt.gray) - fmt.setFontItalic(True) - pattern = '\{.*\}' - self.rules.append( (pattern, fmt) ) - - # Procedure: - fmt = QTextCharFormat() - fmt.setForeground(Qt.blue) - fmt.setFontItalic(True) - #pattern = '(?<=procedure )[A-Za-z]' - # TODO lookbehind does not work, think something else - #self.rules.append( (pattern, fmt) ) - - def highlightBlock(self, text): - for pattern, fmt in self.rules: - expression = QRegExp(pattern) - index = expression.indexIn(text) - while index >= 0: - length = expression.matchedLength() - self.setFormat(index, length, fmt) - index = expression.indexIn(text, index + length) - -class LineNumberArea(QWidget): - def __init__(self, codeedit): - super(LineNumberArea, self).__init__(codeedit) - self.codeedit = codeedit - # TODO: display error in this: self.setToolTip('hello world') - def sizeHint(self): - return QSize(self.codeedit.lineNumberAreaWidth(), 0) - def paintEvent(self, ev): - self.codeedit.lineNumberAreaPaintEvent(ev) - -class CodeEdit(QPlainTextEdit): - def __init__(self, parent=None): - super(CodeEdit, self).__init__(parent) - # members: - self.isUntitled = True - self.filename = None - self.setFont(QFont('Courier')) - self.lineNumberArea = LineNumberArea(self) - h = QFontMetrics(self.font()).height() - print(h) - self.errorPixmap = QPixmap('error.png').scaled(h, h) - self.errorList = [] - - self.blockCountChanged.connect(self.updateLineNumberAreaWidth) - self.updateRequest.connect(self.updateLineNumberArea) - - # Syntax highlighter: - self.highlighter = MySyntaxHighlighter(self.document()) - - def setFileName(self, filename): - self.filename = filename - self.isUntitled = False - self.setWindowTitle(filename) - - def setSource(self, source): - self.setPlainText(source) - def getSource(self): - return self.toPlainText() - Source = property(getSource, setSource) - - def save(self): - self.saveFile() - def saveAs(self): - print('save as') - - def saveFile(self): - if self.isUntitled: - self.saveAs() - else: - source = str(self.toPlainText()) - with open(self.filename, 'w') as f: - f.write(source) - - def highlightErrorLocation(self, row, col): - tc = QTextCursor(self.document()) - tc.clearSelection() - tc.movePosition(tc.Down, tc.MoveAnchor, row - 1) - tc.movePosition(tc.Right, tc.MoveAnchor, col - 1) - tc.movePosition(tc.NextCharacter, tc.KeepAnchor) # Select 1 character - selection = QTextEdit.ExtraSelection() - lineColor = QColor(Qt.red).lighter(160) - selection.format.setBackground(lineColor) - #selection.format.setProperty(QTextFormat.FullWidthSelection, True) - selection.cursor = tc - self.setExtraSelections( [ selection ] ) - def clearErrors(self): - self.setExtraSelections( [ ] ) - def setErrors(self, el): - self.errorList = el - self.lineNumberArea.update() - - def lineNumberAreaWidth(self): - digits = 1 - mx = max(1, self.blockCount()) - while mx >= 10: - mx = mx / 10 - digits += 1 - space = 3 + self.fontMetrics().width('8') * digits + self.errorPixmap.width() + 2 - return space - def lineNumberAreaPaintEvent(self, ev): - painter = QPainter(self.lineNumberArea) - painter.fillRect(ev.rect(), Qt.lightGray) - block = self.firstVisibleBlock() - blockNumber = block.blockNumber() - top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top() - bottom = top + self.blockBoundingRect(block).height() - while block.isValid() and top <= ev.rect().bottom(): - if block.isVisible() and bottom >= ev.rect().top(): - num = str(blockNumber + 1) - painter.setPen(Qt.black) - painter.drawText(0, top, self.lineNumberArea.width(), self.fontMetrics().height(), Qt.AlignRight, num) - for e in self.errorList: - if e.loc.row == blockNumber + 1: - painter.drawPixmap(0, top, self.errorPixmap) - - block = block.next() - top = bottom - bottom = top + self.blockBoundingRect(block).height() - blockNumber += 1 - def resizeEvent(self, ev): - super(CodeEdit, self).resizeEvent(ev) - cr = self.contentsRect() - self.lineNumberArea.setGeometry(QRect(cr.left(), cr.top(), self.lineNumberAreaWidth(), cr.height() )) - def updateLineNumberAreaWidth(self, newBlockCount): - self.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0) - def updateLineNumberArea(self, rect, dy): - if dy > 0: - self.lineNumberArea.scroll(0, dy) - else: - self.lineNumberArea.update(0, rect.y(), self.lineNumberArea.width(), rect.height()) - if rect.contains(self.viewport().rect()): - self.updateLineNumberAreaWidth(0) - diff -r e41e4109addd -r f5fba5b554d7 python/codegenarm.py --- a/python/codegenarm.py Fri Jul 26 20:26:05 2013 +0200 +++ b/python/codegenarm.py Sun Jul 28 19:07:51 2013 +0200 @@ -16,6 +16,9 @@ def generate(self, ircode): assert isinstance(ircode, ir.Module) + # TODO: get these from linker descriptor? + self.outs.getSection('code').address = 0x08000000 + self.outs.getSection('data').address = 0x20000000 self.outs.selectSection('data') for gvar in ircode.Variables: diff -r e41e4109addd -r f5fba5b554d7 python/ide.py --- a/python/ide.py Fri Jul 26 20:26:05 2013 +0200 +++ b/python/ide.py Sun Jul 28 19:07:51 2013 +0200 @@ -283,9 +283,15 @@ ce.setErrors(self.diag.diags) return - self.buildOutput.append("Flashing stm32f4 discovery") code_s = outs.getSection('code') self.debugInfo = code_s.debugInfos() + self.buildOutput.append("Flashing stm32f4 discovery") + if self.ctrlToolbar.device: + bts = code_s.to_bytes() + self.ctrlToolbar.device.writeFlash(0x08000000, bts) + stl = self.ctrlToolbar.device.iface + stl.reset() + stl.halt() self.buildOutput.append("Done!") diff -r e41e4109addd -r f5fba5b554d7 python/outstream.py --- a/python/outstream.py Fri Jul 26 20:26:05 2013 +0200 +++ b/python/outstream.py Sun Jul 28 19:07:51 2013 +0200 @@ -9,6 +9,7 @@ class Section: def __init__(self): + self.address = 0 self.instructions = [] def emit(self, item): @@ -35,11 +36,10 @@ def emit(self, item): assert self.currentSection - self.sections[self.currentSection].emit(item) + self.currentSection.emit(item) - def selectSection(self, s): - self.currentSection = s - self.getSection(s) + def selectSection(self, sname): + self.currentSection = self.getSection(sname) def getLabelAddress(self, lname): assert isinstance(lname, str) @@ -57,16 +57,9 @@ def backpatch(self): """ Fixup references to other parts in the assembler """ - for s in self.sections: - # TODO parameterize this: - if s == 'code': - address = 0x08000000 - elif s == 'data': - address = 0x02000000 - else: - address = 0x0 - - for i in self.sections[s].instructions: + for s in self.sections.values(): + address = s.address + for i in s.instructions: i.address = address i.resolve(self.getLabelAddress) bts = i.encode() diff -r e41e4109addd -r f5fba5b554d7 python/testzcc.py --- a/python/testzcc.py Fri Jul 26 20:26:05 2013 +0200 +++ b/python/testzcc.py Sun Jul 28 19:07:51 2013 +0200 @@ -1,6 +1,8 @@ import unittest import glob import zcc +import outstream +import ppci class ZccTestCase(unittest.TestCase): """ Tests the compiler driver """ @@ -17,6 +19,17 @@ for filename in example_filenames: self.do(filename) + def testSectionAddress(self): + src = "package tst; function void t2() {var int t3; t3 = 2;}" + diag = ppci.DiagnosticsManager() + outs = outstream.TextOutputStream() + self.assertTrue(zcc.zcc(src, outs, diag)) + code = outs.getSection('code') + self.assertEqual(0x08000000, code.address) + data = outs.getSection('data') + self.assertEqual(0x20000000, data.address) + + if __name__ == '__main__': unittest.main()