diff --git a/basis/alien/c-types/c-types.factor b/basis/alien/c-types/c-types.factor index 027fe046b6..a029158be5 100755 --- a/basis/alien/c-types/c-types.factor +++ b/basis/alien/c-types/c-types.factor @@ -218,13 +218,13 @@ M: c-type-name unbox-return c-type unbox-return ; : little-endian? ( -- ? ) 1 *char 1 = ; foldable -GENERIC: heap-size ( name -- size ) foldable +GENERIC: heap-size ( name -- size ) M: c-type-name heap-size c-type heap-size ; M: abstract-c-type heap-size size>> ; -GENERIC: stack-size ( name -- size ) foldable +GENERIC: stack-size ( name -- size ) M: c-type-name stack-size c-type stack-size ; diff --git a/basis/compiler/tree/propagation/transforms/transforms.factor b/basis/compiler/tree/propagation/transforms/transforms.factor index 5aa490bfd3..809b51c6ef 100644 --- a/basis/compiler/tree/propagation/transforms/transforms.factor +++ b/basis/compiler/tree/propagation/transforms/transforms.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008, 2009 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel sequences words fry generic accessors +USING: alien.c-types kernel sequences words fry generic accessors classes.tuple classes classes.algebra definitions stack-checker.dependencies quotations classes.tuple.private math math.partial-dispatch math.private math.intervals sets.private @@ -8,6 +8,7 @@ math.floats.private math.integers.private layouts math.order vectors hashtables combinators effects generalizations assocs sets combinators.short-circuit sequences.private locals growable stack-checker namespaces compiler.tree.propagation.info ; +FROM: math => float ; IN: compiler.tree.propagation.transforms \ equal? [ @@ -307,3 +308,11 @@ CONSTANT: lookup-table-at-max 256 in-d>> second value-info class>> growable class<= [ \ push def>> ] [ f ] if ] "custom-inlining" set-word-prop + +! We want to constant-fold calls to heap-size, and recompile those +! calls when a C type is redefined +\ heap-size [ + dup word? [ + [ inlined-dependency depends-on ] [ heap-size '[ _ ] ] bi + ] [ drop f ] if +] 1 define-partial-eval diff --git a/basis/specialized-arrays/specialized-arrays-tests.factor b/basis/specialized-arrays/specialized-arrays-tests.factor index bc293b19e0..dd561e9d46 100755 --- a/basis/specialized-arrays/specialized-arrays-tests.factor +++ b/basis/specialized-arrays/specialized-arrays-tests.factor @@ -153,3 +153,22 @@ SPECIALIZED-ARRAY: __does_not_exist__ __does_not_exist__ specialized-array-vocab forget-vocab ] with-compilation-unit ] unit-test + +STRUCT: struct-resize-test { x int } ; + +SPECIALIZED-ARRAY: struct-resize-test + +[ 40 ] [ 10 byte-length ] unit-test + +: struct-resize-test-usage ( seq -- seq ) + [ struct-resize-test swap >>x ] map + >struct-resize-test-array + [ x>> ] { } map-as ; + +[ { 10 20 30 } ] [ { 10 20 30 } struct-resize-test-usage ] unit-test + +[ ] [ "IN: specialized-arrays.tests USE: classes.struct USE: alien.c-types STRUCT: struct-resize-test { x int } { y int } ;" eval( -- ) ] unit-test + +[ 80 ] [ 10 byte-length ] unit-test + +[ { 10 20 30 } ] [ { 10 20 30 } struct-resize-test-usage ] unit-test