scripting languages for virtual worlds. outline necessary features classes, prototypes, and mixins...
Post on 20-Dec-2015
219 views
TRANSCRIPT
Outline• Necessary Features• Classes, Prototypes, and Mixins• Static vs. Dynamic Typing• Concurrency• Versioning• Distribution• States• Time• Security• User Concerns
Necessary Features
• Garbage Collection
• Event driven programming
• Fault tolerance
• Standard library
Classes, Prototypes, and Mixins
http://flickr.com/photos/orangeacid/273899875/http://flickr.com/photos/eondxd/672917412/
(Multiple Inheritance) (Prototype Cloning)
Classes, Prototypes, and Mixins
• Classes– Classes define behavior– Inheritance allows reuse of code
• Single inheritance () + Interfaces vs. Multiple Inheritance (C++)
– Dynamic classes force updates– C++, Java, Python, Ruby, ….
Classes, Prototypes, and Mixins
• Prototypes (a.k.a. classless, instance-based)– Objects contain methods, code reuse by cloning– Delegation
• Parent references maintained, method dispatch traces up tree• Changes to parent classes are forced to propagate if not
overloaded by child class
– Concatenation• Pure concatenative prototyping – prototype copied exactly but
given new name• Efficient dispatch, less efficient storage• Changes not easily propagated
– MOO, Javascript, Lua, Self
Classes, Prototypes, and Mixins
• Mixins– A way to reuse code efficiently from multiple
sources without using multiple inheritance– Mixing in a module copies all the methods in that
module to the class• Same copy vs. reference problem as prototypes
– Usually there is a way to check if a module has been mixed in => similar to type checking
Static vs. Dynamic Typing
• Static Typing– All variable types known at compile time– Type errors can be caught at compile time– How many errors are type errors?– Optimizations– Type inference
Static vs. Dynamic Typing
• Dynamic Typing– Variable types not known until runtime– Eval– Metaprogramming– Duck Typing
• Responds to vs. kind of
Static vs. Dynamic Typing
• MOO– Prototype based – closest to duck typing
• LSL– Statically typed– But interaction between objects handled by
messages without type checking
• Unreal Script– Statically typed
Concurrency
• Types of parallelism– Instruction level parallelism– Data parallelism– Task parallelism
• Implicit vs. Explicit Parallelism
Concurrency
• Object scripts are independent of each other
• Components of scripts may largely be independent of each other
• Some form of language or library support for exploiting this is necessary for a scalable solution
Stream Processing
• Exploits data parallelism by making data that can be operated on in parallel a built-in type
• Streams are sequences of data to be operated on
• Kernels are code blocks to be performed on the data
• Streams flow through series of kernels to produce final output
• Examples: Brook, CUDA
Shared-memory / Threading
• Multiple threads running concurrently– Procedural or object-oriented code– Possibly sharing memory
• Communication between threads– Shared memory– Mutexes / condition variables
• Examples: POSIX Threads, OpenMP, Java
Distributed-memory / Actor Model
• Actor Model– Actor – computational entity that responds to
messages by, concurrently• Sending messages to other actors• Create new actors• Change behavior for messages received in the future
– Asynchronous messaging, no shared memory
• Erlang, E, MPI, Smalltalk
States
• State based programming– Multiple states, each containing methods– Methods can be overloaded in different
states– Could be accomplished using switch
statements inside a single method– Complicates inheritance– Mixins? Multidimensional states?
Versioning
• Continuously running system
• Scripts can be updated at any time
• MOO – prototype based, no versioning support
• LSL – scripts local to object only, no need for versioning
Distributed Computation
• Two aspects of distribution– Language (or library) supports distributed
objects– Distributing the interpreter itself
Distributed Computation
• Distributed Objects– Remote Procedure Call / Remote Method
Invocations / MPI• UNIX RPC, Java RMI, XML-RPC, .NET Remoting,
CORBA, DCOM
– Erlang, E – distribution built in• can distribute processes to separate computers• Asynchronous message passing handles this naturally• Promises/proxies can be used for return values
Distributed Computation
• Distributed Interpreter– All nodes running interpreter act as a
single, larger interpreter– Is consistency important?– To my knowledge nobody deals with this at
the language level, programmer is expected to handle it
Distributed Computation
• MOO – no distribution• Unreal Script – Deals with replication
and some local execution, but objects are essentially undistributed
• Second Life – as far as we know, only at land grid level, although they could support object distribution, pure concatenative prototyping anyway
Time
• Some operations can take a relatively long time for a variety of reasons– Animations– Messages to other objects, possibly on
other servers– Resource loading, external resource
requests
Time in UnrealScripts
• Latent functions– Can only be called in state code, which is
lowest on the stack– Regular functions can’t call latent functions
• No delay in calling functions on other objects
Security
• Standard languages don’t have much built-in security, public/private/friend
• MOO uses UNIX-like permission system
• Confused deputy problem
• Access control matrix
• Access control lists? Capabilities?
User Concerns
• We want regular users to write scripts– Familiarity is important, even for those not very
familiar with programming– Simple things can stump beginners
• Case sensitivity• Integer division• Memory management
– Higher level languages built on basic language?– Visual programming?