Skip to content

Commit

Permalink
Revert "Added simple error handling(removed panics)"
Browse files Browse the repository at this point in the history
This reverts commit 7c90b19.
  • Loading branch information
r2b89 committed Nov 23, 2023
1 parent be42c5a commit 6c1a071
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 375 deletions.
19 changes: 4 additions & 15 deletions evaluator/smalltalkEvaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ func NewTestEvaluator() *Evaluator {

func TestEval(codeString string) treeNodes.SmalltalkObjectInterface {
evaluator := NewTestEvaluator()
programNode, _ := parser.InitializeParserFor(codeString)
programNode := parser.InitializeParserFor(codeString)
return evaluator.EvaluateProgram(programNode)
}

func TestEvalWithScope(codeString string, scope *treeNodes.Scope) treeNodes.SmalltalkObjectInterface {
evaluator := NewEvaluatorWithGlobalScope(scope)
programNode, _ := parser.InitializeParserFor(codeString)
programNode := parser.InitializeParserFor(codeString)
return evaluator.EvaluateProgram(programNode)
}

Expand Down Expand Up @@ -62,11 +62,7 @@ func (e *Evaluator) GetGlobalScope() *treeNodes.Scope {
func (e *Evaluator) RunProgram(programString string) treeNodes.SmalltalkObjectInterface {
_, ok := e.programCache[programString]
if !ok {
initializedParser, err := parser.InitializeParserFor(programString)
if err != nil {
return treeNodes.NewSmalltalkString(err.Error())
}
e.programCache[programString] = initializedParser
e.programCache[programString] = parser.InitializeParserFor(programString)
}
evaluatorProgram := e.programCache[programString]
return e.EvaluateProgram(evaluatorProgram)
Expand Down Expand Up @@ -113,9 +109,6 @@ func (e *Evaluator) EvaluateToBool(programString string) bool {

func (e *Evaluator) EvaluateToInterface(programString string) interface{} {
resultObject := e.RunProgram(programString)
if resultObject == nil {
return nil
}
switch resultObject.TypeOf() {
case treeNodes.NUMBER_OBJ:
return resultObject.(*treeNodes.SmalltalkNumber).GetValue()
Expand All @@ -124,11 +117,7 @@ func (e *Evaluator) EvaluateToInterface(programString string) interface{} {
case treeNodes.BOOLEAN_OBJ:
return resultObject.(*treeNodes.SmalltalkBoolean).GetValue()
case treeNodes.ARRAY_OBJ:
array, err := resultObject.(*treeNodes.SmalltalkArray).GetValue()
if err != nil {
return nil
}
return array
return resultObject.(*treeNodes.SmalltalkArray).GetValue()
default:
return nil
}
Expand Down
Loading

0 comments on commit 6c1a071

Please sign in to comment.