YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

iPhone Port...
toddkuen
#1 Posted : Tuesday, May 17, 2011 3:52:23 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 15
Location: USA

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
I have Squirrel working on an iPhone. I have not yet done much testing but the tests seem to work fine.

I built it with Xcode 3.2 (LLVM 4.2 and GCC 4.2) for creating libraries and XCode 4/LLVM 4.2 production build on iOS and Simulator.

No source changes were required - only monkey business to get around XCode 4 library problems and ugliness.

When my testing is complete I will create a blog post on my blog about the steps involved and how to invoke .nut files as resources.

Todd
toddkuen
#2 Posted : Wednesday, May 18, 2011 4:46:09 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 15
Location: USA

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
I have created a post on the issues with XCode4 and building a squirrel library (the post is generic but building squirrel into my app was what caused me to write it).

Building an iPhone app with Squirrel under XCode4

Other than these build issues it just works.

I have done enough with Squirrel linked into my apps at this point to have confidence that it will be great for scripting in all my iPhone apps.

toddkuen
#3 Posted : Friday, May 20, 2011 3:29:27 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 15
Location: USA

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
I have things working well in my project under OS X (see this post on by blog for some additional technical details of working on OS X).

Two requests from the post:

1) The squirrel compiler error hook should pass the user pointer passed into the compiler - its a trivial fix which I made.

2) A little more clarity on the docs on assigning to globals ("<-") versus locals ("=").

Hopefully I will have are more iOS version tested within the next few days.

I will try to get a post up on that as well.


fagiano
#4 Posted : Monday, May 23, 2011 1:30:40 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
Hi

1) Rather than modifying the compiler callback I'd use sq_setforeingptr() and sq_getforeignptr() and set a "context" for the VM.
2) I guess I'm not much of a writer(plus I'm Italian), How would you explain that? I'm glad to fix the doc.

Alberto
Follow me on Twitter @squirrellang
Guest
#5 Posted : Monday, May 23, 2011 11:28:58 PM(UTC)
Rank: Guest

Groups:
Joined: 7/25/2010(UTC)
Posts: 20

Thanks: 0 times
Was thanked: 1 time(s) in 1 post(s)
Yes - I understand how that would work - I would put it into the docs.

Found a minor bug - using "Extends" instead of "extends" crashes the compiler with a bad access.
fagiano
#6 Posted : Tuesday, May 24, 2011 6:31:42 AM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
I'll look into the "extends" issue asap

thanks

Alberto
Follow me on Twitter @squirrellang
toddkuen
#7 Posted : Tuesday, May 24, 2011 3:07:32 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 15
Location: USA

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
Link to blog entry on iPhone use here.

It would be nice if Squirrel were reentrant and had a mechanism for sharing global resources (I speculate about this in the blog).

After some thought I guess it would be nice to have multiple stacks per VM - one per outside the VM OS thread.

Ideally you would be able to create a "local stack" for a VM that would be used by a given OS thread/timer/etc.

Global resources that different threads would share, e.g., the global table or entries in the global table, would have the notion of being locked for access.

I realize that this could slow things down significantly if done wrong but in the long run I can see that having to effectively lock the VM at a high level would cause problems as well...

Food for thought at any rate.

fagiano
#8 Posted : Thursday, May 26, 2011 7:38:30 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
Well, trying to make a dynamic language like squirrel thread-safe is not practical in my opinion. The cost is huge. A global lock(like python) defeats most of the advantages of a multithreaded environment.
I used squirrel in highly concurrent environement for the last 6 years and the fact that is not thread safe is hardly a problem.
A cooperative mutithreading approach allows to yield much better performances without pain. We run 80/100 squirrel VM in a single process but only one runs at any moment( they all run on the same OS thread and also our allocator is not thread safe). We have a around 20 OS threads doing IO and DB work. They pump events to our "main" thread that cooperatively schedules squirrel threads. Squirrel threads run until they invoke a function that needs IO, RPC or DB stuff, internally this function will queue a task in a worker thread and suspend the VM, the scheduler then will pick up the next completed task and resume it's squirrel thread.
We also approach concurrency this way on the client side for dinamically loading content mantaining a "linear source" and hide the asyncronous part for non system programmers.

So I think this is a more productive way to approach multithreading for a dynamic language(also for non dynamic IMHO). I doubt that squirrel will ever be thread-safe if nobody comes out with a better idea than "sandwich every call in a mutex".

I hope this makes sense

