Skip to content
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

Link operations to operators problem. #54

Closed
astlin opened this issue Dec 18, 2017 · 5 comments
Closed

Link operations to operators problem. #54

astlin opened this issue Dec 18, 2017 · 5 comments

Comments

@astlin
Copy link

astlin commented Dec 18, 2017

I've defined non-strict comparison operator '=%':

opp.add("==", 9); opp.add("!=", 9); opp.add("=%", 9);

But it won't match 'ANY_OP' pattern, so this do not work:

opMap.add({ARR, ANY_OP, ANY_TYPE}, &ArrayOnAnyOperation);

And I have to define it explicitly:

opMap.add({ARR, ANY_OP, ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ARR, "=%", ANY_TYPE}, &ArrayOnAnyOperation);

@VinGarcia
Copy link
Member

VinGarcia commented Dec 18, 2017

The masking system is a little complicated. I can think of 2 possible reasons for this problem:

  1. ARR ID is colliding with some existing type making the operation be processed by some built-in one instead of the one you were expecting.
  2. You have defined a more specific operation for this same types, e.g. opMap.add({ANY_TYPE, "=%", ANY_TYPE})

@astlin can you provide the code you use to declare all your operations as well as the hex numeral of ARR? Then I should be able to diagnose what is happening.

@astlin
Copy link
Author

astlin commented Dec 20, 2017

Well, actually there is a declaration of '=%' for ANY_TYPE on ANY_TYPE right before the last one 'ANY ANY ANY'.

opMap.add({ARR, ANY_OP, ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ARR, "=%", ANY_TYPE}, &ArrayOnAnyOperation);
....
opMap.add({ANY_TYPE, "=%", ANY_TYPE}, &AnyLike);
opMap.add({ANY_TYPE, ANY_OP, ANY_TYPE}, &AnyOnAny);

@VinGarcia
Copy link
Member

This {ANY, =%, ANY} operation is most likely taking precedence.

The ANY_OP operations are only evaluated if there is no match with a specific operation, quoting the code:

// Resolve the operation: 
result = exec_operation(p_left, p_right, &data, data.op); 
if (!result) {
  // ANY_OP will only run if no other match is found:
  result = exec_operation(p_left, p_right, &data, ANY_OP); 
}

This could probably be better explained in the docs. In any case I suggest you group your ANY_OP operation declarations and set put them after the rest, so it will be more clear the actual precedence order:

// The order is important between 2 operations with the same operator
// So ARR "=%" ANY will have precedence over ANY "=%" ANY
opMap.add({ARR, "=%", ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ANY_TYPE, "=%", ANY_TYPE}, &AnyLike);

// Likewise {ARR ANY_OP ANY} will have precedence over {ANY ANY_OP ANY}
// But ANY_OP will always have less precedence than specific operations so they should
// be put in last to make it clear.
opMap.add({ARR, ANY_OP, ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ANY_TYPE, ANY_OP, ANY_TYPE}, &AnyOnAny);

I will add this example to the docs and then, if it works for you, close this issue.

@VinGarcia
Copy link
Member

I have updated the doc section on this, and it should be clearer now.

Let me know if this helps.

@astlin
Copy link
Author

astlin commented Dec 20, 2017

Ok. Thanx for explanation.

@astlin astlin closed this as completed Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants