Commit c39ad6ca authored by Dylan Trotter's avatar Dylan Trotter

Add make lint command. Make Go code golint clean.

parent 4aa5110d
......@@ -81,7 +81,7 @@ watch:
-@$(MAKE) test
@while inotifywait -q -e modify --exclude '^\./(build|\.git)/' --recursive .; do sleep 0.2; $(MAKE) test; done
.PHONY: all benchmarks clean cover run test watch
.PHONY: all benchmarks clean cover lint run test watch
# ------------------------------------------------------------------------------
# grumpc compiler
......@@ -140,6 +140,12 @@ $(RUNTIME_COVER_FILE): $(RUNTIME) $(filter %_test.go,$(RUNTIME_SRCS))
cover: $(RUNTIME_COVER_FILE) $(TOOL_BINS)
@bash -c 'comm -12 <(coverparse $< | sed "s/^grumpy/runtime/" | sort) <(git diff --dst-prefix= $(DIFF_COMMIT) | diffrange | sort)' | sort -t':' -k1,1 -k2n,2 | sed 's/$$/: missing coverage/' | tee errors.err
build/bin/golint:
@go get -u github.com/golang/lint/golint
lint: build/bin/golint
@golint runtime
# ------------------------------------------------------------------------------
# Standard library
# ------------------------------------------------------------------------------
......
......@@ -8,13 +8,17 @@ import (
// CodeType is the object representing the Python 'code' type.
var CodeType = newBasisType("code", reflect.TypeOf(Code{}), toCodeUnsafe, ObjectType)
// CodeFlag is a switch controlling the behavior of a Code object.
type CodeFlag int
const (
// CodeFlagVarArg means a Code object accepts *arg parameters.
CodeFlagVarArg CodeFlag = 4
// CodeFlagKWArg means a Code object accepts **kwarg parameters.
CodeFlagKWArg CodeFlag = 8
)
// Code represents Python 'code' objects.
type Code struct {
Object
name string `attr:"co_name"`
......@@ -29,6 +33,7 @@ type Code struct {
fn func(*Frame, []*Object) (*Object, *BaseException)
}
// NewCode creates a new Code object that executes the given fn.
func NewCode(name, filename string, args []FunctionArg, flags CodeFlag, fn func(*Frame, []*Object) (*Object, *BaseException)) *Code {
argc := len(args)
minArgc := 0
......@@ -50,7 +55,9 @@ func toCodeUnsafe(o *Object) *Code {
return (*Code)(o.toPointer())
}
// Eval runs the code object c in the context of the given globals.
func (c *Code) Eval(f *Frame, globals *Dict, args Args, kwargs KWArgs) (*Object, *BaseException) {
// Validate parameters.
argc := len(args)
if argc > c.argc && c.flags&CodeFlagVarArg == 0 {
format := "%s() takes %d arguments (%d given)"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment