Skip to content

Commit

Permalink
Merge branch 'master' of git://factorcode.org/git/factor
Browse files Browse the repository at this point in the history
  • Loading branch information
jckarter committed Nov 6, 2009
2 parents ef192d4 + 4311c33 commit 078e999
Show file tree
Hide file tree
Showing 46 changed files with 472 additions and 534 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -58,6 +58,7 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \
vm/math.o \
vm/nursery_collector.o \
vm/object_start_map.o \
vm/objects.o \
vm/primitives.o \
vm/profiler.o \
vm/quotations.o \
Expand Down
12 changes: 11 additions & 1 deletion basis/compiler/tree/propagation/transforms/transforms.factor
Expand Up @@ -3,7 +3,7 @@
USING: kernel sequences words fry generic accessors
classes.tuple classes classes.algebra definitions
stack-checker.state quotations classes.tuple.private math
math.partial-dispatch math.private math.intervals
math.partial-dispatch math.private math.intervals sets.private
math.floats.private math.integers.private layouts math.order
vectors hashtables combinators effects generalizations assocs
sets combinators.short-circuit sequences.private locals
Expand Down Expand Up @@ -290,3 +290,13 @@ CONSTANT: lookup-table-at-max 256
] [ drop f ] if ;

\ at* [ at-quot ] 1 define-partial-eval

