Skip to content

Commit

Permalink
Merge branch 'master' of github.com:blanu/Song
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Brandon Wiley committed Mar 31, 2020
2 parents 5fb5fab + 5f132b5 commit a61b6be
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.build
/Packages
/*.xcodeproj
query
16 changes: 0 additions & 16 deletions Package.resolved

This file was deleted.

35 changes: 33 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,52 @@ let package = Package(
.library(
name: "Song",
targets: ["Song"]),
.library(
name: "Composition",
targets: ["Composition"]),
.library(
name: "Chorus",
targets: ["Chorus"]),
.library(
name: "Package",
targets: ["Package"]),
.executable(
name: "compose",
targets: ["compose"]),
.executable(
name: "choir",
targets: ["choir"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/yanagiba/swift-ast", from: "0.4.1")
.package(url: "https://github.com/yanagiba/swift-ast", from: "0.4.2"),
.package(url: "https://github.com/OperatorFoundation/Datable", from: "1.1.1"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "Song",
dependencies: ["SwiftAST"]),
.target(
name: "Composition",
dependencies: ["Datable"]),
.target(
name: "Chorus",
dependencies: []),
.target(
name: "Package",
dependencies: []),
.target(
name: "compose",
dependencies: ["Composition", "SwiftAST"]),
.target(
name: "choir",
dependencies: ["Chorus", "Datable", "Package", "SwiftAST"]),
.testTarget(
name: "SongTests",
dependencies: ["Song"]),
dependencies: ["Song", "Composition"]),
],
swiftLanguageVersions: [4]
)
11 changes: 11 additions & 0 deletions Resources/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
</objects>
</document>
Empty file added Sources/Chorus/Chorus.swift
Empty file.
48 changes: 48 additions & 0 deletions Sources/Composition/Composition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Foundation
import Network
import Datable

public func remoteCall(code: String, callback: @escaping (Data) -> Void )
{
let queue = DispatchQueue(label: "network")

let conn = NWConnection(host: NWEndpoint.Host("127.0.0.1"), port: NWEndpoint.Port(integerLiteral: 1234), using: .tcp)
conn.start(queue: queue)

let payload = code.data
let length = payload.count
let length16 = UInt16(length)
let lengthBytes = length16.data
let data = lengthBytes + payload

conn.send(content: data, completion: NWConnection.SendCompletion.contentProcessed(
{
maybeError in

guard maybeError == nil else { return }

conn.receive(minimumIncompleteLength: 2, maximumLength: 2)
{
(maybeData, maybeContext, isComplete, maybeError) in

print("received \(maybeData)")

guard maybeError == nil else { return }
guard let data = maybeData else { return }

let length = Int(data.uint16)

conn.receive(minimumIncompleteLength: length, maximumLength: length)
{
(maybeData, maybeContext, isComplete, maybeError) in

print("received.. \(maybeData)")

guard maybeError == nil else { return }
guard let data = maybeData else { return }

callback(data)
}
}
}))
}
78 changes: 78 additions & 0 deletions Sources/Package/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import Foundation

public struct Package
{
public let name: String
public let type: PackageType

public init(name: String, type: PackageType = .library)
{
self.name = name
self.type = type

guard let _ = try? FileManager.default.createDirectory(atPath: self.name, withIntermediateDirectories: false, attributes: nil) else { return }

let process = Process()
process.currentDirectoryPath = self.name
process.launchPath = "/usr/bin/swift"

switch self.type
{
case .library:
process.arguments = ["package", "init", "--type", "library"]
case .executable:
process.arguments = ["package", "init", "--type", "executable"]
}

process.launch()
process.waitUntilExit()
}

public func update()
{
let process = Process()
process.currentDirectoryPath = self.name
process.launchPath = "/usr/bin/swift"

process.arguments = ["package", "update"]

process.launch()
process.waitUntilExit()
}

public func build()
{
let process = Process()
process.currentDirectoryPath = self.name
process.launchPath = "/usr/bin/swift"

process.arguments = ["build", "-Xswiftc", "-target", "-Xswiftc", "x86_64-apple-macosx10.14"]

process.launch()
process.waitUntilExit()
}

public func run() -> Data
{
let process = Process()
process.currentDirectoryPath = self.name
process.launchPath = "/usr/bin/swift"

process.arguments = ["run"]
let output = Pipe()
process.standardOutput = output
let handle = output.fileHandleForReading

process.launch()
process.waitUntilExit()

let data = handle.readDataToEndOfFile()
return data
}
}

public enum PackageType
{
case library
case executable
}
10 changes: 5 additions & 5 deletions Sources/Song/Decoding/SongDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class SongDecoder {
userInfo=[:]
}

func decode<T>(_ type: [T].Type, from data: Data) throws -> [T] where T : Decodable {
public func decode<T>(_ type: [T].Type, from data: Data) throws -> [T] where T : Decodable {
NSLog("ARRAY DECODE CHOSEN")
NSLog("decode<T> data: \(data as! NSData)")
NSLog("decode<T> data: \(data as NSData)")
self.data=data
let container = self._unkeyedContainer()
do {
Expand Down Expand Up @@ -185,9 +185,9 @@ public class SongDecoder {
}
}

func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable
public func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable
{
NSLog("decode<T> data: \(data as! NSData)")
NSLog("decode<T> data: \(data as NSData)")
self.data=data
if singleType(type) {
let single = self._singleValueContainer()
Expand Down Expand Up @@ -245,7 +245,7 @@ public class SongDecoder {
}
}

func singleType<T>(_ type: T.Type) -> Bool {
public func singleType<T>(_ type: T.Type) -> Bool {
if type == String.self {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public class SongSingleValueDecodingContainer: SingleValueDecodingContainer {

switch ini {
case is PatternInitializer:
let pat = ini as! PatternInitializer
let pat = ini
let maybeEx = pat.initializerExpression
guard let ex = maybeEx else {
throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "Missing initializer expression"))
Expand Down
18 changes: 9 additions & 9 deletions Sources/Song/Encoding/SongEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SongEncoder {
userInfo=[:]
}

func encode<Key, Value>(_ value: [Key: Value]) throws -> Data where Key : Encodable & CodingKey, Value : Encodable {
public func encode<Key, Value>(_ value: [Key: Value]) throws -> Data where Key : Encodable & CodingKey, Value : Encodable {
let map = _container(keyedBy: Key.self)
for (key, val) in value {
do {
Expand All @@ -37,11 +37,11 @@ public class SongEncoder {
return map.data!
}

func encode<Value>(_ value: [Value]) throws -> Data where Value : Encodable {
public func encode<Value>(_ value: [Value]) throws -> Data where Value : Encodable {
if let ints = value as? [Int] {
let list = self._unkeyedContainer()
do {
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: "Int")])
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: Identifier.name("Int"))])
for int in ints {
try list.encode(int)
}
Expand All @@ -53,7 +53,7 @@ public class SongEncoder {
} else if let ints = value as? [Int64] {
let list = self._unkeyedContainer()
do {
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: "Int64")])
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: Identifier.name("Int64"))])
for int in ints {
try list.encode(int)
}
Expand All @@ -65,7 +65,7 @@ public class SongEncoder {
} else if let ints = value as? [Int32] {
let list = self._unkeyedContainer()
do {
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: "Int32")])
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: Identifier.name("Int32"))])
for int in ints {
try list.encode(int)
}
Expand All @@ -77,7 +77,7 @@ public class SongEncoder {
} else if let ints = value as? [Int16] {
let list = self._unkeyedContainer()
do {
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: "Int16")])
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: Identifier.name("Int16"))])
for int in ints {
try list.encode(int)
}
Expand All @@ -89,7 +89,7 @@ public class SongEncoder {
} else if let ints = value as? [Int8] {
let list = self._unkeyedContainer()
do {
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: "Int8")])
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: Identifier.name("Int8"))])
for int in ints {
try list.encode(int)
}
Expand All @@ -101,7 +101,7 @@ public class SongEncoder {
} else {
let list = self._unkeyedContainer()
do {
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: String(describing: Value.self))])
list.type=TypeIdentifier(names: [TypeIdentifier.TypeName(name: Identifier.name(String(describing: Value.self)))])
for val in value {
try list.encode(val)
}
Expand All @@ -113,7 +113,7 @@ public class SongEncoder {
}
}

func encode<Value>(_ value: Value) throws -> Data where Value : Encodable {
public func encode<Value>(_ value: Value) throws -> Data where Value : Encodable {
switch value {
// case is Dictionary<K: Hashable, Any>:
// break
Expand Down
2 changes: 0 additions & 2 deletions Sources/Song/Encoding/SongKeyedEncodingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Foundation

import AST

import Song

typealias Parameter = (CodingKey, Expression)

public class SongKeyedEncodingContainer<K: CodingKey>: KeyedEncodingContainerProtocol {
Expand Down
Loading

0 comments on commit a61b6be

Please sign in to comment.