From 938d279bc93713f0a3b2e97fcadf0bb381a3b643 Mon Sep 17 00:00:00 2001 From: haifenghuang Date: Sat, 13 Jan 2018 10:40:03 +0800 Subject: [PATCH] Modify some of the modules' Inspect() value. --- examples/demo.my | 10 +++------- src/monkey/eval/csv.go | 2 +- src/monkey/eval/file.go | 4 ++-- src/monkey/eval/filepath.go | 10 +++++----- src/monkey/eval/flag.go | 2 +- src/monkey/eval/fmt.go | 2 +- src/monkey/eval/http.go | 14 +++++++------- src/monkey/eval/json.go | 2 +- src/monkey/eval/list.go | 2 +- src/monkey/eval/log.go | 2 +- src/monkey/eval/math.go | 2 +- src/monkey/eval/net.go | 2 +- src/monkey/eval/object.go | 2 +- src/monkey/eval/os.go | 2 +- src/monkey/eval/sort.go | 2 +- src/monkey/eval/sql.go | 2 +- src/monkey/eval/sync.go | 10 +++++----- src/monkey/eval/template.go | 2 +- 18 files changed, 35 insertions(+), 39 deletions(-) diff --git a/examples/demo.my b/examples/demo.my index ae10d76..e59d66d 100644 --- a/examples/demo.my +++ b/examples/demo.my @@ -379,13 +379,9 @@ filepath.walk(".", walkf) println(filelist) //filepath.walk(".", fn(path, fileinfo) { -// if (filepath.ext(path) == ".my") { -// if (filepath.base(path) == "db.my") { -// println("============skipping eval.my============") -// return "SKIP_DIR" -// } else { -// println(path) -// } +// if (filepath.dir(path) =="examples") { +// println("============skipping examples dir============") +// return filepath.SKIP_DIR // } // else { // println(path) diff --git a/src/monkey/eval/csv.go b/src/monkey/eval/csv.go index 97d206b..5ddc1d3 100644 --- a/src/monkey/eval/csv.go +++ b/src/monkey/eval/csv.go @@ -32,7 +32,7 @@ type CsvObj struct { Writer *csv.Writer } -func (c *CsvObj) Inspect() string { return csv_name } +func (c *CsvObj) Inspect() string { return "<" + csv_name + ">"} func (c *CsvObj) Type() ObjectType { return CSV_OBJ } func (c *CsvObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/file.go b/src/monkey/eval/file.go index 6896892..c205536 100644 --- a/src/monkey/eval/file.go +++ b/src/monkey/eval/file.go @@ -22,7 +22,7 @@ func NewIOUtilObj() Object { return ret } -func (i *IOUtilObj) Inspect() string { return ioutil_name } +func (i *IOUtilObj) Inspect() string { return "<" + ioutil_name + ">" } func (i *IOUtilObj) Type() ObjectType { return IOUTIL_OBJ } func (i *IOUtilObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { @@ -185,7 +185,7 @@ type FileObject struct { } func (f *FileObject) IOWriter() io.Writer { return f.File } -func (f *FileObject) Inspect() string { return f.Name } +func (f *FileObject) Inspect() string { return "" } func (f *FileObject) Type() ObjectType { return FILE_OBJ } func (f *FileObject) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { diff --git a/src/monkey/eval/filepath.go b/src/monkey/eval/filepath.go index 5ffd67d..9436775 100644 --- a/src/monkey/eval/filepath.go +++ b/src/monkey/eval/filepath.go @@ -11,7 +11,7 @@ func NewFilePathObj() *FilePathObj { ret := &FilePathObj{} SetGlobalObj(filepath_name, ret) - SetGlobalObj(filepath_name+".SKIP_DIR", NewString("SKIP_DIR")) + SetGlobalObj(filepath_name+".SKIP_DIR", NewInteger(SKIP_DIR)) SetGlobalObj(filepath_name+".SEPARATOR", NewString(string(filepath.Separator))) SetGlobalObj(filepath_name+".LISTSEPARATOR", NewString(string(filepath.ListSeparator))) @@ -19,13 +19,14 @@ func NewFilePathObj() *FilePathObj { } const ( + SKIP_DIR = 1 FILEPATH_OBJ = "FILEPATH_OBJ" filepath_name = "filepath" ) type FilePathObj struct{} -func (f *FilePathObj) Inspect() string { return filepath_name } +func (f *FilePathObj) Inspect() string { return "<" + filepath_name + ">" } func (f *FilePathObj) Type() ObjectType { return FILEPATH_OBJ } func (f *FilePathObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { @@ -424,10 +425,9 @@ func walkFunc(scope *Scope, f *Function, path string, info os.FileInfo) error { } //check for return value, is it a skipDir? - str, ok := r.(*String) + iObj, ok := r.(*Integer) if ok { - skipDir, _ := GetGlobalObj("SKIP_DIR") - if skipDir.(*String).String == str.String { + if iObj.Int64 == SKIP_DIR { return filepath.SkipDir } } diff --git a/src/monkey/eval/flag.go b/src/monkey/eval/flag.go index 1aceee8..d814c36 100644 --- a/src/monkey/eval/flag.go +++ b/src/monkey/eval/flag.go @@ -21,7 +21,7 @@ type FlagObj struct { arguments map[Object]interface{} } -func (f *FlagObj) Inspect() string { return flag_name } +func (f *FlagObj) Inspect() string { return "<" + flag_name + ">" } func (f *FlagObj) Type() ObjectType { return FLAG_OBJ } func (f *FlagObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/fmt.go b/src/monkey/eval/fmt.go index ebfec1a..d246132 100644 --- a/src/monkey/eval/fmt.go +++ b/src/monkey/eval/fmt.go @@ -20,7 +20,7 @@ const ( type FmtObj struct { } -func (f *FmtObj) Inspect() string { return fmt_name } +func (f *FmtObj) Inspect() string { return "<" + fmt_name + ">" } func (f *FmtObj) Type() ObjectType { return FMT_OBJ } func (f *FmtObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/http.go b/src/monkey/eval/http.go index 9a26ad9..94f4747 100644 --- a/src/monkey/eval/http.go +++ b/src/monkey/eval/http.go @@ -106,7 +106,7 @@ func NewHTTPObj() Object { return ret } -func (h *HttpObj) Inspect() string { return http_name } +func (h *HttpObj) Inspect() string { return "<" + http_name + ">" } func (h *HttpObj) Type() ObjectType { return HTTP_OBJ } func (h *HttpObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { @@ -415,7 +415,7 @@ type HttpClient struct { Client *http.Client } -func (h *HttpClient) Inspect() string { return "httpclient" } +func (h *HttpClient) Inspect() string { return "" } func (h *HttpClient) Type() ObjectType { return HTTPCLIENT_OBJ } func (h *HttpClient) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { @@ -544,7 +544,7 @@ type HttpResponse struct { Response *http.Response } -func (h *HttpResponse) Inspect() string { return "httpresponse" } +func (h *HttpResponse) Inspect() string { return "" } func (h *HttpResponse) Type() ObjectType { return HTTPRESPONSE_OBJ } func (h *HttpResponse) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { @@ -593,7 +593,7 @@ type HttpRequest struct { Request *http.Request } -func (h *HttpRequest) Inspect() string { return "httprequest" } +func (h *HttpRequest) Inspect() string { return "" } func (h *HttpRequest) Type() ObjectType { return HTTPREQUEST_OBJ } func (h *HttpRequest) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { @@ -655,7 +655,7 @@ type HttpResponseWriter struct { } func (h *HttpResponseWriter) IOWriter() io.Writer { return h.Writer } -func (h *HttpResponseWriter) Inspect() string { return "http responsewriter" } +func (h *HttpResponseWriter) Inspect() string { return "" } func (h *HttpResponseWriter) Type() ObjectType { return HTTPRESPONSEWRITER_OBJ } func (h *HttpResponseWriter) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { @@ -715,7 +715,7 @@ type HttpServer struct { Server *http.Server } -func (h *HttpServer) Inspect() string { return "httpserver" } +func (h *HttpServer) Inspect() string { return "" } func (h *HttpServer) Type() ObjectType { return HTTPSERVER_OBJ } func (h *HttpServer) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { @@ -827,7 +827,7 @@ type HttpHeader struct { Header http.Header } -func (h *HttpHeader) Inspect() string { return "httpheader" } +func (h *HttpHeader) Inspect() string { return "" } func (h *HttpHeader) Type() ObjectType { return HTTPHEADER_OBJ } func (h *HttpHeader) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { diff --git a/src/monkey/eval/json.go b/src/monkey/eval/json.go index 60e56cd..56dccfb 100644 --- a/src/monkey/eval/json.go +++ b/src/monkey/eval/json.go @@ -22,7 +22,7 @@ func NewJsonObj() Object { return ret } -func (j *Json) Inspect() string { return json_name } +func (j *Json) Inspect() string { return "<" + json_name + ">" } func (j *Json) Type() ObjectType { return JSON_OBJ } func (j *Json) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/list.go b/src/monkey/eval/list.go index 047ea8f..8410a44 100644 --- a/src/monkey/eval/list.go +++ b/src/monkey/eval/list.go @@ -14,7 +14,7 @@ type ListObject struct { List *list.List } -func (l *ListObject) Inspect() string { return LIST_OBJ } +func (l *ListObject) Inspect() string { return "" } func (l *ListObject) Type() ObjectType { return LIST_OBJ } func (l *ListObject) CallMethod(line string, scope *Scope, method string, args ...Object) Object { switch method { diff --git a/src/monkey/eval/log.go b/src/monkey/eval/log.go index c25c8e9..65ed1d1 100644 --- a/src/monkey/eval/log.go +++ b/src/monkey/eval/log.go @@ -28,7 +28,7 @@ type LoggerObj struct { Logger *log.Logger } -func (l *LoggerObj) Inspect() string { return logger_name } +func (l *LoggerObj) Inspect() string { return "<" + logger_name + ">" } func (l *LoggerObj) Type() ObjectType { return LOGGER_OBJ } func (l *LoggerObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/math.go b/src/monkey/eval/math.go index e7fa4dc..44db74e 100644 --- a/src/monkey/eval/math.go +++ b/src/monkey/eval/math.go @@ -39,7 +39,7 @@ func NewMathObj() Object { return ret } -func (m *Math) Inspect() string { return math_name } +func (m *Math) Inspect() string { return "<" + math_name + ">" } func (m *Math) Type() ObjectType { return MATH_OBJ } func (m *Math) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/net.go b/src/monkey/eval/net.go index 7c0acca..b2acb40 100644 --- a/src/monkey/eval/net.go +++ b/src/monkey/eval/net.go @@ -30,7 +30,7 @@ func NewNetObj() Object { return ret } -func (n *NetObj) Inspect() string { return net_name } +func (n *NetObj) Inspect() string { return "<" + net_name + ">" } func (n *NetObj) Type() ObjectType { return NET_OBJ } func (n *NetObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/object.go b/src/monkey/eval/object.go index c21e84e..df05583 100644 --- a/src/monkey/eval/object.go +++ b/src/monkey/eval/object.go @@ -199,7 +199,7 @@ func (e *Enum) GetName(line string, args ...Object) Object { return NIL } -func (b *Builtin) Inspect() string { return "builtin function" } +func (b *Builtin) Inspect() string { return "" } func (b *Builtin) Type() ObjectType { return BUILTIN_OBJ } func (b *Builtin) CallMethod(line string, scope *Scope, method string, args ...Object) Object { panic(NewError(line, NOMETHODERROR, method, b.Type())) diff --git a/src/monkey/eval/os.go b/src/monkey/eval/os.go index 1a80eb0..8766914 100644 --- a/src/monkey/eval/os.go +++ b/src/monkey/eval/os.go @@ -54,7 +54,7 @@ func NewOsObj() Object { return ret } -func (o *Os) Inspect() string { return os_name } +func (o *Os) Inspect() string { return "<" + os_name + ">" } func (o *Os) Type() ObjectType { return OS_OBJ } func (o *Os) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/sort.go b/src/monkey/eval/sort.go index 1ad70dc..68d1b24 100644 --- a/src/monkey/eval/sort.go +++ b/src/monkey/eval/sort.go @@ -33,7 +33,7 @@ func NewSortObj() Object { type SortObj struct{} -func (s *SortObj) Inspect() string { return sort_name } +func (s *SortObj) Inspect() string { return "<" + sort_name + ">" } func (s *SortObj) Type() ObjectType { return SORT_OBJ } func (s *SortObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/sql.go b/src/monkey/eval/sql.go index 5dfac50..2d9cbe3 100644 --- a/src/monkey/eval/sql.go +++ b/src/monkey/eval/sql.go @@ -27,7 +27,7 @@ const ( type SqlsObject struct { } -func (s *SqlsObject) Inspect() string { return sql_name } +func (s *SqlsObject) Inspect() string { return "<" + sql_name + ">" } func (s *SqlsObject) Type() ObjectType { return SQL_OBJ } func (s *SqlsObject) CallMethod(line string, scope *Scope, method string, args ...Object) Object { panic(NewError(line, NOMETHODERROR, method, s.Type())) diff --git a/src/monkey/eval/sync.go b/src/monkey/eval/sync.go index dcbed2e..5579c1a 100644 --- a/src/monkey/eval/sync.go +++ b/src/monkey/eval/sync.go @@ -18,7 +18,7 @@ type SyncCondObj struct { Cond *sync.Cond } -func (c *SyncCondObj) Inspect() string { return SYNCCOND_OBJ } +func (c *SyncCondObj) Inspect() string { return "<" + SYNCCOND_OBJ + ">" } func (c *SyncCondObj) Type() ObjectType { return SYNCCOND_OBJ } func (c *SyncCondObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { @@ -65,7 +65,7 @@ type SyncOnceObj struct { Once *sync.Once } -func (o *SyncOnceObj) Inspect() string { return SYNCONCE_OBJ } +func (o *SyncOnceObj) Inspect() string { return "<" + SYNCONCE_OBJ + ">" } func (o *SyncOnceObj) Type() ObjectType { return SYNCONCE_OBJ } func (o *SyncOnceObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { @@ -110,7 +110,7 @@ type SyncMutexObj struct { Mutex *sync.Mutex } -func (m *SyncMutexObj) Inspect() string { return SYNCMUTEX_OBJ } +func (m *SyncMutexObj) Inspect() string { return "<" + SYNCMUTEX_OBJ + ">" } func (m *SyncMutexObj) Type() ObjectType { return SYNCMUTEX_OBJ } func (m *SyncMutexObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { @@ -146,7 +146,7 @@ type SyncRWMutexObj struct { RWMutex *sync.RWMutex } -func (rwm *SyncRWMutexObj) Inspect() string { return SYNCRWMUTEX_OBJ } +func (rwm *SyncRWMutexObj) Inspect() string { return "<" + SYNCRWMUTEX_OBJ + ">" } func (rwm *SyncRWMutexObj) Type() ObjectType { return SYNCRWMUTEX_OBJ } func (rwm *SyncRWMutexObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { @@ -204,7 +204,7 @@ type SyncWaitGroupObj struct { WaitGroup *sync.WaitGroup } -func (wg *SyncWaitGroupObj) Inspect() string { return SYNCWAITGROUP_OBJ } +func (wg *SyncWaitGroupObj) Inspect() string { return "<" + SYNCWAITGROUP_OBJ + ">" } func (wg *SyncWaitGroupObj) Type() ObjectType { return SYNCWAITGROUP_OBJ } func (wg *SyncWaitGroupObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object { diff --git a/src/monkey/eval/template.go b/src/monkey/eval/template.go index 3a4a944..f3dbaff 100644 --- a/src/monkey/eval/template.go +++ b/src/monkey/eval/template.go @@ -31,7 +31,7 @@ func NewTemplateObj() Object { return ret } -func (t *TemplateObj) Inspect() string { return template_name } +func (t *TemplateObj) Inspect() string { return "<" + template_name +">" } func (t *TemplateObj) Type() ObjectType { return TEMPLATE_OBJ } func (t *TemplateObj) CallMethod(line string, scope *Scope, method string, args ...Object) Object {