: diff-quot ( seq -- quot: ( seq' -- seq'' ) )
tester '[ [ @ not ] filter ] ;

\ diff [ diff-quot ] 1 define-partial-eval

: intersect-quot ( seq -- quot: ( seq' -- seq'' ) )
tester '[ _ filter ] ;

\ intersect [ intersect-quot ] 1 define-partial-eval
2 changes: 1 addition & 1 deletion basis/compression/run-length/run-length.factor
@@ -1,7 +1,7 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators grouping kernel locals math
math.matrices math.order multiline sequence-parser sequences
math.matrices math.order multiline sequences.parser sequences
tools.continuations ;
IN: compression.run-length

Expand Down
3 changes: 0 additions & 3 deletions basis/debugger/debugger-docs.factor
Expand Up @@ -129,9 +129,6 @@ HELP: c-string-error.
HELP: ffi-error.
{ $error-description "Thrown by " { $link dlopen } " and " { $link dlsym } " if a problem occurs while loading a native library or looking up a symbol. See " { $link "alien" } "." } ;

HELP: heap-scan-error.
{ $error-description "Thrown if " { $link next-object } " is called outside of a " { $link begin-scan } "/" { $link end-scan } " pair." } ;

HELP: undefined-symbol-error.
{ $error-description "Thrown if a previously-compiled " { $link alien-invoke } " call refers to a native library symbol which no longer exists." } ;

Expand Down
18 changes: 7 additions & 11 deletions basis/debugger/debugger.factor
Expand Up @@ -103,9 +103,6 @@ HOOK: signal-error. os ( obj -- )
: ffi-error. ( obj -- )
"FFI error" print drop ;

: heap-scan-error. ( obj -- )
"Cannot do next-object outside begin/end-scan" print drop ;

: undefined-symbol-error. ( obj -- )
"The image refers to a library or symbol that was not found at load time"
print drop ;
Expand Down Expand Up @@ -148,14 +145,13 @@ PREDICATE: vm-error < array
{ 6 [ array-size-error. ] }
{ 7 [ c-string-error. ] }
{ 8 [ ffi-error. ] }
{ 9 [ heap-scan-error. ] }
{ 10 [ undefined-symbol-error. ] }
{ 11 [ datastack-underflow. ] }
{ 12 [ datastack-overflow. ] }
{ 13 [ retainstack-underflow. ] }
{ 14 [ retainstack-overflow. ] }
{ 15 [ memory-error. ] }
{ 16 [ fp-trap-error. ] }
{ 9 [ undefined-symbol-error. ] }
{ 10 [ datastack-underflow. ] }
{ 11 [ datastack-overflow. ] }
{ 12 [ retainstack-underflow. ] }
{ 13 [ retainstack-overflow. ] }
{ 14 [ memory-error. ] }
{ 15 [ fp-trap-error. ] }
} ; inline

M: vm-error summary drop "VM error" ;
Expand Down
14 changes: 14 additions & 0 deletions basis/math/statistics/statistics-docs.factor
Expand Up @@ -98,6 +98,19 @@ HELP: histogram*
}
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;

HELP: sorted-histogram
{ $values
{ "seq" sequence }
{ "alist" "an array of key/value pairs" }
}
{ $description "Outputs a " { $link histogram } " of a sequence sorted by number of occurences from lowest to highest." }
{ $examples
{ $example "USING: prettyprint math.statistics ;"
""""abababbbbbbc" sorted-histogram ."""
"{ { 99 1 } { 97 3 } { 98 8 } }"
}
} ;

HELP: sequence>assoc
{ $values
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
Expand Down Expand Up @@ -145,6 +158,7 @@ ARTICLE: "histogram" "Computing histograms"
{ $subsections
histogram
histogram*
sorted-histogram
}
"Combinators for implementing histogram:"
{ $subsections
Expand Down
3 changes: 3 additions & 0 deletions basis/math/statistics/statistics.factor
Expand Up @@ -79,6 +79,9 @@ PRIVATE>
: histogram ( seq -- hashtable )
[ inc-at ] sequence>hashtable ;

: sorted-histogram ( seq -- alist )
histogram >alist sort-values ;

: collect-values ( seq quot: ( obj hashtable -- ) -- hash )
'[ [ dup @ ] dip push-at ] sequence>hashtable ; inline

Expand Down
2 changes: 2 additions & 0 deletions basis/sequences/parser/authors.txt
@@ -0,0 +1,2 @@
Daniel Ehrenberg
Doug Coleman
@@ -1,6 +1,6 @@
USING: tools.test sequence-parser unicode.categories kernel
accessors ;
IN: sequence-parser.tests
IN: sequences.parser.tests

[ "hello" ]
[ "hello" [ take-rest ] parse-sequence ] unit-test
Expand Down
Expand Up @@ -3,7 +3,7 @@
USING: accessors circular combinators.short-circuit fry io
kernel locals math math.order sequences sorting.functor
sorting.slots unicode.categories ;
IN: sequence-parser
IN: sequences.parser

TUPLE: sequence-parser sequence n ;

Expand Down
6 changes: 1 addition & 5 deletions basis/stack-checker/known-words/known-words.factor
Expand Up @@ -623,11 +623,7 @@ M: bad-executable summary
\ <array> { integer object } { array } define-primitive
\ <array> make-flushable

\ begin-scan { } { } define-primitive

\ next-object { } { object } define-primitive

\ end-scan { } { } define-primitive
\ all-instances { } { array } define-primitive

\ size { object } { fixnum } define-primitive
\ size make-flushable
Expand Down
7 changes: 2 additions & 5 deletions basis/tools/memory/memory-docs.factor
Expand Up @@ -13,11 +13,8 @@ ARTICLE: "tools.memory" "Object memory tools"
data-room
code-room
}
"There are a pair of combinators, analogous to " { $link each } " and " { $link filter } ", which operate on the entire collection of objects in the object heap:"
{ $subsections
each-object
instances
}
"A combinator to get objects from the heap:"
{ $subsections instances }
"You can check an object's the heap memory usage:"
{ $subsections size }
"The garbage collector can be invoked manually:"
Expand Down
2 changes: 1 addition & 1 deletion basis/vm/vm.factor
Expand Up @@ -3,7 +3,7 @@
USING: classes.struct alien.c-types alien.syntax ;
IN: vm

TYPEDEF: intptr_t cell
TYPEDEF: uintptr_t cell
C-TYPE: context

STRUCT: zone
Expand Down
4 changes: 1 addition & 3 deletions core/bootstrap/primitives.factor
Expand Up @@ -473,9 +473,7 @@ tuple
{ "resize-array" "arrays" (( n array -- newarray )) }
{ "resize-string" "strings" (( n str -- newstr )) }
{ "<array>" "arrays" (( n elt -- array )) }
{ "begin-scan" "memory" (( -- )) }
{ "next-object" "memory" (( -- obj )) }
{ "end-scan" "memory" (( -- )) }
{ "all-instances" "memory" (( -- array )) }
{ "size" "memory" (( obj -- n )) }
{ "die" "kernel" (( -- )) }
{ "(fopen)" "io.streams.c" (( path mode -- alien )) }
Expand Down
16 changes: 5 additions & 11 deletions core/bootstrap/stage1.factor
Expand Up @@ -17,25 +17,19 @@ load-help? off
! Create a boot quotation for the target
[
[
! Rehash hashtables, since bootstrap.image creates them
! using the host image's hashing algorithms. We don't
! use each-object here since the catch stack isn't yet
! set up.
gc
begin-scan
[ hashtable? ] pusher [ (each-object) ] dip
end-scan
[ rehash ] each
! Rehash hashtables first, since bootstrap.image creates
! them using the host image's hashing algorithms.
[ hashtable? ] instances [ rehash ] each
boot
] %

"math.integers" require
"math.floats" require
"memory" require

"io.streams.c" require
"vocabs.loader" require

"syntax" require
"bootstrap.layouts" require

Expand Down
35 changes: 1 addition & 34 deletions core/memory/memory-docs.factor
Expand Up @@ -2,31 +2,9 @@ USING: help.markup help.syntax debugger sequences kernel
quotations math ;
IN: memory

HELP: begin-scan ( -- )
{ $description "Disables the garbage collector and resets the heap scan pointer to point at the first object in the heap. The " { $link next-object } " word can then be called to advance the heap scan pointer and return successive objects."
$nl
"This word must always be paired with a call to " { $link end-scan } "." }
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;

HELP: next-object ( -- obj )
{ $values { "obj" object } }
{ $description "Outputs the object at the heap scan pointer, and then advances the heap scan pointer. If the end of the heap has been reached, outputs " { $link f } ". This is unambiguous since the " { $link f } " object is tagged immediate and not actually stored in the heap." }
{ $errors "Throws a " { $link heap-scan-error. } " if called outside a " { $link begin-scan } "/" { $link end-scan } " pair." }
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;

HELP: end-scan ( -- )
{ $description "Finishes a heap iteration by re-enabling the garbage collector. This word must always be paired with a call to " { $link begin-scan } "." }
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;

HELP: each-object
{ $values { "quot" { $quotation "( obj -- )" } } }
{ $description "Applies a quotation to each object in the heap. The garbage collector is switched off while this combinator runs, so the given quotation must not allocate too much memory." }
{ $notes "This word is the low-level facility used to implement the " { $link instances } " word." } ;

HELP: instances
{ $values { "quot" { $quotation "( obj -- ? )" } } { "seq" "a fresh sequence" } }
{ $description "Outputs a sequence of all objects in the heap which satisfy the quotation." }
{ $notes "This word relies on " { $link each-object } ", so in particular the garbage collector is switched off while it runs and the given quotation must not allocate too much memory." } ;
{ $description "Outputs a sequence of all objects in the heap which satisfy the quotation." } ;

HELP: gc ( -- )
{ $description "Performs a full garbage collection." } ;
Expand Down Expand Up @@ -56,17 +34,6 @@ HELP: save-image-and-exit ( path -- )
HELP: save
{ $description "Saves a snapshot of the heap to the current image file." } ;

HELP: count-instances
{ $values
{ "quot" quotation }
{ "n" integer } }
{ $description "Applies the predicate quotation to each object in the heap and returns the number of objects that match. Since this word uses " { $link each-object } " with the garbage collector switched off, avoid allocating too much memory in the quotation." }
{ $examples { $unchecked-example
"USING: memory words prettyprint ;"
"[ word? ] count-instances ."
"24210"
} } ;

ARTICLE: "images" "Images"
"Factor has the ability to save the entire state of the system into an " { $emphasis "image file" } ". The image contains a complete dump of all data and code in the current Factor instance."
{ $subsections
Expand Down
19 changes: 2 additions & 17 deletions core/memory/memory.factor
@@ -1,26 +1,11 @@
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel continuations sequences vectors arrays system math
USING: kernel continuations sequences system
io.backend alien.strings memory.private ;
IN: memory

: (each-object) ( quot: ( obj -- ) -- )
next-object dup [
swap [ call ] keep (each-object)
] [ 2drop ] if ; inline recursive

: each-object ( quot -- )
gc begin-scan [ (each-object) ] [ end-scan ] [ ] cleanup ; inline

: count-instances ( quot -- n )
0 swap [ 1 0 ? + ] compose each-object ; inline

: instances ( quot -- seq )
#! To ensure we don't need to grow the vector while scanning
#! the heap, we do two scans, the first one just counts the
#! number of objects that satisfy the predicate.
[ count-instances 100 + <vector> ] keep swap
[ [ push-if ] 2curry each-object ] keep >array ; inline
[ all-instances ] dip filter ; inline

: save-image ( path -- )
normalize-path native-string>alien (save-image) ;
Expand Down
2 changes: 1 addition & 1 deletion extra/c/lexer/lexer-tests.factor
@@ -1,6 +1,6 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors c.lexer kernel sequence-parser tools.test ;
USING: accessors c.lexer kernel sequences.parser tools.test ;
IN: c.lexer.tests

[ 36 ]
Expand Down
2 changes: 1 addition & 1 deletion extra/c/lexer/lexer.factor
Expand Up @@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators combinators.short-circuit
generalizations kernel locals math.order math.ranges
sequence-parser sequences sorting.functor sorting.slots
sequences.parser sequences sorting.functor sorting.slots
unicode.categories ;
IN: c.lexer

Expand Down
2 changes: 1 addition & 1 deletion extra/c/preprocessor/preprocessor.factor
@@ -1,6 +1,6 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: sequence-parser io io.encodings.utf8 io.files
USING: sequences.parser io io.encodings.utf8 io.files
io.streams.string kernel combinators accessors io.pathnames
fry sequences arrays locals namespaces io.directories
assocs math splitting make unicode.categories
Expand Down
2 changes: 1 addition & 1 deletion extra/html/parser/parser.factor
@@ -1,6 +1,6 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays hashtables sequence-parser
USING: accessors arrays hashtables sequences.parser
html.parser.utils kernel namespaces sequences math
unicode.case unicode.categories combinators.short-circuit
quoting fry ;
Expand Down
9 changes: 0 additions & 9 deletions vm/aging_space.hpp
Expand Up @@ -15,15 +15,6 @@ struct aging_space : bump_allocator<object> {
starts.record_object_start_offset(obj);
return obj;
}

cell next_object_after(cell scan)
{
cell size = ((object *)scan)->size();
if(scan + size < here)
return scan + size;
else
return 0;
}
};

}

0 comments on commit 078e999

Please sign in to comment.