8 Commits 116de6e333 ... 6cb66f67e5

Author SHA1 Message Date
  Michael Buesch 6cb66f67e5 pyprofibus: Update 5 years ago
  Michael Buesch 66b2070db6 setup.py: Add basedir to PYTHONPATH 5 years ago
  Michael Buesch 534d5baa89 core/tokenizer: Handle opening parenthesis as separate token 5 years ago
  Michael Buesch 7762288cca core/tokenizer: Fix whitespace parsing in call parameters 5 years ago
  Michael Buesch 443c2d815a gui: Remove isinstance checks 5 years ago
  Michael Buesch 9fd64a33c0 gui: Try to show unhandled exceptions in a message box 5 years ago
  Michael Buesch 8c222b8fe0 dyn-import: Change condition to import cython module 5 years ago
  Michael Buesch 16a03d04d0 gui/lib: Add missing table import 5 years ago

+ 1 - 1
awlsim/awlcompiler/optrans.py

@@ -613,7 +613,7 @@ class AwlOpTranslator(object):
 		# Byte array immediate
 		immediate, fields = AwlDataType.tryParseImmediate_ByteArray(rawOps)
 		if immediate is not None:
-			size = 32 if fields == 9 else 16
+			size = 32 if fields == 10 else 16
 			oper = make_AwlOperator(AwlOperatorTypes.IMM, size, None, None)
 			oper.immediate = immediate
 			return OpDescriptor(oper, fields)

+ 2 - 2
awlsim/awlcompiler/tokenizer.py

@@ -549,8 +549,8 @@ class AwlParser(object):
 				   (c == '(' and not t.haveLabelToken()):
 					# Parenthesis begin
 					t.inParens = True
-					t.addCharacter(c)
 					t.finishCurToken()
+					t.addToken(c)
 					cont(); continue
 				if t.inParens and c == ')':
 					# Parenthesis end
@@ -558,7 +558,7 @@ class AwlParser(object):
 					t.finishCurToken()
 					t.addToken(c)
 					cont(); continue
