aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--interpreter.py14
-rw-r--r--test cases/failing/11 object arithmetic/meson.build2
-rw-r--r--test cases/failing/12 string arithmetic/meson.build4
-rw-r--r--test cases/failing/13 array arithmetic/meson.build4
4 files changed, 15 insertions, 9 deletions
diff --git a/interpreter.py b/interpreter.py
index 941d6bd..cfd8201 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -1589,17 +1589,23 @@ class Interpreter():
def evaluate_arithmeticstatement(self, cur):
l = self.to_native(self.evaluate_statement(cur.left))
r = self.to_native(self.evaluate_statement(cur.right))
- if isinstance(l, str) or isinstance(r, str):
- l = str(l)
- r = str(r)
if cur.operation == 'add':
- return l + r
+ try:
+ return l + r
+ except Exception as e:
+ raise InvalidCode('Invalid use of addition: ' + str(e))
elif cur.operation == 'sub':
+ if not isinstance(l, int) or not isinstance(r, int):
+ raise InvalidCode('Subtraction works only with integers.')
return l - r
elif cur.operation == 'mul':
+ if not isinstance(l, int) or not isinstance(r, int):
+ raise InvalidCode('Multiplication works only with integers.')
return l * r
elif cur.operation == 'div':
+ if not isinstance(l, int) or not isinstance(r, int):
+ raise InvalidCode('Division works only with integers.')
return l // r
else:
raise InvalidCode('You broke me.')
diff --git a/test cases/failing/11 object arithmetic/meson.build b/test cases/failing/11 object arithmetic/meson.build
index 34e3a7a..9a7a656 100644
--- a/test cases/failing/11 object arithmetic/meson.build
+++ b/test cases/failing/11 object arithmetic/meson.build
@@ -1,3 +1,3 @@
-project('object arithmetic')
+project('object arithmetic', 'c')
foo = '5' + meson
diff --git a/test cases/failing/12 string arithmetic/meson.build b/test cases/failing/12 string arithmetic/meson.build
index 753f62b..c02a865 100644
--- a/test cases/failing/12 string arithmetic/meson.build
+++ b/test cases/failing/12 string arithmetic/meson.build
@@ -1,3 +1,3 @@
-project('string arithmetic')
+project('string arithmetic', 'c')
-foo = 'a' / 'b'
+foo = 'a' + 3
diff --git a/test cases/failing/13 array arithmetic/meson.build b/test cases/failing/13 array arithmetic/meson.build
index ceaa8bc..3ddf060 100644
--- a/test cases/failing/13 array arithmetic/meson.build
+++ b/test cases/failing/13 array arithmetic/meson.build
@@ -1,3 +1,3 @@
-project('array arithmetic')
+project('array arithmetic', 'c')
-foo = ['a', 'b'] * ['6', '4']
+foo = ['a', 'b'] * 3