Ticket #330: net4-set.patch
File net4-set.patch, 13.8 KB (added by hopscc, 12 years ago) |
---|
-
Source/Compiler.cobra
522 522 if v, print ' No source file is newer than "[outName]"; skipping compile.' 523 523 return false 524 524 525 def addRunTimeRef(opts as OptionValues) 526 if not opts.containsKey('reference') 527 opts['reference'] = List<of String>() 525 def addRunTimeRef(opts as OptionValues, libName as String) 526 if not opts.containsKey('reference'), opts['reference'] = List<of String>() 528 527 refs = opts['reference'] to List<of String> 529 libName = .backEnd.cobraRuntimeLibFileName530 528 if libName not in refs 531 529 if .verbosity, print 'Adding reference to [libName]' 532 530 refs.add(libName) 533 531 534 532 def runProcess as Process 535 533 return .runProcess(nil, nil) 536 534 -
Source/CommandLine.cobra
194 194 }, 195 195 { 196 196 'name': 'copy-core', 197 'synonyms': ['cc'], 197 198 'type': 'bool', 198 199 'description': 'Copy the Cobra.Core library to the same location as the resulting executable which will insulate the executable from newer Cobra installations.', 199 200 'default': 'no', -
Source/BackEnd.cobra
18 18 var _tagToTypeName = Dictionary<of String, String>() 19 19 """ Map from Typename tags used in compiler to backend specific qualified Type name""" 20 20 21 var _additionalRunTimeLibs = List<of String>() 22 21 23 get name from _name as String 22 24 """Name of this backend: format is 'language-platform' e.g 'c#-clr'.""" 23 25 … … 27 29 get runTimeLibNativeSourceFileName from _runTimeLibNativeSourceFileName as String 28 30 """Name of the backEnd source file containing any native code support for Cobra.Core.""" 29 31 32 get additionalRunTimeLibs from var 33 """Names of additional (System) libs to always reference with ert or not.""" 34 30 35 get compiler from __compiler as Compiler 31 36 32 37 -
Source/Phases/ParsePhase.cobra
153 153 for m in List<of Module>(_parsedModules) 154 154 if m.isCobraLibrary and not m.fileName.endsWith('.dll') 155 155 _parsedModules.remove(m) 156 .compiler.addRunTimeRef(opts) # add ref to runtime dll 156 rtlName = .compiler.backEnd.cobraRuntimeLibFileName 157 .compiler.addRunTimeRef(opts, rtlName) # add ref to runtime dll 157 158 else 158 159 opts['embed-run-time'] = .options['embed-run-time'] 159 160 # errchannel.throwError('Cannot switch -ert:no to -ert:yes in compilerDirective') -
Source/Phases/BindRunTimeLibraryPhase.cobra
14 14 _embedRunTime 15 15 else 16 16 _refRunTime 17 17 _refAdditionalLibs 18 18 19 def _embedRunTime 19 20 if .verbosity >= 2, print 'Embedding Cobra run-time' 20 21 … … 71 72 72 73 def _refRunTime 73 74 if .verbosity >= 2, print 'Referencing Cobra run-time' 74 .compiler.addRunTimeRef(.options) # then reference run-time dll 75 75 rtlName = .compiler.backEnd.cobraRuntimeLibFileName 76 .compiler.addRunTimeRef(.options, rtlName) # then reference run-time dll 77 78 def _refAdditionalLibs 79 for lib in .compiler.backEnd.additionalRunTimeLibs 80 .compiler.addRunTimeRef(.options, lib) 81 76 82 get cobraExeDir as String 77 83 """ 78 84 Returns the directory where cobra.exe is residing. -
Source/BackEndClr/ClrBackEnd.cobra
14 14 _name = 'c#-clr' 15 15 _runTimeLibFileName = 'Cobra.Core.dll' 16 16 _runTimeLibNativeSourceFileName = 'Native.cs' # backEnd source file containing native code support for Cobra.Core 17 # using Net 4.0 compiler 18 # if not compiler.options['native-compiler'].length or compiler.options['native-compiler'] contains '4' 19 _additionalRunTimeLibs = ['System.Core.dll'] # On .Net4.0 17 20 18 21 _tagToTypeName = { 19 22 'Object' : 'System.Object', -
Source/Cobra.Core/Set.cobra
1 1 namespace Cobra.Core 2 2 3 3 use System.Collections 4 #use System.Collections.Generic 5 use System.Collections.ObjectModel 4 6 5 interface ISet<of T> inherits ICollection<of T>, IEnumerable<of T>, ISet7 interface ISet<of T> inherits System.Collections.Generic.ISet<of T>, ICollection<of T>, IEnumerable<of T>, ISet 6 8 7 9 ## Collection type operations 8 10 … … 11 13 12 14 ## Set operations 13 15 14 def isSubsetOf(s as ISet<of T>) as bool15 def isSupersetOf(s as ISet<of T>) as bool16 #def isSubsetOf(s as ISet<of T>) as bool 17 #def isSupersetOf(s as ISet<of T>) as bool 16 18 def intersection(s as ISet<of T>) as ISet<of T> 17 19 def union(s as ISet<of T>) as ISet<of T> 18 20 def difference(s as ISet<of T>) as ISet<of T> … … 20 22 def toList as List<of T> 21 23 22 24 23 class Set<of T> i mplements ISet<of T>, ICollection<of T>, IEnumerable<of T>25 class Set<of T> inherits System.Collections.Generic.HashSet<of T> implements ISet<of T>, ICollection<of T>, IEnumerable<of T>, ISet 24 26 """ 25 A Set holds a hashed, unordered collections of items. 27 A Set holds a hashed, unordered collections of items. 26 28 Membership testing and set operations (intersection, union, etc.) are faster than with lists, but order is not preserved. 27 29 Set implements ICollection, so it has the usual collection operations such as `add`, `count` and `contains`. 28 30 It also has set specific operations including `union`, `intersection` and `isSubsetOf`. … … 30 32 As with other collections, to create a copy of a set, create a new one passing the original to the initializer: 31 33 s = Set<of int>(s) 32 34 35 This one is now based on Net4.0 System.Collections.Generic.HashSet<of T> augmented to support same 36 API as the original cobra implemented version running on .Net2.0. 37 33 38 TODO: 34 39 [-] List style items 35 40 [ ] Can the methods use .getType instead of hardcoding Set? Then subclasses would get created for example .intersection … … 41 46 [ ] Move some method implementations up to ISet extension 42 47 """ 43 48 44 const defaultCapacity = 845 46 var _data as Dictionary<of T, T>47 48 49 ## Initialization 49 50 50 51 cue init 51 .init(.defaultCapacity, nil, nil)52 base.init 52 53 54 # Just for backward compatibility 53 55 cue init(capacity as int) 54 .init(capacity, nil, nil)56 base.init 55 57 56 58 cue init(items as IEnumerable<of T>) 57 59 # CC: ensure for item in items assert .contains(item) or, 58 60 # CC: ensure for item in items get .contains(item) 59 .init(.defaultCapacity, items, nil)61 base.init(items) 60 62 61 63 cue init(comparer as IEqualityComparer<of T>) 62 .init(.defaultCapacity, nil,comparer)64 base.init(comparer) 63 65 64 66 cue init(items as IEnumerable<of T>?, comparer as IEqualityComparer<of T>?) 65 .init(.defaultCapacity,items, comparer)67 base.init(items, comparer) 66 68 69 # also for backwards compatibility 67 70 cue init(capacity as int, items as IEnumerable<of T>?, comparer as IEqualityComparer<of T>?) 68 base.init 69 _data = Dictionary<of T, T>(capacity, comparer) 70 if items, for item in items, _data[item] = item 71 base.init(items, comparer) 71 72 72 73 73 ## IEnumerable 74 ## IEnumerable 75 #def getEnumerator as IEnumerator<of T> - inherited 76 #def getEnumerator as System.Collections.IEnumerator - inherited 74 77 75 def getEnumerator as IEnumerator<of T>76 return _data.keys.getEnumerator77 78 def getEnumerator as System.Collections.IEnumerator79 implements System.Collections.IEnumerable80 return .getEnumerator to System.Collections.IEnumerator81 82 83 78 ## Object 84 85 def equals(other as Object?) as bool is override 79 def equals(other as Object?) as bool is override 86 80 # TODO: could this be more efficient? 87 81 if other inherits Set<of T> 88 82 if .count <> other.count … … 102 96 if not other.contains(item) 103 97 return false 104 98 for item2 in other 105 if not sharp'item2 is T'99 if not item2 inherits T 106 100 return false 107 101 if not .contains(item2 to T) 108 102 return false … … 116 110 code ^= item.getHashCode 117 111 return code 118 112 113 ## ICollection - all inherited 114 #def add(item as T) 115 #def clear 116 #def copyTo(array as T[], arrayIndex as int) 117 #get count as int 118 #def contains(item as T) as bool 119 #get isReadOnly as bool 120 #def remove(item as T) as bool 119 121 120 ## ICollection121 122 def add(item as T)123 ensure .contains(item)124 _data[item] = item125 126 def clear127 ensure .count == 0128 _data.clear129 130 def copyTo(array as T[], arrayIndex as int)131 _data.keys.copyTo(array, arrayIndex)132 133 get count as int134 ensure result >= 0135 return _data.count136 137 def contains(item as T) as bool138 return _data.containsKey(item)139 140 get isReadOnly as bool141 return false142 143 def remove(item as T) as bool144 ensure145 not .contains(item)146 # .contains(item) implies result TODO: How to say "old this"?147 body148 return _data.remove(item)149 150 151 122 # ISet 152 153 123 get countOfISet as int 154 return _data.count124 return base.count 155 125 156 def contains(item as Object) as bool 126 def contains(item as Object) as bool 157 127 implements ISet 158 return if(sharp'item is T', .contains(item to T), false)128 return if(sharp'item is T', base.contains(item to T), false) 159 129 160 130 161 131 ## Set operations 162 132 163 def isSubsetOf(s as ISet<of T>) as bool 164 for item in this 165 if not s.contains(item) 166 return false 167 return true 133 #def isSubsetOf(s as ISet<of T>) as bool 134 #def isSupersetOf(s as ISet<of T>) as bool 168 135 169 def isSupersetOf(s as ISet<of T>) as bool170 return s.isSubsetOf(this)171 172 136 def intersection(s as ISet<of T>) as ISet<of T> 173 137 """ 174 138 Returns a new set containing only the elements that are in this set and `s`. (AND) 139 base.intersectionWith modifies this set 175 140 """ 176 r = Set<of T>() 177 for item in this 178 if s.contains(item) 179 r.add(item) 141 #r = Set<of T>() 142 #for item in this 143 # if s.contains(item) 144 # r.add(item) 145 #return r 146 r = Set<of T>(this) 147 r.intersectWith(s) 180 148 return r 181 149 182 150 def union(s as ISet<of T>) as ISet<of T> 183 151 """ 184 152 Returns a new set containing the elements of that are in this set or `s`. (OR) 153 base.unionWith modifies this set 185 154 """ 186 155 r = Set<of T>(this) 187 r. addRange(s)156 r.unionWith(s) 188 157 return r 158 #r = Set<of T>(this) 159 #r.addRange(s) 160 #return r 161 189 162 190 163 def difference(s as ISet<of T>) as ISet<of T> 191 164 """ … … 200 173 def symmetricDifference(s as ISet<of T>) as ISet<of T> 201 174 """ 202 175 Returns a new set with elements in either s or t but not both. (XOR) 176 base.symmetricExceptWith modifies this set. 203 177 """ 204 r = Set<of T>() 205 for item in this 206 if not s.contains(item) 207 r.add(item) 208 for item in s 209 if not .contains(item) 210 r.add(item) 178 r = Set<of T>(this) 179 r.symmetricExceptWith(s) 211 180 return r 181 #r = Set<of T>() 182 #for item in this 183 # if not s.contains(item) 184 # r.add(item) 185 #for item in s 186 # if not .contains(item) 187 # r.add(item) 188 #return r 212 189 213 190 214 191 ## List<of T>-inspired Members … … 222 199 for item in items 223 200 .add(item) 224 201 225 #def asReadOnly as ReadOnlyCollection<of T>226 # TODO227 202 def asReadOnly as ReadOnlyCollection<of T> 203 return ReadOnlyCollection<of T>(.toList ) 204 228 205 # TODO 229 206 #def convertAll<of TOutput>(converter as Converter<of T, TOutput>) as Set<of TOutput> 230 207 # newSet = Set<of TOutput>() … … 232 209 # newSet.add(converter(item)) 233 210 # return newSet 234 211 235 # TODO 236 #def exists(predicate as Predicate<of T>) as bool 237 # for item in this 238 # if predicate(item) 239 # return true 240 # return false 212 def exists(predicate as Predicate<of T>) as bool 213 for item in this 214 if predicate(item) 215 return true 216 return false 241 217 242 218 # TODO: find 243 219 # TODO: findAll … … 258 234 result.count == .count 259 235 result.typeOf is .typeOf 260 236 body 261 type = .typeOf 262 newList = type(this) 263 return newList 237 return .memberwiseClone to ISet<of T> 264 238 265 239 def toList as List<of T> 266 240 return List<of T>(this) 267 241 268 interface ISet inherits IEnumerable242 interface ISet inherits System.Collections.IEnumerable 269 243 """ 270 244 This interface is to facilitate Set<of>.equals when the generic types are different (which 271 245 does not necessarily restrict the two sets from having the same contents). … … 280 254 test 281 255 s = Set<of int>() 282 256 assert s.count == 0 257 s1 = Set<of int>() 258 assert s1.count == 0 259 assert s is not s1 260 assert s == s1 261 assert s.getHashCode <> s1.getHashCode 262 263 s = Set<of int>() 264 assert s.count == 0 283 265 t = Set<of int>() to ISet<of int> 284 266 assert t.count == 0 285 267 assert s is not t … … 354 336 355 337 r = Set<of int>([1, 2]).symmetricDifference(Set<of int>([2, 3])) 356 338 assert r.toList == [1, 3] or r.toList == [3, 1] 357 339 340 p = Set<of int>([1,2,3,4]).exists( do(i as int)) 341 return i % 2 == 0 342 assert p 343 344 p = Set<of int>([1,2,3,4]).exists( do(i as int)) 345 return i >5 346 assert not p 347