chore: Makefile improvements and cleanup #2
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,6 +9,9 @@
|
|||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
lambda
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
|
|||||||
151
.golangci.yml
151
.golangci.yml
@@ -1,230 +1,83 @@
|
|||||||
---
|
|
||||||
# golangci-lint configuration file made by @ccoVeille
|
|
||||||
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
|
|
||||||
# Author: @ccoVeille
|
|
||||||
# License: MIT
|
|
||||||
# Variant: 03-safe
|
|
||||||
# Version: v2.0.0
|
|
||||||
#
|
|
||||||
version: "2"
|
version: "2"
|
||||||
|
|
||||||
formatters:
|
formatters:
|
||||||
enable:
|
enable:
|
||||||
# format the code
|
|
||||||
- gofmt
|
- gofmt
|
||||||
# format the block of imports
|
|
||||||
- gci
|
- gci
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
# format the code with Go standard library
|
|
||||||
gofmt:
|
gofmt:
|
||||||
# simplify the code
|
|
||||||
# https://pkg.go.dev/cmd/gofmt#hdr-The_simplify_command
|
|
||||||
simplify: true
|
simplify: true
|
||||||
rewrite-rules:
|
rewrite-rules:
|
||||||
# replace `interface{}` with `any` in the code on format
|
|
||||||
- pattern: 'interface{}'
|
- pattern: 'interface{}'
|
||||||
replacement: 'any'
|
replacement: 'any'
|
||||||
|
|
||||||
# make sure imports are always in a deterministic order
|
gci:
|
||||||
# https://github.com/daixiang0/gci/
|
|
||||||
gci: # define the section orders for imports
|
|
||||||
sections:
|
sections:
|
||||||
# Standard section: captures all standard packages.
|
|
||||||
- standard
|
- standard
|
||||||
# Default section: catchall that is not standard or custom
|
|
||||||
- default
|
- default
|
||||||
# linters that related to local tool, so they should be separated
|
|
||||||
- localmodule
|
- localmodule
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
exclusions:
|
exclusions:
|
||||||
# these presets where present in the v1 version of golangci-lint
|
|
||||||
# it's interesting to keep them when migrating, but removing them should be the goal
|
|
||||||
presets:
|
presets:
|
||||||
# exclude check on comments format in godoc
|
|
||||||
# These are common false positives in poor code
|
|
||||||
# you should not use this on recent code you write from scratch
|
|
||||||
# More information: https://golangci-lint.run/usage/false-positives/#comments
|
|
||||||
#
|
|
||||||
# Please uncomment the following line if your code is not using the godoc format
|
|
||||||
- comments
|
- comments
|
||||||
|
|
||||||
# Common false positives
|
|
||||||
# feel free to remove this if you don't have any false positives
|
|
||||||
# More information: https://golangci-lint.run/usage/false-positives/#common-false-positives
|
|
||||||
- common-false-positives
|
- common-false-positives
|
||||||
|
|
||||||
# Legacy preset is not recommended anymore
|
|
||||||
# More information: https://golangci-lint.run/usage/false-positives/#legacy
|
|
||||||
- legacy
|
- legacy
|
||||||
|
|
||||||
# std-error-handling is a set of rules that avoid reporting unhandled errors on common functions/methods
|
|
||||||
# More information: https://golangci-lint.run/usage/false-positives/#std-error-handling
|
|
||||||
- std-error-handling
|
- std-error-handling
|
||||||
|
|
||||||
# some linters are enabled by default
|
|
||||||
# https://golangci-lint.run/usage/linters/
|
|
||||||
#
|
|
||||||
# enable some extra linters
|
|
||||||
enable:
|
enable:
|
||||||
# Errcheck is a program for checking for unchecked errors in Go code.
|
|
||||||
- errcheck
|
- errcheck
|
||||||
|
|
||||||
# Vet examines Go source code and reports suspicious constructs.
|
|
||||||
- govet
|
- govet
|
||||||
|
|
||||||
# Detects when assignments to existing variables are not used.
|
|
||||||
- ineffassign
|
- ineffassign
|
||||||
|
|
||||||
# It's a set of rules from staticcheck. See https://staticcheck.io/
|
|
||||||
- staticcheck
|
- staticcheck
|
||||||
|
|
||||||
# Checks Go code for unused constants, variables, functions and types.
|
|
||||||
- unused
|
- unused
|
||||||
|
|
||||||
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
|
|
||||||
# Drop-in replacement of golint.
|
|
||||||
- revive
|
- revive
|
||||||
|
|
||||||
# make sure to use t.Helper() when needed
|
|
||||||
- thelper
|
- thelper
|
||||||
|
|
||||||
# mirror suggests rewrites to avoid unnecessary []byte/string conversion
|
|
||||||
- mirror
|
- mirror
|
||||||
|
|
||||||
# detect the possibility to use variables/constants from the Go standard library.
|
|
||||||
- usestdlibvars
|
- usestdlibvars
|
||||||
|
|
||||||
# Finds commonly misspelled English words.
|
|
||||||
- misspell
|
- misspell
|
||||||
|
|
||||||
# Checks for duplicate words in the source code.
|
|
||||||
- dupword
|
- dupword
|
||||||
|
|
||||||
# linter to detect errors invalid key values count
|
|
||||||
- loggercheck
|
- loggercheck
|
||||||
|
|
||||||
# detect when a package or method could be replaced by one from the standard library
|
|
||||||
- exptostd
|
- exptostd
|
||||||
|
|
||||||
# detects nested contexts in loops or function literals
|
|
||||||
- fatcontext
|
- fatcontext
|
||||||
|
|
||||||
# Reports uses of functions with replacement inside the testing package.
|
|
||||||
- usetesting
|
- usetesting
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
revive:
|
revive:
|
||||||
rules:
|
rules:
|
||||||
# these are the default revive rules
|
|
||||||
# you can remove the whole "rules" node if you want
|
|
||||||
# BUT
|
|
||||||
# ! /!\ they all need to be present when you want to add more rules than the default ones
|
|
||||||
# otherwise, you won't have the default rules, but only the ones you define in the "rules" node
|
|
||||||
|
|
||||||
# Blank import should be only in a main or test package, or have a comment justifying it.
|
|
||||||
- name: blank-imports
|
- name: blank-imports
|
||||||
|
|
||||||
# context.Context() should be the first parameter of a function when provided as argument.
|
|
||||||
- name: context-as-argument
|
- name: context-as-argument
|
||||||
arguments:
|
arguments:
|
||||||
- allowTypesBefore: "*testing.T"
|
- allowTypesBefore: "*testing.T"
|
||||||
|
|
||||||
# Basic types should not be used as a key in `context.WithValue`
|
|
||||||
- name: context-keys-type
|
- name: context-keys-type
|
||||||
|
|
||||||
# Importing with `.` makes the programs much harder to understand
|
|
||||||
- name: dot-imports
|
- name: dot-imports
|
||||||
|
|
||||||
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
|
|
||||||
- name: empty-block
|
- name: empty-block
|
||||||
|
|
||||||
# for better readability, variables of type `error` must be named with the prefix `err`.
|
|
||||||
- name: error-naming
|
- name: error-naming
|
||||||
|
|
||||||
# for better readability, the errors should be last in the list of returned values by a function.
|
|
||||||
- name: error-return
|
- name: error-return
|
||||||
|
|
||||||
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
|
|
||||||
- name: error-strings
|
- name: error-strings
|
||||||
|
|
||||||
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
|
|
||||||
- name: errorf
|
- name: errorf
|
||||||
|
|
||||||
# check naming and commenting conventions on exported symbols.
|
|
||||||
- name: exported
|
- name: exported
|
||||||
arguments:
|
arguments:
|
||||||
# make error messages clearer
|
|
||||||
- "sayRepetitiveInsteadOfStutters"
|
- "sayRepetitiveInsteadOfStutters"
|
||||||
|
|
||||||
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
|
|
||||||
- name: increment-decrement
|
- name: increment-decrement
|
||||||
|
|
||||||
# highlights redundant else-blocks that can be eliminated from the code
|
|
||||||
# - name: indent-error-flow
|
|
||||||
|
|
||||||
# This rule suggests a shorter way of writing ranges that do not use the second value.
|
|
||||||
- name: range
|
- name: range
|
||||||
|
|
||||||
# receiver names in a method should reflect the struct name (p for Person, for example)
|
|
||||||
- name: receiver-naming
|
- name: receiver-naming
|
||||||
|
|
||||||
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
|
|
||||||
- name: redefines-builtin-id
|
- name: redefines-builtin-id
|
||||||
|
|
||||||
# redundant else-blocks that can be eliminated from the code.
|
|
||||||
# - name: superfluous-else
|
|
||||||
|
|
||||||
# prevent confusing name for variables when using `time` package
|
|
||||||
- name: time-naming
|
- name: time-naming
|
||||||
|
|
||||||
# warns when an exported function or method returns a value of an un-exported type.
|
|
||||||
- name: unexported-return
|
- name: unexported-return
|
||||||
|
|
||||||
# spots and proposes to remove unreachable code. also helps to spot errors
|
|
||||||
- name: unreachable-code
|
- name: unreachable-code
|
||||||
|
|
||||||
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
|
|
||||||
- name: unused-parameter
|
- name: unused-parameter
|
||||||
|
|
||||||
# report when a variable declaration can be simplified
|
|
||||||
- name: var-declaration
|
- name: var-declaration
|
||||||
|
|
||||||
# warns when initialism, variable or package naming conventions are not followed.
|
|
||||||
- name: var-naming
|
- name: var-naming
|
||||||
|
|
||||||
misspell:
|
misspell:
|
||||||
# Correct spellings using locale preferences for US or UK.
|
|
||||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
|
||||||
# Default ("") is to use a neutral variety of English.
|
|
||||||
locale: US
|
locale: US
|
||||||
|
|
||||||
# List of words to ignore
|
|
||||||
# among the one defined in https://github.com/golangci/misspell/blob/master/words.go
|
|
||||||
ignore-rules: []
|
ignore-rules: []
|
||||||
# - valor
|
|
||||||
# - and
|
|
||||||
|
|
||||||
# Extra word corrections.
|
|
||||||
extra-words: []
|
extra-words: []
|
||||||
# - typo: "whattever"
|
|
||||||
# correction: "whatever"
|
|
||||||
|
|
||||||
output:
|
output:
|
||||||
# Order to use when sorting results.
|
|
||||||
# Possible values: `file`, `linter`, and `severity`.
|
|
||||||
#
|
|
||||||
# If the severity values are inside the following list, they are ordered in this order:
|
|
||||||
# 1. error
|
|
||||||
# 2. warning
|
|
||||||
# 3. high
|
|
||||||
# 4. medium
|
|
||||||
# 5. low
|
|
||||||
# Either they are sorted alphabetically.
|
|
||||||
#
|
|
||||||
# Default: ["file"]
|
|
||||||
sort-order:
|
sort-order:
|
||||||
- linter
|
- linter
|
||||||
- severity
|
- severity
|
||||||
- file # filepath, line, and column.
|
- file
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"makefile.configureOnOpen": false
|
||||||
|
}
|
||||||
45
Makefile
45
Makefile
@@ -1,21 +1,40 @@
|
|||||||
BINARY_NAME=lambda.exe
|
BINARY_NAME=lambda
|
||||||
|
|
||||||
it:
|
|
||||||
@ go build -o ${BINARY_NAME} ./cmd/lambda
|
|
||||||
@ chmod +x ${BINARY_NAME}
|
|
||||||
|
|
||||||
TEST=simple
|
TEST=simple
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := help
|
||||||
|
.SILENT:
|
||||||
|
.PHONY: help it run profile explain graph clean
|
||||||
|
|
||||||
|
help:
|
||||||
|
echo "Available targets:"
|
||||||
|
echo " it - Build the lambda binary"
|
||||||
|
echo " run - Build and run with sample input (default: simple.txt)"
|
||||||
|
echo " profile - Build and run with CPU profiling enabled"
|
||||||
|
echo " explain - Run with explanation mode and profiling"
|
||||||
|
echo " graph - Generate CPU profile visualization"
|
||||||
|
echo " clean - Remove build artifacts"
|
||||||
|
echo ""
|
||||||
|
echo "Usage: make run TEST=<sample-name>"
|
||||||
|
|
||||||
|
it:
|
||||||
|
go build -o ${BINARY_NAME} ./cmd/lambda
|
||||||
|
|
||||||
run: it
|
run: it
|
||||||
@ ./lambda.exe - < ./samples/$(TEST).txt > program.out
|
./lambda - < ./samples/$(TEST).txt > program.out
|
||||||
|
|
||||||
profile: it
|
profile: it
|
||||||
@ ./lambda.exe -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out
|
mkdir -p profile
|
||||||
|
./lambda -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out
|
||||||
|
|
||||||
explain: it
|
explain: it
|
||||||
@ ./lambda.exe -x -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out
|
mkdir -p profile
|
||||||
|
./lambda -x -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out
|
||||||
|
|
||||||
graph:
|
graph: profile
|
||||||
@ go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof
|
go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof
|
||||||
@ go tool pprof -svg profile/cpu.prof > profile/cpu.svg
|
go tool pprof -svg profile/cpu.prof > profile/cpu.svg
|
||||||
@ open profile/cpu.svg
|
echo "Profile graph saved to 'file://profile/cpu.svg'"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${BINARY_NAME} program.out
|
||||||
|
rm -rf profile/
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package deltanet
|
package deltanet
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
// A connection between exactly two nodes in a graph.
|
// A connection between exactly two nodes in a graph.
|
||||||
type Edge struct {
|
type Edge struct {
|
||||||
A, B Node
|
A, B Node
|
||||||
@@ -28,8 +26,6 @@ func (e Edge) IsPrincipleEdge() bool {
|
|||||||
return e.A.GetMainPort() == e && e.B.GetMainPort() == e
|
return e.A.GetMainPort() == e && e.B.GetMainPort() == e
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type Node interface {
|
type Node interface {
|
||||||
// Returns the principle port that the node is attached to.
|
// Returns the principle port that the node is attached to.
|
||||||
GetMainPort() Edge
|
GetMainPort() Edge
|
||||||
@@ -42,8 +38,6 @@ type Node interface {
|
|||||||
GetLabel() string
|
GetLabel() string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type EraserNode struct {
|
type EraserNode struct {
|
||||||
Main Edge
|
Main Edge
|
||||||
}
|
}
|
||||||
@@ -52,8 +46,6 @@ func (n EraserNode) GetLabel() string { return "Ⓧ" }
|
|||||||
func (n EraserNode) GetMainPort() Edge { return n.Main }
|
func (n EraserNode) GetMainPort() Edge { return n.Main }
|
||||||
func (n EraserNode) GetAuxPorts() []Edge { return []Edge{} }
|
func (n EraserNode) GetAuxPorts() []Edge { return []Edge{} }
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type ReplicatorNode struct {
|
type ReplicatorNode struct {
|
||||||
Main Edge
|
Main Edge
|
||||||
Level uint
|
Level uint
|
||||||
@@ -68,8 +60,6 @@ func (n ReplicatorNode) GetAuxPorts() []Edge { return n.Aux }
|
|||||||
// Returns the level of the replicator node.
|
// Returns the level of the replicator node.
|
||||||
func (n ReplicatorNode) GetLevel() uint { return n.Level }
|
func (n ReplicatorNode) GetLevel() uint { return n.Level }
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type FanNode struct {
|
type FanNode struct {
|
||||||
Label string
|
Label string
|
||||||
Main Edge
|
Main Edge
|
||||||
@@ -80,8 +70,6 @@ func (n FanNode) GetLabel() string { return n.Label }
|
|||||||
func (n FanNode) GetMainPort() Edge { return n.Main }
|
func (n FanNode) GetMainPort() Edge { return n.Main }
|
||||||
func (n FanNode) GetAuxPorts() []Edge { return []Edge{n.Left, n.Right} }
|
func (n FanNode) GetAuxPorts() []Edge { return []Edge{n.Left, n.Right} }
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type TerminalNode struct {
|
type TerminalNode struct {
|
||||||
Label string
|
Label string
|
||||||
Main Edge
|
Main Edge
|
||||||
@@ -90,5 +78,3 @@ type TerminalNode struct {
|
|||||||
func (n TerminalNode) GetLabel() string { return n.Label }
|
func (n TerminalNode) GetLabel() string { return n.Label }
|
||||||
func (n TerminalNode) GetMainPort() Edge { return n.Main }
|
func (n TerminalNode) GetMainPort() Edge { return n.Main }
|
||||||
func (n TerminalNode) GetAuxPorts() []Edge { return []Edge{} }
|
func (n TerminalNode) GetAuxPorts() []Edge { return []Edge{} }
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ type Expression interface {
|
|||||||
Copy() Expression
|
Copy() Expression
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type Abstraction struct {
|
type Abstraction struct {
|
||||||
Parameter string
|
Parameter string
|
||||||
Body Expression
|
Body Expression
|
||||||
@@ -24,8 +22,6 @@ func NewAbstraction(parameter string, body Expression) *Abstraction {
|
|||||||
return &Abstraction{Parameter: parameter, Body: body}
|
return &Abstraction{Parameter: parameter, Body: body}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
Abstraction Expression
|
Abstraction Expression
|
||||||
Argument Expression
|
Argument Expression
|
||||||
@@ -43,8 +39,6 @@ func NewApplication(function Expression, argument Expression) *Application {
|
|||||||
return &Application{Abstraction: function, Argument: argument}
|
return &Application{Abstraction: function, Argument: argument}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type Variable struct {
|
type Variable struct {
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
@@ -61,8 +55,6 @@ func NewVariable(name string) *Variable {
|
|||||||
return &Variable{Value: name}
|
return &Variable{Value: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type Visitor interface {
|
type Visitor interface {
|
||||||
VisitAbstraction(*Abstraction)
|
VisitAbstraction(*Abstraction)
|
||||||
VisitApplication(*Application)
|
VisitApplication(*Application)
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ type Expression interface {
|
|||||||
IsExpression()
|
IsExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type Abstraction struct {
|
type Abstraction struct {
|
||||||
Parameters []string
|
Parameters []string
|
||||||
Body Expression
|
Body Expression
|
||||||
@@ -30,8 +28,6 @@ func (Application) IsExpression() {}
|
|||||||
func (Atom) IsExpression() {}
|
func (Atom) IsExpression() {}
|
||||||
func (Clause) IsExpression() {}
|
func (Clause) IsExpression() {}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func NewAbstraction(parameter []string, body Expression) *Abstraction {
|
func NewAbstraction(parameter []string, body Expression) *Abstraction {
|
||||||
return &Abstraction{Parameters: parameter, Body: body}
|
return &Abstraction{Parameters: parameter, Body: body}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ type Statement interface {
|
|||||||
IsStatement()
|
IsStatement()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
type LetStatement struct {
|
type LetStatement struct {
|
||||||
Name string
|
Name string
|
||||||
Parameters []string
|
Parameters []string
|
||||||
@@ -19,8 +17,6 @@ type DeclareStatement struct {
|
|||||||
func (LetStatement) IsStatement() {}
|
func (LetStatement) IsStatement() {}
|
||||||
func (DeclareStatement) IsStatement() {}
|
func (DeclareStatement) IsStatement() {}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func NewLet(name string, parameters []string, body Expression) *LetStatement {
|
func NewLet(name string, parameters []string, body Expression) *LetStatement {
|
||||||
return &LetStatement{Name: name, Parameters: parameters, Body: body}
|
return &LetStatement{Name: name, Parameters: parameters, Body: body}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user