Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: try async for code eval #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 23 additions & 34 deletions Beacon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
F3B1990E299518F900FE664F /* AutocompleteProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3B19905299518F900FE664F /* AutocompleteProvider.swift */; };
F3B199142995195C00FE664F /* KeyboardKit in Frameworks */ = {isa = PBXBuildFile; productRef = F3B199132995195C00FE664F /* KeyboardKit */; };
F3B199152995199000FE664F /* stdlib in Resources */ = {isa = PBXBuildFile; fileRef = F3B198DB2995181700FE664F /* stdlib */; };
F3CEF79D2A94D3E000DC8858 /* KeyboardKit in Frameworks */ = {isa = PBXBuildFile; productRef = F3CEF79C2A94D3E000DC8858 /* KeyboardKit */; };
F3CEF79E2A94D85500DC8858 /* Keyboard.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = F3B198F1299518E900FE664F /* Keyboard.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
F3D296822A404A3E00AD21A2 /* History.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D296812A404A3E00AD21A2 /* History.swift */; };
F3D296832A404A3E00AD21A2 /* History.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3D296812A404A3E00AD21A2 /* History.swift */; };
Expand All @@ -64,6 +63,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
F31AB4F72AE0490F0074EA1B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = F3B198C2299517DA00FE664F /* Project object */;
proxyType = 1;
remoteGlobalIDString = F3B198F0299518E900FE664F;
remoteInfo = Keyboard;
};
F3E1DFF02A31F56800B4A553 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = F3B198C2299517DA00FE664F /* Project object */;
Expand Down Expand Up @@ -159,7 +165,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F3CEF79D2A94D3E000DC8858 /* KeyboardKit in Frameworks */,
F3DF828B2A4F22FF00F6CD19 /* libk.a in Frameworks */,
F3AC4D262A4F6C3100B4FECD /* curl.xcframework in Frameworks */,
F32D9E9629967067007BC97C /* libcbqn.a in Frameworks */,
Expand Down Expand Up @@ -342,10 +347,10 @@
);
dependencies = (
F3E1DFF12A31F56800B4A553 /* PBXTargetDependency */,
F31AB4F82AE0490F0074EA1B /* PBXTargetDependency */,
);
name = Beacon;
packageProductDependencies = (
F3CEF79C2A94D3E000DC8858 /* KeyboardKit */,
);
productName = Beacon;
productReference = F3B198CA299517DA00FE664F /* Beacon.app */;
Expand Down Expand Up @@ -399,9 +404,7 @@
);
mainGroup = F3B198C1299517DA00FE664F;
packageReferences = (
F3B1990F2995193C00FE664F /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */,
F3B199122995195C00FE664F /* XCRemoteSwiftPackageReference "KeyboardKit" */,
F3CEF79B2A94D3E000DC8858 /* XCRemoteSwiftPackageReference "KeyboardKit" */,
);
productRefGroup = F3B198CB299517DA00FE664F /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -506,6 +509,11 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
F31AB4F82AE0490F0074EA1B /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = F3B198F0299518E900FE664F /* Keyboard */;
targetProxy = F31AB4F72AE0490F0074EA1B /* PBXContainerItemProxy */;
};
F3E1DFF12A31F56800B4A553 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = F3B198F0299518E900FE664F /* Keyboard */;
Expand Down Expand Up @@ -594,6 +602,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -641,7 +650,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MERGEABLE_LIBRARY = NO;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand All @@ -658,6 +667,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -699,7 +709,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MERGEABLE_LIBRARY = NO;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand All @@ -720,7 +730,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Beacon/Preview Content\"";
DEVELOPMENT_TEAM = KPW29M2DBH;
ENABLE_PREVIEWS = YES;
Expand All @@ -733,7 +743,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -744,7 +754,7 @@
"$(PROJECT_DIR)/Beacon/libs",
"$(PROJECT_DIR)/Beacon/Libs",
);
MARKETING_VERSION = 1.1.5;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = arrscience.Beacons;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -767,7 +777,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Beacon/Preview Content\"";
DEVELOPMENT_TEAM = KPW29M2DBH;
ENABLE_PREVIEWS = YES;
Expand All @@ -780,7 +790,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -791,7 +801,7 @@
"$(PROJECT_DIR)/Beacon/libs",
"$(PROJECT_DIR)/Beacon/Libs",
);
MARKETING_VERSION = 1.1.5;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = arrscience.Beacons;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -908,14 +918,6 @@
kind = branch;
};
};
F3B1990F2995193C00FE664F /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/siteline/SwiftUI-Introspect";
requirement = {
branch = master;
kind = branch;
};
};
F3B199122995195C00FE664F /* XCRemoteSwiftPackageReference "KeyboardKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/KeyboardKit/KeyboardKit";
Expand All @@ -924,14 +926,6 @@
minimumVersion = 7.0.0;
};
};
F3CEF79B2A94D3E000DC8858 /* XCRemoteSwiftPackageReference "KeyboardKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/KeyboardKit/KeyboardKit";
requirement = {
kind = exactVersion;
version = 7.9.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -945,11 +939,6 @@
package = F3B199122995195C00FE664F /* XCRemoteSwiftPackageReference "KeyboardKit" */;
productName = KeyboardKit;
};
F3CEF79C2A94D3E000DC8858 /* KeyboardKit */ = {
isa = XCSwiftPackageProductDependency;
package = F3CEF79B2A94D3E000DC8858 /* XCRemoteSwiftPackageReference "KeyboardKit" */;
productName = KeyboardKit;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = F3B198C2299517DA00FE664F /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
"revision" : "f6bd1def639641b2cff9ca4cddbb4615aa717e5c",
"version" : "7.9.0"
}
},
{
"identity" : "swiftui-introspect",
"kind" : "remoteSourceControl",
"location" : "https://github.com/siteline/SwiftUI-Introspect",
"state" : {
"branch" : "master",
"revision" : "a5a1d7c305e9d9082958de04d521be57a88d431a"
}
}
],
"version" : 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Beacon/ArraygroundApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ArraygroundApp: App {
.preferredColorScheme(appearanceSwitch)
// Dashboard().tag(1)
}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.onChange(of: selectedView) {
.onChange(of: selectedView) { _ in
dismissKeyboard()
}
}
Expand Down
23 changes: 20 additions & 3 deletions Beacon/Components/ReplInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,26 @@ struct ReplInput: View {
}