-				if ((self.__inAnyHeaderOrGlobal() or self.__inVariableSection()) and\
+				if ((self.__inAnyHeaderOrGlobal() or self.__inVariableSection() or t.inParens) and\
 				    c in {'=', ':', '{', '}', '.'}) or\
 				   c in {',', '[', ']'} or\
 				   (c == '=' and len(t.tokens) == 1 and not t.curToken):

+ 5 - 3
awlsim/common/dynamic_import.py

@@ -2,7 +2,7 @@
 #
 # AWL simulator - Python library importer
 #
-# Copyright 2014 Michael Buesch <m@bues.ch>
+# Copyright 2014-2018 Michael Buesch <m@bues.ch>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -42,8 +42,10 @@ def importModule(moduleName):
 	except ImportError as e: #@nocov
 		importlib = None
 
-	if cython_helper.shouldUseCython(moduleName):
-		moduleName = cython_helper.cythonModuleName(moduleName) #@nocov
+	# If we are running in cython module,
+	# translate the moduleName to its cython name.
+#@cy	moduleName = cython_helper.cythonModuleName(moduleName)
+
 	if importlib:
 		mod = importlib.import_module(moduleName)
 	else:

+ 21 - 21
awlsim/core/datatypes.py

@@ -547,15 +547,16 @@ class AwlDataType(OptionalImmutable):
 		value = None
 		if tokens is None:
 			value = 0
-		elif len(tokens) == 9:
+		elif len(tokens) == 10:
 			if typeId == self.TYPE_DWORD:
 				value, fields = self.tryParseImmediate_ByteArray(
 							tokens)
-		elif len(tokens) == 5:
+		elif len(tokens) == 6:
 			if typeId == self.TYPE_WORD:
 				value, fields = self.tryParseImmediate_ByteArray(
 							tokens)
-			elif typeId == self.TYPE_DT:
+		elif len(tokens) == 5:
+			if typeId == self.TYPE_DT:
 				value = self.tryParseImmediate_DT(tokens)
 			elif typeId == self.TYPE_TOD:
 				value = self.tryParseImmediate_TOD(tokens)
@@ -1144,30 +1145,29 @@ class AwlDataType(OptionalImmutable):
 
 	@classmethod
 	def tryParseImmediate_ByteArray(cls, tokens):
-		tokens = [ t.upper() for t in tokens ]
-		if not tokens[0].startswith("B#("):
+		if tokens[0].upper() != "B#" or tokens[1] != "(":
 			return None, None
 		try:
-			if len(tokens) >= 5 and\
-			   tokens[2] == ',' and\
-			   tokens[4] == ')':
-				fields = 5
-				a, b = int(tokens[1], 10),\
-				       int(tokens[3], 10)
+			if len(tokens) >= 6 and\
+			   tokens[3] == ',' and\
+			   tokens[5] == ')':
+				fields = 6
+				a, b = int(tokens[2], 10),\
+				       int(tokens[4], 10)
 				if a < 0 or a > 0xFF or\
 				   b < 0 or b > 0xFF:
 					raise ValueError
 				immediate = (a << 8) | b
-			elif len(tokens) >= 9 and\
-			     tokens[2] == ',' and\
-			     tokens[4] == ',' and\
-			     tokens[6] == ',' and\
-			     tokens[8] == ')':
-				fields = 9
-				a, b, c, d = int(tokens[1], 10),\
-					     int(tokens[3], 10),\
-					     int(tokens[5], 10),\
-					     int(tokens[7], 10)
+			elif len(tokens) >= 10 and\
+			     tokens[3] == ',' and\
+			     tokens[5] == ',' and\
+			     tokens[7] == ',' and\
+			     tokens[9] == ')':
+				fields = 10
+				a, b, c, d = int(tokens[2], 10),\
+					     int(tokens[4], 10),\
+					     int(tokens[6], 10),\
+					     int(tokens[8], 10)
 				if a < 0 or a > 0xFF or\
 				   b < 0 or b > 0xFF or\
 				   c < 0 or c > 0xFF or\

+ 2 - 1
awlsim/gui/library.py

@@ -2,7 +2,7 @@
 #
 # AWL simulator - GUI standard library window
 #
-# Copyright 2014 Michael Buesch <m@bues.ch>
+# Copyright 2014-2018 Michael Buesch <m@bues.ch>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@ from awlsim.gui.icons import *
 
 from awlsim.core.systemblocks.system_sfc import *
 from awlsim.core.systemblocks.system_sfb import *
+from awlsim.core.systemblocks.tables import SFC_table, SFB_table
 
 from awlsim.library.libentry import *
 from awlsim.library.libselection import *

+ 0 - 1
awlsim/gui/mainwindow.py

@@ -370,7 +370,6 @@ class MainWidget(QWidget):
 		libSelection: The AwlLibEntrySelection() instance.
 		Returns True, if the selection has successfully been added.
 		"""
-		assert(isinstance(libSelection, AwlLibEntrySelection))
 		return self.projectTreeModel.libSelectionAdd(libSelection,
 							     parentWidget=self)
 

+ 0 - 2
awlsim/gui/projecttreewidget.py

@@ -529,7 +529,6 @@ class ProjectTreeModel(QAbstractItemModel):
 		symbol: The Symbol() instance to add.
 		Returns True, if adding was successfull.
 		"""
-		assert(isinstance(symbol, Symbol))
 		project = self.getProject()
 		mnemonics = project.getCpuConf().getConfiguredMnemonics()
 		symTabSources = project.getSymTabSources()
@@ -601,7 +600,6 @@ class ProjectTreeModel(QAbstractItemModel):
 		libSelection: The AwlLibEntrySelection() to add.
 		Returns True, if adding was successfull.
 		"""
-		assert(isinstance(libSelection, AwlLibEntrySelection))
 		project = self.getProject()
 		libSelections = project.getLibSelections()
 

+ 13 - 4
awlsim/gui/startup.py

@@ -105,12 +105,21 @@ def guiShutdownCleanup():
 		AwlValidator.shutdown()
 
 # Install a handler for unhandled exceptions.
-def __unhandledExceptionHook(type, value, traceback):
-	print("awlsim-gui: ABORTING due to unhandled exception:",
-	      file=sys.stderr)
-	__orig_excepthook(type, value, traceback)
+def __unhandledExceptionHook(etype, value, tb):
+	text = "awlsim-gui: ABORTING due to unhandled exception:"
+	print(text, file=sys.stderr)
+	__orig_excepthook(etype, value, tb)
 	# Try to clean up now.
 	guiShutdownCleanup()
+	# Try to show an error message box.
+	with suppressAllExc:
+		import traceback
+		QMessageBox.critical(
+			None,
+			"awlsim-gui: Unhandled exception",
+			text + "\n\n\n" + "".join(traceback.format_exception(etype, value, tb)),
+			QMessageBox.Ok,
+			QMessageBox.Ok)
 	# Call QCoreApplication.exit() so that we return from exec_()
 	qapp.exit(ExitCodes.EXIT_ERR_OTHER)
 __orig_excepthook = sys.excepthook

+ 13 - 8
setup.py

@@ -17,32 +17,37 @@
 #  AWLSIM_CYTHON_PARALLEL:
 #	0:           Do not use parallel compilation for Cython modules.
 #	1 (default): Invoke multiple compilers in parallel (faster on multicore).
-#	2:           Invole multiple compilers only, if setup.py is being executed by Python 2.
-#	3:           Invole multiple compilers only, if setup.py is being executed by Python 3.
+#	2:           Invoke multiple compilers only, if setup.py is being executed by Python 2.
+#	3:           Invoke multiple compilers only, if setup.py is being executed by Python 3.
 #
 #  AWLSIM_PROFILE:
 #	0 (default): Do not enable profiling support in compiled Cython modules.
 #	1:           Enable profiling support in compiled Cython modules.
 #
 
-from __future__ import print_function
+from __future__ import division, absolute_import, print_function, unicode_literals
+
+import sys, os
+basedir = os.path.abspath(os.path.dirname(__file__))
+
+# Add the basedir and basedir/misc to PYTHONPATH before
+# we try to import awlsim.common.version and setup_cython.
+for base in (os.getcwd(), basedir):
+	sys.path.insert(0, os.path.join(base, "misc"))
+	sys.path.insert(0, base)
 
-import sys
-import os
 import re
 import warnings
 from distutils.core import setup
-from awlsim.common.version import VERSION_STRING
 try:
 	from cx_Freeze import setup, Executable
 	cx_Freeze = True
 except ImportError:
 	cx_Freeze = False
 
-sys.path.insert(0, "./misc")
+from awlsim.common.version import VERSION_STRING
 import setup_cython
 
-basedir = os.path.abspath(os.path.dirname(__file__))
 
 isWindows = os.name.lower() in {"nt", "ce"}
 isPosix = os.name.lower() == "posix"

+ 0 - 0
submodules/pyprofibus


Some files were not shown because too many files changed in this diff