fancadescala/core/src/main/scala/tf/bug/fancade/Main.scala

194 lines
12 KiB
Scala
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tf.bug.fancade
object Main {
def main(args: Array[String]): Unit = {
import Fanscript._
import tf.bug.shinji.syntax.all._
// min, max, start, result, after -> end, index, sum, before
val sum: (Number.type × Number.type × Pull.type × Number.type × Pull.type) (Pull.type × Number.type × Number.type × Pull.type) = {
val getSum: T.type Number.type = Builtin.GetNumber("Sum")
val setSum: (Number.type × Pull.type) Pull.type = Builtin.SetNumber("Sum")
val addToSum: (Number.type × Pull.type) Pull.type = {
val add: (Number.type × Number.type) Number.type = Builtin.AddNumbers
val sumAsFirstInput: (T.type × Number.type) (Number.type × Number.type) = fanscript.first(getSum)
val branch: Number.type (T.type × Number.type) = fanscript.deunitorLeft
val justSecondInput: Number.type (Number.type × Number.type) = fanscript.andThen(branch, sumAsFirstInput)
val addSum: Number.type Number.type = fanscript.ldimap[Number.type × Number.type, Number.type, Number.type](justSecondInput).apply(add)
val storeSum: (Number.type × Pull.type) Pull.type = setSum
fanscript.ldimap[Number.type × Pull.type, Pull.type, Number.type × Pull.type](fanscript.lbimap(addSum)).apply(storeSum)
}
val getIndex: T.type Number.type = Builtin.GetNumber("Index")
val setIndex: (Number.type × Pull.type) Pull.type = Builtin.SetNumber("Index")
val indexGreaterThan: Number.type Bool.type = {
val greaterThan: (Number.type × Number.type) Bool.type = Builtin.GreaterThan
val indexAsFirstInput: (T.type × Number.type) (Number.type × Number.type) = fanscript.first(getIndex)
val branch: Number.type (T.type × Number.type) = fanscript.deunitorLeft
val comparisonAsSecondInput: Number.type (Number.type × Number.type) = fanscript.andThen(branch, indexAsFirstInput)
fanscript.andThen(comparisonAsSecondInput, greaterThan)
}
val indexNotGreaterThan: Number.type Bool.type = fanscript.andThen(indexGreaterThan, Builtin.Not)
val checkContinue: (Number.type × Pull.type × Pull.type × Pull.type) Pull.type = {
val ifBlock: (Bool.type × Pull.type × Pull.type × Pull.type) Pull.type = Builtin.If
val checkGreater: (Number.type × Pull.type × Pull.type × Pull.type) (Bool.type × Pull.type × Pull.type × Pull.type) = {
val one: (Number.type × Pull.type) (Bool.type × Pull.type) = fanscript.first(indexGreaterThan)
val two: (Number.type × Pull.type × Pull.type) (Bool.type × Pull.type × Pull.type) = fanscript.first(one)
val three: (Number.type × Pull.type × Pull.type × Pull.type) (Bool.type × Pull.type × Pull.type × Pull.type) = fanscript.first(two)
three
}
fanscript.andThen(checkGreater, ifBlock)
}
// sumToIndex -> before
val initializeSum: Pull.type Pull.type = {
val zero: T.type Number.type = Builtin.NumberValue(0.0F)
val zeroAsInput: (T.type × Pull.type) (Number.type × Pull.type) = fanscript.first(zero)
val branch: Pull.type (T.type × Pull.type) = fanscript.deunitorLeft[Pull.type]
fanscript.andThen(fanscript.andThen(branch, zeroAsInput), setSum)
}
// min, indexToLoopStart -> sumToIndex
val initializeIndex: (Number.type × Pull.type) Pull.type = setIndex
// max, start, ◌, after -> (indexToLoopStart + incrementToLoop)
val startLoop: (Number.type × Pull.type × Pull.type × Pull.type) Pull.type = checkContinue
// result, increaseSum -> end
val increaseSum: (Number.type × Pull.type) Pull.type = addToSum
// incrementToLoop -> increaseSum
val incrementIndex: Pull.type Pull.type = {
val get: T.type Number.type = getIndex
val set: (Number.type × Pull.type) Pull.type = setIndex
val one: T.type Number.type = Builtin.NumberValue(1.0F)
val additionOperands: T.type (Number.type × Number.type) = fanscript.merge(get, one)
val add: T.type Number.type = fanscript.andThen(additionOperands, Builtin.AddNumbers)
val carryPull: (T.type × Pull.type) (Number.type × Pull.type) = fanscript.first(add)
val branch: Pull.type (T.type × Pull.type) = fanscript.deunitorLeft[Pull.type]
fanscript.andThen(fanscript.andThen(branch, carryPull), set)
}
// min, indexToLoopStart -> before
val initialize: (Number.type × Pull.type) Pull.type = fanscript.andThen(initializeIndex, initializeSum)
// result, incrementToLoop -> end
val postLoop: (Number.type × Pull.type) Pull.type = {
val carryResult = fanscript.second[Pull.type, Pull.type, Number.type](incrementIndex)
fanscript.andThen(carryResult, increaseSum)
}
// max, start, after -> (indexToLoopStart + incrementToLoop)
val condition: (Number.type × Pull.type × Pull.type) Pull.type = {
val zThree: (Number.type × Pull.type) (Number.type × Pull.type × Pull.type) =
fanscript.andThen(fanscript.deunitorRight, fanscript.rbimap(Z))
val zFour: (Number.type × Pull.type × Pull.type) (Number.type × Pull.type × Pull.type × Pull.type) =
fanscript.lbimap(zThree)
fanscript.ldimap[Number.type × Pull.type × Pull.type × Pull.type, Pull.type, Number.type × Pull.type × Pull.type](zFour).apply(checkContinue)
}
// min, max, start, result, after -> end, index, sum, before
val result: (Number.type × Number.type × Pull.type × Number.type × Pull.type) (Pull.type × Number.type × Number.type × Pull.type) = {
// max, start, after -> indexToLoopStart, incrementToLoop
val duplicateCondition: (Number.type × Pull.type × Pull.type) (Pull.type × Pull.type) =
fanscript.andThen(condition, fanscript.duplicate)
// min, indexToLoopStart, result, incrementToLoop -> before, end
val conditionPrecursors: (Number.type × Pull.type × Number.type × Pull.type) (Pull.type × Pull.type) =
fanscript.associateRight[Number.type × Pull.type, Number.type, Pull.type] >>> (initialize *** postLoop)
// min, result, (indexToLoopStart, incrementToLoop) -> end, before
val orientConditionPrecursors: ((Number.type × Number.type) × (Pull.type × Pull.type)) (Pull.type × Pull.type) = {
val flattenAssoc: ((Number.type × Number.type) × (Pull.type × Pull.type)) (((Number.type × Number.type) × Pull.type) × Pull.type) = fanscript.associateLeft
val assocInside: (((Number.type × Number.type) × Pull.type) × Pull.type) ((Number.type × (Number.type × Pull.type)) × Pull.type) = fanscript.lbimap(fanscript.associateRight)
val swapInside: ((Number.type × (Number.type × Pull.type)) × Pull.type) ((Number.type × (Pull.type × Number.type)) × Pull.type) = fanscript.lbimap(fanscript.rbimap(fanscript.swap))
val reassocInside: ((Number.type × (Pull.type × Number.type)) × Pull.type) (((Number.type × Pull.type) × Number.type) × Pull.type) = fanscript.lbimap(fanscript.associateLeft)
val orientConditionInputs: ((Number.type × Number.type) × (Pull.type × Pull.type)) (((Number.type × Pull.type) × Number.type) × Pull.type) =
fanscript.andThen(fanscript.andThen(fanscript.andThen(flattenAssoc, assocInside), swapInside), reassocInside)
val swapEnd: (Pull.type × Pull.type) (Pull.type × Pull.type) = fanscript.swap
fanscript.dimap(orientConditionInputs, swapEnd)(conditionPrecursors)
}
// min, max, start, result, after -> end, before
val nonNumbers: (Number.type × Number.type × Pull.type × Number.type × Pull.type) (Pull.type × Pull.type) = {
val duplicateConditionLeftNumbers: ((Number.type × Number.type) × (Number.type × Pull.type × Pull.type)) ((Number.type × Number.type) × (Pull.type × Pull.type)) =
fanscript.second[Number.type × Pull.type × Pull.type, Pull.type × Pull.type, Number.type × Number.type](duplicateCondition)
// (min, result), (max, start, after) -> end, before
val aggregate: ((Number.type × Number.type) × (Number.type × Pull.type × Pull.type)) (Pull.type × Pull.type) =
fanscript.andThen(duplicateConditionLeftNumbers, orientConditionPrecursors)
// (max, start, after, (min, result)) -> end, before
val align: (Number.type × Pull.type × Pull.type × (Number.type × Number.type)) (Pull.type × Pull.type) =
fanscript.andThen(fanscript.swap, aggregate)
// max, start, after, min, result -> end, before
val assoc: (Number.type × Pull.type × Pull.type × Number.type × Number.type) (Pull.type × Pull.type) =
fanscript.andThen(fanscript.associateRight, align)
// min, max, start, result, after -> max, start, after, min, result
val realign: ((((Number.type × Number.type) × Pull.type) × Number.type) × Pull.type) ((((Number.type × Pull.type) × Pull.type) × Number.type) × Number.type) = {
val one: ((((Number.type × Number.type) × Pull.type) × Number.type) × Pull.type) (((Number.type × (Number.type × Pull.type)) × Number.type) × Pull.type) =
fanscript.lbimap(fanscript.lbimap(fanscript.associateRight))
val two: (((Number.type × (Number.type × Pull.type)) × Number.type) × Pull.type) ((((Number.type × Pull.type) × Number.type) × Number.type) × Pull.type) =
fanscript.lbimap(fanscript.lbimap(fanscript.swap))
val three: ((((Number.type × Pull.type) × Number.type) × Number.type) × Pull.type) (((Number.type × Pull.type) × Number.type) × (Number.type × Pull.type)) =
fanscript.associateRight
val four: (((Number.type × Pull.type) × Number.type) × (Number.type × Pull.type)) (((Number.type × Pull.type) × Number.type) × (Pull.type × Number.type)) =
fanscript.rbimap(fanscript.swap)
val five: (((Number.type × Pull.type) × Number.type) × (Pull.type × Number.type)) ((((Number.type × Pull.type) × Number.type) × Pull.type) × Number.type) =
fanscript.associateLeft
val six: ((((Number.type × Pull.type) × Number.type) × Pull.type) × Number.type) (((Number.type × Pull.type) × (Number.type × Pull.type)) × Number.type) =
fanscript.lbimap(fanscript.associateRight)
val seven: (((Number.type × Pull.type) × (Number.type × Pull.type)) × Number.type) (((Number.type × Pull.type) × (Pull.type × Number.type)) × Number.type) =
fanscript.lbimap(fanscript.rbimap(fanscript.swap))
val eight: (((Number.type × Pull.type) × (Pull.type × Number.type)) × Number.type) ((((Number.type × Pull.type) × Pull.type) × Number.type) × Number.type) =
fanscript.lbimap(fanscript.associateLeft)
fanscript.andThen(
fanscript.andThen(
fanscript.andThen(
fanscript.andThen(
fanscript.andThen(
fanscript.andThen(
fanscript.andThen(
one,
two
),
three
),
four
),
five
),
six
),
seven
),
eight
)
}
fanscript.andThen(realign, assoc)
}
// end, before -> end, index, sum, before
val addOutputs: (Pull.type × Pull.type) (Pull.type × Number.type × Number.type × Pull.type) =
fanscript.lbimap(fanscript.andThen(
fanscript.andThen[Pull.type, Pull.type × T.type, Pull.type × Number.type](fanscript.deunitorRight[Pull.type], fanscript.rbimap(getIndex)),
fanscript.andThen[Pull.type × Number.type, Pull.type × Number.type × T.type, Pull.type × Number.type × Number.type](fanscript.deunitorRight[Pull.type × Number.type], fanscript.rbimap(getSum))
))
fanscript.andThen(nonNumbers, addOutputs)
}
result
}
pprint.pprintln(sum)
}
}