diff --git a/Makefile b/Makefile index 5971e54746..42e5d6e47f 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ bsd: macosx: $(MAKE) $(BINARY) \ CFLAGS="$(DEFAULT_CFLAGS)" \ - LIBS="$(DEFAULT_LIBS)" \ + LIBS="$(DEFAULT_LIBS) -framework Cocoa -framework OpenGL" \ MACOSX=y macosx-sdl: diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index f822105140..28f27c5650 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -19,6 +19,7 @@ + ui/help: +- changelog in the UI - make the UI look better, something like this: http://twb.ath.cx/~twb/darcs/OBSOLETE/factor/final.html - fix remaining HTML stream issues @@ -29,9 +30,9 @@ - document tools - document conventions - new turtle graphics tutorial -- better line spacing in ui +- better line spacing in ui and html - use vertex arrays and display lists to speed up ui -- tabular formatting +- tabular formatting - for inspector and changes - don't multiplex in the event loop if there is no pending i/o + compiler/ffi: diff --git a/library/alien/alien-callback.factor b/library/alien/alien-callback.factor index 060dcf9365..bf80103403 100644 --- a/library/alien/alien-callback.factor +++ b/library/alien/alien-callback.factor @@ -13,7 +13,7 @@ TUPLE: alien-callback-error ; M: alien-callback-error summary ( error -- ) drop "Words calling ``alien-callback'' cannot run in the interpreter. Compile the caller word and try again." ; -: alien-callback ( ... return parameters quot -- ... ) +: alien-callback ( return parameters quot -- address ) throw ; : callback-bottom ( node -- ) diff --git a/library/alien/aliens.factor b/library/alien/aliens.factor index c082650b90..50be39fd51 100644 --- a/library/alien/aliens.factor +++ b/library/alien/aliens.factor @@ -17,7 +17,8 @@ sequences ; ! parameter, or a missing abi parameter indicates the cdecl ABI ! should be used, which is common on Unix. -: ( address -- alien ) f ; inline +: ( address -- alien ) + dup zero? [ drop f ] [ f ] if ; inline UNION: c-ptr byte-array alien ; diff --git a/library/cocoa/runtime.factor b/library/cocoa/runtime.factor index e7e9ad6fea..422f5e7ac9 100644 --- a/library/cocoa/runtime.factor +++ b/library/cocoa/runtime.factor @@ -64,7 +64,6 @@ FUNCTION: objc-method* class_getClassMethod ( objc-class* class, SEL selector ) BEGIN-STRUCT: objc-method-list FIELD: void* obsolete FIELD: int count - FIELD: objc-method elements END-STRUCT FUNCTION: objc-method-list* class_nextMethodList ( objc-class* class, void** iterator ) ; diff --git a/library/cocoa/subclassing.factor b/library/cocoa/subclassing.factor index b52e9ac384..14f5b4d443 100644 --- a/library/cocoa/subclassing.factor +++ b/library/cocoa/subclassing.factor @@ -1,17 +1,41 @@ ! Copyright (C) 2006 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. IN: objc -USING: alien kernel kernel-internals libc math sequences ; +USING: alien arrays compiler hashtables kernel kernel-internals +libc math namespaces sequences strings ; -: ( -- lists ) - "void*" -1 over 0 set-alien-unsigned-cell ; +: encode-types ( return types -- encoding ) + >r 1array r> append + [ alien>objc-types get hash ] map >string ; + +: prepare-method ( { name return types quot } -- sel type imp ) + [ first3 encode-types >r sel_registerName r> ] keep + [ % \ alien-callback , ] [ ] make compile-1 ; + +: init-method ( method alien -- ) + >r prepare-method r> + [ set-objc-method-imp ] keep + [ set-objc-method-types ] keep + set-objc-method-name ; + +: ( n -- alien ) + "objc-method-list" c-size + "objc-method" c-size rot * + 1 calloc ; + +: ( methods -- alien ) + dup length dup -rot + [ pick objc-method-nth init-method ] 2each ; + +: ( methods -- lists ) + alien-address + "void*" [ 0 set-alien-unsigned-cell ] keep ; : ( name info -- class ) "objc-class" [ set-objc-class-info ] keep - [ >r r> set-objc-class-name ] keep - over set-objc-class-methodLists ; + [ >r r> set-objc-class-name ] keep ; +! The Objective C object model is a bit funny. ! Every class has a metaclass. ! The superclass of the metaclass of X is the metaclass of the @@ -21,20 +45,22 @@ USING: alien kernel kernel-internals libc math sequences ; ! root class of X. : meta-meta-class ( class -- class ) root-class objc-class-isa ; -: ( superclass name -- class ) +: ( methods superclass name -- class ) CLS_META [ >r dup objc-class-isa r> set-objc-class-super-class ] keep - [ >r meta-meta-class r> set-objc-class-isa ] keep ; + [ >r meta-meta-class r> set-objc-class-isa ] keep + [ >r r> set-objc-class-methodLists ] keep ; -: ( metaclass superclass name -- class ) +: ( methods metaclass superclass name -- class ) CLS_CLASS [ set-objc-class-super-class ] keep - [ set-objc-class-isa ] keep ; + [ set-objc-class-isa ] keep + [ >r r> set-objc-class-methodLists ] keep ; -: (define-objc-class) ( superclass name -- class ) +: (define-objc-class) ( imeth cmeth superclass name -- class ) >r objc-class r> [ ] 2keep dup objc_addClass ; -: define-objc-class ( superclass name -- class ) +: define-objc-class ( imeth cmeth superclass name -- class ) dup class-exists? - [ nip objc-class ] [ (define-objc-class) ] if ; + [ >r 3drop r> objc-class ] [ (define-objc-class) ] if ; diff --git a/library/cocoa/utilities.factor b/library/cocoa/utilities.factor index 4f3fea637f..d615bcb4d5 100644 --- a/library/cocoa/utilities.factor +++ b/library/cocoa/utilities.factor @@ -47,12 +47,12 @@ H{ { CHAR: @ "id" } { CHAR: # "id" } { CHAR: : "SEL" } -} hash objc>alien-types set-global +} objc>alien-types set-global SYMBOL: alien>objc-types objc>alien-types get hash>alist [ reverse ] map alist>hash -alien>objc-types get +alien>objc-types set-global : objc-struct-type ( i string -- ctype ) 2dup CHAR: = -rot index* swap subseq ; diff --git a/library/inference/known-words.factor b/library/inference/known-words.factor index c3f01d7db5..8261174ce9 100644 --- a/library/inference/known-words.factor +++ b/library/inference/known-words.factor @@ -381,9 +381,6 @@ sequences strings vectors words prettyprint ; \ dlsym [ [ string object ] [ integer ] ] "infer-effect" set-word-prop \ dlclose [ [ dll ] [ ] ] "infer-effect" set-word-prop -\ [ [ integer ] [ alien ] ] "infer-effect" set-word-prop -\ t "flushable" set-word-prop - \ [ [ integer ] [ byte-array ] ] "infer-effect" set-word-prop \ t "flushable" set-word-prop diff --git a/native/alien.c b/native/alien.c index 0218b7dfdc..bac2b21015 100644 --- a/native/alien.c +++ b/native/alien.c @@ -99,8 +99,12 @@ void primitive_alien_to_string(void) /* convert Factor string to C string allocated in the Factor heap */ void primitive_string_to_alien(void) { + CELL string, type; maybe_gc(0); - drepl(tag_object(string_to_alien(untag_string(dpeek()),true))); + string = dpeek(); + type = type_of(string); + if(type != ALIEN_TYPE && type != BYTE_ARRAY_TYPE && type != F_TYPE) + drepl(tag_object(string_to_alien(untag_string(string),true))); } /* image loading */