| |
| /pliant/language/debug/dbc.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 |
abstract | |
| 20 |
[This module implements 'require' and 'ensure' DbC functions.] ; eol | |
| 21 |
doc | |
| 22 |
[Documentation is available ] ; link "here" "debugging" | |
| 23 |
| |
| 24 |
| |
| 25 |
meta require e | |
| 26 |
if e:size=1 and e:0:ident="{}" | |
| 27 |
for (var Int i) 0 e:0:size-1 | |
| 28 |
e:0:i compile_as (expression immediat check:x substitute x e:0:i) | |
| 29 |
e suckup e:0:i | |
| 30 |
e set_void_result | |
| 31 |
| |
| 32 |
function optimize_incorporate_ensure gc | |
| 33 |
arg_rw GeneratorContext gc | |
| 34 |
var Pointer:Arrow c :> pliant_general_dictionary first "pliant ensure" | |
| 35 |
while c<>null and (entry_type:c<>Expression or { var Link:Expression post :> c map Expression ; post:value<>(addressof gc:function) }) | |
| 36 |
c :> pliant_general_dictionary next "pliant ensure" c | |
| 37 |
if c<>null | |
| 38 |
var Link:Expression post :> c map Expression | |
| 39 |
var Pointer:Arrow a :> post:instructions first | |
| 40 |
while a<>null | |
| 41 |
gc insert_at_section_bottom section_terminate (a map Instruction) | |
| 42 |
a :> post:instructions next a | |
| 43 |
pliant_general_dictionary remove "pliant ensure" c | |
| 44 |
record_optimizer_function optimize_incorporate_ensure "pliant optimizer initialize" | |
| 45 |
| |
| 46 |
meta ensure e | |
| 47 |
var Pointer:Arrow c :> pliant_general_dictionary first "pliant function" | |
| 48 |
if c=null or entry_type:c<>Function | |
| 49 |
return | |
| 50 |
if e:size=1 and e:0:ident="{}" | |
| 51 |
var Link:Expression post :> new Expression | |
| 52 |
post value := c | |
| 53 |
for (var Int i) 0 e:0:size-1 | |
| 54 |
e:0:i compile_as (expression immediat check:x substitute x e:0:i) | |
| 55 |
post suckup e:0:i | |
| 56 |
e set_void_result | |
| 57 |
e define "pliant ensure" addressof:post e:module | |
| 58 |
| |
| 59 |
export require ensure | |
| |