feat: meaningful comments for internal packages
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// Package "cli" provides miscellaneous helper functions.
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package "config" parses ad handles the user settings given to the program.
|
||||||
package config
|
package config
|
||||||
|
|
||||||
// Configuration settings for the program.
|
// Configuration settings for the program.
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Package "engine" provides an extensible interface for users to interfact with
|
||||||
|
// lambda calculus.
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -6,16 +8,19 @@ import (
|
|||||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A process for reducing one lambda expression.
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
Expression *lambda.Expression
|
Expression *lambda.Expression
|
||||||
emitter.Emitter
|
emitter.Emitter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new engine, given an unreduced lambda expression.
|
||||||
func New(config *config.Config, expression *lambda.Expression) *Engine {
|
func New(config *config.Config, expression *lambda.Expression) *Engine {
|
||||||
return &Engine{Config: config, Expression: expression}
|
return &Engine{Config: config, Expression: expression}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Begin the reduction process.
|
||||||
func (e Engine) Run() {
|
func (e Engine) Run() {
|
||||||
e.Emit("start")
|
e.Emit("start")
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Package "explanation" provides a observer to gather the reasoning during the
|
||||||
|
// reduction, and present a thorough explanation to the user for each step.
|
||||||
package explanation
|
package explanation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -7,10 +9,12 @@ import (
|
|||||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Track the reductions made by a reduction proess.
|
||||||
type Tracker struct {
|
type Tracker struct {
|
||||||
process *engine.Engine
|
process *engine.Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attaches a new explanation tracker to a process.
|
||||||
func Track(process *engine.Engine) *Tracker {
|
func Track(process *engine.Engine) *Tracker {
|
||||||
tracker := &Tracker{process: process}
|
tracker := &Tracker{process: process}
|
||||||
process.On("start", tracker.Start)
|
process.On("start", tracker.Start)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Package "performance" provides a tracker to observer CPU performance during
|
||||||
|
// execution.
|
||||||
package performance
|
package performance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -6,16 +8,20 @@ import (
|
|||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Observes a reduction process, and publishes a CPU performance profile on
|
||||||
|
// completion.
|
||||||
type Tracker struct {
|
type Tracker struct {
|
||||||
File string
|
File string
|
||||||
filePointer *os.File
|
filePointer *os.File
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a performance tracker that outputs a profile to "file".
|
||||||
func Track(file string) *Tracker {
|
func Track(file string) *Tracker {
|
||||||
return &Tracker{File: file}
|
return &Tracker{File: file}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Begin profiling.
|
||||||
func (t *Tracker) Start() {
|
func (t *Tracker) Start() {
|
||||||
var absPath string
|
var absPath string
|
||||||
|
|
||||||
@@ -40,6 +46,7 @@ func (t *Tracker) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop profiling.
|
||||||
func (t *Tracker) End() {
|
func (t *Tracker) End() {
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
t.filePointer.Close()
|
t.filePointer.Close()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Package "statistics" provides a way to observer reduction speed during
|
||||||
|
// execution.
|
||||||
package statistics
|
package statistics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -5,15 +7,18 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Statistics for a specific reduction.
|
||||||
type Results struct {
|
type Results struct {
|
||||||
StepsTaken uint64 // Number of steps taken during execution.
|
StepsTaken uint64 // Number of steps taken during execution.
|
||||||
TimeElapsed uint64 // The time (ms) taken for execution to complete.
|
TimeElapsed uint64 // The time (ms) taken for execution to complete.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the average number of operations per second of the execution.
|
||||||
func (r Results) OpsPerSecond() float32 {
|
func (r Results) OpsPerSecond() float32 {
|
||||||
return float32(r.StepsTaken) / (float32(r.TimeElapsed) / 1000)
|
return float32(r.StepsTaken) / (float32(r.TimeElapsed) / 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format the results as a string.
|
||||||
func (r Results) String() string {
|
func (r Results) String() string {
|
||||||
builder := strings.Builder{}
|
builder := strings.Builder{}
|
||||||
fmt.Fprintln(&builder, "Time Spent:", r.TimeElapsed, "ms")
|
fmt.Fprintln(&builder, "Time Spent:", r.TimeElapsed, "ms")
|
||||||
@@ -6,11 +6,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// An observer, to track reduction performance.
|
||||||
type Tracker struct {
|
type Tracker struct {
|
||||||
start time.Time
|
start time.Time
|
||||||
steps uint64
|
steps uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new reduction performance tracker.
|
||||||
func Track() *Tracker {
|
func Track() *Tracker {
|
||||||
return &Tracker{}
|
return &Tracker{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user