From 4743a2a2bc4e3927b2ff163c827472d3f25eae62 Mon Sep 17 00:00:00 2001 From: slava Date: Sat, 11 Mar 2006 03:57:57 +0000 Subject: [PATCH] Debugging subclassing --- TODO.FACTOR.txt | 12 +++++---- examples/cocoa/opengl.factor | 27 ++++++++++++------- library/cocoa/init-cocoa.factor | 1 + library/cocoa/subclassing.factor | 4 +-- library/cocoa/utilities.factor | 46 +++++++++++++++++--------------- 5 files changed, 52 insertions(+), 38 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 31d5f86979..51092c5459 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -2,6 +2,11 @@ - win64 port - get factor running on mac intel +- amd64 %unbox-struct +- amd64 %write-barrier +- amd64 %box-struct +- x86 %box-struct +- x86 %write-barrier + io: @@ -14,6 +19,7 @@ + objective C/cocoa: - autoload frameworks in cocoa class words +- auto-define classes in obj-c class words - subclassing - super message sends @@ -38,16 +44,12 @@ + compiler/ffi: - inform-compile dies with funny error -- amd64 %unbox-struct -- amd64 %write-barrier - float intrinsics - complex float type - complex float intrinsics - out of memory from overflow check - remove literal table -- value type struct inputs to callbacks - C functions returning structs by value -- signal handler should not lose stack pointers - FIELD: char key_vector[32]; - FIELD: union { char b[20]; short s[10]; long l[5]; } data; - MEMBER: long pad[24]; @@ -56,7 +58,6 @@ - the invalid recursion form case needs to be fixed, for inlines too - code gc - compiled gc check slows things down -- new x86 write barrier + misc: @@ -64,3 +65,4 @@ - slice: if sequence or seq start is changed, abstraction violation - make 3.4 bits>double an error - colorcoded prettyprinting for vocabularies +- signal handler should not lose stack pointers diff --git a/examples/cocoa/opengl.factor b/examples/cocoa/opengl.factor index 4afe3460ad..4728f1418d 100644 --- a/examples/cocoa/opengl.factor +++ b/examples/cocoa/opengl.factor @@ -1,14 +1,21 @@ IN: cocoa-opengl -USING: alien cocoa compiler io kernel math objc objc-NSObject -objc-NSOpenGLView objc-NSWindow parser sequences threads ; +USING: alien cocoa compiler io kernel math objc objc-NSObject objc-NSOpenGLView objc-NSWindow parser sequences +threads ; -{ - { "drawRect:" "void" { "int" "int" "int" "int" } [ drop ] } -} { } -"NSOpenGLView" "FactorView" define-objc-class -"FactorView" import-objc-class +: init-FactorView-class + { + { + "drawRect:" "void" { "NSRect" } + [ 3drop "drawRect: called" print ] + } + } { } "NSOpenGLView" "FactorView" define-objc-class drop + "FactorView" import-objc-class ; parsing -: +init-FactorView-class + +USE: objc-FactorView + +: NSOpenGLView [alloc] 0 0 100 100 NSOpenGLView [defaultPixelFormat] [initWithFrame:pixelFormat:] ; @@ -16,10 +23,10 @@ objc-NSOpenGLView objc-NSWindow parser sequences threads ; "OpenGL demo" 10 10 600 600 dup - + [setContentView:] -dup f [makeKeyAndOrderFront:] +f [makeKeyAndOrderFront:] event-loop diff --git a/library/cocoa/init-cocoa.factor b/library/cocoa/init-cocoa.factor index 9159f1c902..489c501daa 100644 --- a/library/cocoa/init-cocoa.factor +++ b/library/cocoa/init-cocoa.factor @@ -29,6 +29,7 @@ USING: cocoa compiler io kernel objc sequences words ; "NSOpenGLView" "NSSpeechSynthesizer" "NSURLRequest" + "NSView" "NSWindow" "PDFDocument" "PDFView" diff --git a/library/cocoa/subclassing.factor b/library/cocoa/subclassing.factor index 53d7cf1244..aea6108ea2 100644 --- a/library/cocoa/subclassing.factor +++ b/library/cocoa/subclassing.factor @@ -5,8 +5,8 @@ USING: alien arrays compiler hashtables kernel kernel-internals libc math namespaces sequences strings ; : encode-types ( return types -- encoding ) - >r 1array r> append - [ [ alien>objc-types get hash , CHAR: 0 , ] each ] "" make ; + [ swap , { "id" "SEL" } % % ] { } make + [ [ alien>objc-types get hash % CHAR: 0 , ] each ] "" make ; : prepare-method ( { name return types quot } -- sel type imp ) [ first3 encode-types >r sel_registerName r> ] keep diff --git a/library/cocoa/utilities.factor b/library/cocoa/utilities.factor index 3a82cf168c..e17ecaaf91 100644 --- a/library/cocoa/utilities.factor +++ b/library/cocoa/utilities.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. IN: objc USING: alien arrays errors hashtables kernel lists math -namespaces parser sequences words ; +namespaces parser sequences strings words ; TUPLE: selector name object ; @@ -29,30 +29,34 @@ C: selector ( name -- sel ) [ set-selector-name ] keep ; SYMBOL: objc>alien-types H{ - { CHAR: c "char" } - { CHAR: i "int" } - { CHAR: s "short" } - { CHAR: l "long" } - { CHAR: q "longlong" } - { CHAR: C "uchar" } - { CHAR: I "uint" } - { CHAR: S "ushort" } - { CHAR: L "ulong" } - { CHAR: Q "ulonglong" } - { CHAR: f "float" } - { CHAR: d "double" } - { CHAR: B "bool" } - { CHAR: v "void" } - { CHAR: * "char*" } - { CHAR: @ "id" } - { CHAR: # "id" } - { CHAR: : "SEL" } + { "c" "char" } + { "i" "int" } + { "s" "short" } + { "l" "long" } + { "q" "longlong" } + { "C" "uchar" } + { "I" "uint" } + { "S" "ushort" } + { "L" "ulong" } + { "Q" "ulonglong" } + { "f" "float" } + { "d" "double" } + { "B" "bool" } + { "v" "void" } + { "*" "char*" } + { "@" "id" } + { "#" "id" } + { ":" "SEL" } } objc>alien-types set-global SYMBOL: alien>objc-types objc>alien-types get hash>alist [ reverse ] map alist>hash -alien>objc-types set-global +H{ + { "NSPoint" "{_NSPoint=ff}" } + { "NSRect" "{_NSRect=ffff}" } + { "NSSize" "{_NSSize=ff}" } +} hash-union alien>objc-types set-global : objc-struct-type ( i string -- ctype ) 2dup CHAR: = -rot index* swap subseq ; @@ -63,7 +67,7 @@ alien>objc-types set-global { [ dup CHAR: ^ = ] [ 3drop "void*" ] } { [ dup CHAR: { = ] [ drop objc-struct-type ] } { [ dup CHAR: [ = ] [ 3drop "void*" ] } - { [ t ] [ 2nip objc>alien-types get hash ] } + { [ t ] [ 2nip ch>string objc>alien-types get hash ] } } cond ; : parse-objc-type ( string -- ctype ) 0 swap (parse-objc-type) ;