Skip to content

Commit 705c818

Browse files
committed
Fix unary and pow
1 parent 185fd46 commit 705c818

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
0.2.22
2+
3+
17.03.2016
4+
5+
Fixes:
6+
7+
* Fix unary op handling
8+
* Convert ** to `math:pow`
9+

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A restricted Python to idiomatic JavaScript / Ruby / Go / C# translator
77

88
[Pseudo](https://github.com/alehander42/pseudo) is a framework for high level code generation: it is used by this compiler to translate a subset of Python to all Pseudo-supported languages
99

10-
**If you are using Python3.5 and you experience problems with an already installed version of pseudo-python, please upgrade it to `0.2.20` (`pip3 install pseudo-python --upgrade`)**
10+
**If you are using Python3.5 and you experience problems with an already installed version of pseudo-python, please upgrade it to `0.2.22` (`pip3 install pseudo-python --upgrade`)**
1111

1212

1313

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.20
1+
0.2.22

pseudo_python/api_translator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def len_expander(type, message, args):
102102

103103
'sin': StandardCall('math', 'sin'),
104104
'cos': StandardCall('math', 'cos'),
105-
'tan': StandardCall('math', 'tan')
105+
'tan': StandardCall('math', 'tan'),
106+
'pow': lambda left, right, pseudo_type: Node('binary_op',
107+
op='**', left=left, right=right, pseudo_type=pseudo_type)
106108
},
107109

108110
're': {

pseudo_python/ast_translator.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,22 @@ def _translate_binop(self, op, left, right, location):
729729
left_node, right_node = self._translate_node(left), self._translate_node(right)
730730
binop_type = TYPED_API['operators'][op](left_node['pseudo_type'], right_node['pseudo_type'])[-1]
731731
if binop_type == 'Float' or binop_type == 'Int':
732-
return {
733-
'type': 'binary_op',
734-
'op': op,
735-
'left': left_node,
736-
'right': right_node,
737-
'pseudo_type': binop_type
738-
}
732+
if op == '**': # math:pow(left, right)
733+
return {
734+
'type': 'standard_call',
735+
'namespace': 'math',
736+
'args': [left_node, right_node],
737+
'pseudo_type': binop_type,
738+
'function': 'pow'
739+
}
740+
else:
741+
return {
742+
'type': 'binary_op',
743+
'op': op,
744+
'left': left_node,
745+
'right': right_node,
746+
'pseudo_type': binop_type
747+
}
739748
else:
740749
if left_node['pseudo_type'] == 'String' and op == '%':
741750
if left_node['type'] != 'string':
@@ -814,20 +823,20 @@ def _translate_unaryop(self, operand, op, location):
814823
value = operand
815824
if isinstance(op, ast.USub):
816825
value_node = self._translate_node(value)
817-
if value_node.pseudo_type != 'Int' and value_node.pseudo_type != 'Float':
826+
if value_node['pseudo_type'] != 'Int' and value_node['pseudo_type'] != 'Float':
818827
raise type_check_error('- expects Int or Float',
819828
location, self.lines[location[0]],
820-
wrong_type=value_node.pseudo_type)
829+
wrong_type=value_node['pseudo_type'])
821830
return {
822831
'type': 'unary_op',
823832
'op': '-',
824833
'value': value_node,
825-
'pseudo_type': value_node.pseudo_type
834+
'pseudo_type': value_node['pseudo_type']
826835
}
827836
elif isinstance(op, ast.Not):
828837
value_node = self._testable(self._translate_node(value))
829-
if value_node.type == 'standard_method_call' and value_node.message == 'present?':
830-
value_node.message = 'empty?'
838+
if value_node['type'] == 'standard_method_call' and value_node['message'] == 'present?':
839+
value_node['message'] = 'empty?'
831840
return value_node
832841
else:
833842
return {

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pseudo-python',
5-
version='0.2.20',
5+
version='0.2.22',
66
description='a python3 to pseudo compiler',
77
author='Alexander Ivanov',
88
author_email='alehander42@gmail.com',

0 commit comments

Comments
 (0)