Skip to content

Commit c26bef2

Browse files
committed
Support asynchronous APIs in LispKitRepl. Fix compiler warnings.
1 parent 22c4c42 commit c26bef2

File tree

11 files changed

+108
-79
lines changed

11 files changed

+108
-79
lines changed

LispKit.xcodeproj/project.pbxproj

+10-4
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@
332332
CC703A1F218D0B3000E71EA9 /* support.sld in Copy pre-installed LispKit library: LispKit CLOS Support */ = {isa = PBXBuildFile; fileRef = CC703A1C218D09F700E71EA9 /* support.sld */; };
333333
CC703A21218D123F00E71EA9 /* 95.sld in Copy pre-installed SRFI libraries */ = {isa = PBXBuildFile; fileRef = CC703A20218D122100E71EA9 /* 95.sld */; };
334334
CC72862D1F52B32C00EEBC58 /* heap.sld in Copy pre-installed LispKit libraries */ = {isa = PBXBuildFile; fileRef = CC72862C1F52B2F600EEBC58 /* heap.sld */; };
335-
CC74D3462AEA47DA0054CC5A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC74D3452AEA47DA0054CC5A /* main.swift */; };
336335
CC74D3482AEA48000054CC5A /* AppInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC74D3472AEA48000054CC5A /* AppInfo.swift */; };
337336
CC74D34C2AEA498D0054CC5A /* LispKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCAD52BA1C48403800DBD8EE /* LispKit.framework */; };
338337
CC74D34D2AEA498D0054CC5A /* LispKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CCAD52BA1C48403800DBD8EE /* LispKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -1292,6 +1291,9 @@
12921291
CCE4AECE204212EC008BF7E8 /* SourceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE4AECD204212EC008BF7E8 /* SourceManager.swift */; };
12931292
CCE4AED0204217D8008BF7E8 /* SourcePosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE4AECF204217D8008BF7E8 /* SourcePosition.swift */; };
12941293
CCE7CA461F8EC07000FD7ECA /* iterate.sld in Copy pre-installed LispKit libraries */ = {isa = PBXBuildFile; fileRef = CCE7CA451F8D819600FD7ECA /* iterate.sld */; };
1294+
CCE9C27F2C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE9C27E2C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift */; };
1295+
CCE9C2802C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE9C27E2C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift */; };
1296+
CCE9C2992C41DCA800DE1AD7 /* LispKitRepl.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE9C2812C41D70300DE1AD7 /* LispKitRepl.swift */; };
12951297
CCEEF3911FAF4024006C4581 /* 158.sld in Copy pre-installed SRFI libraries */ = {isa = PBXBuildFile; fileRef = CCEEF3901FAF3F70006C4581 /* 158.sld */; };
12961298
CCEEF3931FB3CB50006C4581 /* wt-tree.sld in Copy pre-installed LispKit libraries */ = {isa = PBXBuildFile; fileRef = CCEEF3921FB3CB03006C4581 /* wt-tree.sld */; };
12971299
CCEF3E3327CB66D900FB56EB /* 149.sld in Copy pre-installed SRFI libraries */ = {isa = PBXBuildFile; fileRef = CCEF3E3227CB656700FB56EB /* 149.sld */; };
@@ -3276,7 +3278,6 @@
32763278
CC703A20218D122100E71EA9 /* 95.sld */ = {isa = PBXFileReference; lastKnownFileType = text; path = 95.sld; sourceTree = "<group>"; };
32773279
CC72862C1F52B2F600EEBC58 /* heap.sld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = heap.sld; sourceTree = "<group>"; };
32783280
CC74D33B2AEA47420054CC5A /* LispKitRepl */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = LispKitRepl; sourceTree = BUILT_PRODUCTS_DIR; };
3279-
CC74D3452AEA47DA0054CC5A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
32803281
CC74D3472AEA48000054CC5A /* AppInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfo.swift; sourceTree = "<group>"; };
32813282
CC74D3492AEA48260054CC5A /* AppInfo.tmpl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AppInfo.tmpl; sourceTree = "<group>"; };
32823283
CC750BD71F5AC68900CD82A2 /* PDF.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PDF.scm; sourceTree = "<group>"; };
@@ -3683,6 +3684,8 @@
36833684
CCE4AECD204212EC008BF7E8 /* SourceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceManager.swift; sourceTree = "<group>"; };
36843685
CCE4AECF204217D8008BF7E8 /* SourcePosition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourcePosition.swift; sourceTree = "<group>"; };
36853686
CCE7CA451F8D819600FD7ECA /* iterate.sld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iterate.sld; sourceTree = "<group>"; tabWidth = 3; };
3687+
CCE9C27E2C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuth2DeviceGrantLK.swift; sourceTree = "<group>"; };
3688+
CCE9C2812C41D70300DE1AD7 /* LispKitRepl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LispKitRepl.swift; sourceTree = "<group>"; };
36863689
CCEA5A17263D5E6300D78C62 /* lispkit-repl-ios.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "lispkit-repl-ios.png"; sourceTree = "<group>"; };
36873690
CCEEF3901FAF3F70006C4581 /* 158.sld */ = {isa = PBXFileReference; lastKnownFileType = text; path = 158.sld; sourceTree = "<group>"; };
36883691
CCEEF3921FB3CB03006C4581 /* wt-tree.sld */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "wt-tree.sld"; sourceTree = "<group>"; };
@@ -4259,7 +4262,7 @@
42594262
CC74D33C2AEA47420054CC5A /* LispKitRepl */ = {
42604263
isa = PBXGroup;
42614264
children = (
4262-
CC74D3452AEA47DA0054CC5A /* main.swift */,
4265+
CCE9C2812C41D70300DE1AD7 /* LispKitRepl.swift */,
42634266
CC74D3472AEA48000054CC5A /* AppInfo.swift */,
42644267
CC74D3492AEA48260054CC5A /* AppInfo.tmpl */,
42654268
);
@@ -4873,6 +4876,7 @@
48734876
CC2DA74F2780FE1100DE69CF /* MethodProfiler.swift */,
48744877
CC372CDC27D5532D0091C474 /* String.swift */,
48754878
CCB5DF5B29A16D62005E6453 /* Data.swift */,
4879+
CCE9C27E2C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift */,
48764880
);
48774881
path = Base;
48784882
sourceTree = "<group>";
@@ -5350,7 +5354,7 @@
53505354
isa = PBXSourcesBuildPhase;
53515355
buildActionMask = 2147483647;
53525356
files = (
5353-
CC74D3462AEA47DA0054CC5A /* main.swift in Sources */,
5357+
CCE9C2992C41DCA800DE1AD7 /* LispKitRepl.swift in Sources */,
53545358
CC74D3482AEA48000054CC5A /* AppInfo.swift in Sources */,
53555359
);
53565360
runOnlyForDeploymentPostprocessing = 0;
@@ -5465,6 +5469,7 @@
54655469
CC93A6611D0777A9008350C8 /* TextOutput.swift in Sources */,
54665470
CC5BBC791D5268D000367E8F /* HashTable.swift in Sources */,
54675471
CCD5B6082C276696002BF2F0 /* ThreadFutureLibrary.swift in Sources */,
5472+
CCE9C27F2C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift in Sources */,
54685473
CC2DA7572781037B00DE69CF /* EvalCondition.swift in Sources */,
54695474
CCCB66E4283056E30004827D /* StyledTextLibrary.swift in Sources */,
54705475
CC6A3B6A1C539DCA00E962E2 /* ManagedObjectPool.swift in Sources */,
@@ -5517,6 +5522,7 @@
55175522
CCC48CB025E5B97100D082AD /* FileHandler.swift in Sources */,
55185523
CCC48C9025E5B95B00D082AD /* Cell.swift in Sources */,
55195524
CCD5B60C2C295951002BF2F0 /* HTTPLibrary.swift in Sources */,
5525+
CCE9C2802C41B72000DE1AD7 /* OAuth2DeviceGrantLK.swift in Sources */,
55205526
CC1D53332BE7AB4000EE1A24 /* CustomExpr.swift in Sources */,
55215527
CCC48CC625E5B98600D082AD /* BytevectorLibrary.swift in Sources */,
55225528
CCC48C6F25E5B94300D082AD /* Timer.swift in Sources */,

