From e688a0421303fb51afe31bb4b36774011bfac76d Mon Sep 17 00:00:00 2001 From: dos-reis Date: Thu, 9 May 2013 01:34:59 +0000 Subject: Simplify copy --- src/ChangeLog | 6 ++++++ src/algebra/list.spad.pamphlet | 17 +++++------------ src/interp/g-opt.boot | 4 ++-- src/interp/lisp-backend.boot | 3 ++- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index eb9daa09..fd3781d3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2013-05-08 Gabriel Dos Reis + + * 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 * interp/c-util.boot (almostPure?): New. 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], -- cgit v1.2.3