-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Range: Inclusive and exclusive operators #142
Comments
I'm not a fan of inclusive range but, since it's something ruby has, we have to implement it in order to prevent someone confusing with the different behavior (especially one who has a ruby background). I'll add this to the TODO list. |
I was looking at this too, might take a crack at it. |
@ThakeeNathees did you want an entirely new object type or did we want an attribute on the exiting Also, part of this would be changing the current |
Just so it's clear:
Change pocketlang
Add
|
Yes, I want the behavior to match Ruby. I have a slightly different way, that instead of adding a boolean
Instead, we split the opcode pk_compiler.c - - case TK_DOTDOT: emitOpcode(compiler, OP_RANGE); break;
case TK_DOTDOT: emitOpcode(compiler, OP_RANGE_IN); break;
case TK_DOTDOTDOT: emitOpcode(compiler, OP_RANGE_EX); break; pk_vm.c - OPCODE(RANGE):
OPCODE(RANGE_IN):
OPCODE(RANGE_EX):
{
Var to = PEEK(-1); // Don't pop yet, we need the reference for gc.
Var from = PEEK(-2); // Don't pop yet, we need the reference for gc.
if (!IS_NUM(from) || !IS_NUM(to)) {
RUNTIME_ERROR(newString(vm, "Range arguments must be number."));
}
DROP(); // to
DROP(); // from
- PUSH(VAR_OBJ(newRange(vm, AS_NUM(from), AS_NUM(to))));
double from = AS_NUM(from), to = AS_NUM(to);
if (instruction == OP_RANGE_IN) to = 1;
PUSH(VAR_OBJ(newRange(vm, from, to)));
DISPATCH();
} @tsujp If you have any suggestions let me know and If you need any help feel free to ping me. |
I've got the implementation working but these macros (far above my current level) are too much for me. See the PR as I'm not sure whether to discuss here or there. I'll follow wherever you reply. PR: #142 |
Since pocketlang is in an early stage: What if pocketlang had two range operators like ruby or wren (".." and "...")?
The text was updated successfully, but these errors were encountered: