def ___parse___(self, parser): # x << y << z << value y = parser.parse(self.y) if isinstance(self.x, _VarSymbol): return special.set(varcache(self.x.name), y) if isinstance(self.x, _lshift): vars = _get_assign_vars_chain(self.x) i = len(vars)-1 set_stmts = [special.set(vars[i], y)] while i>0: i -= 1 set_stmts.append(special.set(vars[i], vars[i+1])) return special.begin(*set_stmts) elif isinstance(self.x, tuple) or isinstance(self.x, list): vars = self.x elif isinstance(self.x, _div): vars = _get_assign_vars_list(self.x) else: raise DinpySyntaxError() return special.set_list(vars, y)
def testLoopUntil(self): eq_(eval(tag_loop_label(let([(i,3)], LoopUntilForm((set(i, sub(i, 1)), prin(i)), eq(i,0))))), None)
def testLoopTimes(self): eq_(eval(tag_loop_label(let([(i,3)], LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))), None)
def testloop(self): eq_(eval(let([(i,3)], block(a, set(i, sub(i, 1)), if_(eq(i, 0), exit_block(a, 1)), continue_block(a)), i)), 0)
def test_do1(self): eq_(preparse(do[v.i << 1]), preparse(special.begin(special.set(i, 1))))
def test5(self): eq_(preparse(macro.a == at()[prin(1)]), special.set(a, special.MacroForm(((), prin(1)))))
def test_block2(self): eq_(preparse(block.a[v.i << 1]), special.block('a', special.set(i, 1)))
def test_do1(self): eq_(preparse(do[v.i<<1]), preparse(special.begin(special.set(i, 1))))
def testset(self): eq_(preparse(set(a, 2)), set(a, 2))
def ___parse___(self, parser): if isinstance(self.x, _Unary) and isinstance(self.x.x, _VarSymbol): x = varcache(self.x.x.name) return special.set(x, arith.add(x, 1)) else: return parser.parse(self.x)
def test_assign_chain(self): eq_(preparse(i << j << 1), preparse(special.begin(special.set(j, 1), special.set(i, j))))
def test_single_assign(self): eq_(preparse(i << 1), preparse(special.set(i, 1)))
def test_dec(self): eq_(preparse(--i), preparse(special.set(i, arith.sub(i, 1))))
def test_assign1(self): eq_(preparse(v.i<<1), preparse(special.set(i, 1)))
def test_inc(self): eq_(preparse(++i),preparse(special.set(i, arith.add(i,1))))
def getitem_to_list(argument=None): if argument is not None: _x = DummyVar('_x') return and_p(getitem(_x), special.set(argument, to_list(_x))) else: return getitem()
def test_dec(self): eq_(preparse(--i), preparse(special.set(i, arith.sub(i,1))))
def test5(self): eq_(preparse(fun.a == at()[prin(1)]), special.set(a, special.FunctionForm(((), prin(1)))))
def test_single_assign(self): eq_(preparse(i<<1), preparse(special.set(i, 1)))
def test_assign1(self): eq_(preparse(v.i << 1), preparse(special.set(i, 1)))
def test_assign_chain(self): eq_(preparse(i<<j<<1), preparse(special.begin(special.set(j, 1), special.set(i, j))))
def testset(self): eq_(eval(set(a,2)), 2)
def test_block2(self): eq_(preparse(block.a[ v.i << 1 ]), special.block('a', special.set(i,1)))
def test_unwind_protect_loop(self): eq_(eval(let([(i,3)], block(a, set(i, sub(i, 1)), if_(eq(i, 0), exit_block(a, 1)), unwind_protect(continue_block(a), prin(2))), i)), 0)
def test5(self): eq_(preparse(fun. a== at()[prin(1)]), special.set(a, special.FunctionForm(((), prin(1)))))
def testLoopWhen(self): eq_(eval(tag_loop_label(let([(i,3)], LoopWhenForm((set(i, sub(i, 1)), prin(i)), gt(i,0))))), None)
def test5(self): eq_(preparse(macro. a== at()[prin(1)]), special.set(a, special.MacroForm(((), prin(1)))))
def test_let_set(self): eq_(eval(let([(a,1)], set(a,2), a)), 2) eq_(eval(let([(a,1)], let([(b,1)], set(a,2), a))), 2)
def test_inc(self): eq_(preparse(++i), preparse(special.set(i, arith.add(i, 1))))