HStack {
TextField("Type \(languageToString(l: lang))...", text: $text, axis: .vertical)
Spacer()
TextField("", text: $text, axis: .vertical)
.onSubmit {
onSubmit?()
}
.toolbar {
toolbar
}
.placeholder(when: text.isEmpty) {
Text("Type \(languageToString(l: lang))...").font(.monospaced(.system(size: 16))()).opacity(0.3)
}
.lineLimit(1 ... 8)
.keyboardType(.asciiCapable)
.submitLabel(.done)
.disableAutocorrection(true)
.font(font)
.frame(minHeight: 36)
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) //
.overlay(
RoundedRectangle(cornerRadius: 48)
RoundedRectangle(cornerRadius: 18)
.stroke(.gray.opacity(0.2), lineWidth: 1)
)
Button(action: {
Expand All @@ -84,3 +88,16 @@ struct ReplInput: View {
}
}
}

extension View {
func placeholder<Content: View>(
when shouldShow: Bool,
alignment: Alignment = .leading,
@ViewBuilder placeholder: () -> Content
) -> some View {
ZStack(alignment: alignment) {
placeholder().opacity(shouldShow ? 1 : 0)
self
}
}
}
12 changes: 9 additions & 3 deletions Beacon/Models/History.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import Foundation
let d = UserDefaults.standard

struct Entry: Hashable, Codable, Identifiable {
var id: String = UUID().uuidString
var id: UUID
var src: String
var out: String
var lang: Language
var tokens: [[Token]]
var isLoading: Bool
}

enum Buffers {
Expand Down Expand Up @@ -40,11 +41,16 @@ enum Buffers {
class HistoryModel: ObservableObject {
@Published var history: [String: [Entry]] = ["default": []]

func addMessage(with src: String, out: String, lang: Language, for key: String) {
func addMessage(id: UUID, with src: String, out: String, lang: Language, for key: String, isLoading: Bool) {
if !isLoading {
if let index = history[key]?.firstIndex(where: { $0.id == id }) {
history[key]?.remove(at: index)
}
}
let tokenize = lang == .k
? tokenize(src, lexK(src))
: tokenize(src, lexBQN(src))
let entry = Entry(src: src, out: out, lang: lang, tokens: tokenize)
let entry = Entry(id: id, src: src, out: out, lang: lang, tokens: tokenize, isLoading: isLoading)
if var entries = history[key] {
entries.append(entry)
history[key] = entries
Expand Down
2 changes: 1 addition & 1 deletion Beacon/Utilities/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func lexBQN(_ code: String) -> [String] {
let dmdC = "D"
let dmd = "←↩,⋄→⇐"
let comC = "C"
let newL = "E"
let _newL = "E"

var res = Array(repeating: "", count: code.count)
var i = code.startIndex
Expand Down
6 changes: 3 additions & 3 deletions Beacon/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func kCmd(_ inp: UnsafePointer<Int8>) {
b.deallocate()
}

func e(input: String) -> String {
func e(input: String) async -> String {
var input = input
if input.contains("•Import ") {
let i = input.split(separator: "•Import ")
Expand All @@ -58,11 +58,11 @@ func e(input: String) -> String {
input = "\(vars) •Import \"\(Bundle.main.resourcePath!)/bqn-libs/\(filename)\""
}
input = input.replacingOccurrences(of: "\"", with: #""""#)
input = "((•ReBQN{repl⇐\"loose\"})⎊{𝕊: •Out \"Error: \"∾•CurrentError@}) \"\(input)\""
input = "RRR \"\(input)\""
return runCmd(cbqnCmd, input)
}

func ke(input: String) -> String {
func ke(input: String) async -> String {
var input = input.replacingOccurrences(of: "\\", with: #"\\"#)
input = input.replacingOccurrences(of: "\"", with: #"\""#)
input = ".[{line `k@.\"\(input)\"};[];{`0:(,\"Error: \"),(-2_\"\n\"\\x)}]"
Expand Down
Loading
Loading