| |
| /pliant/language/type/misc/bool.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/ring3.pli" | |
| 18 |
| |
| 19 |
| |
| 20 |
type Bool | |
| 21 |
field Byte value | |
| 22 |
| |
| 23 |
if false | |
| 24 |
function build b | |
| 25 |
arg_w Bool b | |
| 26 |
b := addressof:false map Bool | |
| 27 |
| |
| 28 |
| |
| 29 |
function 'cast CBool' b -> cb | |
| 30 |
arg Bool b ; arg CBool cb | |
| 31 |
extension ; has_no_side_effect | |
| 32 |
cb := false ; addressof:cb map Bool := b | |
| 33 |
| |
| 34 |
function 'cast Bool' cb -> b | |
| 35 |
arg CBool cb ; arg Bool b | |
| 36 |
reduction ; has_no_side_effect | |
| 37 |
if cb | |
| 38 |
b := addressof:true map Bool | |
| 39 |
else | |
| 40 |
b := addressof:false map Bool | |
| 41 |
| |
| 42 |
| |
| 43 |
method data 'to string' options -> string | |
| 44 |
arg Bool data ; arg Str options string | |
| 45 |
if options="raw" or options="db" | |
| 46 |
string := shunt data "true" "false" | |
| 47 |
else | |
| 48 |
string := shunt data "[dq]true[dq]" "[dq]false[dq]" | |
| 49 |
| |
| 50 |
method data 'from string' string options may_skip skiped offset -> status | |
| 51 |
arg_w Bool data ; arg Str string options ; arg CBool may_skip ; arg_w Int skiped offset ; arg Status status | |
| 52 |
var Str strue sfalse | |
| 53 |
if options="raw" or options="db" | |
| 54 |
strue := "true" ; sfalse := "false" | |
| 55 |
else | |
| 56 |
strue := "[dq]true[dq]" ; sfalse := "[dq]false[dq]" | |
| 57 |
var Int stop | |
| 58 |
if not may_skip | |
| 59 |
stop := 0 | |
| 60 |
else | |
| 61 |
stop := string:len-strue:len | |
| 62 |
for (var Int i) 0 stop | |
| 63 |
if (string i strue:len)=strue | |
| 64 |
data := true | |
| 65 |
skiped := i | |
| 66 |
offset := i+strue:len | |
| 67 |
return success | |
| 68 |
if (string i sfalse:len)=sfalse | |
| 69 |
data := false | |
| 70 |
skiped := i | |
| 71 |
offset := i+sfalse:len | |
| 72 |
return success | |
| 73 |
data := false | |
| 74 |
status := failure | |
| 75 |
| |
| 76 |
| |
| 77 |
function new_true -> b | |
| 78 |
arg Bool b | |
| 79 |
strong_definition ; has_no_side_effect | |
| 80 |
b := addressof:true map Bool | |
| 81 |
| |
| 82 |
function new_false -> b | |
| 83 |
strong_definition ; has_no_side_effect | |
| 84 |
arg Bool b | |
| 85 |
b := addressof:false map Bool | |
| 86 |
| |
| 87 |
alias true new_true | |
| 88 |
alias false new_false | |
| 89 |
| |
| 90 |
| |
| 91 |
export Bool 'cast CBool' 'cast Bool' true false | |
| |