v
v copied to clipboard
Interpreter doesn't display bit shifted values in some cases
V version: 0.2.4 509367b OS: Linux
What did you do?
____ ____
\ \ / / | Welcome to the V REPL (for help with V itself, type exit , then run v help ).
\ \/ / | Note: the REPL is highly experimental. For best V experience, use a text editor,
\ / | save your code in a main.v file and execute: v run main.v
\ / | V 0.2.4 509367b . Use list to see the accumulated program so far.
\__/ | Use Ctrl-C or exit to exit, or help to see other available commands.
>>> 4 >> 1
2
>>> 4 << 1
>>> println(4 << 1)
8
>>> typeof(4 >> 1).name
int literal
>>> typeof(4 << 1).name
>>> println(typeof(4 << 1).name)
int literal
What did you expect to see?
Expression 4 << 1
should print 8 in the terminal and typeof(4 << 1)
should be displayed the same as typeof(4 >> 1)
What did you see instead?
Weird behavior that doesn't make sense. (AFAIK, << should be a simple bit shift operation)
Idk if this is related, but << is also used to append to arrays. Maybe interpreter is getting confused?
Idk if this is related, but << is used to spend to arrays. Maybe interpreter is getting confused?
Yes, the problem lies here: https://github.com/vlang/v/blob/master/cmd/tools/vrepl.v#L405
The REPL assumes that all lines containing <<
are array appendices, so it considers them a statement instead of an expression. I'm not sure how to fix this though without some ugly workarounds.
The best way to "fix" this would be to finish the "new" interpreter, and replace the REPL with that.
Isn't there a way to first parse the code, then analyze the AST and finally compile it to C code, which is then executed?
@JalonSolov
Is there any project currently in development for the new interpreter? I ask because I'm interested in contributing! =)