Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: replace custom server with noise-serde-lib
- Loading branch information
Showing
14 changed files
with
862 additions
and
769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
TEMP_DIR=temp | ||
BUILD_DIR=build | ||
ARCH=$(shell uname -m) | ||
|
||
COCOA_MAN_DIR=cocoa/remember/Resources/manual | ||
COCOA_CORE_DIR=cocoa/remember/Resources/core/$(shell uname -m) | ||
APP_SRC=cocoa/remember | ||
RKT_SRC=core | ||
RKT_FILES=$(shell find ${RKT_SRC} -name '*.rkt') | ||
RKT_MAIN_ZO=${RKT_SRC}/compiled/main_rkt.zo | ||
|
||
.PHONY: all | ||
all: $(COCOA_CORE_DIR)/bin/remember-core $(COCOA_MAN_DIR)/index.html | ||
|
||
|
||
## Core ################################################################ | ||
|
||
CORE_SRC_DIR=core | ||
CORE_OBJ_DIR=core/compiled | ||
|
||
$(COCOA_CORE_DIR)/bin/remember-core: $(BUILD_DIR)/bin/remember-core | ||
rm -fr $(COCOA_CORE_DIR) && mkdir -p $(COCOA_CORE_DIR) | ||
cp -r $(BUILD_DIR)/* $(COCOA_CORE_DIR)/ | ||
|
||
$(BUILD_DIR)/bin/remember-core: $(TEMP_DIR)/remember-core | ||
rm -fr $(BUILD_DIR) && mkdir -p $(BUILD_DIR) | ||
raco distribute $(BUILD_DIR) $(TEMP_DIR)/remember-core | ||
RESOURCES_PATH=${APP_SRC}/res | ||
RUNTIME_NAME=runtime-${ARCH} | ||
RUNTIME_PATH=${RESOURCES_PATH}/${RUNTIME_NAME} | ||
MANUAL_PATH=${RESOURCES_PATH}/manual | ||
|
||
$(TEMP_DIR)/remember-core: $(CORE_OBJ_DIR)/main_rkt.zo migrations/*.sql | ||
rm -fr $(TEMP_DIR) && mkdir -p $(TEMP_DIR) | ||
raco exe -o $(TEMP_DIR)/remember-core core/main.rkt | ||
CORE_ZO=${RESOURCES_PATH}/core-${ARCH}.zo | ||
|
||
$(CORE_OBJ_DIR)/main_rkt.zo: core/*.rkt | ||
|
||
$(CORE_OBJ_DIR)/%_rkt.zo: core/%.rkt | ||
raco make -j $(shell nproc || echo 16) -v $< | ||
|
||
|
||
## Phony ############################################################### | ||
.PHONY: all | ||
all: ${CORE_ZO} ${APP_SRC}/remember/Backend.swift | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -fr $(CORE_OBJ_DIR) $(COCOA_CORE_DIR) $(BUILD_DIR) $(TEMP_DIR) | ||
rm -fr ${RESOURCES_PATH} | ||
|
||
${RKT_MAIN_ZO}: ${RKT_FILES} | ||
raco make -j 16 -v ${RKT_SRC}/main.rkt | ||
|
||
${CORE_ZO}: ${RKT_MAIN_ZO} | ||
mkdir -p ${RESOURCES_PATH} | ||
rm -fr ${RUNTIME_PATH} | ||
raco ctool \ | ||
--runtime ${RUNTIME_PATH} \ | ||
--runtime-access ${RUNTIME_NAME} \ | ||
--mods $@ ${RKT_SRC}/main.rkt | ||
|
||
## Manual ############################################################## | ||
${APP_SRC}/remember/Backend.swift: ${CORE_ZO} | ||
raco noise-serde-codegen ${RKT_SRC}/main.rkt > $@ | ||
|
||
$(COCOA_MAN_DIR)/index.html: manual/*.scrbl | ||
raco scribble --html --dest $(COCOA_MAN_DIR) +m manual/index.scrbl | ||
${MANUAL_PATH}/index.html: manual/*.scrbl | ||
raco scribble --html --dest ${MANUAL_PATH} +m manual/index.scrbl | ||
|
||
website/manual/index.html: manual/*.scrbl | ||
raco scribble --html --dest website/manual +m manual/index.scrbl | ||
make -C website manual/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
// This file was automatically generated by noise-serde-lib. | ||
import Foundation | ||
import NoiseBackend | ||
import NoiseSerde | ||
|
||
public enum TokenData: Readable, Writable { | ||
case relativeTime(UVarint, Symbol) | ||
case namedDate(String) | ||
case namedDatetime(String) | ||
case recurrence(UVarint, Symbol) | ||
case tag(String) | ||
|
||
public static func read(from inp: InputPort, using buf: inout Data) -> TokenData { | ||
let tag = UVarint.read(from: inp, using: &buf) | ||
switch tag { | ||
case 0x0000: | ||
return .relativeTime( | ||
UVarint.read(from: inp, using: &buf), | ||
Symbol.read(from: inp, using: &buf) | ||
) | ||
case 0x0001: | ||
return .namedDate( | ||
String.read(from: inp, using: &buf) | ||
) | ||
case 0x0002: | ||
return .namedDatetime( | ||
String.read(from: inp, using: &buf) | ||
) | ||
case 0x0003: | ||
return .recurrence( | ||
UVarint.read(from: inp, using: &buf), | ||
Symbol.read(from: inp, using: &buf) | ||
) | ||
case 0x0004: | ||
return .tag( | ||
String.read(from: inp, using: &buf) | ||
) | ||
default: | ||
preconditionFailure("TokenData: unexpected tag \(tag)") | ||
} | ||
} | ||
|
||
public func write(to out: OutputPort) { | ||
switch self { | ||
case .relativeTime(let delta, let modifier): | ||
UVarint(0x0000).write(to: out) | ||
delta.write(to: out) | ||
modifier.write(to: out) | ||
case .namedDate(let date): | ||
UVarint(0x0001).write(to: out) | ||
date.write(to: out) | ||
case .namedDatetime(let datetime): | ||
UVarint(0x0002).write(to: out) | ||
datetime.write(to: out) | ||
case .recurrence(let delta, let modifier): | ||
UVarint(0x0003).write(to: out) | ||
delta.write(to: out) | ||
modifier.write(to: out) | ||
case .tag(let name): | ||
UVarint(0x0004).write(to: out) | ||
name.write(to: out) | ||
} | ||
} | ||
} | ||
|
||
public struct Entry: Readable, Writable { | ||
public let id: UVarint | ||
public let title: String | ||
public let dueIn: String? | ||
public let recurs: Bool | ||
|
||
public init( | ||
id: UVarint, | ||
title: String, | ||
dueIn: String?, | ||
recurs: Bool | ||
) { | ||
self.id = id | ||
self.title = title | ||
self.dueIn = dueIn | ||
self.recurs = recurs | ||
} | ||
|
||
public static func read(from inp: InputPort, using buf: inout Data) -> Entry { | ||
return Entry( | ||
id: UVarint.read(from: inp, using: &buf), | ||
title: String.read(from: inp, using: &buf), | ||
dueIn: String?.read(from: inp, using: &buf), | ||
recurs: Bool.read(from: inp, using: &buf) | ||
) | ||
} | ||
|
||
public func write(to out: OutputPort) { | ||
id.write(to: out) | ||
title.write(to: out) | ||
dueIn.write(to: out) | ||
recurs.write(to: out) | ||
} | ||
} | ||
|
||
public struct Location: Readable, Writable { | ||
public let line: UVarint | ||
public let column: UVarint | ||
public let offset: UVarint | ||
|
||
public init( | ||
line: UVarint, | ||
column: UVarint, | ||
offset: UVarint | ||
) { | ||
self.line = line | ||
self.column = column | ||
self.offset = offset | ||
} | ||
|
||
public static func read(from inp: InputPort, using buf: inout Data) -> Location { | ||
return Location( | ||
line: UVarint.read(from: inp, using: &buf), | ||
column: UVarint.read(from: inp, using: &buf), | ||
offset: UVarint.read(from: inp, using: &buf) | ||
) | ||
} | ||
|
||
public func write(to out: OutputPort) { | ||
line.write(to: out) | ||
column.write(to: out) | ||
offset.write(to: out) | ||
} | ||
} | ||
|
||
public struct Span: Readable, Writable { | ||
public let lo: Location | ||
public let hi: Location | ||
|
||
public init( | ||
lo: Location, | ||
hi: Location | ||
) { | ||
self.lo = lo | ||
self.hi = hi | ||
} | ||
|
||
public static func read(from inp: InputPort, using buf: inout Data) -> Span { | ||
return Span( | ||
lo: Location.read(from: inp, using: &buf), | ||
hi: Location.read(from: inp, using: &buf) | ||
) | ||
} | ||
|
||
public func write(to out: OutputPort) { | ||
lo.write(to: out) | ||
hi.write(to: out) | ||
} | ||
} | ||
|
||
public struct Token: Readable, Writable { | ||
public let text: String | ||
public let span: Span | ||
public let data: TokenData? | ||
|
||
public init( | ||
text: String, | ||
span: Span, | ||
data: TokenData? | ||
) { | ||
self.text = text | ||
self.span = span | ||
self.data = data | ||
} | ||
|
||
public static func read(from inp: InputPort, using buf: inout Data) -> Token { | ||
return Token( | ||
text: String.read(from: inp, using: &buf), | ||
span: Span.read(from: inp, using: &buf), | ||
data: TokenData?.read(from: inp, using: &buf) | ||
) | ||
} | ||
|
||
public func write(to out: OutputPort) { | ||
text.write(to: out) | ||
span.write(to: out) | ||
data.write(to: out) | ||
} | ||
} | ||
|
||
public class Backend { | ||
let impl: NoiseBackend.Backend! | ||
|
||
init(withZo zo: URL, andMod mod: String, andProc proc: String) { | ||
impl = NoiseBackend.Backend(withZo: zo, andMod: mod, andProc: proc) | ||
} | ||
|
||
public func archive(entryWithId id: UVarint) -> Future<String, Void> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0000).write(to: out) | ||
id.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Void in } | ||
) | ||
} | ||
|
||
public func commit(command s: String) -> Future<String, Entry> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0001).write(to: out) | ||
s.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Entry in | ||
return Entry.read(from: inp, using: &buf) | ||
} | ||
) | ||
} | ||
|
||
public func createDatabaseCopy() -> Future<String, String> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0002).write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> String in | ||
return String.read(from: inp, using: &buf) | ||
} | ||
) | ||
} | ||
|
||
public func delete(entryWithId id: UVarint) -> Future<String, Void> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0003).write(to: out) | ||
id.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Void in } | ||
) | ||
} | ||
|
||
public func getPendingEntries() -> Future<String, [Entry]> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0004).write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> [Entry] in | ||
return [Entry].read(from: inp, using: &buf) | ||
} | ||
) | ||
} | ||
|
||
public func installCallback(internalWithId id: UVarint, andAddr addr: Varint) -> Future<String, Void> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0005).write(to: out) | ||
id.write(to: out) | ||
addr.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Void in } | ||
) | ||
} | ||
|
||
public func mergeDatabaseCopy(atPath path: String) -> Future<String, Void> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0006).write(to: out) | ||
path.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Void in } | ||
) | ||
} | ||
|
||
public func parse(command s: String) -> Future<String, [Token]> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0007).write(to: out) | ||
s.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> [Token] in | ||
return [Token].read(from: inp, using: &buf) | ||
} | ||
) | ||
} | ||
|
||
public func snooze(entryWithId id: UVarint, forMinutes minutes: UVarint) -> Future<String, Void> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0008).write(to: out) | ||
id.write(to: out) | ||
minutes.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Void in } | ||
) | ||
} | ||
|
||
public func undo() -> Future<String, Void> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x0009).write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Void in } | ||
) | ||
} | ||
|
||
public func update(entryWithId id: UVarint, andCommand s: String) -> Future<String, Entry?> { | ||
return impl.send( | ||
writeProc: { (out: OutputPort) in | ||
UVarint(0x000a).write(to: out) | ||
id.write(to: out) | ||
s.write(to: out) | ||
}, | ||
readProc: { (inp: InputPort, buf: inout Data) -> Entry? in | ||
return Entry?.read(from: inp, using: &buf) | ||
} | ||
) | ||
} | ||
} |
Oops, something went wrong.