From 69b8cc5a18adfe61f576534e4e0b11db48e9ba73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwena=C3=ABl=20Delaval?= Date: Sat, 25 Jun 2016 08:37:47 +0200 Subject: [PATCH] Added operator (=>) in Pervasives module Operator (=>) for implication added in Pervasives module. "a => b" is translated into "not a or b" at code generation. --- compiler/obc/c/cgen.ml | 4 +++- compiler/obc/java/java_printer.ml | 3 +++ lib/pervasives.epi | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/obc/c/cgen.ml b/compiler/obc/c/cgen.ml index 67b2d71..a9b265b 100644 --- a/compiler/obc/c/cgen.ml +++ b/compiler/obc/c/cgen.ml @@ -310,7 +310,9 @@ and cop_of_op_aux op_name cexps = match op_name with | "+" | "-" | "*" | "/" | "*." | "/." | "+." | "-." | "%" | "<<<" | ">>>" | "&&&" | "|||" | "<" | ">" | "<=" | ">=" | "<=." | "<." | ">=." | ">."), [el;er] -> - Cbop (copname op, el, er) + Cbop (copname op, el, er) + | "=>", [el;er] -> + Cbop ("||", (Cuop("!",el)), er) | _ -> Cfun_call(op, cexps) end | { qual = Module "Iostream"; name = "printf" } -> diff --git a/compiler/obc/java/java_printer.ml b/compiler/obc/java/java_printer.ml index d2d7050..5eb0e05 100644 --- a/compiler/obc/java/java_printer.ml +++ b/compiler/obc/java/java_printer.ml @@ -168,6 +168,9 @@ and op ff (f, e_l) = | "~-" | "~-." -> let e = Misc.assert_1 e_l in fprintf ff "-%a" exp e + | "=>" -> + let e1,e2 = Misc.assert_2 e_l in + fprintf ff "(@[!%a or %a@])" exp e1 exp e2 | "assert" -> let e = Misc.assert_1 e_l in fprintf ff "assert(%a)" exp e diff --git a/lib/pervasives.epi b/lib/pervasives.epi index c75c764..6014fbb 100644 --- a/lib/pervasives.epi +++ b/lib/pervasives.epi @@ -64,6 +64,7 @@ external val fun (|||)(int;int) returns (int) external val fun (~-.)(float) returns (float) external val fun do_stuff(int) returns (int) external val fun between(int;int) returns (int) +external val fun (=>)(bool;bool) returns (bool) external val fun exit(bool) returns () external val fun assert(bool) returns ()