diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index b11d4526a1..19347e5a3e 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,10 +1,8 @@ + native: -- gc when memory is tight - f >n: crashes - typecases: type error reporting bad - image output -- 64-bit "bignums" - floats - {...} vectors - parsing should be parsing @@ -48,6 +46,7 @@ + misc: +- compiled stack traces broken - should i -i inf -inf be parsing words? - namespace clone drops static var bindings - ditch map diff --git a/factor/FactorReader.java b/factor/FactorReader.java index c105c61d86..81a982d6fe 100644 --- a/factor/FactorReader.java +++ b/factor/FactorReader.java @@ -331,12 +331,7 @@ public class FactorReader if(interp.getVocabulary(name) == null) error("Undefined vocabulary: " + name); - Cons use = getUse(); - - if(!Cons.contains(use,name)) - use = new Cons(name,use); - - setUse(use); + setUse(new Cons(name,getUse())); } //}}} //{{{ parse() method diff --git a/library/cross-compiler.factor b/library/cross-compiler.factor new file mode 100644 index 0000000000..c617de8f90 --- /dev/null +++ b/library/cross-compiler.factor @@ -0,0 +1,178 @@ +! :folding=none:collapseFolds=1: + +! $Id$ +! +! Copyright (C) 2004 Slava Pestov. +! +! Redistribution and use in source and binary forms, with or without +! modification, are permitted provided that the following conditions are met: +! +! 1. Redistributions of source code must retain the above copyright notice, +! this list of conditions and the following disclaimer. +! +! 2. Redistributions in binary form must reproduce the above copyright notice, +! this list of conditions and the following disclaimer in the documentation +! and/or other materials provided with the distribution. +! +! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +IN: cross-compiler +USE: arithmetic +USE: kernel +USE: lists +USE: parser +USE: stack +USE: stdio +USE: streams +USE: strings +USE: vectors +USE: vectors +USE: vocabularies +USE: words + +IN: kernel +DEFER: getenv +DEFER: setenv +DEFER: save-image +DEFER: handle? +DEFER: room + +IN: strings +DEFER: str= +DEFER: str-hashcode + +IN: io-internals +DEFER: open-file +DEFER: server-socket +DEFER: close-fd +DEFER: accept-fd +DEFER: read-line-fd-8 +DEFER: write-fd-8 +DEFER: flush-fd +DEFER: shutdown-fd + +IN: words +DEFER: +DEFER: word-primitive +DEFER: set-word-primitive +DEFER: word-parameter +DEFER: set-word-parameter +DEFER: word-plist +DEFER: set-word-plist + +IN: cross-compiler + +: primitives, ( -- ) + 1 [ + execute + call + ifte + cons? + cons + car + cdr + rplaca + rplacd + vector? + + vector-length + set-vector-length + vector-nth + set-vector-nth + string? + str-length + str-nth + str-compare + str= + str-hashcode + index-of* + substring + sbuf? + + sbuf-length + set-sbuf-length + sbuf-nth + set-sbuf-nth + sbuf-append + sbuf>str + fixnum? + bignum? + + + - + * + / + mod + /mod + bitand + bitor + bitxor + bitnot + shift< + shift> + < + <= + > + >= + word? + + word-primitive + set-word-primitive + word-parameter + set-word-parameter + word-plist + set-word-plist + drop + dup + swap + over + pick + nip + tuck + rot + >r + r> + eq? + getenv + setenv + open-file + garbage-collection + save-image + datastack + callstack + set-datastack + set-callstack + handle? + exit* + server-socket + close-fd + accept-fd + read-line-fd-8 + write-fd-8 + flush-fd + shutdown-fd + room + ] [ + swap succ tuck primitive, + ] each drop ; + +: version, ( -- ) + "version" [ "kernel" ] search version unit compound, ; + +: make-image ( -- ) + #! Make an image for the C interpreter. + [ + "/library/platform/native/boot.factor" run-resource + ] with-image + + ! Uncomment this on sparc and powerpc. + ! "big-endian" on + "factor.image" write-image ; diff --git a/library/debugger.factor b/library/debugger.factor index 1aa21cb187..d54e09631b 100644 --- a/library/debugger.factor +++ b/library/debugger.factor @@ -54,6 +54,10 @@ USE: unparser : in-parser? ( -- ? ) "line" get "pos" get and ; +: error-handler-hook + #! The game overrides this. + ; + : default-error-handler ( error -- ) #! Print the error and return to the top level. [ @@ -63,6 +67,8 @@ USE: unparser ":s :r :n :c show stacks at time of error." print java? [ ":j shows Java stack trace." print ] when + error-handler-hook + ] when* ; : :s ( -- ) "error-datastack" get . ; diff --git a/library/httpd/http-common.factor b/library/httpd/http-common.factor index b9b2000f77..30ca631e63 100644 --- a/library/httpd/http-common.factor +++ b/library/httpd/http-common.factor @@ -53,9 +53,7 @@ USE: url-encoding : httpd-error ( error -- ) dup log-error - [ "text/html" response ] [ error-body ] cleave - cat2 - print ; + <% dup "text/html" response % error-body % %> print ; : read-header-iter ( alist -- alist ) read dup "" = [ diff --git a/library/httpd/responder.factor b/library/httpd/responder.factor index 4346f7c203..c0cf4f3156 100644 --- a/library/httpd/responder.factor +++ b/library/httpd/responder.factor @@ -1,4 +1,4 @@ -! :folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/image.factor b/library/image.factor similarity index 98% rename from library/platform/native/image.factor rename to library/image.factor index 3c1ed9826a..0693086ced 100644 --- a/library/platform/native/image.factor +++ b/library/image.factor @@ -184,7 +184,7 @@ DEFER: ' object-tag here-as swap 11 >header emit dup str-length emit - dup hashcode fixnum-mask bitand emit + dup hashcode ( fixnum-mask bitand ) emit pack-string pad ; @@ -224,7 +224,7 @@ IN: cross-compiler dup word-name "name" swons , dup word-vocabulary "vocabulary" swons , - [ "parsing" get >boolean ] bind "parsing" swons , + "parsing" swap word-property >boolean "parsing" swons , ,] ' ; diff --git a/library/init.factor b/library/init.factor index 3f0d4ba0b3..0d70404f00 100644 --- a/library/init.factor +++ b/library/init.factor @@ -44,9 +44,13 @@ USE: strings ! on all other words already being defined. : init-search-path ( -- ) - #! Sets up the default vocabularies. + ! For files + "user" "file-in" set + [ "user" "builtins" ] "file-use" set + ! For interactive + "user" "in" set [ - "user" ! This is first + "user" "arithmetic" "builtins" "combinators" @@ -72,10 +76,8 @@ USE: strings "vectors" "vocabularies" "words" - "scratchpad" ! This is last - ] "use" set - ! New words go in 'user' vocabulary. - "user" "in" set ; + "scratchpad" + ] "use" set ; : init-scratchpad ( -- ) #! The contents of the scratchpad vocabulary is not saved diff --git a/library/lists.factor b/library/lists.factor index fa37fd315f..1f5bd9cfa4 100644 --- a/library/lists.factor +++ b/library/lists.factor @@ -94,10 +94,6 @@ USE: stack 2drop f ] ifte ; -: count ( n -- [ 1 2 3 ... n ] ) - #! If n <= 0, pushes the empty list. - [ [ ] times* ] cons expand ; - : nth ( n list -- list[n] ) #! Gets the nth element of a proper list by successively #! iterating down the cdr pointer. @@ -165,32 +161,20 @@ USE: stack #! DESTRUCTIVE. Reverse the given list, without consing. f swap nreverse-iter ; -~<< partition-iterI - R1 R2 A D C -- A C r:R1 r:R2 r:A r:D r:C >>~ +: partition-add ( obj ? ret1 ret2 -- ret1 ret2 ) + >r >r [ r> cons r> ] [ r> r> swapd cons ] ifte ; inline -~<< partition-iterT{ - r:R1 r:R2 r:A r:D r:C -- A R1 r:R1 r:R2 r:D r:C >>~ +: partition-step ( ret1 ret2 ref combinator car -- ret1 ret2 ) + >r 2swap r> -rot >r >r dup >r swap call r> swap r> r> + partition-add ; inline -~<< }partition-iterT - R1 r:R1X r:R2 r:D r:C -- R1 R2 D C >>~ - -~<< partition-iterF{ - r:R1 r:R2 r:A r:D r:C -- A R2 r:R1 r:R2 r:D r:C >>~ - -~<< }partition-iterF - R2 r:R1 r:R2X r:D r:C -- R1 R2 D C >>~ - -: partition-iter ( ref ret1 ret2 list combinator -- ref ret1 ret2 ) - #! Helper word for 'partition'. - over [ - ! Note this ifte must be in tail position! - >r uncons r> partition-iterI >r >r dup r> r> call [ - partition-iterT{ cons }partition-iterT partition-iter - ] [ - partition-iterF{ cons }partition-iterF partition-iter - ] ifte +: partition-iter ( ret1 ret2 ref combinator list -- ret1 ret2 ) + dup [ + 3dup cdr >r >r >r + car partition-step + r> r> r> partition-iter ] [ - 2drop + 3drop ] ifte ; inline interpret-only : partition ( ref list combinator -- list1 list2 ) @@ -200,19 +184,8 @@ USE: stack #! the first or second list. #! The combinator must have stack effect: #! ( ref element -- ? ) - [ ] [ ] 2swap partition-iter rot drop ; inline interpret-only - -: remove ( obj list -- list ) - #! Remove all occurrences of the object from the list. - dup [ - 2dup car = [ - cdr remove - ] [ - uncons swapd remove cons - ] ifte - ] [ - nip - ] ifte ; + swap >r >r >r [ ] [ ] r> r> r> partition-iter ; + inline interpret-only : sort ( list comparator -- sorted ) #! Sort the elements in a proper list using a comparator. @@ -235,6 +208,18 @@ USE: stack #! Sorts the list into ascending numerical order. [ > ] sort ; +: remove ( obj list -- list ) + #! Remove all occurrences of the object from the list. + dup [ + 2dup car = [ + cdr remove + ] [ + uncons swapd remove cons + ] ifte + ] [ + nip + ] ifte ; + ! Redefined below DEFER: tree-contains? @@ -293,13 +278,6 @@ DEFER: tree-contains? transp over >r >r call r> cons r> ] each drop nreverse ; inline interpret-only -: map ( [ items ] [ code ] -- [ mapping ] ) - #! Applies the code to each item, returns a list that - #! contains the result of each application. - #! - #! This combinator will not compile. - 2list restack each unstack ; inline interpret-only - : subset-add ( car pred accum -- accum ) >r over >r call r> r> rot [ cons ] [ nip ] ifte ; diff --git a/library/math/arithmetic.factor b/library/math/arithmetic.factor index 069605bbfb..237dc1533a 100644 --- a/library/math/arithmetic.factor +++ b/library/math/arithmetic.factor @@ -57,14 +57,14 @@ USE: stack >=< call ; inline interpret-only : max ( x y -- z ) - 2dup > -rot ? ; + 2dup > [ drop ] [ nip ] ifte ; : min ( x y -- z ) - 2dup < -rot ? ; + 2dup < [ drop ] [ nip ] ifte ; : between? ( x min max -- ? ) #! Push if min <= x <= max. - [ [ dup ] dip max ] dip min = ; + >r dupd max r> min = ; : sq dup * ; inline diff --git a/library/platform/jvm/boot-sumo.factor b/library/platform/jvm/boot-sumo.factor index d835dd0888..8628bc8654 100644 --- a/library/platform/jvm/boot-sumo.factor +++ b/library/platform/jvm/boot-sumo.factor @@ -99,8 +99,9 @@ USE: parser "/library/telnetd.factor" run-resource ! telnetd !!! Java -> native VM image cross-compiler. -"/library/platform/native/image.factor" run-resource ! cross-compiler -"/library/platform/native/cross-compiler.factor" run-resource ! cross-compiler +"/library/image.factor" run-resource ! cross-compiler +"/library/cross-compiler.factor" run-resource ! cross-compiler +"/library/platform/jvm/cross-compiler.factor" run-resource ! cross-compiler !!! HTTPD. "/library/httpd/url-encoding.factor" run-resource ! url-encoding diff --git a/library/platform/jvm/combinators.factor b/library/platform/jvm/combinators.factor index a54c9bf3e9..de2b617ed0 100644 --- a/library/platform/jvm/combinators.factor +++ b/library/platform/jvm/combinators.factor @@ -39,3 +39,10 @@ USE: stack restack call unstack ; interpret-only + +: map ( [ items ] [ code ] -- [ mapping ] ) + #! Applies the code to each item, returns a list that + #! contains the result of each application. + #! + #! This combinator will not compile. + 2list restack each unstack ; inline interpret-only diff --git a/library/platform/jvm/cross-compiler.factor b/library/platform/jvm/cross-compiler.factor new file mode 100644 index 0000000000..34b3295228 --- /dev/null +++ b/library/platform/jvm/cross-compiler.factor @@ -0,0 +1,53 @@ +! :folding=none:collapseFolds=1: + +! $Id$ +! +! Copyright (C) 2004 Slava Pestov. +! +! Redistribution and use in source and binary forms, with or without +! modification, are permitted provided that the following conditions are met: +! +! 1. Redistributions of source code must retain the above copyright notice, +! this list of conditions and the following disclaimer. +! +! 2. Redistributions in binary form must reproduce the above copyright notice, +! this list of conditions and the following disclaimer in the documentation +! and/or other materials provided with the distribution. +! +! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +IN: cross-compiler +USE: arithmetic +USE: kernel +USE: lists +USE: parser +USE: stack +USE: stdio +USE: streams +USE: strings +USE: vectors +USE: vectors +USE: vocabularies +USE: words + +: worddef, ( word -- ) + dup compound-or-compiled? [ + dup word-of-worddef swap compound>list compound, + ] [ + drop + ] ifte ; + +: cross-compile ( quot -- ) + [ dup worddef? [ worddef, ] [ drop ] ifte ] each ; + +: cross-compile-resource ( resource -- ) + parse-resource cross-compile ; diff --git a/library/platform/jvm/stack2.factor b/library/platform/jvm/stack2.factor index 9c8b81b427..5e9b368582 100644 --- a/library/platform/jvm/stack2.factor +++ b/library/platform/jvm/stack2.factor @@ -65,7 +65,7 @@ USE: vectors clone set-callstack* ; interpret-only : clear ( -- ) - #! Clear the datastack. For interactive use only; invoking this from a - #! word definition will clobber any values left on the data stack by the - #! caller. + #! Clear the datastack. For interactive use only; invoking + #! this from a word definition will clobber any values left + #! on the data stack by the caller. datastack* vector-clear ; diff --git a/library/platform/native/arithmetic.factor b/library/platform/native/arithmetic.factor new file mode 100644 index 0000000000..e39f8e9586 --- /dev/null +++ b/library/platform/native/arithmetic.factor @@ -0,0 +1,24 @@ +! This file will go away very shortly! + +IN: arithmetic +USE: combinators +USE: kernel +USE: logic +USE: stack + +: integer? dup fixnum? swap bignum? or ; + +: max ( x y -- z ) + 2dup > [ drop ] [ nip ] ifte ; + +: min ( x y -- z ) + 2dup < [ drop ] [ nip ] ifte ; + +: between? ( x min max -- ? ) + #! Push if min <= x <= max. + >r dupd max r> min = ; + +: pred 1 - ; inline +: succ 1 + ; inline + +: neg 0 swap - ; inline diff --git a/library/platform/native/boot.factor b/library/platform/native/boot.factor index f71183ae7c..61b899f27d 100644 --- a/library/platform/native/boot.factor +++ b/library/platform/native/boot.factor @@ -47,6 +47,7 @@ primitives, [ "/library/ansi.factor" "/library/assoc.factor" + "/library/cross-compiler.factor" "/library/combinators.factor" "/library/cons.factor" "/library/continuations.factor" @@ -54,10 +55,12 @@ primitives, "/library/errors.factor" "/library/format.factor" "/library/hashtables.factor" + "/library/image.factor" "/library/init.factor" "/library/inspector.factor" "/library/inspect-vocabularies.factor" "/library/interpreter.factor" + "/library/lists.factor" "/library/list-namespaces.factor" "/library/logging.factor" "/library/logic.factor" @@ -76,11 +79,12 @@ primitives, "/library/words.factor" "/library/math/math-combinators.factor" "/library/math/namespace-math.factor" + "/library/platform/native/arithmetic.factor" + "/library/platform/native/cross-compiler.factor" "/library/platform/native/errors.factor" "/library/platform/native/io-internals.factor" "/library/platform/native/stream.factor" "/library/platform/native/kernel.factor" - "/library/platform/native/image.factor" "/library/platform/native/namespaces.factor" "/library/platform/native/parse-numbers.factor" "/library/platform/native/parser.factor" @@ -96,17 +100,6 @@ primitives, ] [ cross-compile-resource ] each -[ - ! We don't include all of 'lists' or 'math' yet... - between? min max - append add remove contains unique - pred succ neg fib each nreverse nreverse-iter - max 2list length reverse nth list? 2rlist - all? clone-list clone-list-iter subset subset-iter - subset-add car= cdr= cons= cons-hashcode - tree-contains? =-or-contains? - last* last inject integer? -] [ worddef worddef, ] each version, diff --git a/library/platform/native/cross-compiler.factor b/library/platform/native/cross-compiler.factor index 632443b2d2..1480420c8e 100644 --- a/library/platform/native/cross-compiler.factor +++ b/library/platform/native/cross-compiler.factor @@ -26,169 +26,22 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: cross-compiler -USE: arithmetic -USE: kernel USE: lists +USE: namespaces USE: parser -USE: stack -USE: stdio -USE: streams -USE: strings -USE: vectors -USE: vectors -USE: vocabularies -USE: words - -IN: kernel -DEFER: getenv -DEFER: setenv -DEFER: save-image -DEFER: handle? -DEFER: room - -IN: strings -DEFER: str= -DEFER: str-hashcode - -IN: io-internals -DEFER: open-file -DEFER: server-socket -DEFER: close-fd -DEFER: accept-fd -DEFER: read-line-fd-8 -DEFER: write-fd-8 -DEFER: flush-fd -DEFER: shutdown-fd - -IN: words -DEFER: -DEFER: word-primitive -DEFER: set-word-primitive -DEFER: word-parameter -DEFER: set-word-parameter -DEFER: word-plist -DEFER: set-word-plist - -IN: cross-compiler - -: primitives, ( -- ) - 1 [ - execute - call - ifte - cons? - cons - car - cdr - rplaca - rplacd - vector? - - vector-length - set-vector-length - vector-nth - set-vector-nth - string? - str-length - str-nth - str-compare - str= - str-hashcode - index-of* - substring - sbuf? - - sbuf-length - set-sbuf-length - sbuf-nth - set-sbuf-nth - sbuf-append - sbuf>str - fixnum? - bignum? - + - - - * - / - mod - /mod - bitand - bitor - bitxor - bitnot - shift< - shift> - < - <= - > - >= - word? - - word-primitive - set-word-primitive - word-parameter - set-word-parameter - word-plist - set-word-plist - drop - dup - swap - over - pick - nip - tuck - rot - >r - r> - eq? - getenv - setenv - open-file - garbage-collection - save-image - datastack - callstack - set-datastack - set-callstack - handle? - exit* - server-socket - close-fd - accept-fd - read-line-fd-8 - write-fd-8 - flush-fd - shutdown-fd - room - ] [ - swap succ tuck primitive, - ] each drop ; - -: worddef, ( word -- ) - dup compound-or-compiled? [ - dup word-of-worddef swap compound>list compound, - ] [ - drop - ] ifte ; - -: version, ( -- ) - "version" [ "kernel" ] search - version unit - - worddef, ; - -: cross-compile ( quot -- ) - [ dup worddef? [ worddef, ] [ drop ] ifte ] each ; : cross-compile-resource ( resource -- ) - parse-resource cross-compile ; + [ + ! Replace ; with our own + "file-use" get + "cross-compiler-syntax" swons + "file-use" set + run-resource + ] bind ; -: make-image ( -- ) - #! Make an image for the C interpreter. - [ - "/library/platform/native/boot.factor" run-resource - ] with-image +IN: cross-compiler-syntax +USE: builtins - ! Uncomment this on sparc and powerpc. - ! "big-endian" on - "factor.image" write-image ; +: ; ( -- ) + #! Cross-compile the just-read definition. + nreverse compound, ; parsing diff --git a/library/platform/native/kernel.factor b/library/platform/native/kernel.factor index 7907393328..24d7e74689 100644 --- a/library/platform/native/kernel.factor +++ b/library/platform/native/kernel.factor @@ -110,5 +110,3 @@ IN: strings : >char ; : >upper ; : >lower ; -IN: lists -: sort ; diff --git a/library/platform/native/parse-stream.factor b/library/platform/native/parse-stream.factor index d4a7e9d596..efd0f964a6 100644 --- a/library/platform/native/parse-stream.factor +++ b/library/platform/native/parse-stream.factor @@ -35,6 +35,7 @@ USE: namespaces USE: stack USE: stdio USE: streams +USE: strings : next-line ( -- str ) "parse-stream" get freadln @@ -58,8 +59,8 @@ USE: streams : init-parser ( name -- seed ) "parse-name" set - "user" "in" set - [ "builtins" "user" ] "use" set + "file-in" get "in" set + "file-use" get "use" set f ; : parse-stream ( name stream -- code ) @@ -72,3 +73,9 @@ USE: streams : run-file ( file -- ) parse-file call ; + +: resource-path ( -- path ) + "resource-path" get [ "." ] unless* ; + +: run-resource ( file -- ) + resource-path swap cat2 run-file ; diff --git a/library/platform/native/stack.factor b/library/platform/native/stack.factor index b936bae628..48d5eac64c 100644 --- a/library/platform/native/stack.factor +++ b/library/platform/native/stack.factor @@ -26,12 +26,20 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: stack +USE: vectors : 2drop ( x x -- ) drop drop ; : 3drop ( x x x -- ) drop drop drop ; : 2dup ( x y -- x y x y ) over over ; +: 3dup ( x y z -- x y z x y z ) pick pick pick ; : 2swap ( x y z t -- z t x y ) rot >r rot r> ; : -rot ( x y z -- z x y ) rot rot ; : dupd ( x y -- x x y ) >r dup r> ; : swapd ( x y z -- y x z ) >r swap r> ; : transp ( x y z -- z y x ) swap rot ; + +: clear ( -- ) + #! Clear the datastack. For interactive use only; invoking + #! this from a word definition will clobber any values left + #! on the data stack by the caller. + 0 set-datastack ;