alien.c-types: cleanup

db4
Slava Pestov 2010-05-04 19:33:46 -04:00
parent 5fbc42e184
commit de8e0ccd5c
6 changed files with 79 additions and 70 deletions

View File

@ -164,17 +164,12 @@ M: c-type stack-size size>> cell align ;
MIXIN: value-type MIXIN: value-type
: c-getter ( name -- quot ) : c-getter ( name -- quot )
c-type-getter [ [ c-type-getter ] [ c-type-boxer-quot ] bi append ;
[ "Cannot read struct fields with this type" throw ]
] unless* ;
: c-type-getter-boxer ( name -- quot )
[ c-getter ] [ c-type-boxer-quot ] bi append ;
: c-setter ( name -- quot ) : c-setter ( name -- quot )
c-type-setter [ [ c-type-unboxer-quot [ [ ] ] [ '[ _ 2dip ] ] if-empty ]
[ "Cannot write struct fields with this type" throw ] [ c-type-setter ]
] unless* ; bi append ;
: array-accessor ( c-type quot -- def ) : array-accessor ( c-type quot -- def )
[ [
@ -295,7 +290,7 @@ M: pointer c-type
c-ptr >>class c-ptr >>class
c-ptr >>boxed-class c-ptr >>boxed-class
[ alien-cell ] >>getter [ alien-cell ] >>getter
[ [ >c-ptr ] 2dip set-alien-cell ] >>setter [ set-alien-cell ] >>setter
bootstrap-cell >>size bootstrap-cell >>size
bootstrap-cell >>align bootstrap-cell >>align
bootstrap-cell >>align-first bootstrap-cell >>align-first
@ -304,30 +299,6 @@ M: pointer c-type
"alien_offset" >>unboxer "alien_offset" >>unboxer
\ void* define-primitive-type \ void* define-primitive-type
<c-type>
integer >>class
integer >>boxed-class
[ alien-signed-4 ] >>getter
[ set-alien-signed-4 ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_signed_4" >>boxer
"to_fixnum" >>unboxer
\ int define-primitive-type
<c-type>
integer >>class
integer >>boxed-class
[ alien-unsigned-4 ] >>getter
[ set-alien-unsigned-4 ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_unsigned_4" >>boxer
"to_cell" >>unboxer
\ uint define-primitive-type
<c-type> <c-type>
fixnum >>class fixnum >>class
fixnum >>boxed-class fixnum >>boxed-class
@ -338,6 +309,7 @@ M: pointer c-type
2 >>align-first 2 >>align-first
"from_signed_2" >>boxer "from_signed_2" >>boxer
"to_fixnum" >>unboxer "to_fixnum" >>unboxer
[ >fixnum ] >>unboxer-quot
\ short define-primitive-type \ short define-primitive-type
<c-type> <c-type>
@ -350,6 +322,7 @@ M: pointer c-type
2 >>align-first 2 >>align-first
"from_unsigned_2" >>boxer "from_unsigned_2" >>boxer
"to_cell" >>unboxer "to_cell" >>unboxer
[ >fixnum ] >>unboxer-quot
\ ushort define-primitive-type \ ushort define-primitive-type
<c-type> <c-type>
@ -362,6 +335,7 @@ M: pointer c-type
1 >>align-first 1 >>align-first
"from_signed_1" >>boxer "from_signed_1" >>boxer
"to_fixnum" >>unboxer "to_fixnum" >>unboxer
[ >fixnum ] >>unboxer-quot
\ char define-primitive-type \ char define-primitive-type
<c-type> <c-type>
@ -374,34 +348,14 @@ M: pointer c-type
1 >>align-first 1 >>align-first
"from_unsigned_1" >>boxer "from_unsigned_1" >>boxer
"to_cell" >>unboxer "to_cell" >>unboxer
[ >fixnum ] >>unboxer-quot
\ uchar define-primitive-type \ uchar define-primitive-type
cpu ppc? [
<c-type>
[ alien-unsigned-4 c-bool> ] >>getter
[ [ >c-bool ] 2dip set-alien-unsigned-4 ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_boolean" >>boxer
"to_boolean" >>unboxer
] [
<c-type>
[ alien-unsigned-1 c-bool> ] >>getter
[ [ >c-bool ] 2dip set-alien-unsigned-1 ] >>setter
1 >>size
1 >>align
1 >>align-first
"from_boolean" >>boxer
"to_boolean" >>unboxer
] if
\ bool define-primitive-type
<c-type> <c-type>
math:float >>class math:float >>class
math:float >>boxed-class math:float >>boxed-class
[ alien-float ] >>getter [ alien-float ] >>getter
[ [ >float ] 2dip set-alien-float ] >>setter [ set-alien-float ] >>setter
4 >>size 4 >>size
4 >>align 4 >>align
4 >>align-first 4 >>align-first
@ -415,7 +369,7 @@ M: pointer c-type
math:float >>class math:float >>class
math:float >>boxed-class math:float >>boxed-class
[ alien-double ] >>getter [ alien-double ] >>getter
[ [ >float ] 2dip set-alien-double ] >>setter [ set-alien-double ] >>setter
8 >>size 8 >>size
8-byte-alignment 8-byte-alignment
"from_double" >>boxer "from_double" >>boxer
@ -425,14 +379,40 @@ M: pointer c-type
\ double define-primitive-type \ double define-primitive-type
cell 8 = [ cell 8 = [
<c-type>
fixnum >>class
fixnum >>boxed-class
[ alien-signed-4 ] >>getter
[ set-alien-signed-4 ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_signed_4" >>boxer
"to_fixnum" >>unboxer
[ >fixnum ] >>unboxer-quot
\ int define-primitive-type
<c-type>
fixnum >>class
fixnum >>boxed-class
[ alien-unsigned-4 ] >>getter
[ set-alien-unsigned-4 ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_unsigned_4" >>boxer
"to_cell" >>unboxer
[ >fixnum ] >>unboxer-quot
\ uint define-primitive-type
<c-type> <c-type>
integer >>class integer >>class
integer >>boxed-class integer >>boxed-class
[ alien-signed-cell ] >>getter [ alien-signed-cell ] >>getter
[ set-alien-signed-cell ] >>setter [ set-alien-signed-cell ] >>setter
bootstrap-cell >>size 8 >>size
bootstrap-cell >>align 8 >>align
bootstrap-cell >>align-first 8 >>align-first
"from_signed_cell" >>boxer "from_signed_cell" >>boxer
"to_fixnum" >>unboxer "to_fixnum" >>unboxer
\ longlong define-primitive-type \ longlong define-primitive-type
@ -442,9 +422,9 @@ M: pointer c-type
integer >>boxed-class integer >>boxed-class
[ alien-unsigned-cell ] >>getter [ alien-unsigned-cell ] >>getter
[ set-alien-unsigned-cell ] >>setter [ set-alien-unsigned-cell ] >>setter
bootstrap-cell >>size 8 >>size
bootstrap-cell >>align 8 >>align
bootstrap-cell >>align-first 8 >>align-first
"from_unsigned_cell" >>boxer "from_unsigned_cell" >>boxer
"to_cell" >>unboxer "to_cell" >>unboxer
\ ulonglong define-primitive-type \ ulonglong define-primitive-type
@ -463,6 +443,30 @@ M: pointer c-type
\ ulonglong c-type \ uintptr_t typedef \ ulonglong c-type \ uintptr_t typedef
\ ulonglong c-type \ size_t typedef \ ulonglong c-type \ size_t typedef
] [ ] [
<c-type>
integer >>class
integer >>boxed-class
[ alien-signed-cell ] >>getter
[ set-alien-signed-cell ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_signed_cell" >>boxer
"to_fixnum" >>unboxer
\ int define-primitive-type
<c-type>
integer >>class
integer >>boxed-class
[ alien-unsigned-cell ] >>getter
[ set-alien-unsigned-cell ] >>setter
4 >>size
4 >>align
4 >>align-first
"from_unsigned_cell" >>boxer
"to_cell" >>unboxer
\ uint define-primitive-type
<long-long-type> <long-long-type>
integer >>class integer >>class
integer >>boxed-class integer >>boxed-class
@ -495,6 +499,12 @@ M: pointer c-type
\ uint c-type \ size_t typedef \ uint c-type \ size_t typedef
] if ] if
cpu ppc? \ uint \ uchar ? c-type clone
[ >c-bool ] >>unboxer-quot
[ c-bool> ] >>boxer-quot
object >>boxed-class
\ bool define-primitive-type
] with-compilation-unit ] with-compilation-unit
M: char-16-rep rep-component-type drop char ; M: char-16-rep rep-component-type drop char ;

View File

@ -68,8 +68,7 @@ M: value-type c-type-getter
drop [ swap <displaced-alien> ] ; drop [ swap <displaced-alien> ] ;
M: value-type c-type-setter ( type -- quot ) M: value-type c-type-setter ( type -- quot )
[ c-type-getter ] [ c-type-unboxer-quot ] [ heap-size ] tri [ c-type-getter ] [ heap-size ] bi '[ @ swap _ memcpy ] ;
'[ @ swap @ _ memcpy ] ;
M: array c-type-boxer-quot M: array c-type-boxer-quot
unclip [ array-length ] dip [ <c-direct-array> ] 2curry ; unclip [ array-length ] dip [ <c-direct-array> ] 2curry ;

View File

@ -169,7 +169,7 @@ PREDICATE: alien-callback-type-word < typedef-word
: global-quot ( type word -- quot ) : global-quot ( type word -- quot )
name>> current-library get '[ _ _ address-of 0 ] name>> current-library get '[ _ _ address-of 0 ]
swap c-type-getter-boxer append ; swap c-getter append ;
: define-global ( type word -- ) : define-global ( type word -- )
[ nip ] [ global-quot ] 2bi (( -- value )) define-declared ; [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;

View File

@ -211,7 +211,7 @@ UNION-STRUCT: struct-test-float-and-bits
{ name "y" } { name "y" }
{ offset 4 } { offset 4 }
{ initial 123 } { initial 123 }
{ class integer } { class $[ cell 4 = integer fixnum ? ] }
{ type int } { type int }
} }
T{ struct-slot-spec T{ struct-slot-spec
@ -235,7 +235,7 @@ UNION-STRUCT: struct-test-float-and-bits
{ name "bits" } { name "bits" }
{ offset 0 } { offset 0 }
{ type uint } { type uint }
{ class integer } { class $[ cell 4 = integer fixnum ? ] }
{ initial 0 } { initial 0 }
} }
} ] [ struct-test-float-and-bits c-type fields>> ] unit-test } ] [ struct-test-float-and-bits c-type fields>> ] unit-test

View File

@ -101,7 +101,7 @@ MACRO: <struct-boa> ( class -- quot: ( ... -- struct ) )
GENERIC: (reader-quot) ( slot -- quot ) GENERIC: (reader-quot) ( slot -- quot )
M: struct-slot-spec (reader-quot) M: struct-slot-spec (reader-quot)
[ type>> c-type-getter-boxer ] [ type>> c-getter ]
[ offset>> [ >c-ptr ] swap suffix ] bi prepend ; [ offset>> [ >c-ptr ] swap suffix ] bi prepend ;
M: struct-bit-slot-spec (reader-quot) M: struct-bit-slot-spec (reader-quot)

View File

@ -45,7 +45,7 @@ byte-array>A DEFINES byte-array>${A}
A{ DEFINES ${A}{ A{ DEFINES ${A}{
A@ DEFINES ${A}@ A@ DEFINES ${A}@
NTH [ T dup c-type-getter-boxer array-accessor ] NTH [ T dup c-getter array-accessor ]
SET-NTH [ T dup c-setter array-accessor ] SET-NTH [ T dup c-setter array-accessor ]
WHERE WHERE