Skip to content

Commit 9b7bc13

Browse files
committed
Fixed reading from file return bug
1 parent 58f28ab commit 9b7bc13

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

evaluator/evaluator.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,21 @@ func unwrapReturnValue(obj object.Object) object.Object {
443443
}
444444

445445
func evalStringInfixExpression(operator string, left, right object.Object, line int) object.Object {
446-
if operator != "+" {
447-
return newError("Mstari %d: Operesheni Haielweki: %s %s %s", line, left.Type(), operator, right.Type())
448-
}
449446

450447
leftVal := left.(*object.String).Value
451448
rightVal := right.(*object.String).Value
452449

453-
return &object.String{Value: leftVal + rightVal}
450+
switch operator {
451+
case "+":
452+
return &object.String{Value: leftVal + rightVal}
453+
// doesn't work for some reason, maybe cause its cause its 4am
454+
// case "==":
455+
// return nativeBoolToBooleanObject(leftVal == rightVal)
456+
// case "!=":
457+
// return nativeBoolToBooleanObject(leftVal != rightVal)
458+
default:
459+
return newError("Mstari %d: Operesheni Haielweki: %s %s %s", line, left.Type(), operator, right.Type())
460+
}
454461
}
455462

456463
func evalIndexExpression(left, index object.Object, line int) object.Object {

repl/repl.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Read(contents string) {
4949
program := p.ParseProgram()
5050

5151
if len(p.Errors()) != 0 {
52-
// fmt.Println(colorfy(ERROR_FACE, 31))
52+
fmt.Println(colorfy(ERROR_FACE, 31))
5353
fmt.Println("Kuna Errors Zifuatazo:")
5454

5555
for _, msg := range p.Errors() {
@@ -59,7 +59,9 @@ func Read(contents string) {
5959
}
6060
evaluated := evaluator.Eval(program, env)
6161
if evaluated != nil {
62-
fmt.Println(colorfy(evaluated.Inspect(), 32))
62+
if evaluated.Type() != object.NULL_OBJ {
63+
fmt.Println(colorfy(evaluated.Inspect(), 32))
64+
}
6365
}
6466

6567
}

0 commit comments

Comments
 (0)