LispKit.xcodeproj/xcshareddata/xcschemes/LispKitRepl.xcscheme

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
ReferencedContainer = "container:LispKit.xcodeproj">
7070
</BuildableReference>
7171
</BuildableProductRunnable>
72+
<CommandLineArguments>
73+
<CommandLineArgument
74+
argument = "-x"
75+
isEnabled = "YES">
76+
</CommandLineArgument>
77+
</CommandLineArguments>
7278
<EnvironmentVariables>
7379
<EnvironmentVariable
7480
key = "TERM"

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ all: run
44

55
run: debug
66
ifeq ($(program),)
7-
.build/debug/LispKitRepl -r Sources/LispKit/Resources -d LispKit
7+
.build/debug/LispKitRepl -x -r Sources/LispKit/Resources -d LispKit
88
else
9-
.build/debug/LispKitRepl -r Sources/LispKit/Resources -d LispKit $(program)
9+
.build/debug/LispKitRepl -x -r Sources/LispKit/Resources -d LispKit $(program)
1010
endif
1111

1212
debug: replinfo
13-
swift build -Xswiftc "-D" -Xswiftc "SPM"
13+
swift build
1414

1515
repl: release
1616
ifeq ($(program),)
@@ -20,13 +20,13 @@ else
2020
endif
2121

