From: David Kerkeslager Date: Sun, 6 Aug 2017 20:18:21 +0000 (-0400) Subject: Add support for ternary comparison operators X-Git-Url: https://code.kerkeslager.com/?a=commitdiff_plain;h=59cb91d6dbee0b40416ff265565b426958770d45;p=fur Add support for ternary comparison operators --- 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) {