Hi,

I was able to use gambit in an iPhone app a while ago when the iPhone API was first released. I tried to do it again last night and I am really close but I am still missing something... I tought I should share my experience with you. Here is what have done:

1) To compile libgambc.a for the arm architecture 
a) I made a new XCode project from the "BDS Static Library" template
b) Downloaded the latest gambit source code and made ./configure 
b) copied all the C files in lib/ into the project
c) copied all headers in include into the project
d) selected the Device iPhoneOS 2.2.1 SDK in XCode
e) build the library

2) Created a new iPhone project with XCode (used the "View Based Application" template)
a) added libgambc.a to the frameworks of the project
b) added gambit.h to the project

3) Created a Initial-Tests.scm file containing

(define (fact n)
  (if (= n 0)
      1
      (* n (fact (- n 1)))))


(c-define (compute-factorial n) (char-string) char-string "computeFact" "extern"
 (display (string-append "input: " n))
 (let* ((nn (string->number n))
(fn (fact nn)))
   (display (string-append "result: " (number->string fn)))
   (number->string fn)))


4) Compiled the scheme file: gsc -link Initial-Tests

5) Copied the generated C files into the XCode project

6) Added compilation flags for those two files: -lgambc -D___LIBRARY

7) Modified the application initialization sequence to call the Gambit setup function (in my TestSimpleAppDelegate.m)

#define ___VERSION 404002
#import "gambit.h"
#import "TestSimpleApp3AppDelegate.h"
#import "TestSimpleApp3ViewController.h"

#define SCHEME_LIBRARY_LINKER ____20_Initial_2d_Tests__

___BEGIN_C_LINKAGE
extern ___mod_or_lnk SCHEME_LIBRARY_LINKER (___global_state_struct*);
___END_C_LINKAGE


@implementation TestSimpleApp3AppDelegate

@synthesize window;
@synthesize viewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

 

___setup_params_struct setup_params;
___setup_params_reset (&setup_params);
setup_params.version = ___VERSION;
setup_params.linker  = SCHEME_LIBRARY_LINKER;
___setup (&setup_params);


    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}


8) Added textfields to the GUI to input the value and show the result.
9) Added a call to computeFact(sn) to actually compute the thing

10) Built the application in debug mode.

The result is that when computeFact gets called it does the whole computation (I see the debuggin display calls in the console) but the call to crashes while returning the result. The crash comes from gambit setup.c  (line 1820: CALL_STEP;). If I continue in gdb the function returns the proper result and everything is Ok. 

I just too ingnorant of gambit virtual machine internals to understand why the call cannot properly return.

Maybe someone that is more experienced with Gambit FFI can help us on this last point.

Thank you and sorry for the length of my post...

Francois



On 9-Apr-09, at 11:33 AM, Pavel Dudrenov wrote:

On Thu, Apr 9, 2009 at 7:41 AM, Jeremie Lasalle Ratelle
<pouexmachinax@gmail.com> wrote:
(1) i'm not as good with gambit on mac os x as i am with gambit on linux
(and haven't put in the time to figure out what i'm configuring incorrectly
on the mac)

What is the problem?

(2) cocoa bindings / dealing with xcode / ...

Carbon bindings are straightforward with the FFI. Cocoa is a problem
because it is in Objective C.

Is there a way for gambit to look up object symbols?

_______________________________________________
Gambit-list mailing list
Gambit-list@iro.umontreal.ca
https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list

_______________________________________________
Gambit-list mailing list
Gambit-list@iro.umontreal.ca
https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list