Coder Social home page Coder Social logo

goto's People

Contributors

pandeykartikey avatar vrongmeal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goto's Issues

len() built-in produces incorrect results

I had this issue with my overhauled/enhanced version of monkey, so it was the first thing I looked for:

Sample program:

cat len.goto
print( len( "狐犬" ) );

Execution:

goto len.goto 
6
null

You want to change your primitive to use something like this:

return &object.Integer{Value: int64(utf8.RuneCountInString(arg.Value))}

Rather than:

return &object.Integer{Value: int64(len(arg.Value))}

lexer: Doesn't catch unterminated string

The following program hangs forever:

$ cat in.go
print( "steve );

The following quick patch is one potential solution:

diff --git a/lexer/lexer.go b/lexer/lexer.go
index dafc23a..48c7654 100644
--- a/lexer/lexer.go
+++ b/lexer/lexer.go
@@ -47,7 +47,7 @@ func (l *Lexer) skipComments() {
 func (l *Lexer) readSequence(f func(byte) bool) string {
        position := l.position
 
-       for f(l.ch) {
+       for l.ch != 0 && f(l.ch) {
                l.readChar()
        }

Ideally you'd return token.ILLEGAL if the function didn't match and you hit EOF, so perhaps something better needs to be done.

eval: panic on division by zero

The following program panics:

$ cat  div.to
print( 1 / 0 );

$ goto div.to
panic: runtime error: integer divide by zero

goroutine 1 [running]:
github.com/pandeykartikey/goto/eval.evalInfixIntegerExpression(0x5f95ef, 0x1, 0xc0000b4048, 0xc0000b4040, 0x0, 0x410d1b)
	/home/skx/go/src/github.com/pandeykartikey/goto/eval/eval.go:113 +0x6fc
github.com/pandeykartikey/goto/eval.evalInfixExpression(0x5f95ef, 0x1, 0x54df20, 0xc0000b4048, 0x54df20, 0xc0000b4040, 0x7f0ab170e100, 0x20300000000000)
..

You probabl want to catch that in evalInfixIntegerExpression and return an error, something like:

frodo ~/go/src/github.com/pandeykartikey/goto $ git diff eval/eval.go
diff --git a/eval/eval.go b/eval/eval.go
index c2e3e43..9a05b11 100644
--- a/eval/eval.go
+++ b/eval/eval.go
@@ -110,6 +110,9 @@ func evalInfixIntegerExpression(op string, left *object.Integer, right *object.I
        case "*":
                return &object.Integer{Value: leftVal * rightVal}
        case "/":
+               if rightVal == 0 {
+                       return errorMessageToObject("division by zero")
+               }
                return &object.Integer{Value: leftVal / rightVal}
        case "%":
                return &object.Integer{Value: leftVal % rightVal}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.