| |
| /pliant/language/basic/implicit.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
scope "/pliant/language/" "/pliant/install/" | |
| 17 |
module "/pliant/install/ring2.pli" | |
| 18 |
| |
| 19 |
| |
| 20 |
type ImplicitArea | |
| 21 |
field Str ident | |
| 22 |
field Link:Module module | |
| 23 |
| |
| 24 |
gvar Relation rec | |
| 25 |
gvar List implicits | |
| 26 |
| |
| 27 |
| |
| 28 |
meta implicit e | |
| 29 |
if e:size<2 | |
| 30 |
return | |
| 31 |
for (var Int i) 0 e:size-2 | |
| 32 |
if e:i:ident="" | |
| 33 |
return | |
| 34 |
var ImplicitArea sa | |
| 35 |
for (var Int i) 0 e:size-2 | |
| 36 |
var Link:ImplicitArea sa2 :> new ImplicitArea sa | |
| 37 |
sa2 ident := e:i ident | |
| 38 |
sa2 module :> e module | |
| 39 |
implicits append addressof:sa2 | |
| 40 |
e:(e:size-1) compile | |
| 41 |
e suckup e:(e:size-1) | |
| 42 |
for (var Int i) 0 e:size-2 | |
| 43 |
implicits remove implicits:last | |
| 44 |
e set_void_result | |
| 45 |
| |
| 46 |
| |
| 47 |
function try_implicits e | |
| 48 |
arg_rw Expression e | |
| 49 |
var Link:Expression ee | |
| 50 |
if (rec query addressof:e null)<>null | |
| 51 |
return | |
| 52 |
var Pointer:Arrow a :> implicits last | |
| 53 |
while a<>null | |
| 54 |
var Pointer:ImplicitArea sa :> a map ImplicitArea | |
| 55 |
if (addressof e:module)=(addressof sa:module) | |
| 56 |
var CBool try := true | |
| 57 |
if (e:ident=":=" or e:ident=":>") and e:size=2 and e:0:ident<>"" | |
| 58 |
ee :> expression ident ". "+e:0:ident+" "+e:ident subexpressions (expression ident sa:ident) (e:0 0 e:0:size) e:1 | |
| 59 |
if (e might_compile_as ee) | |
| 60 |
e properties := ee properties | |
| 61 |
try := false | |
| 62 |
if e:0:size>=1 and e:0:0:is_pure_ident | |
| 63 |
ee :> expression ident ". "+e:0:0:ident+" "+e:ident subexpressions (expression ident sa:ident subexpressions (expression ident e:0:ident)) (e:0 1 e:0:size-1) e:1 | |
| 64 |
if (e might_compile_as ee) | |
| 65 |
e properties := ee properties | |
| 66 |
try := false | |
| 67 |
if try | |
| 68 |
if e:size=0 | |
| 69 |
rec define addressof:e null addressof:void | |
| 70 |
e might_compile_as (expression ident sa:ident subexpressions e) | |
| 71 |
rec define addressof:e null null | |
| 72 |
else | |
| 73 |
ee :> expression ident sa:ident subexpressions (expression duplicate e subexpressions) (e 0 e:size) | |
| 74 |
if not (e might_compile_as ee) | |
| 75 |
if e:ident<>"" | |
| 76 |
var Link:Expression first :> expression ident sa:ident subexpressions (expression ident e:ident) | |
| 77 |
rec define addressof:first null addressof:void | |
| 78 |
ee :> expression ident "()" subexpressions first (e 0 e:size) | |
| 79 |
if (e might_compile_as ee) | |
| 80 |
e properties := ee:0:0 properties | |
| 81 |
rec define addressof:first null null | |
| 82 |
else | |
| 83 |
e properties := ee:0 properties | |
| 84 |
a :> implicits previous a | |
| 85 |
| |
| 86 |
alias 'pliant failedtocompile rewrite' try_implicits | |
| 87 |
export implicit 'pliant failedtocompile rewrite' | |
| |