2222
release: replinfo
23-
swift build -c release -Xswiftc "-D" -Xswiftc "SPM"
23+
swift build -c release
2424

2525
replinfo:
2626
sed "s/CURRENT-DATE/$(shell date +%s)/" Sources/LispKitRepl/AppInfo.tmpl > Sources/LispKitRepl/AppInfo.swift
2727

2828
test:
29-
swift test -Xswiftc "-D" -Xswiftc "SPM"
29+
swift test
3030

3131
update:
3232
carthage update --platform macOS

Sources/LispKit/Graphics/Drawing.swift

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import CoreGraphics
2222
import Cocoa
23+
import AppKit
2324

2425
///
2526
/// Class `Drawing` represents a sequence of drawing instructions. The class offers the

Sources/LispKit/Primitives/DrawingLibrary.swift

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import Foundation
2222
import Cocoa
23+
import AppKit
2324
import MarkdownKit
2425

2526
///

Sources/LispKitRepl/AppInfo.swift

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020

2121
import Foundation
22+
import LispKit
2223

2324
///
2425
/// Struct `AppInfo` provides meta-information on the application and build-related
@@ -30,22 +31,19 @@ public struct AppInfo {
3031
public static let name = "LispKit Shell"
3132

3233
// Version of the application
33-
public static let version = "2.4.2"
34+
public static let version = "2.5"
3435

3536
// Copyright message
3637
public static let copyright = "Copyright © 2016–2024 Matthias Zenger. All rights reserved."
3738

38-
#if SPM
39-
public static let prompt = "> "
40-
#else
41-
public static let prompt = ""
42-
#endif
39+
// Prompt string
40+
public static let prompt = LispKitContext.bundle == nil ? "> " : ""
4341

4442
// Build date/time
4543
public static let buildDate = { () -> String in
4644
let dateFormatter = DateFormatter()
4745
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
48-
return dateFormatter.string(from: Date(timeIntervalSince1970: 1717359751))
46+
return dateFormatter.string(from: Date(timeIntervalSince1970: 1720824594))
4947
}()
5048
public static let buildAnnotation = " (\(AppInfo.buildDate))"
5149
}

Sources/LispKitRepl/AppInfo.tmpl

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020

2121
import Foundation
22+
import LispKit
2223

