Swiftpack.co -  App-Maker-Software/SwiftInterpreter as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
App-Maker-Software/SwiftInterpreter
Swift Interpreter less than 1 megabyte with optional support for Combine and SwiftUI
.package(url: "https://github.com/App-Maker-Software/SwiftInterpreter.git", from: "0.4.2")

Swift Interpreter

An embeddable Swift interpreter for all versions of iOS, Mac, tvOS, and watchOS. Takes in Swift AST data constructed from SwiftAST. Powers LiveApp and App Maker Professional.

Features

Optional Libraries Supported

  • Foundation
  • Combine
  • SwiftUI

See TEST_RESULTS.md.

Test Results

The Swift interpreter has automated tests which run against real compiled Swift. You can see those test results in the generated MD file called TEST_RESULTS.md.

Each time run_tests.sh is run while on the "staging" or "main" branch, this md TEST_RESULTS.md is automatically updated.

Adding a Test

You can add a new test by adding a folder under CodeTests with the desired test suite name with swift files for each test you would like to run.

For example: Tests/SwiftInterpreterTests/CodeTests/TEST_SUITE/TEST_NAME.swift

Some example test files:

// assert matching_return_value
var arr = [0]
arr.append(10)
return arr[1]
// assert matching_stack_value_x
var x = 5
x += 10
// assert does_not_compile
let x = 5
let y = 5.0
let z = x + y // error, you cannot sum an Int and Double

These will automatically produce a test to compare the result of running the interpreted Swift against the result of running compiled Swift.

There are three assertions currently supported.

  1. // assert matching_return_value
  • you must provide a return statement at the end of your program
  1. // assert matching_stack_value_x
  • where x can be any global variable name
  1. // assert does_not_compile
  • does not attempt to compile the Swift code, as it would fail
  • test expects interpreter to throw an error

Building from Source

Note: The Swift Interpreter is provided as a prebuilt binary, if you would like to have access to source, contact Joe Hinkle.

To build from source, first clone SwiftInterpreterSource in the same directory as this repo.

image

Then run swift package generate-xcodeproj to produce SwiftInterpreter.xcodeproj.

Then drag the SwiftInterpreterSource folder into the navigation panel of SwiftInterpreter. This should prompt asking to create a workspace. Create the workspace under the SwiftInterpreter folder and call it SwiftInterpreter.xcworkspace.

image

Rewrite the target SwiftInterpreterSource to have the name SwiftInterpreterBinary in order to trick this repo into using the source instead of the binary target.

Now when you build, it will automatically build the Swift Interpreter from source and use that in your tests.

GitHub

link
Stars: 2
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.4.2
4 weeks ago

0.4.2

  • os func compilation condition support #if os(iOS)
  • active compilation condition flags such as #if DEBUG support
  • onHover modifier
  • Bug fix where memberwise initializers for custom structs couldn't support more than one parameter
  • Improved closure support
  • Other bug fixes

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API