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