Skip to content

Commit

Permalink
Merge pull request #11 from Unity-Technologies/unity-staging
Browse files Browse the repository at this point in the history
pull unity-staging changes already in 4.1 into unity-4.1 (with excuses to Mr. Jonathan)
  • Loading branch information
bamboo committed Feb 5, 2013
2 parents 7fda040 + 89ed224 commit 1dd863d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 62 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'idea'

allprojects {
group = 'unityscript'
version = '0.1.1'
version = '0.1.2'

repositories {
ivy { url 'http://unity-technologies.github.com/kaizen/repositories/unstable' }
Expand Down Expand Up @@ -52,7 +52,7 @@ project(':us') {
project(':UnityScript') {
dependencies {
'default' project(':UnityScript.Lang')
['Boo.Lang.Extensions', 'Boo.Lang.Parser', 'Boo.Lang.Compiler', 'Boo.Lang.PatternMatching'].each {
['Boo.Lang.Extensions', 'Boo.Lang.Parser', 'Boo.Lang.Compiler', 'Boo.Lang.PatternMatching', 'Boo.Lang.Useful'].each {
'default' "boo:$it:$booVersion"
}
}
Expand Down
2 changes: 1 addition & 1 deletion default.build
Expand Up @@ -31,7 +31,7 @@
<arg file="${build.dir}/UnityScript.Tests.dll" />
</exec>

<nunit2 unless="${mono}">
<nunit2 unless="${mono}">
<formatter type="Plain" />
<test>
<assemblies basedir="${build.dir}">
Expand Down
73 changes: 21 additions & 52 deletions src/UnityScript.Lang/Array.boo
Expand Up @@ -3,9 +3,7 @@ namespace UnityScript.Lang
import System
import System.Collections

class Array(IList, Boo.Lang.Runtime.ICoercible):

InnerList = System.Collections.Generic.List of object()
class Array(CollectionBase, Boo.Lang.Runtime.ICoercible):

def constructor():
pass
Expand All @@ -24,47 +22,6 @@ class Array(IList, Boo.Lang.Runtime.ICoercible):
AddRange(items[0])
else:
AddRange(items)

def GetEnumerator():
return InnerList.GetEnumerator()

def CopyTo(target as System.Array, targetIndex as int):
elementType = target.GetType().GetElementType()
elementsToCopy = Math.Min(len(target) - targetIndex, Count)
sourceIndex = 0
while sourceIndex < elementsToCopy:
rawArrayIndexing:
target[targetIndex++] = Boo.Lang.Runtime.RuntimeServices.Coerce(InnerList[sourceIndex++], elementType)

Count:
get: return InnerList.Count

ICollection.IsSynchronized:
get: return false

ICollection.SyncRoot:
get: return self

def Clear():
InnerList.Clear()

def Contains(o):
return InnerList.Contains(o)

def IndexOf(o):
return InnerList.IndexOf(o)

def Insert(index as int, element):
InnerList.Insert(index, element)

def RemoveAt(index as int):
InnerList.RemoveAt(index)

IList.IsReadOnly:
get: return false

IList.IsFixedSize:
get: return false

static def op_Implicit(e as IEnumerable) as Array:
if e is null: return null
Expand All @@ -91,9 +48,7 @@ class Array(IList, Boo.Lang.Runtime.ICoercible):
return self

def ToBuiltin(type as System.Type):
result = System.Array.CreateInstance(type, Count)
CopyTo(result, 0)
return result
return self.InnerList.ToArray(type)

def Add(value as object, *items):
self.AddImpl(value, items)
Expand Down Expand Up @@ -188,8 +143,15 @@ class Array(IList, Boo.Lang.Runtime.ICoercible):

callable Comparison(lhs as object, rhs as object) as int

private class ComparisonComparer(IComparer):
def constructor(comparison as Comparison):
_comparison = comparison
def Compare(lhs, rhs):
return _comparison(lhs, rhs)
_comparison as Comparison

def Sort(comparison as Comparison):
self.InnerList.Sort({ x, y | comparison(x, y) })
self.InnerList.Sort(ComparisonComparer(comparison))

def sort(comparison as Comparison):
Sort(comparison)
Expand All @@ -200,14 +162,15 @@ class Array(IList, Boo.Lang.Runtime.ICoercible):
return self

def sort() as Array:
return self.Sort()
self.Sort()
return self

# Combine to a string
def Join (seperator as String):
return Builtins.join(self.InnerList, seperator)

def join (seperator as String):
return self.Join(seperator)
return Builtins.join(self.InnerList, seperator)

# Remove
def Remove (obj as Object):
Expand All @@ -226,9 +189,13 @@ class Array(IList, Boo.Lang.Runtime.ICoercible):
def AddRange([required] collection as IEnumerable):
for item in collection:
self.InnerList.Add(item)

override protected def OnValidate(newValue):
pass // anything goes

private def AddImpl(value as object, [required] items as IEnumerable):
self.InnerList.Add(value)

for item in items:
self.InnerList.Add(item)
return self.InnerList.Count
Expand All @@ -245,9 +212,11 @@ class Array(IList, Boo.Lang.Runtime.ICoercible):

private def ConcatImpl(value as ICollection, [required] items as IEnumerable):
arr = Array (self.InnerList)
arr.AddRange(value)
arr.InnerList.AddRange(value)

for item as ICollection in items:
arr.AddRange(item)
arr.InnerList.AddRange(item)

return arr

private def EnsureCapacity(capacity as int):
Expand Down
11 changes: 9 additions & 2 deletions src/UnityScript/UnityScriptCompiler.boo
Expand Up @@ -5,8 +5,15 @@ import Boo.Lang.Compiler
class UnityScriptCompiler:

[getter(Parameters)]
_parameters = UnityScriptCompilerParameters()
_compiler = BooCompiler(_parameters)
_parameters as UnityScriptCompilerParameters
_compiler as BooCompiler

def constructor():
self(UnityScriptCompilerParameters())

def constructor([required] parameters as UnityScriptCompilerParameters):
_parameters = parameters
_compiler = BooCompiler(_parameters)

def Run():
return _compiler.Run()
Expand Down
13 changes: 8 additions & 5 deletions src/UnityScript/UnityScriptCompilerParameters.boo
Expand Up @@ -5,7 +5,7 @@ import Boo.Lang.Compiler
import Boo.Lang.Compiler.Services
import Boo.Lang.Compiler.TypeSystem
import Boo.Lang.Compiler.TypeSystem.Services

import Boo.Lang.Compiler.TypeSystem.Reflection
import UnityScript.TypeSystem

class UnityScriptCompilerParameters(CompilerParameters):
Expand All @@ -25,9 +25,15 @@ class UnityScriptCompilerParameters(CompilerParameters):
property DisableEval as string

property TabSize = DefaultTabSize

def constructor():
self(true)

def constructor(loadDefaultReferences as bool):
super(Boo.Lang.Compiler.TypeSystem.Reflection.ReflectionTypeSystemProvider(), loadDefaultReferences)
self(ReflectionTypeSystemProvider(), loadDefaultReferences)

def constructor(reflectionTypeSystemProvider as IReflectionTypeSystemProvider, loadDefaultReferences as bool):
super(reflectionTypeSystemProvider, loadDefaultReferences)
self.Checked = false
self.OutputType = CompilerOutputType.Library
self.Environment = DeferredEnvironment() {
Expand All @@ -41,9 +47,6 @@ class UnityScriptCompilerParameters(CompilerParameters):
self.References.Add(typeof(UnityScript.Lang.Array).Assembly)
self.References.Add(GetType().Assembly)

def constructor():
self(true)

def AddToEnvironment(serviceType as System.Type, factory as ObjectFactory):
(Environment as DeferredEnvironment).Add(serviceType, factory)

Expand Down

0 comments on commit 1dd863d

Please sign in to comment.