aboutsummaryrefslogtreecommitdiff
path: root/src/interp/g-util.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2010-11-16 16:08:49 +0000
committerdos-reis <gdr@axiomatics.org>2010-11-16 16:08:49 +0000
commit1b31c2ee8c940986d448dfc226b00fc6f6af6639 (patch)
tree74248b28006e29b46b405615cc0bf1a3d5d505de /src/interp/g-util.boot
parentad10d0cf79ab09a0175fc95ef5a71033a8de0a1a (diff)
downloadopen-axiom-1b31c2ee8c940986d448dfc226b00fc6f6af6639.tar.gz
* interp/g-opt.boot ($VMsideEffectFreeOperators): Include %s2c
builtin. * interp/g-util.boot (stringToChar): New. (expandCst): Use it. (expandS2c): Likewise. New. * interp/spad.lisp (|$Newline): Move to interp/sys-macros.lisp. * interp/sys-macros.lisp (|$Backspace): New. (|$HorizontalTab|): Likewise. (|$VerticalTab|): Likewise. (|$FormFeed|): Likewise. (|$CarriageReturn|): Likewise. * algebra/string.spad.pamphlet (Character) [newline]: New. [carriageReturn]: Likewise. [linefeed]: Likewise. [formfeed]: Likewise. [backspace]: Likewise. [horizontalTab]: Likewise. [verticalTab]: Likewise. [char]: Tidy.
Diffstat (limited to 'src/interp/g-util.boot')
-rw-r--r--src/interp/g-util.boot25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/interp/g-util.boot b/src/interp/g-util.boot
index 96bbe1fd..e8fe239c 100644
--- a/src/interp/g-util.boot
+++ b/src/interp/g-util.boot
@@ -61,6 +61,19 @@ usedSymbol?(s,x) ==
usedSymbol?(s,body)
or/[usedSymbol?(s,x') for x' in x]
+
+++ Return the character designated by the string `s'.
+stringToChar: %String -> %Char
+stringToChar s ==
+ #s = 1 => char s
+ s = '"\a" => $Bell
+ s = '"\n" => $Newline
+ s = '"\f" => $FormFeed
+ s = '"\r" => $CarriageReturn
+ s = '"\b" => $Backspace
+ s = '"\t" => $HorizontalTab
+ s = '"\v" => $VerticalTab
+ error strconc("invalid character designator: ", s)
--% VM forms
@@ -253,9 +266,14 @@ expandBcompl ['%bcompl,x] ==
-- Character operations
expandCcst ['%ccst,s] ==
+ -- FIXME: this expander should return forms, instead of character constants
not string? s => error "operand is not a string constant"
- #s ~= 1 => error "string constant must contain exactly one character"
- char s
+ stringToChar s
+
+++ string-to-character conversion.
+expandS2c ['%s2c, x] ==
+ string? x => expandCcst ['%ccst, x]
+ ['stringToChar, x]
-- Integer operations
expandIneg ['%ineg,x] ==
@@ -364,7 +382,7 @@ for x in [
['%and, :'AND],
['%or, :'OR],
- -- character binary operations
+ -- character operations
['%ceq, :'CHAR_=],
['%clt, :'CHAR_<],
['%cle, :'CHAR_<_=],
@@ -479,6 +497,7 @@ for x in [
['%bcompl, :function expandBcompl],
['%ccst, :function expandCcst],
+ ['%s2c, :function expandS2c],
['%ieq, :function expandIeq],
['%igt, :function expandIgt],