Skip to content

Commit

Permalink
gonna do something like this https://github.com/Jonak-Adipta-Kalita/J…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonak-Adipta-Kalita committed May 10, 2023
1 parent 7b2b043 commit 86ea5c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 1 addition & 2 deletions evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func isTruthy(obj object.Object) bool {
}

func newError(format, file string, line int, a ...interface{}) *object.Error {
if file == "" {
if file == "<stdin>" {
return &object.Error{Message: fmt.Sprintf(format, a...)}
}
args := append([]interface{}{file, line}, a...)
Expand Down Expand Up @@ -783,7 +783,6 @@ func evalForeachExpression(fle *ast.ForeachStatement, env *object.Environment, f
}

func evalObjectCallExpression(call *ast.ObjectCallExpression, env *object.Environment, file string, line int) object.Object {

obj := Eval(call.Object, env)
if method, ok := call.Call.(*ast.CallExpression); ok {
args := evalExpressions(call.Call.(*ast.CallExpression).Arguments, env)
Expand Down
15 changes: 15 additions & 0 deletions object/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package object

type Error struct {
Message string
File string
Line int
StartPos int
EndPos int
}

func (e *Error) Type() ObjectType { return ERROR_OBJ }
func (e *Error) Inspect() string { return e.Message }
func (e *Error) InvokeMethod(method string, args ...Object) Object {
return nil
}
10 changes: 0 additions & 10 deletions object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ func (f *Function) InvokeMethod(method string, args ...Object) Object {
return nil
}

type Error struct {
Message string
}

func (e *Error) Type() ObjectType { return ERROR_OBJ }
func (e *Error) Inspect() string { return "ERROR: " + e.Message }
func (e *Error) InvokeMethod(method string, args ...Object) Object {
return nil
}

type String struct {
Value string
offset int
Expand Down

0 comments on commit 86ea5c7

Please sign in to comment.