///////////////////////////////////////////////////////////////////////////////
//                             Lisaac Library                                //
//                                                                           //
//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
//                                                                           //
//   This program is free software: you can redistribute it and/or modify    //
//   it under the terms of the GNU General Public License as published by    //
//   the Free Software Foundation, either version 3 of the License, or       //
//   (at your option) any later version.                                     //
//                                                                           //
//   This program is distributed in the hope that it will be useful,         //
//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//   GNU General Public License for more details.                            //
//                                                                           //
//   You should have received a copy of the GNU General Public License       //
//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                           //
//                     http://isaacproject.u-strasbg.fr/                     //
///////////////////////////////////////////////////////////////////////////////
Section Header
  
  + name    := BLOCK;


  - copyright   := "2003-2005 Jérome Boutet, 2003-2007 Benoit Sonntag";
   
  - comment := "Block instruction library { ... } .";
  
Section Inherit
  
  - parent_object:OBJECT := OBJECT;
  
Section Public
    
  //
  // Conditional :
  //
  
  - '||' Left 10 other:BLOCK :BOOLEAN <-
  (
    value || other
  );
  
  - '&&' Left 20 other:BLOCK :BOOLEAN <-
  (
    value && other
  );
  
  - if test:BOOLEAN <-
  (
    test.if_true {
      value;
    };
  );
  
  //
  // Loop :
  //
  
  - while_do body:BLOCK <-
  ( //? {body!=NULL};
    
    value.if {
      body.value;
      while_do body;
    };
  );
  
  - do_while test:BLOCK <-
  ( //? {test!=NULL};
    
    value;
    test.value.if {
      do_while test;
    };
  );
  
  - until_do body:BLOCK <-
  ( // ? {body!=NULL};
    
    (! value).if {
      body.value;
      until_do body;
    };
  );
  
  - do_until test:BLOCK <-
  ( //? {test!=NULL};
    
    value;
    (! test.value).if {
      do_until test;
    };
  );
  
  - while_do body:BLOCK ensure test:BLOCK <-
  // Mix loop version beetween `while_do' and `do_while'
  (
    value.if {
      body.value;
      test.value.if {
	while_do body ensure test;
      };
    };
  );
  
  /*
  - until_do body:BLOCK or_until test:BLOCK <-
  (
    (! value).if {
      body.value;
      (! test.value).if {
	until_do body or_until test;
      };
    };
  );
  */
  
  //
  // Debug: Require / Ensure / Check
  //
  
  - '?' msg:STRING_CONSTANT <-
  // User assertion with message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >=10) && {! value}).if {      
      crash_on ptr with_message msg;   
    };
  );
  
  - '?' <-
  // User assertion without message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >=10) && {! value}).if {      
      crash_on ptr with_message "User assertion violated.";   
    };
  );
  
  - '-?' msg:STRING_CONSTANT <-
  // Require assertion with message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >= 5) && {! value}).if {
      crash_on ptr with_message msg;   
    };
  );
  
  - '-?' <-
  // Require assertion without message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >= 5) && {! value}).if {
      crash_on ptr with_message "Require assertion violated.";   
    };
  );
  
  - '+?' msg:STRING_CONSTANT <-
  // Ensure assertion with message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >= 15) && {! value}).if {
      crash_on ptr with_message msg;   
    };
  );
  
  - '+?' <-
  // Require assertion without message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >= 15) && {! value}).if {
      crash_on ptr with_message "Ensure assertion violated.";   
    };
  );

  - '?#' val:INTEGER <-
  // Other assertion without message.
  ( + ptr:POINTER;
    
    ptr := top_runtime_stack;
    ((debug_level >= val) && {! value}).if {
      crash_on ptr with_message "Assertion violated.";   
    };
  );
  
  //
  // Code debug.
  //
  
  - '!' <-
  (
    (debug_level >=10).if { 
      value; 
    };
  );
  
  
  