aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2008-01-15 08:50:07 +0000
committerdos-reis <gdr@axiomatics.org>2008-01-15 08:50:07 +0000
commitb4e36d2669e4d86d5e183d279e07079a7d6e26bd (patch)
tree939097e6ca6364393f3cd65f297c5bbd8e4ef4ee
parentc4283c6a980fa9faacc66090e90d6243ae6c03db (diff)
downloadopen-axiom-b4e36d2669e4d86d5e183d279e07079a7d6e26bd.tar.gz
* algebra/syntax.spad (autoCoerce$Syntax): Add overloads.
* interp/compiler.boot (coerceExtraHard): Always coerce by autoCoerce. * testsuite/interpreter/case.spad: Likewise. * testsuite/interpreter/case.input: New.
-rw-r--r--src/ChangeLog8
-rw-r--r--src/algebra/syntax.spad38
-rw-r--r--src/interp/compiler.boot2
-rw-r--r--src/testsuite/interpreter/case.input5
-rw-r--r--src/testsuite/interpreter/case.spad10
5 files changed, 57 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 9fc72faf..a99d946c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2008-01-15 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * algebra/syntax.spad (autoCoerce$Syntax): Add overloads.
+ * interp/compiler.boot (coerceExtraHard): Always coerce by
+ autoCoerce.
+ * testsuite/interpreter/case.spad: Likewise.
+ * testsuite/interpreter/case.input: New.
+
2008-01-14 Gabriel Dos Reis <gdr@cs.tamu.edu>
* interp/compiler.boot (compSymbol): Don't handle possible
diff --git a/src/algebra/syntax.spad b/src/algebra/syntax.spad
index b6331f4f..d07bad13 100644
--- a/src/algebra/syntax.spad
+++ b/src/algebra/syntax.spad
@@ -56,25 +56,41 @@ Syntax(): Public == Private where
++ coerce(i) injects the integer value `i' into the Syntax domain
coerce: % -> Integer
- ++ coerce(i) extracts the integer value `i' from the Syntax domain
+ ++ coerce(s) extracts and integer value from the syntax `s'
+ autoCoerce: % -> Integer
+ ++ autoCoerce(s) forcibly extracts an integer value from
+ ++ the syntax `s'; no check performed. To be called only
+ ++ at the discretion of the compiler.
coerce: DoubleFloat -> %
++ coerce(f) injects the float value `f' into the Syntax domain
coerce: % -> DoubleFloat
- ++ coerce(f) extracts the float value `f' from the Syntax domain
+ ++ coerce(s) extracts a float value from the syntax `s'.
+ autoCoerce: % -> DoubleFloat
+ ++ autoCoerce(s) forcibly extracts a float value from the syntax `s';
+ ++ no check performed. To be called only at the discretion of
+ ++ the compiler
coerce: Symbol -> %
++ coerce(s) injects the symbol `s' into the Syntax domain.
coerce: % -> Symbol
- ++ coerce(s) extracts the symbol `s' from the Syntax domain.
+ ++ coerce(s) extracts a symbol from the syntax `s'.
+ autoCoerce: % -> Symbol
+ ++ autoCoerce(s) forcibly extracts a symbo from the Syntax
+ ++ domain `s'; no check performed. To be called only at
+ ++ at the discretion of the compiler.
coerce: String -> %
++ coerce(s) injects the string value `s' into the syntax domain
coerce: % -> String
- ++ coerce(s) extract the string value `s' from the syntax domain
+ ++ coerce(s) extracts a string value from the syntax `s'.
+ autoCoerce: % -> String
+ ++ autoCoerce(s) forcibly extracts a string value from
+ ++ the syntax `s'; no check performed. To be called only at
+ ++ the discretion of the compiler.
buildSyntax: (Symbol, List %) -> %
++ buildSyntax(op, [a1, ..., an]) builds a syntax object for op(a1,...,an).
@@ -135,13 +151,19 @@ Syntax(): Public == Private where
coerce(i: Integer): % ==
i pretend %
- ccoerce(i: %): Integer ==
+ autoCoerce(i: %): Integer == -- used for hard coercion
+ i : Integer
+
+ coerce(i: %): Integer ==
i case Integer => i
userError "invalid conversion target type"
coerce(f: DoubleFloat): % ==
f pretend %
+ autoCoerce(f: %): DoubleFloat == -- used for hard coercion
+ f : DoubleFloat
+
coerce(f: %): DoubleFloat ==
f case DoubleFloat => f
userError "invalid conversion target type"
@@ -149,6 +171,9 @@ Syntax(): Public == Private where
coerce(s: Symbol): % ==
s pretend %
+ autoCoerce(s: %): Symbol == -- used for hard coercion
+ s : Symbol
+
coerce(s: %): Symbol ==
s case Symbol => s
userError "invalid conversion target type"
@@ -156,6 +181,9 @@ Syntax(): Public == Private where
coerce(s: String): % ==
s pretend %
+ autoCoerce(s: %): String == -- used for hard coercion
+ s : String
+
coerce(s: %): String ==
s case String => s
userError "invalid conversion target type"
diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot
index c6841f5b..8915a10b 100644
--- a/src/interp/compiler.boot
+++ b/src/interp/compiler.boot
@@ -1243,7 +1243,7 @@ coerceExtraHard(T is [x,m',e],m) ==
m' is ['Record,:.] and m = $Expression =>
[['coerceRe2E,x,['ELT,COPY m',0]],m,e]
belongsTo?(m',["UnionType"],e) and hasUniqueCaseView(x,m,e) =>
- coerceByModemap(T,m)
+ autoCoerceByModemap(T,m)
nil
++ returns true if mode `m' is known to belong to category `cat' in
diff --git a/src/testsuite/interpreter/case.input b/src/testsuite/interpreter/case.input
new file mode 100644
index 00000000..085099d4
--- /dev/null
+++ b/src/testsuite/interpreter/case.input
@@ -0,0 +1,5 @@
+++ Contributed by Yixin Cao
+)co "case.spad"
+b:=convert("b")@Symbol
+c:=b::Syntax
+test c
diff --git a/src/testsuite/interpreter/case.spad b/src/testsuite/interpreter/case.spad
new file mode 100644
index 00000000..edbdaadd
--- /dev/null
+++ b/src/testsuite/interpreter/case.spad
@@ -0,0 +1,10 @@
+++ Contibuted by Yixin Cao
+)abbrev domain TD TestDomain
+TestDomain :Public == Private where
+ Public == with
+ test: Syntax -> Boolean
+
+ Private == add
+ test(x) ==
+ if x case Symbol then coerce(x)@Symbol
+ x case Symbol