Serializing higher-order functions with protobuf
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Functions.xcodeproj
Functions
Report
.gitignore
LICENSE.md
Package.swift
README.md

README.md

Functions

Sample input file

Type:
int32
bool
binaryop = (int32, int32) -> int32

Symbol:
add(int32, int32) -> int32
subtract(int32, int32) -> int32
randomop() -> binaryop

Function:
f1: (int32, int32, int32) -> int32
f2: (binaryop) -> int32
f3: (int32, int32, int32, int32) -> int32
f4: () -> int32
f5: (int32, int32) -> binaryop

Usage (Swift)

let encoding = f1Encode { o1, o2, o3 in
    subtract(
        add(o1, 2 as Int32),
        add(o2, o3)
    )
}
class Implementation: Symbols {
    func add(_ o1: Int32, _ o2: Int32) -> Int32 {
        return o1 + o2
    }
    func subtract(_ o1: Int32, _ o2: Int32) -> Int32 {
        return o1 - o2
    }
    func randomop() -> binaryop {
        return { o1, o2 in o1 * o2 }
    }
}

let function = try! f1Decode(function: encoding, symbols: Implementation())
assert(function(1, 2, 3) == -2)

Getting Started

  1. Write specification file (See sample input)
  2. Compile specification to protobuf file and source code file 1
  3. Compile protobuf file to source code file 2
  4. Add both source code file 1 and 2 to your project

Demo

Demos mentioned in the report can be found on the releases page