Fix some the linters problems reported by the golang-cli
This commit is contained in:
parent
fabb3cbb32
commit
3f554445d8
|
@ -55,7 +55,6 @@ linters:
|
||||||
- dogsled
|
- dogsled
|
||||||
- dupl
|
- dupl
|
||||||
- errcheck
|
- errcheck
|
||||||
- exhaustive
|
|
||||||
- funlen
|
- funlen
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- goconst
|
- goconst
|
||||||
|
|
|
@ -49,11 +49,11 @@ func (t *Bool) Hash() uint32 {
|
||||||
return hash.Of(append([]byte{byte(ast.Bool)}, bytes...))
|
return hash.Of(append([]byte{byte(ast.Bool)}, bytes...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Bool) isTrue() bool {
|
func (t *Bool) IsTrue() bool {
|
||||||
return t.value
|
return t.value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Bool) isFalse() bool {
|
func (t *Bool) IsFalse() bool {
|
||||||
return !t.value
|
return !t.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ func PrNativeFn(rt *Runtime, scope IScope, n Node, args *List) (IExpr, IError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrnNativeFn(rt *Runtime, scope IScope, n Node, args *List) (IExpr, IError) {
|
func PrnNativeFn(rt *Runtime, scope IScope, n Node, args *List) (IExpr, IError) {
|
||||||
|
|
||||||
Prn(rt, toRepresentables(args.Rest().(IColl))...)
|
Prn(rt, toRepresentables(args.Rest().(IColl))...)
|
||||||
return MakeNil(n), nil
|
return MakeNil(n), nil
|
||||||
}
|
}
|
||||||
|
@ -69,7 +68,6 @@ func RequireNativeFn(rt *Runtime, scope IScope, n Node, args *List) (IExpr, IErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HashNativeFn(rt *Runtime, scope IScope, n Node, args *List) (IExpr, IError) {
|
func HashNativeFn(rt *Runtime, scope IScope, n Node, args *List) (IExpr, IError) {
|
||||||
|
|
|
@ -86,7 +86,7 @@ func REPL(flags map[string]bool) {
|
||||||
rl.HistoryEnable()
|
rl.HistoryEnable()
|
||||||
defer rl.Close()
|
defer rl.Close()
|
||||||
|
|
||||||
fmt.Println(`
|
fmt.Print(`
|
||||||
_______ _______ ______ _______ _______ _______
|
_______ _______ ______ _______ _______ _______
|
||||||
| __| ___| __ \ ___| | | ___|
|
| __| ___| __ \ ___| | | ___|
|
||||||
|__ | ___| < ___| | ___|
|
|__ | ___| < ___| | ___|
|
||||||
|
@ -99,7 +99,7 @@ bootstrap the Serene's compiler.
|
||||||
It comes with ABSOLUTELY NO WARRANTY;
|
It comes with ABSOLUTELY NO WARRANTY;
|
||||||
This is free software, and you are welcome
|
This is free software, and you are welcome
|
||||||
to redistribute it under certain conditions;
|
to redistribute it under certain conditions;
|
||||||
for details take a look at the LICENSE file.
|
for details take a look at the LICENSE file.\n\n
|
||||||
`)
|
`)
|
||||||
for {
|
for {
|
||||||
rl.SetPrompt(fmt.Sprintf("%s> ", rt.CurrentNS().GetName()))
|
rl.SetPrompt(fmt.Sprintf("%s> ", rt.CurrentNS().GetName()))
|
||||||
|
|
|
@ -160,7 +160,6 @@ func MakeRuntimeError(rt *Runtime, e IExpr, errno errors.Errno, msg string) IErr
|
||||||
errno: errno,
|
errno: errno,
|
||||||
trace: rt.Stack.ToTraceBack(),
|
trace: rt.Stack.ToTraceBack(),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeSyntaxErrorf(n Node, msg string, a ...interface{}) IError {
|
func MakeSyntaxErrorf(n Node, msg string, a ...interface{}) IError {
|
||||||
|
|
|
@ -209,9 +209,9 @@ tco:
|
||||||
// Instructions should change the return value, but errors
|
// Instructions should change the return value, but errors
|
||||||
// are ok
|
// are ok
|
||||||
if forms.GetType() == ast.Instruction {
|
if forms.GetType() == ast.Instruction {
|
||||||
err := ProcessInstruction(rt, forms.(*Instruction))
|
e := ProcessInstruction(rt, forms.(*Instruction))
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return nil, err
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
@ -269,7 +269,6 @@ tco:
|
||||||
}
|
}
|
||||||
|
|
||||||
switch sform {
|
switch sform {
|
||||||
|
|
||||||
// `ns` evaluation rules:
|
// `ns` evaluation rules:
|
||||||
// * The first element has to be a symbol representing the
|
// * The first element has to be a symbol representing the
|
||||||
// name of the namespace. ( We won't evaluate the first
|
// name of the namespace. ( We won't evaluate the first
|
||||||
|
@ -317,10 +316,10 @@ tco:
|
||||||
// TODO: Implement `concat` in serene itself when we have protocols available
|
// TODO: Implement `concat` in serene itself when we have protocols available
|
||||||
// Concats all the collections together.
|
// Concats all the collections together.
|
||||||
case "concat":
|
case "concat":
|
||||||
evaledForms, err := evalForm(rt, scope, list.Rest().(*List))
|
evaledForms, e := evalForm(rt, scope, list.Rest().(*List))
|
||||||
|
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return nil, err
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
lists := evaledForms.(*List).ToSlice()
|
lists := evaledForms.(*List).ToSlice()
|
||||||
|
@ -358,10 +357,10 @@ tco:
|
||||||
return nil, MakeError(rt, list, "'cons' needs exactly 3 arguments")
|
return nil, MakeError(rt, list, "'cons' needs exactly 3 arguments")
|
||||||
}
|
}
|
||||||
|
|
||||||
evaledForms, err := evalForm(rt, scope, list.Rest().(*List))
|
evaledForms, e := evalForm(rt, scope, list.Rest().(*List))
|
||||||
|
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return nil, err
|
return nil, e
|
||||||
}
|
}
|
||||||
coll, ok := evaledForms.(*List).Rest().First().(IColl)
|
coll, ok := evaledForms.(*List).Rest().First().(IColl)
|
||||||
|
|
||||||
|
@ -444,21 +443,21 @@ tco:
|
||||||
return nil, MakeError(rt, args, "'if' needs exactly 3 aruments")
|
return nil, MakeError(rt, args, "'if' needs exactly 3 aruments")
|
||||||
}
|
}
|
||||||
|
|
||||||
pred, err := EvalForms(rt, scope, args.First())
|
pred, e := EvalForms(rt, scope, args.First())
|
||||||
result := pred.GetType()
|
result := pred.GetType()
|
||||||
|
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return nil, err
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == ast.Bool && pred.(*Bool).isFalse()) || result == ast.Nil {
|
if (result == ast.Bool && pred.(*Bool).IsFalse()) || result == ast.Nil {
|
||||||
// Falsy clause
|
// Falsy clause
|
||||||
exprs = append([]IExpr{args.Rest().Rest().First()}, restOfExprs(exprs, i)...)
|
exprs = append([]IExpr{args.Rest().Rest().First()}, restOfExprs(exprs, i)...)
|
||||||
} else {
|
} else {
|
||||||
// Truthy clause
|
// Truthy clause
|
||||||
exprs = append([]IExpr{args.Rest().First()}, restOfExprs(exprs, i)...)
|
exprs = append([]IExpr{args.Rest().First()}, restOfExprs(exprs, i)...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
goto body // rewrite
|
goto body // rewrite
|
||||||
|
|
||||||
|
@ -487,9 +486,9 @@ tco:
|
||||||
if list.Count() != 2 {
|
if list.Count() != 2 {
|
||||||
return nil, MakeError(rt, list, "'eval' needs exactly 1 arguments")
|
return nil, MakeError(rt, list, "'eval' needs exactly 1 arguments")
|
||||||
}
|
}
|
||||||
form, err := evalForm(rt, scope, list.Rest().(*List))
|
form, e := evalForm(rt, scope, list.Rest().(*List))
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return nil, err
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err = EvalForms(rt, scope, form)
|
ret, err = EvalForms(rt, scope, form)
|
||||||
|
@ -538,8 +537,7 @@ tco:
|
||||||
// TODO: We need to destruct the bindings here and remove this check
|
// TODO: We need to destruct the bindings here and remove this check
|
||||||
// for the symbol type
|
// for the symbol type
|
||||||
if name.GetType() != ast.Symbol {
|
if name.GetType() != ast.Symbol {
|
||||||
err := MakeError(rt, name, "'let' doesn't support desbbtructuring yet, use a symbol.")
|
return nil, MakeError(rt, name, "'let' doesn't support desbbtructuring yet, use a symbol.")
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// You might be wondering why we're using `EvalForms` here to evaluate
|
// You might be wondering why we're using `EvalForms` here to evaluate
|
||||||
|
|
|
@ -127,7 +127,6 @@ func (sp *StringParser) next(skipWhitespace bool) *string {
|
||||||
// contains a separator or not. In a Lisp whitespace and someother characters
|
// contains a separator or not. In a Lisp whitespace and someother characters
|
||||||
// are conceptually the same and we need to treat them the same as well.
|
// are conceptually the same and we need to treat them the same as well.
|
||||||
func isSeparator(c *string) bool {
|
func isSeparator(c *string) bool {
|
||||||
|
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -561,7 +560,6 @@ func readQuasiquotedExpr(parser IParsable) (IExpr, IError) {
|
||||||
// important function in the parser which dispatches the call to different
|
// important function in the parser which dispatches the call to different
|
||||||
// reader functions based on the first character
|
// reader functions based on the first character
|
||||||
func readExpr(parser IParsable) (IExpr, IError) {
|
func readExpr(parser IParsable) (IExpr, IError) {
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
c := parser.next(true)
|
c := parser.next(true)
|
||||||
|
|
||||||
|
|
|
@ -29,24 +29,25 @@ import (
|
||||||
|
|
||||||
func toRepresanbleString(ast ...IRepresentable) string {
|
func toRepresanbleString(ast ...IRepresentable) string {
|
||||||
var results []string
|
var results []string
|
||||||
|
|
||||||
for _, x := range ast {
|
for _, x := range ast {
|
||||||
results = append(results, x.String())
|
results = append(results, x.String())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(results, " ")
|
return strings.Join(results, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func toPrintableString(ast ...IRepresentable) string {
|
func toPrintableString(ast ...IRepresentable) string {
|
||||||
var results []string
|
var results []string
|
||||||
for _, x := range ast {
|
|
||||||
|
|
||||||
|
for _, x := range ast {
|
||||||
if printable, ok := x.(IPrintable); ok {
|
if printable, ok := x.(IPrintable); ok {
|
||||||
results = append(results, printable.PrintToString())
|
results = append(results, printable.PrintToString())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
results = append(results, x.String())
|
results = append(results, x.String())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(results, " ")
|
return strings.Join(results, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +186,6 @@ func printErrorWithTraceBack(rt *Runtime, err IError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintError(rt *Runtime, err IError) {
|
func PrintError(rt *Runtime, err IError) {
|
||||||
|
|
||||||
switch err.GetErrType() {
|
switch err.GetErrType() {
|
||||||
case SyntaxError, SemanticError:
|
case SyntaxError, SemanticError:
|
||||||
printError(rt, err, 0)
|
printError(rt, err, 0)
|
||||||
|
|
|
@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import "serene-lang.org/bootstrap/pkg/ast"
|
|
||||||
|
|
||||||
// func qqLoop(xs []IExpr) IExpr {
|
// func qqLoop(xs []IExpr) IExpr {
|
||||||
// acc := MakeEmptyList()
|
// acc := MakeEmptyList()
|
||||||
// for i := len(xs) - 1; 0 <= i; i -= 1 {
|
// for i := len(xs) - 1; 0 <= i; i -= 1 {
|
||||||
|
@ -62,114 +60,114 @@ import "serene-lang.org/bootstrap/pkg/ast"
|
||||||
// return e
|
// return e
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
const qqQUOTE string = "*quote*"
|
// const qqQUOTE string = "*quote*"
|
||||||
|
|
||||||
func isSymbolEqual(e IExpr, name string) bool {
|
// func isSymbolEqual(e IExpr, name string) bool {
|
||||||
if e.GetType() == ast.Symbol && e.(*Symbol).GetName() == name {
|
// if e.GetType() == ast.Symbol && e.(*Symbol).GetName() == name {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
func isQuasiQuote(e IExpr) bool {
|
// func isQuasiQuote(e IExpr) bool {
|
||||||
return isSymbolEqual(e, "quasiquote")
|
// return isSymbolEqual(e, "quasiquote")
|
||||||
}
|
// }
|
||||||
|
|
||||||
func isUnquote(e IExpr) bool {
|
// func isUnquote(e IExpr) bool {
|
||||||
return isSymbolEqual(e, "unquote")
|
// return isSymbolEqual(e, "unquote")
|
||||||
}
|
// }
|
||||||
|
|
||||||
func isUnquoteSplicing(e IExpr) bool {
|
// func isUnquoteSplicing(e IExpr) bool {
|
||||||
return isSymbolEqual(e, "unquote-splicing")
|
// return isSymbolEqual(e, "unquote-splicing")
|
||||||
}
|
// }
|
||||||
|
|
||||||
func qqSimplify(e IExpr) (IExpr, IError) {
|
// func qqSimplify(e IExpr) (IExpr, IError) {
|
||||||
return e, nil
|
// return e, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func qqProcess(rt *Runtime, e IExpr) (IExpr, IError) {
|
// func qqProcess(rt *Runtime, e IExpr) (IExpr, IError) {
|
||||||
switch e.GetType() {
|
// switch e.GetType() {
|
||||||
|
|
||||||
// Example: `x => (*quote* x) => (quote x)
|
// // Example: `x => (*quote* x) => (quote x)
|
||||||
case ast.Symbol:
|
// case ast.Symbol:
|
||||||
sym, err := MakeSymbol(MakeNodeFromExpr(e), qqQUOTE)
|
// sym, err := MakeSymbol(MakeNodeFromExpr(e), qqQUOTE)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
//newErr := makeErrorAtPoint()
|
// //newErr := makeErrorAtPoint()
|
||||||
// TODO: uncomment next line when we have stackable errors
|
// // TODO: uncomment next line when we have stackable errors
|
||||||
// newErr.stack(err)
|
// // newErr.stack(err)
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
elems := []IExpr{
|
// elems := []IExpr{
|
||||||
sym,
|
// sym,
|
||||||
e,
|
// e,
|
||||||
}
|
// }
|
||||||
|
|
||||||
n := MakeNodeFromExprs(elems)
|
// n := MakeNodeFromExprs(elems)
|
||||||
if n == nil {
|
// if n == nil {
|
||||||
n = &sym.Node
|
// n = &sym.Node
|
||||||
}
|
// }
|
||||||
return MakeList(
|
// return MakeList(
|
||||||
*n,
|
// *n,
|
||||||
elems,
|
// elems,
|
||||||
), nil
|
// ), nil
|
||||||
|
|
||||||
case ast.List:
|
// case ast.List:
|
||||||
list := e.(*List)
|
// list := e.(*List)
|
||||||
first := list.First()
|
// first := list.First()
|
||||||
|
|
||||||
// Example: ``... reads as (quasiquote (quasiquote ...)) and this if will check
|
// // Example: ``... reads as (quasiquote (quasiquote ...)) and this if will check
|
||||||
// for the second `quasiquote`
|
// // for the second `quasiquote`
|
||||||
if isQuasiQuote(first) {
|
// if isQuasiQuote(first) {
|
||||||
result, err := qqCompletelyProcess(rt, list.Rest().First())
|
// result, err := qqCompletelyProcess(rt, list.Rest().First())
|
||||||
|
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
return qqProcess(rt, result)
|
// return qqProcess(rt, result)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Example: `~x reads as (quasiquote (unquote x))
|
// // Example: `~x reads as (quasiquote (unquote x))
|
||||||
if isUnquote(first) {
|
// if isUnquote(first) {
|
||||||
return list.Rest().First(), nil
|
// return list.Rest().First(), nil
|
||||||
}
|
// }
|
||||||
// ???
|
// // ???
|
||||||
if isUnquoteSplicing(first) {
|
// if isUnquoteSplicing(first) {
|
||||||
return nil, MakeError(rt, first, "'unquote-splicing' is not allowed out of a collection.")
|
// return nil, MakeError(rt, first, "'unquote-splicing' is not allowed out of a collection.")
|
||||||
}
|
// }
|
||||||
|
|
||||||
// p := list
|
// // p := list
|
||||||
// q := MakeEmptyList()
|
// // q := MakeEmptyList()
|
||||||
// for {
|
// // for {
|
||||||
// p = p.Rest().(*List)
|
// // p = p.Rest().(*List)
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
return e, nil
|
// return e, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func qqRemoveQQFunctions(e IExpr) (IExpr, IError) {
|
// func qqRemoveQQFunctions(e IExpr) (IExpr, IError) {
|
||||||
return e, nil
|
// return e, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func qqCompletelyProcess(rt *Runtime, e IExpr) (IExpr, IError) {
|
// func qqCompletelyProcess(rt *Runtime, e IExpr) (IExpr, IError) {
|
||||||
rawResult, err := qqProcess(rt, e)
|
// rawResult, err := qqProcess(rt, e)
|
||||||
|
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
if rt.IsQQSimplificationEnabled() {
|
// if rt.IsQQSimplificationEnabled() {
|
||||||
rawResult, err = qqSimplify(rawResult)
|
// rawResult, err = qqSimplify(rawResult)
|
||||||
|
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return qqRemoveQQFunctions(rawResult)
|
// return qqRemoveQQFunctions(rawResult)
|
||||||
}
|
// }
|
||||||
|
|
||||||
func quasiquote(rt *Runtime, e IExpr) (IExpr, IError) {
|
// func quasiquote(rt *Runtime, e IExpr) (IExpr, IError) {
|
||||||
return qqCompletelyProcess(rt, e)
|
// return qqCompletelyProcess(rt, e)
|
||||||
}
|
// }
|
||||||
|
|
Loading…
Reference in New Issue