aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog8
-rw-r--r--src/algebra/array1.spad.pamphlet58
-rw-r--r--src/algebra/strap/POLYCAT-.lsp3
-rw-r--r--src/interp/sys-macros.lisp3
4 files changed, 44 insertions, 28 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 8763deef..b236b0f8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,13 @@
2009-04-26 Gabriel Dos Reis <gdr@cs.tamu.edu>>
+ * interp/sys-macros.lisp (makeSimpleArrayFromList): New.
+ * algebra/array1.spad.pamphlet (construct$PrimitiveArray): Implement.
+ (copy$PrimitiveArray): Likewise.
+ (IndexedOneDimensionalArray): Rework. Explicitly use
+ PrimitiveArray(S) as representation domain.
+
+2009-04-26 Gabriel Dos Reis <gdr@cs.tamu.edu>>
+
* algebra/domain.spad.pamphlet (Constructor): Use Identifier.
2009-04-26 Gabriel Dos Reis <gdr@cs.tamu.edu>
diff --git a/src/algebra/array1.spad.pamphlet b/src/algebra/array1.spad.pamphlet
index 7fe6df24..00117332 100644
--- a/src/algebra/array1.spad.pamphlet
+++ b/src/algebra/array1.spad.pamphlet
@@ -20,10 +20,13 @@ PrimitiveArray(S:Type): OneDimensionalArrayAggregate S == add
minIndex x ==
0
-
+
empty() ==
makeSimpleArray(getVMType(S)$Lisp,0$Lisp)$Lisp
+ construct l ==
+ makeSimpleArrayFromList(getVMType(S)$Foreign(Builtin),l)$Foreign(Builtin)
+
new(n, x) ==
makeFilledSimpleArray(getVMType(S)$Lisp,n,x)$Lisp
@@ -42,6 +45,9 @@ PrimitiveArray(S:Type): OneDimensionalArrayAggregate S == add
fill!(x, s) ==
FILL(x,s)$Foreign(Builtin)
+ copy x ==
+ COPY_-SEQ(x)$Foreign(Builtin)
+
@
@@ -362,24 +368,27 @@ FlexibleArray(S: Type) == Implementation where
IndexedOneDimensionalArray(S:Type, mn:Integer):
OneDimensionalArrayAggregate S == add
- Qmax ==> QVMAXINDEX$Lisp
- Qsize ==> QVSIZE$Lisp
- Qelt ==> QVELT$Lisp
- Qsetelt ==> QSETVELT$Lisp
--- Qelt1 ==> QVELT_-1$Lisp
--- Qsetelt1 ==> QSETVELT_-1$Lisp
- Qnew ==> GETREFV$Lisp
- I ==> Integer
-
- #x == Qsize x
- fill_!(x, s) == (for i in 0..Qmax x repeat Qsetelt(x, i, s); x)
- minIndex x == mn
-
- empty() == Qnew(0$Lisp)
- new(n, s) == fill_!(Qnew n,s)
-
- map_!(f, s1) ==
- n:Integer := Qmax(s1)
+ macro Qmax == maxIndexOfSimpleArray$Foreign(Builtin)
+ macro Qsize == sizeOfSimpleArray$Foreign(Builtin)
+ macro Qelt == getSimpleArrayEntry$Foreign(Builtin)
+ macro Qsetelt == setSimpleArrayEntry$Foreign(Builtin)
+ macro I == Integer
+ Rep == PrimitiveArray S
+
+ newArray(n: Integer): % ==
+ makeSimpleArray(getVMType(S)$Foreign(Builtin),n)$Foreign(Builtin)
+
+ #x == # rep x
+ copy x == per copy rep x
+ fill!(x, s) == per fill!(rep x, s)
+ minIndex x == mn
+
+ empty() == per empty()$Rep
+ new(n, s) == per new(n,s)$Rep
+ construct l == per construct(l)$Rep
+
+ map!(f, s1) ==
+ n: Integer := Qmax(s1)
n < 0 => s1
for i in 0..n repeat Qsetelt(s1, i, f(Qelt(s1,i)))
s1
@@ -387,14 +396,14 @@ IndexedOneDimensionalArray(S:Type, mn:Integer):
map(f, s1) ==
n:Integer := Qmax(s1)
n < 0 => s1
- ss2:% := Qnew(n+1)
+ ss2:% := newArray(n+1)
for i in 0..n repeat Qsetelt(ss2, i, f(Qelt(s1,i)))
ss2
map(f, a, b) ==
maxind:Integer := min(Qmax a, Qmax b)
maxind < 0 => empty()
- c:% := Qnew(maxind+1)
+ c:% := newArray(maxind+1)
for i in 0..maxind repeat
Qsetelt(c, i, f(Qelt(a,i),Qelt(b,i)))
c
@@ -452,12 +461,7 @@ OneDimensionalArray(S:Type): Exports == Implementation where
oneDimensionalArray: (NonNegativeInteger, S) -> %
++ oneDimensionalArray(n,s) creates an array from n copies of element s
Implementation == IndexedOneDimensionalArray(S, ARRAYMININDEX) add
- oneDimensionalArray(u) ==
- n := #u
- n = 0 => empty()
- a := new(n, first u)
- for i in 2..n for x in rest u repeat a.i := x
- a
+ oneDimensionalArray(u) == construct u
oneDimensionalArray(n,s) == new(n,s)
@
diff --git a/src/algebra/strap/POLYCAT-.lsp b/src/algebra/strap/POLYCAT-.lsp
index d6fea686..7fd8802c 100644
--- a/src/algebra/strap/POLYCAT-.lsp
+++ b/src/algebra/strap/POLYCAT-.lsp
@@ -561,7 +561,8 @@
(LETT #0# |b| |POLYCAT-;P2R|)
(LETT |i| (SPADCALL |w| (|getShellEntry| $ 104))
|POLYCAT-;P2R|)
- (LETT #1# (QVSIZE |w|) |POLYCAT-;P2R|) G190
+ (LETT #1# (|sizeOfSimpleArray| |w|) |POLYCAT-;P2R|)
+ G190
(COND
((OR (> |i| #1#) (ATOM #0#)
(PROGN
diff --git a/src/interp/sys-macros.lisp b/src/interp/sys-macros.lisp
index 1564206b..db4b08ec 100644
--- a/src/interp/sys-macros.lisp
+++ b/src/interp/sys-macros.lisp
@@ -334,6 +334,9 @@
(defmacro |makeFilledSimpleArray| (|t| |n| |v|)
`(make-array ,|n| :element-type ,|t| :initial-element ,|v|))
+(defmacro |makeSimpleArrayFromList| (|t| |l|)
+ `(make-array (list-length ,|l|) :element-type ,|t| :initial-contents ,|l|))
+
(defmacro |getSimpleArrayEntry| (|a| |i|)
`(aref (the simple-array ,|a|) (the fixnum ,|i|)))