-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add relation and equality operators #17
base: master
Are you sure you want to change the base?
Conversation
src/scripts/generator_base.py
Outdated
declaration_string += "%s = '%s';\n" % (str(key), str(value)) | ||
else: | ||
declaration_string += "%s = %d;\n" % (str(key), value) | ||
declaration_string += "%s = %s;\n" % (str(key), str(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This utility function is changes over and over the PRs. This should be finalized somehow.
|
||
class _InnerValues(): | ||
generated_filename = '''relation-equality-ops-{NUMBER}.js''' # The file name prefix of the generated | ||
relational_and_equality_operators = ["equ", "nequ", "sequ", "snequ", "less", "moreorequ", "more", "lessorequ"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest the: eq, neq, less, less_eq, greater, greater_eq
namings.
elif (decider == 3): | ||
self.operands[i] = "false" | ||
elif (decider == 4): | ||
self.operands[i] = "NaN" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
if decider <= 4:
self.operands[i] = special_values[i]
converted = "true" | ||
else: | ||
converted = "false" | ||
return converted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest: return "true" if value else "false";
converted = "false" | ||
return converted | ||
|
||
# Add comas to the value if it is meant to be a string in the test case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: comas
(left_value == "undefined" and right_value == "null") or | ||
(left_value == "null" and right_value == "undefined") or | ||
(left_value == "true" and right_value == "true") or | ||
(left_value == "false" and right_value == "false")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a mapping or something for these special cases. This look like a but ugly.
6683c57
to
5ca07d7
Compare
Updated the patch. |
|
||
class _InnerValues(): | ||
generated_filename = '''relation-equality-ops-{NUMBER}.js''' # The file name prefix of the generated | ||
relational_and_equality_operators = ["eq", "neq", "seq", "sneq", "less", "less_eq", "greater", "greater_eq"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assembly-like form would be much better. Please use the followings or the lowercase version of them instead!
EQ = equal
NE = not equal
GT = greater
LT = lesser
GE = greater and equal
LE = lesser and equal
SE (or STRICT_EQ) = strict equal
SN (or STRICT_NQ) = not strict equal
"seq": self.seq, | ||
"neq": self.neq, | ||
"sneq": self.sneq, | ||
} # Functions for the operators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about to generate getattr(self, relational_and_equality_operators[i])
for each elements of relational_and_equality_operators
?
} # Functions for the operators | ||
|
||
# Generating the expression with operands and operators | ||
def expression_maker(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expression_maker
? The expression_generator
sounds better.
|
||
# If it does not match the cases above and values are not undefined or null | ||
elif (left_value != "undefined" and left_value != "null" and right_value != "null" | ||
and right_value != "undefined"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif left_value not in ["undefined", "null"] and right_value not in ["undefined", "null"]:
?
result = left_converted < right_converted | ||
else: | ||
result = int(left_converted) < int(right_converted) | ||
result = self.convert_true_false_to_lowercase_string(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please combine these expressions!
# Greater than operator | ||
def greater(self, left_value, right_value): | ||
if (left_value == "NaN" or right_value == "NaN" or | ||
left_value == "undefined" or right_value == "undefined"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
if left_value in ["NaN", "undefined"] or right_value in ["NaN", "undefined"]:
# Less than or equal operator | ||
def less_eq(self, left_value, right_value): | ||
if (left_value == "NaN" or right_value == "NaN" or | ||
left_value == "undefined" or right_value == "undefined"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
if left_value in ["NaN", "undefined"] or right_value in ["NaN", "undefined"]:
# Greater than or equal operator | ||
def greater_eq(self, left_value, right_value): | ||
if (left_value == "NaN" or right_value == "NaN" or | ||
left_value == "undefined" or right_value == "undefined"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
if left_value in ["NaN", "undefined"] or right_value in ["NaN", "undefined"]:
write_file(gen_settings, self.file_output) | ||
self.debug(Messages.done, self.options) | ||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you create separate main
function? Do you want to call this why you are importing this class?
If you do not want that the main
will be callable, please move its body under if __name__ == '__main__':
block!
5ca07d7
to
ec29d28
Compare
Updated the patch according to the review, and also found and fixed some bugs. I corrected almost everything mentioned, I have to reply to some questions.
I already have a function with that name so its not possible.
I had to check for true or false before, because it would try to convert the default value to int, and it throws error, this way it is still shorter and simpler than before.
I did not want it to make it callable, but this review gave me and idea so I left it as it was, but if you do not agree I will change it. When we reach the end of this project, and we will have more generators, we could create a script which calls all the generators and they each generate the same number of test cases which number is given by argparser, and we could add a command line option to run the generated tests with the test runner script after the generators finished generating, and maybe an another one, which deletes the .js files which did not fail (This would not be useful in all the cases, but as an option). And if this project seems to be useful, we could insert it to jerryscript's run-tests.py with a command line option. What do you think? |
It sounds weird. Please, try to find a different function name.
Well, probably I wrote the
This can be done and could be a good option, but I still can't see the need of a separate |
ec29d28
to
7085814
Compare
def eq_helper_special_cases(self, values): | ||
special_cases = [["undefined", "undefined"], ["null", "null"], ["undefined", "null"], | ||
["null", "undefined"], ["true", "true"], ["false", "false"]] | ||
return True if values in special_cases else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return values in special_cases
is enough
7085814
to
513310b
Compare
This generator tests ES v5.1 11.8. - 11.9. (except 11.8.7. and 11.8.6.), relation and equality operators (
> >= <= < == === != !==
).The new validate function:
A test case looks like this: