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: ...@@ -81,7 +81,7 @@ watch:
-@$(MAKE) test -@$(MAKE) test
@while inotifywait -q -e modify --exclude '^\./(build|\.git)/' --recursive .; do sleep 0.2; $(MAKE) test; done @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 # grumpc compiler
...@@ -140,6 +140,12 @@ $(RUNTIME_COVER_FILE): $(RUNTIME) $(filter %_test.go,$(RUNTIME_SRCS)) ...@@ -140,6 +140,12 @@ $(RUNTIME_COVER_FILE): $(RUNTIME) $(filter %_test.go,$(RUNTIME_SRCS))
cover: $(RUNTIME_COVER_FILE) $(TOOL_BINS) 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 @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 # Standard library
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
......
...@@ -8,13 +8,17 @@ import ( ...@@ -8,13 +8,17 @@ import (
// CodeType is the object representing the Python 'code' type. // CodeType is the object representing the Python 'code' type.
var CodeType = newBasisType("code", reflect.TypeOf(Code{}), toCodeUnsafe, ObjectType) var CodeType = newBasisType("code", reflect.TypeOf(Code{}), toCodeUnsafe, ObjectType)
// CodeFlag is a switch controlling the behavior of a Code object.
type CodeFlag int type CodeFlag int
const ( const (
// CodeFlagVarArg means a Code object accepts *arg parameters.
CodeFlagVarArg CodeFlag = 4 CodeFlagVarArg CodeFlag = 4
CodeFlagKWArg CodeFlag = 8 // CodeFlagKWArg means a Code object accepts **kwarg parameters.
CodeFlagKWArg CodeFlag = 8
) )
// Code represents Python 'code' objects.
type Code struct { type Code struct {
Object Object
name string `attr:"co_name"` name string `attr:"co_name"`
...@@ -29,6 +33,7 @@ type Code struct { ...@@ -29,6 +33,7 @@ type Code struct {
fn func(*Frame, []*Object) (*Object, *BaseException) 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 { func NewCode(name, filename string, args []FunctionArg, flags CodeFlag, fn func(*Frame, []*Object) (*Object, *BaseException)) *Code {
argc := len(args) argc := len(args)
minArgc := 0 minArgc := 0
...@@ -50,7 +55,9 @@ func toCodeUnsafe(o *Object) *Code { ...@@ -50,7 +55,9 @@ func toCodeUnsafe(o *Object) *Code {
return (*Code)(o.toPointer()) 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) { func (c *Code) Eval(f *Frame, globals *Dict, args Args, kwargs KWArgs) (*Object, *BaseException) {
// Validate parameters.
argc := len(args) argc := len(args)
if argc > c.argc && c.flags&CodeFlagVarArg == 0 { if argc > c.argc && c.flags&CodeFlagVarArg == 0 {
format := "%s() takes %d arguments (%d given)" 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