[SCM] Lisaac compiler branch, mildred-projects, updated. lisaac-0.12-413-g2e161fd

Mildred Ki'Lya silkensedai at online.fr
Wed Aug 5 10:08:21 UTC 2009


The following commit has been merged in the mildred-projects branch:
commit 2e161fda3db4dbdb321e947680ec890bcfc00bca
Author: Mildred Ki'Lya <silkensedai at online.fr>
Date:   Wed Aug 5 12:03:09 2009 +0200

    Merge LIP_PRINT with LIP_CALL. The parser accepts now any king of message
    
    The parser grammar has changed to be more flexible, now we have:
      //// FUNCTION     -> 'if' '{' { EXPR ';' }  '}' [ 'else' '{' { EXPR ';' } '}' ]
      ////               | identifier [ EXPR_ARGUMENT ]
    
    instead of:
      //// FUNCTION     -> 'if' '{' { EXPR ';' }  '}' [ 'else' '{' { EXPR ';' } '}' ]
      ////               | 'print'
    
    It means we can implement any other kind of message in LIP_CALL. The code in
    LIP_PRINT has moved there.
    
    There is some ugly workaround in ther parser (grep for UGLY), see comments for
    more details.

diff --git a/src/lip/lip_boolean.li b/src/lip/lip_boolean.li
index 579780f..5f02868 100644
--- a/src/lip/lip_boolean.li
+++ b/src/lip/lip_boolean.li
@@ -82,6 +82,15 @@ Section Public
     value.print;
   );
 
+  - append_in str:STRING <-
+  (
+    value.if {
+      str.append "TRUE";
+    } else {
+      str.append "FALSE";
+    };
+  );
+
 Section LIP_CONSTANT
   
   - my_copy other:SELF :LIP_CONSTANT <- other;
diff --git a/src/lip/lip_call.li b/src/lip/lip_call.li
index 9dbcab9..93d974e 100644
--- a/src/lip/lip_call.li
+++ b/src/lip/lip_call.li
@@ -34,6 +34,8 @@ Section Inherit
 Section Public
 
   + project :LIP_PROJECT;
+
+  + receiver:LIP_CODE;
   
   + name:STRING_CONSTANT;
   
@@ -43,22 +45,23 @@ Section Public
   // Creation.
   //
 
-  - create p:POSITION in proj:LIP_PROJECT name n:STRING_CONSTANT with arg:LIP_CODE :SELF <-
+  - create p:POSITION in proj:LIP_PROJECT self rec:LIP_CODE name n:STRING_CONSTANT with arg:LIP_CODE :SELF <-
   ( + result:SELF;
     result := clone;
-    result.make p in proj name n with arg;
+    result.make p in proj self rec name n with arg;
     result
   );
 
-  - make p:POSITION in proj:LIP_PROJECT name n:STRING_CONSTANT with arg:LIP_CODE <-
+  - make p:POSITION in proj:LIP_PROJECT self rec:LIP_CODE name n:STRING_CONSTANT with arg:LIP_CODE <-
   [
     -? {proj != NULL};
     -? {p.code != 0};
   ]
   (
-    project := proj;
+    project  := proj;
+    receiver := rec;
     position := p;
-    name := n;
+    name     := n;
     argument := arg;
   );
 
@@ -68,99 +71,171 @@ Section Public
   
   - run <-
   ( + slot:LIP_SLOT_CODE;
-    + val:LIP_CONSTANT;
+    + val,self:LIP_CONSTANT;
     + str:LIP_STRING;    
     + path:STRING_CONSTANT;
     + is_rec:BOOLEAN;
     
     (argument != NULL).if {
-      val := argument.run_expr;    
-    };    
-    (name = ALIAS_STR.slot_exit).if {
-      (val != NULL).if {
-        warning_error (position,"No argument for `exit' method.");
+      val := argument.run_expr;
+    };
+    (receiver != NULL).if {
+      self := receiver.run_expr;
+      (self = NULL).if {
+        semantic_error (position, "Incorrect type.");
       };
-      // TODO: Mildred: exit with the correct code
-      die_with_code exit_failure_code;      
-    }.elseif {name = ALIAS_STR.slot_path} then {
-      str ?= val;
-      (str = NULL).if {
-        semantic_error (position,"String argument needed.");
+    };
+    (self = NULL).if {
+      //
+      // Call with no receiver
+      //
+// string_tmp.copy name;
+// (val = NULL).if {
+//   string_tmp.append ";\n";
+// } else {
+//   string_tmp.append " (";
+//   val.append_in string_tmp;
+//   string_tmp.append ")\n";
+// };
+// string_tmp.print;
+      (name = ALIAS_STR.slot_exit).if {
+        (val != NULL).if {
+          warning_error (position,"No argument for `exit' method.");
+        };
+        die_with_code exit_failure_code;
+      }.elseif {name = ALIAS_STR.slot_path} then {
+        str ?= val;
+        (str = NULL).if {
+          semantic_error (position,"String argument needed.");
+        };
+        path := str.value;
+        (path.last = '*').if {
+          string_tmp.copy path;
+          string_tmp.remove_last 1;
+          path := ALIAS_STR.get string_tmp;
+          is_rec := TRUE;
+        };
+        project.load_directory path is_recursive is_rec;
+      }.elseif {name = ALIAS_STR.slot_run} then {
+        str ?= val;
+        (str = NULL).if {
+          semantic_error (position,"String argument needed.");
+        };
+        string_tmp.clear;
+        str.append_in string_tmp;
+        ENVIRONMENT.execute_command string_tmp;
+      } else {
+        slot := project.get_method name;
+        (slot = NULL).if {
+          string_tmp.copy "Code slot `";
+          string_tmp.append name;
+          string_tmp.append "' not found.";
+          semantic_error (position,string_tmp);
+        };
+        (slot.run_with val).if_false {
+          semantic_error (position,"Invalid argument.");
+        };
       };
-      path := str.value;
-      (path.last = '*').if {
-        string_tmp.copy path; 
-        string_tmp.remove_last 1;        
-        path := ALIAS_STR.get string_tmp;
-        is_rec := TRUE;
-      };        
-      project.load_directory path is_recursive is_rec;
-    }.elseif {name = ALIAS_STR.slot_run} then {
-      str ?= val;
-      (str = NULL).if {
-        semantic_error (position,"String argument needed.");
-      };      
-      string_tmp.clear;
-      str.append_in string_tmp;
-      ENVIRONMENT.execute_command string_tmp; 
-    } else {    
-      slot := project.get_method name;
-      (slot = NULL).if {
+    } else {
+      //
+      // Call with a receiver
+      //
+      (name = ALIAS_STR.slot_print).if {
+        self.print;
+      } else {
         string_tmp.copy "Slot `";
         string_tmp.append name;
-        string_tmp.append "' not found.";
+        string_tmp.append "' not found (Self = `";
+        self.append_in string_tmp;
+        string_tmp.append "').";
         semantic_error (position,string_tmp);
       };
-      (slot.run_with val).if_false {
-        semantic_error (position,"Invalid argument.");
-      };
     };
     (val != NULL).if {
       val.free;
     };
+    (self != NULL).if {
+      self.free;
+    };
   );
   
   - run_expr:LIP_CONSTANT <-
   ( + slot:LIP_SLOT_DATA;
     + str:LIP_STRING;
-    + val:LIP_CONSTANT;
+    + val,self:LIP_CONSTANT;
     + result:LIP_CONSTANT;
     + res:INTEGER;
     
     (argument != NULL).if {
       val := argument.run_expr;    
-    };    
-    (name = ALIAS_STR.slot_run).if {
-      str ?= val;
-      (str = NULL).if {
-        semantic_error (position,"String argument needed.");
-      };      
-      string_tmp.clear;
-      str.append_in string_tmp;
-      res := ENVIRONMENT.execute_command string_tmp; 
-      result := LIP_INTEGER.get res;
-    }.elseif {name = ALIAS_STR.slot_get_integer} then {
-      IO.read_integer;
-      result := LIP_INTEGER.get (IO.last_integer);      
-    }.elseif {name = ALIAS_STR.slot_get_string} then {
-      IO.read_line;
-      result := LIP_STRING.get (ALIAS_STR.get (IO.last_string));
-    } else {
-      slot := project.get_data name;
-      (slot = NULL).if {
-        slot := stack.last;
+    };
+    (receiver != NULL).if {
+      self := receiver.run_expr;
+      (self = NULL).if {
+        semantic_error (position, "Incorrect type.");
+      };
+    };
+    (self = NULL).if {
+      //
+      // Call with no receiver
+      //
+// string_tmp.copy name;
+// (val = NULL).if {
+//   string_tmp.append ";\n";
+// } else {
+//   string_tmp.append " (";
+//   val.append_in string_tmp;
+//   string_tmp.append ")\n";
+// };
+// string_tmp.print;
+      (name = ALIAS_STR.slot_run).if {
+        str ?= val;
+        (str = NULL).if {
+          semantic_error (position,"String argument needed.");
+        };
+        string_tmp.clear;
+        str.append_in string_tmp;
+        res := ENVIRONMENT.execute_command string_tmp;
+        result := LIP_INTEGER.get res;
+      }.elseif {name = ALIAS_STR.slot_get_integer} then {
+        IO.read_integer;
+        result := LIP_INTEGER.get (IO.last_integer);
+      }.elseif {name = ALIAS_STR.slot_get_string} then {
+        IO.read_line;
+        result := LIP_STRING.get (ALIAS_STR.get (IO.last_string));
+      } else {
+        slot := project.get_data name;
+        ((slot = NULL) && {!stack.is_empty}).if {
+          slot := stack.last;
+          (slot.name != name).if {
+            slot := NULL;
+          };
+        };
         (slot = NULL).if {
-          string_tmp.copy "Slot `";
+          string_tmp.copy "Data slot `";
           string_tmp.append name;
           string_tmp.append "' not found.";
           semantic_error (position,string_tmp);
         };
-      };        
-      result := slot.get_value;
+        result := slot.get_value;
+      };
+    } else {
+      //
+      // Call with a receiver
+      //
+      string_tmp.copy "Slot `";
+      string_tmp.append name;
+      string_tmp.append "' not found (Self = `";
+      self.append_in string_tmp;
+      string_tmp.append "').";
+      semantic_error (position,string_tmp);
     };
     (val != NULL).if {
       val.free;
     };
+    (self != NULL).if {
+      self.free;
+    };
     result
   );
 
diff --git a/src/lip/lip_constant.li b/src/lip/lip_constant.li
index 2d840a3..7c514c8 100644
--- a/src/lip/lip_constant.li
+++ b/src/lip/lip_constant.li
@@ -157,6 +157,8 @@ Section Public
   );
   
   - print <- deferred;
+
+  - append_in str:STRING <- deferred;
   
 Section LIP_CONSTANT
   
diff --git a/src/lip/lip_integer.li b/src/lip/lip_integer.li
index e6bf608..8f32c3f 100644
--- a/src/lip/lip_integer.li
+++ b/src/lip/lip_integer.li
@@ -92,6 +92,11 @@ Section Public
   (
     value.print;
   );
+
+  - append_in str:STRING <-
+  (
+    str.append (value.to_string);
+  );
   
 Section LIP_CONSTANT
     
diff --git a/src/lip/lip_print.li b/src/lip/lip_print.li
deleted file mode 100644
index 399e07c..0000000
--- a/src/lip/lip_print.li
+++ /dev/null
@@ -1,68 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//                             Lisaac Compiler                               //
-//                                                                           //
-//                   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      := LIP_PRINT;
-
-  - copyright := "2003-2008 Sonntag Benoit";
-
-  - author    := "Sonntag Benoit (sonntag at icps.u-strasbg.fr)";
-  - comment   := "The main prototype";
-
-Section Inherit
-
-  + parent_lip_code:Expanded LIP_CODE; 
-
-Section Public
-  
-  + message:LIP_CODE;
-  
-  //
-  // Creation.
-  //
-
-  - create p:POSITION message rec:LIP_CODE :SELF <-
-  ( + result:SELF;
-    result := clone;
-    result.make p message rec;
-    result
-  );
-
-  - make p:POSITION message rec:LIP_CODE <-
-  ( 
-    position := p;
-    message := rec;
-  );
-  
-  //
-  // Run.
-  //
-  
-  - run <-
-  ( + val:LIP_CONSTANT;
-    
-    val := message.run_expr;
-    (val = NULL).if {
-      semantic_error (position,"Incorrect type.");
-    };
-    val.print;
-    val.free;
-  );
\ No newline at end of file
diff --git a/src/lip/lip_slot_code.li b/src/lip/lip_slot_code.li
index 3f74a06..20503b2 100644
--- a/src/lip/lip_slot_code.li
+++ b/src/lip/lip_slot_code.li
@@ -108,8 +108,8 @@ Section Public
     (result).if {      
       (argument != NULL).if {
         ? { val != NULL };
-        result := argument.set_value val;                
-        stack.add_last argument;          
+        result := argument.set_value val;
+        stack.add_last argument;
       } else {
         stack.add_last NULL;
       };
diff --git a/src/lip/lip_string.li b/src/lip/lip_string.li
index 84c8dda..75ebadf 100644
--- a/src/lip/lip_string.li
+++ b/src/lip/lip_string.li
@@ -82,8 +82,9 @@ Section Public
     append_in string_tmp;
     string_tmp.print;
   );
-  
-  - append_in str:STRING <-
+
+  - append_in str:STRING <- str.append value;
+  /*
   ( + i:INTEGER;
     + car:CHARACTER;
      
@@ -115,6 +116,7 @@ Section Public
       i := i + 1;
     };
   );
+  */
   
 Section LIP_CONSTANT
     
diff --git a/src/parser.li b/src/parser.li
index 7a6bf2b..4e7df82 100644
--- a/src/parser.li
+++ b/src/parser.li
@@ -2899,10 +2899,12 @@ Section Private
   
   - readlip_function rec:LIP_CODE :LIP_CODE <-  
   //// FUNCTION     -> 'if' '{' { EXPR ';' }  '}' [ 'else' '{' { EXPR ';' } '}' ]
-  ////               | 'print'
+  ////               | identifier [ EXPR_ARGUMENT ]
   ( + result:LIP_CODE;
     + the,els:FAST_ARRAY[LIP_CODE];
     + val:LIP_CODE;
+    + nam:STRING_CONSTANT;
+    + arg:LIP_CODE;
     
     (read_word (ALIAS_STR.slot_if)).if {
       the := ALIAS_ARRAY[LIP_CODE].new;      
@@ -2936,8 +2938,12 @@ Section Private
         els := ALIAS_ARRAY[LIP_CODE].copy els;
       };
       result := LIP_IF.create current_position if rec then the else els;    
-    }.elseif {read_word (ALIAS_STR.slot_print)} then {
-      result := LIP_PRINT.create current_position message rec;
+    //}.elseif {read_word (ALIAS_STR.slot_print)} then {
+    //  result := LIP_PRINT.create current_position message rec;
+    }.elseif {read_identifier} then {
+      nam := last_string;
+      arg := readlip_expr_argument;
+      result := LIP_CALL.create current_position in lip_prj self rec name nam with arg;
     };
     result
   );
@@ -3042,9 +3048,14 @@ Section Private
       };
       result := LIP_UNARY.create current_position operator type with result;
     }.elseif {read_identifier} then {
-      nam := last_string;
+      nam := ALIAS_STR.get (STRING.create_from_string last_string); // UGLY
+      // If we don't convert last_string to STRING and back to STRING_CONSTANT
+      // the compiler *seems* to optimize out nam or reorder the nam and arg
+      // instructions. Whatever, the compiler uses last_string instead of nam in
+      // the LIP_CALL creation. Of course this doesn't work since
+      // readlip_expr_argument changes last_string
       arg := readlip_expr_argument;
-      result := LIP_CALL.create current_position in lip_prj name nam with arg;      
+      result := LIP_CALL.create current_position in lip_prj self NULL name nam with arg;
     } else {
       result := readlip_expr_base;
     };
@@ -3103,7 +3114,10 @@ Section Private
   ( + result:LIP_CODE;
 
     (read_identifier).if {
-      result := LIP_CALL.create current_position in lip_prj name last_string with NULL;
+// string_tmp.copy "Read ident: ";
+// string_tmp.append last_string;
+// warning_error (current_position, string_tmp);
+      result := LIP_CALL.create current_position in lip_prj self NULL name last_string with NULL;
     } else {
       result := readlip_expr_base;      
     };

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list