<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi,</div><div><br></div><div>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:</div><div><br></div><div>1) To compile libgambc.a for the arm architecture </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>a) I made a new XCode project from the "BDS Static Library" template</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>b) Downloaded the latest gambit source code and made ./configure <br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>b) copied all the C files in lib/ into the project<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>c) copied all headers in include into the project<br></div><div><span class="Apple-tab-span" style="white-space:pre">  </span>d) selected the Device iPhoneOS 2.2.1 SDK in XCode<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>e) build the library<br></div><div><br></div><div>2) Created a new iPhone project with XCode (used the "View Based Application" template)</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>a) added libgambc.a to the frameworks of the project<br></div><div><span class="Apple-tab-span" style="white-space:pre">       </span>b) added gambit.h to the project</div><div><br></div><div>3) Created a Initial-Tests.scm file containing</div><div><br></div><div><div><font class="Apple-style-span" face="Courier">(define (fact n)</font></div><div><font class="Apple-style-span" face="Courier">  (if (= n 0)</font></div><div><font class="Apple-style-span" face="Courier">      1</font></div><div><font class="Apple-style-span" face="Courier">      (* n (fact (- n 1)))))</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">(c-define (compute-factorial n) (char-string) char-string "computeFact" "extern"</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">     </font></span><font class="Apple-style-span" face="Courier">  (display (string-append "input: " n))</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">     </font></span><font class="Apple-style-span" face="Courier">  (let* ((nn (string->number n))</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">           </font></span><font class="Apple-style-span" face="Courier"> (fn (fact nn)))</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">   </font></span><font class="Apple-style-span" face="Courier">    (display (string-append "result: " (number->string fn)))</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">        </font></span><font class="Apple-style-span" face="Courier">    (number->string fn)))</font></div><div><br></div><div><br></div><div>4) Compiled the scheme file: gsc -link Initial-Tests</div><div><br></div><div>5) Copied the generated C files into the XCode project</div><div><br></div><div>6) Added compilation flags for those two files: -lgambc -D___LIBRARY</div><div><br></div><div>7) Modified the application initialization sequence to call the Gambit setup function (in my TestSimpleAppDelegate.m)</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(100, 56, 32); ">#define ___VERSION <span style="color: #1c00cf">404002</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(196, 26, 22); "><span style="color: #643820">#import </span>"gambit.h"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(196, 26, 22); "><span style="color: #643820">#import </span>"TestSimpleApp3AppDelegate.h"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(196, 26, 22); "><span style="color: #643820">#import </span>"TestSimpleApp3ViewController.h"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(100, 56, 32); ">#define SCHEME_LIBRARY_LINKER ____20_Initial_2d_Tests__</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">___BEGIN_C_LINKAGE</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #aa0d91">extern</span> ___mod_or_lnk SCHEME_LIBRARY_LINKER (<span style="color: #3f6e74">___global_state_struct</span>*);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">___END_C_LINKAGE</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #aa0d91">@implementation</span> TestSimpleApp3AppDelegate</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(170, 13, 145); ">@synthesize<span style="color: #000000"> window;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #aa0d91">@synthesize</span> viewController;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">- (<span style="color: #aa0d91">void</span>)applicationDidFinishLaunching:(<span style="color: #5c2699">UIApplication</span> *)application {    </div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> <br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(63, 110, 116); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>___setup_params_struct<span style="color: #000000"> setup_params;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(38, 71, 75); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>___setup_params_reset<span style="color: #000000"> (&setup_params);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>setup_params.<span style="color: #5c2699">version</span> = <span style="color: #643820">___VERSION</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">   </span>setup_params.linker  = SCHEME_LIBRARY_LINKER;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">       </span><span style="color: #26474b">___setup</span> (&setup_params);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">     </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000">    </span>// Override point for customization after app launch    </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(63, 110, 116); "><span style="color: #000000">    [</span>window<span style="color: #000000"> </span><span style="color: #2e0d6e">addSubview</span><span style="color: #000000">:</span>viewController<span style="color: #000000">.</span><span style="color: #2e0d6e">view</span><span style="color: #000000">];</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(46, 13, 110); "><span style="color: #000000">    [</span><span style="color: #3f6e74">window</span><span style="color: #000000"> </span>makeKeyAndVisible<span style="color: #000000">];</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px;"><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></span></font></div></div><div>8) Added textfields to the GUI to input the value and show the result.</div><div>9) Added a call to <span class="Apple-style-span" style="color: rgb(38, 71, 75); font-family: Monaco; font-size: 10px; ">computeFact(sn) <span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; ">to actually compute the thing</span></span></div><div><br></div><div>10) Built the application in debug mode.</div><div><br></div><div>The result is that when <span class="Apple-style-span" style="color: rgb(38, 71, 75); font-family: Monaco; font-size: 10px; ">computeFact <span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; ">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. </span></span></div><div><br></div><div>I just too ingnorant of gambit virtual machine internals to understand why the call cannot properly return.</div><div><br></div><div>Maybe someone that is more experienced with Gambit FFI can help us on this last point.</div><div><br></div><div>Thank you and sorry for the length of my post...</div><div><br></div><div>Francois</div><div><br></div><div><br></div><div><br></div></div><div><div>On 9-Apr-09, at 11:33 AM, Pavel Dudrenov wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Thu, Apr 9, 2009 at 7:41 AM, Jeremie Lasalle Ratelle<br><<a href="mailto:pouexmachinax@gmail.com">pouexmachinax@gmail.com</a>> wrote:<br><blockquote type="cite"><blockquote type="cite">(1) i'm not as good with gambit on mac os x as i am with gambit on linux<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">(and haven't put in the time to figure out what i'm configuring incorrectly<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">on the mac)<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">What is the problem?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">(2) cocoa bindings / dealing with xcode / ...<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Carbon bindings are straightforward with the FFI. Cocoa is a problem<br></blockquote><blockquote type="cite">because it is in Objective C.<br></blockquote><br>Is there a way for gambit to look up object symbols?<br><br><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">Gambit-list mailing list<br></blockquote><blockquote type="cite"><a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br></blockquote><blockquote type="cite"><a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br></blockquote><blockquote type="cite"><br></blockquote>_______________________________________________<br>Gambit-list mailing list<br><a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list<br></div></blockquote></div><br></body></html>