cpu.architecture alien alien.accessors alien.strings quotations
layouts system compiler.units io io.files io.encodings.binary
io.streams.memory accessors combinators effects continuations fry
-classes vocabs vocabs.loader vocabs.parser ;
+classes vocabs vocabs.loader vocabs.parser words.symbol ;
+QUALIFIED: math
IN: alien.c-types
+SYMBOLS:
+ char uchar
+ short ushort
+ int uint
+ long ulong
+ longlong ulonglong
+ float double
+ void* bool ;
+
DEFER: <int>
DEFER: *char
{
{ [ CHAR: ] over member? ] [ parse-array-type ] }
{ [ dup search c-type-word? ] [ parse-c-type-name resolve-typedef ] }
- { [ dup c-types get at ] [ dup c-types get at resolve-typedef ] }
+ { [ dup c-types get at ] [ c-types get at resolve-typedef ] }
{ [ "*" ?tail ] [ parse-c-type-name resolve-pointer-type ] }
[ no-c-type ]
} cond ;
M: string typedef ( old new -- ) c-types get set-at ;
M: word typedef ( old new -- )
+ [ nip define-symbol ]
[ name>> typedef ]
- [ swap "c-type" set-word-prop ] 2bi ;
+ [ swap "c-type" set-word-prop ] 2tri ;
TUPLE: long-long-type < c-type ;
: if-void ( type true false -- )
pick "void" = [ drop nip call ] [ nip call ] if ; inline
-SYMBOLS:
- char uchar
- short ushort
- int uint
- long ulong
- longlong ulonglong
- float double
- void* bool ;
-
CONSTANT: primitive-types
{
char uchar
\ bool define-primitive-type
<c-type>
- float >>class
- float >>boxed-class
+ math:float >>class
+ math:float >>boxed-class
[ alien-float ] >>getter
[ [ >float ] 2dip set-alien-float ] >>setter
4 >>size
\ float define-primitive-type
<c-type>
- float >>class
- float >>boxed-class
+ math:float >>class
+ math:float >>boxed-class
[ alien-double ] >>getter
[ [ >float ] 2dip set-alien-double ] >>setter
8 >>size
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel combinators alien alien.strings alien.c-types
-alien.syntax math.parser prettyprint.backend prettyprint.custom
-prettyprint.sections definitions see see.private ;
+alien.syntax arrays math.parser prettyprint.backend
+prettyprint.custom prettyprint.sections definitions see see.private
+strings words ;
IN: alien.prettyprint
M: alien pprint*
M: c-type-word definer drop \ C-TYPE: f ;
M: c-type-word definition drop f ;
+GENERIC: pprint-c-type ( c-type -- )
+M: word pprint-c-type pprint-word ;
+M: string pprint-c-type text ;
+M: array pprint-c-type pprint* ;
+
M: typedef-word see-class*
<colon
\ TYPEDEF: pprint-word
- dup "typedef" word-prop pprint-word
+ dup "c-type" word-prop pprint-c-type
pprint-word
block> ;
4 >>align
"box_boolean" >>boxer
"to_boolean" >>unboxer
- "bool" define-primitive-type
+ bool define-primitive-type
] with-compilation-unit
M: x86.64 reserved-area-size 0 ;
-! The ABI for passing structs by value is pretty messed up
-<< "void*" c-type clone "__stack_value" define-primitive-type
-stack-params "__stack_value" c-type (>>rep) >>
+SYMBOL: (stack-value)
+! The ABI for passing structs by value is pretty great
+<< void* c-type clone \ (stack-value) define-primitive-type
+stack-params \ (stack-value) c-type (>>rep) >>
: struct-types&offset ( struct-type -- pairs )
fields>> [
: flatten-large-struct ( c-type -- seq )
heap-size cell align
- cell /i "__stack_value" c-type <repetition> ;
+ cell /i \ (stack-value) c-type <repetition> ;
M: struct-type flatten-value-type ( type -- seq )
dup heap-size 16 > [
M: x86.64 temp-reg RAX ;
<<
-"longlong" "ptrdiff_t" typedef
-"longlong" "intptr_t" typedef
-"int" c-type "long" define-primitive-type
-"uint" c-type "ulong" define-primitive-type
+longlong ptrdiff_t typedef
+longlong intptr_t typedef
+int c-type long define-primitive-type
+uint c-type ulong define-primitive-type
>>
compiler.cfg.stack-frame
compiler.codegen
compiler.codegen.fixup ;
+FROM: math => float ;
IN: cpu.x86
<< enable-fixnum-log2 >>