This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addTaxes(amount : Int) -> Int { | |
| return amount * 1.19 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| typealias TPerson = (name:String, age:Int, male:Bool) | |
| struct SPerson{ | |
| let name : String | |
| let age : Int | |
| let male : Bool | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var i = 0 | |
| func fib(_ number : Int)->Int { | |
| i += 1 | |
| return number <= 2 ? number : fib(number-1)+fib(number-2) | |
| } | |
| var j = 0 | |
| var fibRow = [0, 1, 2] | |
| func fibC(_ number:Int)->Int{ | |
| if number >= fibRow.count { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var componentTypes = new HashSet<string>(); | |
| foreach (var type in doc.Compilation.MainAssembly.TopLevelTypeDefinitions){ | |
| foreach (var parentType in type.DirectBaseTypes) { | |
| if (parentType.FullName == "Entitas.IComponent"){ | |
| var name = type.FullName; | |
| if(name.EndsWith("Component")){ | |
| // names should contain component name without Component sufix. | |
| name = name.Substring(0, name.Length - "Component".Length); | |
| } | |
| componentTypes.Add(name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Console.WriteLine ("File : " + doc.FileName); | |
| SyntaxTree ast = doc.ParsedDocument.GetAst<SyntaxTree> (); | |
| HashSet<string> typeNames = new HashSet<string> (); | |
| var astResolver = new CSharpAstResolver (doc.Compilation, ast, (CSharpUnresolvedFile)doc.ParsedDocument.ParsedFile); | |
| foreach (var identifier in ast.Descendants.OfType<MemberReferenceExpression> ()) { | |
| var targetString = identifier.Target.ToString (); | |
| // FIXME: Game specific | |
| if(targetString == "CoreGameMatcher" || targetString == "MetaGameMatcher" || targetString == "UIMatcher"){ | |
| AddType (identifier, typeNames, componentTypes); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void AddType (MemberReferenceExpression identifier, HashSet<string> typeNames, HashSet<string> componentTypes) | |
| { | |
| var memberName = UppercaseFirst(identifier.MemberName); | |
| if(!componentTypes.Contains(memberName)){ | |
| foreach(string prefix in new string[]{"Has", "Add", "Is", "Replace", "Remove", "Set"}){ | |
| if(memberName.StartsWith(prefix)){ | |
| memberName = memberName.TrimStart(prefix.ToCharArray()); | |
| break; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct LowerBoundary<T : Comparable> { | |
| let ls : T | |
| let rs : T | |
| var part : T {return rs} | |
| var isTrue : Bool { return ls < rs } | |
| } | |
| infix operator <& { associativity left precedence 200 } | |
| func <& <Element: Comparable> (left: Element, right: Element) -> LowerBoundary<Element> { | |
| return LowerBoundary(ls: left, rs: right) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol Boundary { | |
| typealias Element : Comparable | |
| var part : Element {get} | |
| var isTrue : Bool {get} | |
| } | |
| protocol LowerBoundary : Boundary{} | |
| protocol UpperBoundary : Boundary{} | |
| struct LowerBoundaryExclusive<T : Comparable> : LowerBoundary { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Comparable { | |
| func insideBoundary(a : Self, _ b : Self) -> Bool { | |
| let (left, right) = (min(a,b), max(a, b)) | |
| return self >= left && self <= right | |
| } | |
| func insideBoundary(inclusive a : Self, exclusive b : Self) -> Bool { | |
| return insideBoundary(a, b) && self != b | |
| } | |
| func insideBoundary(exclusive a : Self, exclusive b : Self) -> Bool { | |
| return insideBoundary(inclusive: a, exclusive: b) && self != a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func testStringToByteArray1(){ | |
| let value : StaticString = "maxim" | |
| let data = UnsafeMutablePointer<UInt8>.alloc(500_000) | |
| var cursor = 0 | |
| let time1 = NSDate() | |
| for _ in 0...100_000 { | |
| let buf = value.utf8Start | |
| let length = value.byteSize |