From 59cb91d6dbee0b40416ff265565b426958770d45 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Sun, 6 Aug 2017 16:18:21 -0400 Subject: [PATCH] Add support for ternary comparison operators --- examples/13_ternary_comparison.fur | 11 +++++++++++ examples/13_ternary_comparison.fur.output.txt | 4 ++++ templates/program.c | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 examples/13_ternary_comparison.fur create mode 100644 examples/13_ternary_comparison.fur.output.txt diff --git a/examples/13_ternary_comparison.fur b/examples/13_ternary_comparison.fur new file mode 100644 index 0000000..695873a --- /dev/null +++ b/examples/13_ternary_comparison.fur @@ -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 index 0000000..1e6d32f --- /dev/null +++ b/examples/13_ternary_comparison.fur.output.txt @@ -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 diff --git a/templates/program.c b/templates/program.c index 650c1e8..58ddd36 100644 --- a/templates/program.c +++ b/templates/program.c @@ -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) { -- 2.20.1