Commits

Anonymous committed 24795c6

Fix a bug and add a missing method in dictionaries, reported in
LP #525015. Thanks to R. David Murray for submitting the failing
tests.

Comments (0)

Files changed (3)

Lib/test/bootstrap/dicts.py

 if a: print('success: one element dict')
 else: print('failure: one element dict')
 
-
 print('test: display dict element')
 b = a['foo']
 if b == 1: print('success: display dict element')
 b = a['bar']
 if b == 'baz': print('success: add element to dict')
 else: print('failure: add element to dict')
+
+print("test: integer as index")
+a = {1: 2}
+b = list(a.keys())
+if b[0] == 1: print('success: integer as index')
+else: print('failure: integer as index')
+
+print('test: multiple elements')
+a = {1: 2, 3: 4, 5: 6}
+if len(a) == 3: print('success: multiple elements')
+else: print('failure: multiple elements')

src/builtins/lists.pir

     if null args goto done
     iterator = iter args
 
+  loop:
     unless iterator goto done
     key = shift iterator
     value = shift iterator
     result[key] = value
+    goto loop
   done:
 
     .return (result)

src/classes/pyniedict.pir

     .return (result)
 .end
 
+.sub 'keys' :method
+    .local pmc ret, iterator
+
+    ret = new 'list'
+    
+    iterator = iter self
+loop:
+    unless iterator goto done
+    $S0 = shift iterator
+    push ret, $S0
+    goto loop
+
+done:
+    .return (ret)
+.end
 
 # Local Variables:
 #   mode: pir