2324
///
2425
/// Struct `AppInfo` provides meta-information on the application and build-related
@@ -30,16 +31,13 @@ public struct AppInfo {
3031
public static let name = "LispKit Shell"
3132

3233
// Version of the application
33-
public static let version = "2.4.2"
34+
public static let version = "2.5"
3435

3536
// Copyright message
3637
public static let copyright = "Copyright © 2016–2024 Matthias Zenger. All rights reserved."
3738

38-
#if SPM
39-
public static let prompt = "> "
40-
#else
41-
public static let prompt = "➤ "
42-
#endif
39+
// Prompt string
40+
public static let prompt = LispKitContext.bundle == nil ? "> " : "➤ "
4341

4442
// Build date/time
4543
public static let buildDate = { () -> String in

Sources/LispKitRepl/LispKitRepl.swift

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// LispKitRepl.swift
3+
// LispKit
4+
//
5+
// Created by Matthias Zenger on 12/07/2024.
6+
// Copyright © 2024 ObjectHub. All rights reserved.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
21+
import Foundation
22+
import LispKit
23+
import LispKitTools
24+
25+
@main
26+
struct LispKitRepl {
27+
static func main() {
28+
let repl = LispKitTools.LispKitRepl(name: AppInfo.name,
29+
version: AppInfo.version,
30+
build: AppInfo.buildAnnotation,
31+
copyright: AppInfo.copyright,
32+
prompt: AppInfo.prompt)
33+
let features = ["repl"]
34+
guard repl.flagsValid() else {
35+
exit(1)
36+
}
37+
if repl.shouldRunRepl() {
38+
if LispKitContext.bundle == nil {
39+
guard repl.configurationSuccessfull(implementationName: "LispKit",
40+
implementationVersion: "2.4.0",
41+
includeInternalResources: false,
42+
defaultDocDirectory: "LispKit",
43+
features: features) else {
44+
exit(1)
45+
}
46+
} else {
47+
guard repl.configurationSuccessfull(features: features) else {
48+
exit(1)
49+
}
50+
}
51+
// Execute the read-eval-print loop in a new thread
52+
if repl.runloop.wasSet {
53+
repl.toolMessage = "[enabled run loop]"
54+
let main = Thread {
55+
let succeeded = repl.run()
56+
repl.release()
57+
exit(succeeded ? 0 : 1)
58+
}
59+
main.start()
60+
RunLoop.current.run()
61+
} else {
62+
let succeeded = repl.run()
63+
repl.release()
64+
exit(succeeded ? 0 : 1)
65+
}
66+
}
67+
}
68+
}

Sources/LispKitRepl/main.swift

-56
This file was deleted.

Sources/LispKitTools/LispKitRepl.swift

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ open class LispKitRepl {
3232
public let toolVersion: String
3333
public let toolBuild: String
3434
public let toolCopyright: String
35+
public var toolMessage: String? = nil
3536

3637
// Flags
3738
public let flags: Flags
@@ -53,6 +54,7 @@ open class LispKitRepl {
5354
public let quiet: Option
5455
public let raw: Option
5556
public let tabWidth: SingletonArgument<Int>
57+
public let runloop: Option
5658
public let help: Option
5759

5860
// LispKit setup
@@ -116,6 +118,8 @@ open class LispKitRepl {
116118
self.tabWidth = f.int("t", "tabwidth",
117119
description: "Width of a tab character.",
118120
value: 2)
121+
self.runloop = f.option("x", "runloop",
122+
description: "Enable runloop, i.e. support asynchronous APIs")
119123
self.help = f.option("h", "help",
120124
description: "Show description of usage and options of this tools.")
121125
// Instantiate the terminal
@@ -439,6 +443,9 @@ open class LispKitRepl {
439443
let props = Terminal.fullColorSupport ? TextStyle.bold.properties : TextProperties.none
440444
self.printOpt(props.apply(to: "\(self.toolName) \(self.toolVersion)\(self.toolBuild)"))
441445
self.printOpt(props.apply(to: "\(self.toolCopyright)"))
446+
if let toolMessage = self.toolMessage {
447+
self.printOpt(TextProperties.none.apply(to: toolMessage))
448+
}
442449
}
443450

444451
open func runRepl() -> Bool {

Tests/LispKitTests/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.4.0</string>
18+
<string>2.5</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)