ciao
Alberto
Follow me on Twitter @squirrellang
toddkuen
#9 Posted : Friday, May 27, 2011 2:19:55 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 15
Location: USA

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
What you describe is more or less what I ended up doing - multiple VMs for different purposes that get scheduled in a way that protects from reentrancy problems.

I can see why its the way it is and I agree that overhead with locking quickly becomes a problem.

Guest
#10 Posted : Friday, May 27, 2011 8:30:35 PM(UTC)
Rank: Guest

Groups:
Joined: 7/25/2010(UTC)
Posts: 20

Thanks: 0 times
Was thanked: 1 time(s) in 1 post(s)
fagiano wrote:
Well, trying to make a dynamic language like squirrel thread-safe is not practical in my opinion. The cost is huge. A global lock(like python) defeats most of the advantages of a multithreaded environment.
I used squirrel in highly concurrent environement for the last 6 years and the fact that is not thread safe is hardly a problem.
ciao
Alberto


Correct me if this is wrong, but Lua and Squirrel have advantage over Python in that the global lock limits to only one interpreter in a process for Python, while Squirrel and Lua can have multiple, non-interferencing, interpreters in a process at the same time.
atai
#11 Posted : Friday, May 27, 2011 8:33:55 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/16/2005(UTC)
Posts: 310

Thanks: 18 times
Was thanked: 18 time(s) in 14 post(s)
OK I posted the previous message. Not sure how I posted as a guest, but the guest account can be used for spam purposes, so maybe Alberto wants to consider disabling guest posting.
fagiano
#12 Posted : Saturday, May 28, 2011 4:13:16 AM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
toddkuen wrote:
What you describe is more or less what I ended up doing - multiple VMs for different purposes that get scheduled in a way that protects from reentrancy problems.


I'm not sure this is the same thing I meant. We use only 1 shared state and bout 100 "coroutines"(squirrel threads) that share the same root table and resources. We only call sq_open() once and then the other VMs are created with sq_newthread() and scheduled with sq_suspendvm() and sq_wakeupvm(). On my work PC (Core 2 Quad) I can schedule ~1000000 squirrel threads per second per CPU core.
BTW squirrel's API is 100% reentrant. It has no global variables, you can call sq_open() as many times you wish per process. It is not thread safe but it is reentrant.

atai wrote:
Correct me if this is wrong, but Lua and Squirrel have advantage over Python in that the global lock limits to only one interpreter in a process for Python, while Squirrel and Lua can have multiple, non-interferencing, interpreters in a process at the same time.


Well the global lock in python is not strictly related to the fact tha python is not reentrant. They use a global lock so that they can use OS threads and OS thread related objects like blocking sockets etc... . The global lock guarantees that only 1 python thread runs at any point in time so that it doesn't matter in what os thread it is running. For python this makes kind of sense as its scope is quite different than squirrel and lua.

Lua's approach of just wrapping each api in a mutex sound like a waste of time to me. Even with mutexes you should not go so fine grained.

atai wrote:
OK I posted the previous message. Not sure how I posted as a guest, but the guest account can be used for spam purposes, so maybe Alberto wants to consider disabling guest posting.


Only this forum('stuff' forum) allows guests so that people can say stuff "I can't login". This post belongs to API review board anyway :)

ciao
Alberto
Follow me on Twitter @squirrellang
toddkuen
#13 Posted : Thursday, June 2, 2011 6:24:04 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 15
Location: USA

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
I've been thinking about your comments on 1 shared state and how you use squirrel.

I too have a single OS thread doing things - but I also have responses to events. On the Mac these are considered to be in the same "thread" - the "main" thread.

But I also have async network events arriving which are not on the same "main" thread - therefore I have to careful to keep things separate between the two as far as squirrel is concerned.

My app is a game-like music app with no where near the performance demands you have but there are cases where the UI display and network async events, for example, cross paths.

From a multi-threading perspective I still think Squirrel would be fine except for writes/updates if you have a separate squirrel stack per OS thread. I would have to believe that the closures execute read-only save for the "global table" and stack access - though I have not looked.

I would imagine perhaps a "synchronized" modifier to add to a class or table - expensive to access but I think less work than me diddling around outside squirrel to accomplish the same thing.

Deena7slater
#14 Posted : Tuesday, June 14, 2011 1:00:42 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/14/2011(UTC)
Posts: 1
Woman
Location: 1540 Butler St Se, Washington

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
While building an iPhone app with Squirrel under XCode4 how to add controller?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.305 seconds.