aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog6
-rw-r--r--src/algebra/list.spad.pamphlet17
-rw-r--r--src/interp/g-opt.boot4
-rw-r--r--src/interp/lisp-backend.boot3
4 files changed, 15 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index eb9daa09..fd3781d3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
2013-05-08 Gabriel Dos Reis <gdr@integrable-solutions.net>
+ * algebra/list.spad.pamphlet (List) [copy]: Simplify.
+ * interp/g-opt.boot (%lcopy): New side-effect free builtin.
+ * interp/lisp-backend.boot: Translate it.
+
+2013-05-08 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
* interp/c-util.boot (almostPure?): New.
(foldExportedFunctionReferences): Use it.
diff --git a/src/algebra/list.spad.pamphlet b/src/algebra/list.spad.pamphlet
index ea7960fb..9f0cc282 100644
--- a/src/algebra/list.spad.pamphlet
+++ b/src/algebra/list.spad.pamphlet
@@ -72,19 +72,18 @@ List(S:Type): Exports == Implementation where
import %tail: % -> % from Foreign Builtin
import %lreverse: % -> % from Foreign Builtin
import %lreverse!: % -> % from Foreign Builtin
+ import %lcopy: % -> % from Foreign Builtin
import %llength: % -> NonNegativeInteger from Foreign Builtin
import %icst0: NonNegativeInteger from Foreign Builtin
import %icst1: NonNegativeInteger from Foreign Builtin
import %idec: Integer -> Integer from Foreign Builtin
Qpush ==> PUSH$Lisp
- cycleMax ==> 1000 -- value used in checking for cycles
nil == %nil
null l == %peq(l,%nil)
cons(s, l) == %pair(s,l)
append(l:%, t:%) == %lconcat(l,t)
-
#x == %llength x
concat(s:S,x:%) == %pair(s,x)
eq?(x,y) == %peq(x,y)
@@ -110,11 +109,11 @@ List(S:Type): Exports == Implementation where
empty? x => error "Cannot update an empty list"
%store(%tail x,y)$Foreign(Builtin)
%tail x
- construct l == l pretend %
- parts s == s pretend List S
+ construct l == l
+ parts s == s
reverse! x == %lreverse! x
reverse x == %lreverse x
- minIndex x == 1
+ minIndex x == %icst1
rest(x, n) ==
for i in %icst1..n repeat
@@ -122,13 +121,7 @@ List(S:Type): Exports == Implementation where
x := %tail x
x
- copy x ==
- y := empty()
- for i in %icst0.. while not empty? x repeat
- if i = cycleMax and cyclic? x then error "cyclic list"
- y := %pair(%head x,y)
- x := %tail x
- %lreverse! y
+ copy x == %lcopy x
if S has CoercibleTo(OutputForm) then
coerce(x):OutputForm ==
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 775b3b8a..782fb33f 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -1,6 +1,6 @@
-- Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
-- All rights reserved.
--- Copyright (C) 2007-2012, Gabriel Dos Reis.
+-- Copyright (C) 2007-2013, Gabriel Dos Reis.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -652,7 +652,7 @@ $VMsideEffectFreeOperators ==
%zexp %zlog %zsin %zcos %ztan %zasin %zacos %zatan
%zsinh %zcosh %ztanh %zasinh %zacosh %zatanh
%nil %pair %list %pair? %lconcat %llength %lfirst %lsecond %lthird
- %lreverse %lempty? %hash %ismall? %string? %f2s STRINGIMAGE
+ %lreverse %lempty? %lcopy %hash %ismall? %string? %f2s STRINGIMAGE
%ccst %ccstmax %ceq %clt %cle %cgt %cge %c2i %i2c %s2c %c2s %cup %cdown
%sname
%strlength %streq %i2s %schar %strlt %strconc
diff --git a/src/interp/lisp-backend.boot b/src/interp/lisp-backend.boot
index 438c191c..73af3a96 100644
--- a/src/interp/lisp-backend.boot
+++ b/src/interp/lisp-backend.boot
@@ -1,4 +1,4 @@
--- Copyright (C) 2011-2012, Gabriel Dos Reis.
+-- Copyright (C) 2011-2013, Gabriel Dos Reis.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -615,6 +615,7 @@ for x in [
['%lthird, :'CADDR],
['%pair?, :'CONSP],
['%tail, :'CDR],
+ ['%lcopy, :'COPY_-LIST],
-- binary list operations
['%lconcat, :'APPEND],