diff --git a/moo/kernel/Apex.moo b/moo/kernel/Apex.moo index f5476f9..066ba01 100644 --- a/moo/kernel/Apex.moo +++ b/moo/kernel/Apex.moo @@ -112,6 +112,8 @@ extend Apex ## ------------------------------------------------------- method(#dual,#primitive,#lenient) _shallowCopy. method(#dual,#primitive) shallowCopy. + method(#dual,#primitive,#lenient) _copy. ## alias to _shallowCopy + method(#dual,#primitive) copy. ## alias to shallowCopy ## ------------------------------------------------------- ## ------------------------------------------------------- diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index 6345e71..8664943 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -110,6 +110,17 @@ class SequenceableCollection(Collection) startIndex to: stopIndex do: [:i | aBlock value: (self at: i) value: i]. } + + method swap: anIndex with: anotherIndex + { + ## the subclass must implement at: and at:put for this to work. + + | tmp | + tmp := self at: anIndex. + self at: anIndex put: (self at: anotherIndex). + self at: anotherIndex put: tmp. + } + } ## ------------------------------------------------------------------------------- diff --git a/moo/lib/exec.c b/moo/lib/exec.c index afe0ac4..0b62edd 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -3800,6 +3800,7 @@ static pf_t pftab[] = { "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } }, { "Apex_basicSize", { moo_pf_basic_size, 0, 0 } }, { "Apex_class", { moo_pf_class, 0, 0 } }, + { "Apex_copy", { moo_pf_shallow_copy, 0, 0 } }, { "Apex_hash", { pf_hash, 0, 0 } }, { "Apex_isKindOf:", { moo_pf_is_kind_of, 1, 1, } }, { "Apex_perform", { pf_perform, 1, MA } }, diff --git a/moo/lib/gc.c b/moo/lib/gc.c index f68a7d9..c81c9bf 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -1082,6 +1082,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) /* copy the payload */ MOO_MEMCPY (z + 1, oop + 1, get_payload_bytes(moo, oop)); + MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */ return z; #else @@ -1095,6 +1096,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) moo_popvolat(moo); MOO_MEMCPY (z, oop, total_bytes); + MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */ return z; #endif } diff --git a/moo/lib/pf-basic.c b/moo/lib/pf-basic.c index 0595f74..bb72ebd 100644 --- a/moo/lib/pf-basic.c +++ b/moo/lib/pf-basic.c @@ -253,7 +253,6 @@ moo_pfrc_t moo_pf_shallow_copy (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) return MOO_PF_SUCCESS; } - /* -------------------------------------------------------------------------------- * BASIC ACCESS * -------------------------------------------------------------------------------- */