Add support for ternary comparison operators
authorDavid Kerkeslager <kerkeslager@gmail.com>
Sun, 6 Aug 2017 20:18:21 +0000 (16:18 -0400)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Sun, 6 Aug 2017 20:18:21 +0000 (16:18 -0400)
examples/13_ternary_comparison.fur [new file with mode: 0644]
examples/13_ternary_comparison.fur.output.txt [new file with mode: 0644]
templates/program.c

diff --git a/examples/13_ternary_comparison.fur b/examples/13_ternary_comparison.fur
new file mode 100644 (file)
index 0000000..695873a
--- /dev/null
@@ -0,0 +1,11 @@
+print('1 < 2 < 2: ')
+print(1 < 2 < 2)
+print('\n')
+print('2 < 2 < 2: ')
+print(2 < 2 < 2)
+print('\n')
+print('1 < 2 < 3: ')
+print(1 < 2 < 3)
+print('\n')
+print('2 < 2 < 3: ')
+print(2 < 2 < 3)
diff --git a/examples/13_ternary_comparison.fur.output.txt b/examples/13_ternary_comparison.fur.output.txt
new file mode 100644 (file)
index 0000000..1e6d32f
--- /dev/null
@@ -0,0 +1,4 @@
+1 < 2 < 2: false
+2 < 2 < 2: false
+1 < 2 < 3: true
+2 < 2 < 3: false
\ No newline at end of file
index 650c1e8..58ddd36 100644 (file)
@@ -318,6 +318,15 @@ Object builtin$lessThanOrEqual(Object left, Object right)
   return result;
 }
 
+Object builtin$and(Object left, Object right)
+{
+  assert(left.type == BOOLEAN);
+  assert(right.type == BOOLEAN);
+
+  Object result = { BOOLEAN, left.instance.boolean && right.instance.boolean };
+  return result;
+}
+
 {% if 'pow' in builtins %}
 Object builtin$pow(Object base, Object exponent)
 {