Anonymous avatar Anonymous committed 7a23248

Move objects into a python-standard directory structure.

Comments (0)

Files changed (9)

Objects/dictobject.pir

+.sub '' :anon :init :load
+    $P0 = subclass 'Hash', [ 'dict' ]
+
+#    $P1 = get_global [ 'type' ], 'wrap_class'
+#    $P1('dict', $P0)
+
+#    $P2 = get_class 'Hash'
+#    $P1 = getinterp
+#    $P1.'hll_map'($P2, $P0)
+.end
+
+.namespace [ 'dict' ]
+
+.sub 'get_string' :vtable
+    .local pmc iterator
+    .local string result
+
+    iterator = iter self
+
+    result = '{'
+    unless iterator goto done
+
+    # first element separately, to handle commas properly
+    $S0 = shift iterator
+    $P0 = self[$S0]
+    $S1 = 'repr'($S0)
+    result .= $S1
+    result .= ': '
+    $S1 = 'repr'($P0)
+    result .= $S1
+
+loop:
+    unless iterator goto done
+    result .= ', '
+
+    $S0 = shift iterator
+    $P0 = self[$S0]
+    $S1 = 'repr'($S0)
+    result .= $S1
+    result .= ':'
+    $S1 = 'repr'($P0)
+    result .= $S1
+    goto loop
+
+done:
+    result .= '}'
+    .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
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+

Objects/listobject.pir

+.sub '' :anon :init :load
+    $P0 = subclass 'ResizablePMCArray', [ 'list' ]
+
+    $P1 = get_global [ 'type' ], 'wrap_class'
+    $P1('list', $P0)
+
+    $P2 = get_class 'ResizablePMCArray'
+    $P1 = getinterp
+    $P1.'hll_map'($P2, $P0)
+.end
+
+
+.namespace [ 'list' ]
+
+
+=item list([sequence])
+
+Return a list whose items are the same and in the same order as sequence's items.
+sequence may be either a sequence, a container that supports iteration, or an
+iterator object. If sequence is already a list, a copy is made and returned,
+similar to sequence[:]. For instance, list('abc') returns ['a', 'b', 'c'] and
+list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, returns a new
+empty list, [].
+
+=cut
+
+.sub '__init__' :method
+    .param pmc sequence :optional
+    .param int has_seq :opt_flag
+
+    unless has_seq goto no_seq
+    self.'extend'(sequence)
+  no_seq:
+    # do nothing, just an empty list
+.end
+
+.sub 'get_string' :vtable
+    .local pmc iterator
+    .local string result
+
+    iterator = iter self
+
+    result = '['
+    unless iterator goto done
+
+    # first element separately, to handle commas properly
+    $P0 = shift iterator
+    $S0 = 'repr'($P0)
+    result .= $S0
+
+loop:
+    unless iterator goto done
+    result .= ', '
+
+    $P0 = shift iterator
+    $S0 = 'repr'($P0)
+    result .= $S0
+    goto loop
+
+done:
+    result .= ']'
+    .return (result)
+.end
+
+
+.sub 'is_equal' :vtable
+    .param pmc other
+
+    $I0 = isa other, [ 'list' ]
+    unless $I0 goto no
+
+    $I0 = elements self
+    $I1 = elements other
+    if $I0 != $I1 goto no
+
+    .local pmc i, j, item1, item2
+    i = iter self
+    j = iter other
+loop:
+    # if no more elements and everything matched, then yes
+    unless i goto yes
+    item1 = shift i
+    item2 = shift j
+    if item1 != item2 goto no
+    goto loop
+
+yes:
+    .return (1)
+
+no:
+    .return (0)
+.end
+
+
+.sub 'append' :method
+    .param pmc x
+    push self, x
+.end
+
+
+.sub 'count' :method
+    .param pmc value
+
+    .local pmc ret, iterator
+    ret = new 'Integer'
+    ret = 0
+    
+    iterator = iter self
+loop:
+    unless iterator goto done
+    $P0 = shift iterator
+    if $P0 != value goto loop
+    inc ret
+    goto loop
+
+done:
+    .return (ret)
+.end
+
+
+.sub 'extend' :method
+    .param pmc iterable
+    $I0 = elements self
+    splice self, iterable, $I0, 0
+.end
+
+
+.sub 'index' :method
+    .param pmc value
+    .param pmc start        :optional
+    .param int has_start    :opt_flag
+    .param pmc stop         :optional
+    .param int has_stop     :opt_flag
+
+    if has_start goto not_yet
+    if has_stop goto not_yet
+
+    .local pmc iterator
+    .local int idx
+    
+    idx = -1
+    iterator = iter self
+loop:
+    unless iterator goto not_found
+    inc idx
+    $P0 = shift iterator
+    unless $P0 == value goto loop
+
+    # found!
+    .return (idx)
+
+not_found:
+    $P0 = new 'Exception'
+    $P0 = 'ValueError'
+    throw $P0
+
+not_yet:
+    $P0 = new 'Exception'
+    $P0 = 'NotImplementedError'      # XXX
+    throw $P0
+.end
+
+
+.sub 'insert' :method
+    .param pmc index
+    .param pmc object
+
+    $I0 = index
+    $P0 = new 'ResizablePMCArray'
+    push $P0, object
+    splice self, $P0, $I0, 0
+.end
+
+.sub 'pop' :method
+    .param int idx      :optional
+    .param int has_idx  :opt_flag
+
+    unless has_idx goto no_idx
+    $P1 = self[idx]
+    delete self[idx]
+    .return($P1)
+
+no_idx:
+    $P1 = pop self
+    .return($P1)
+.end
+
+
+.sub 'remove' :method
+    .param pmc value
+    $I0 = self.'index'(value)
+    delete self[$I0]
+.end
+
+
+.sub 'reverse' :method
+    .local int i, j
+    .local pmc a, b
+
+    i = 0
+    j = elements self
+    dec j
+
+loop:
+    if i >= j goto done
+
+    a = self[i]
+    b = self[j]
+    self[i] = b
+    self[j] = a
+
+    inc i
+    dec j
+    goto loop
+
+done:
+.end
+
+
+.sub 'sort' :method
+    .param pmc key          :named :optional
+    .param pmc reverse      :named :optional
+    
+    $P0 = new 'Exception'
+    $P0 = 'NotImplementedError'      # XXX
+    throw $P0
+.end
+
+.namespace []

Objects/stringobject.pir

+.sub '' :anon :init :load
+    $P0 = subclass 'String', [ 'str' ]
+
+    $P1 = get_global [ 'type' ], 'wrap_class'
+    $P1('str', $P0)
+    
+    $P2 = get_class 'String'
+    $P1 = getinterp
+    $P1.'hll_map'($P2, $P0)
+.end
+
+
+.namespace [ 'str' ]
+
+
+=item str([object])
+
+Return a string containing a nicely printable representation of an object.
+For strings, this returns the string itself. The difference with
+repr(object) is that str(object) does not always attempt to return
+a string that is acceptable to eval(); its goal is to return a
+printable string. If no argument is given, returns the empty string, ''.
+
+=cut
+
+.sub '__init__' :method
+    .param pmc obj :optional
+    .param int has_obj :opt_flag
+    
+    unless has_obj goto done
+    $S0 = obj
+    self = $S0
+  done:
+.end
+
+.sub '__repr__' :method
+    .local string result
+    result = "'"
+    
+    # XXX escaping
+    $S0 = self
+    result .= $S0
+    
+    result .= "'"
+    .return (result)
+.end
+
+.sub 'split' :method
+    .param pmc sep          :optional :named('sep')
+    .param int has_sep      :opt_flag
+    .param int maxsplit     :optional :named('maxsplit')
+    .param int has_maxsplit :opt_flag
+
+    unless has_sep goto not_yet
+    if has_maxsplit goto not_yet
+
+    $S0 = sep
+    $S1 = self
+    $P0 = split $S0, $S1
+    # convert from ResizableStringArray to Pynie list
+    .tailcall 'listmaker'($P0 :flat)
+
+not_yet:
+    $P0 = new 'Exception'
+    $P0 = 'NotImplementedError'         # XXX
+    raise ($P0)
+.end
+
+.sub 'join' :method
+    .param pmc seq
+    $S0 = self
+    $S1 = join $S0, seq
+    .return ($S1)
+.end
+
+.namespace []

Objects/typeobject.pir

+.sub '' :anon :init
+    # setup type Class
+    $P0 = newclass [ 'type' ]
+    addattribute $P0, '_class'
+
+    # XXX there should be a type object wrapping the type class
+.end
+
+.namespace [ 'type' ]
+
+.sub 'make_type_object'
+    .param pmc _class
+
+    .local pmc init_args
+    init_args = new 'Hash'
+    init_args['_class'] = _class
+
+    $P1 = new [ 'type' ], init_args
+
+    .return ($P1)
+.end
+
+.sub 'wrap_class'
+    .param string name
+    .param pmc _class
+    
+    .local pmc make_type_object
+    make_type_object = get_global 'make_type_object'
+    $P0 = make_type_object(_class)
+    
+    set_hll_global name, $P0
+.end
+
+.sub 'invoke' :vtable
+    .param pmc args :slurpy
+    .param pmc kwargs :named :slurpy
+
+    $P0 = getattribute self, '_class'
+    # XXX $P1 should be an instance of self
+    $P1 = new $P0
+
+    $I0 = can $P1, '__init__'
+    unless $I0 goto done
+    $P1.'__init__'(args :flat, kwargs :flat)
+
+done:
+    .return ($P1)
+.end
+
+.sub 'get_string' :vtable
+    $P0 = getattribute self, '_class'
+    $S0 = $P0.'name'()
+
+    $S1 = "<class '"
+    $S1 .= $S0
+    $S1 .= "'>"
+
+    .return ($S1)
+.end
+
+.namespace []
   'src/builtins/io.pir',
   'src/builtins/lists.pir',
   'src/builtins/oper.pir',
-  'src/classes/pynietype.pir',
-  'src/classes/pynielist.pir',
-  'src/classes/pyniestr.pir',
-  'src/classes/pyniedict.pir',
+  'Objects/typeobject.pir',
+  'Objects/listobject.pir',
+  'Objects/stringobject.pir',
+  'Objects/dictobject.pir',
   ]
 
 CLEANUPS = GEN_SOURCES + [

src/classes/pyniedict.pir

-.sub '' :anon :init :load
-    $P0 = subclass 'Hash', [ 'dict' ]
-
-#    $P1 = get_global [ 'type' ], 'wrap_class'
-#    $P1('dict', $P0)
-
-#    $P2 = get_class 'Hash'
-#    $P1 = getinterp
-#    $P1.'hll_map'($P2, $P0)
-.end
-
-.namespace [ 'dict' ]
-
-.sub 'get_string' :vtable
-    .local pmc iterator
-    .local string result
-
-    iterator = iter self
-
-    result = '{'
-    unless iterator goto done
-
-    # first element separately, to handle commas properly
-    $S0 = shift iterator
-    $P0 = self[$S0]
-    $S1 = 'repr'($S0)
-    result .= $S1
-    result .= ': '
-    $S1 = 'repr'($P0)
-    result .= $S1
-
-loop:
-    unless iterator goto done
-    result .= ', '
-
-    $S0 = shift iterator
-    $P0 = self[$S0]
-    $S1 = 'repr'($S0)
-    result .= $S1
-    result .= ':'
-    $S1 = 'repr'($P0)
-    result .= $S1
-    goto loop
-
-done:
-    result .= '}'
-    .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
-#   fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4 ft=pir:
-

src/classes/pynielist.pir

-.sub '' :anon :init :load
-    $P0 = subclass 'ResizablePMCArray', [ 'list' ]
-
-    $P1 = get_global [ 'type' ], 'wrap_class'
-    $P1('list', $P0)
-
-    $P2 = get_class 'ResizablePMCArray'
-    $P1 = getinterp
-    $P1.'hll_map'($P2, $P0)
-.end
-
-
-.namespace [ 'list' ]
-
-
-=item list([sequence])
-
-Return a list whose items are the same and in the same order as sequence's items.
-sequence may be either a sequence, a container that supports iteration, or an
-iterator object. If sequence is already a list, a copy is made and returned,
-similar to sequence[:]. For instance, list('abc') returns ['a', 'b', 'c'] and
-list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, returns a new
-empty list, [].
-
-=cut
-
-.sub '__init__' :method
-    .param pmc sequence :optional
-    .param int has_seq :opt_flag
-
-    unless has_seq goto no_seq
-    self.'extend'(sequence)
-  no_seq:
-    # do nothing, just an empty list
-.end
-
-.sub 'get_string' :vtable
-    .local pmc iterator
-    .local string result
-
-    iterator = iter self
-
-    result = '['
-    unless iterator goto done
-
-    # first element separately, to handle commas properly
-    $P0 = shift iterator
-    $S0 = 'repr'($P0)
-    result .= $S0
-
-loop:
-    unless iterator goto done
-    result .= ', '
-
-    $P0 = shift iterator
-    $S0 = 'repr'($P0)
-    result .= $S0
-    goto loop
-
-done:
-    result .= ']'
-    .return (result)
-.end
-
-
-.sub 'is_equal' :vtable
-    .param pmc other
-
-    $I0 = isa other, [ 'list' ]
-    unless $I0 goto no
-
-    $I0 = elements self
-    $I1 = elements other
-    if $I0 != $I1 goto no
-
-    .local pmc i, j, item1, item2
-    i = iter self
-    j = iter other
-loop:
-    # if no more elements and everything matched, then yes
-    unless i goto yes
-    item1 = shift i
-    item2 = shift j
-    if item1 != item2 goto no
-    goto loop
-
-yes:
-    .return (1)
-
-no:
-    .return (0)
-.end
-
-
-.sub 'append' :method
-    .param pmc x
-    push self, x
-.end
-
-
-.sub 'count' :method
-    .param pmc value
-
-    .local pmc ret, iterator
-    ret = new 'Integer'
-    ret = 0
-    
-    iterator = iter self
-loop:
-    unless iterator goto done
-    $P0 = shift iterator
-    if $P0 != value goto loop
-    inc ret
-    goto loop
-
-done:
-    .return (ret)
-.end
-
-
-.sub 'extend' :method
-    .param pmc iterable
-    $I0 = elements self
-    splice self, iterable, $I0, 0
-.end
-
-
-.sub 'index' :method
-    .param pmc value
-    .param pmc start        :optional
-    .param int has_start    :opt_flag
-    .param pmc stop         :optional
-    .param int has_stop     :opt_flag
-
-    if has_start goto not_yet
-    if has_stop goto not_yet
-
-    .local pmc iterator
-    .local int idx
-    
-    idx = -1
-    iterator = iter self
-loop:
-    unless iterator goto not_found
-    inc idx
-    $P0 = shift iterator
-    unless $P0 == value goto loop
-
-    # found!
-    .return (idx)
-
-not_found:
-    $P0 = new 'Exception'
-    $P0 = 'ValueError'
-    throw $P0
-
-not_yet:
-    $P0 = new 'Exception'
-    $P0 = 'NotImplementedError'      # XXX
-    throw $P0
-.end
-
-
-.sub 'insert' :method
-    .param pmc index
-    .param pmc object
-
-    $I0 = index
-    $P0 = new 'ResizablePMCArray'
-    push $P0, object
-    splice self, $P0, $I0, 0
-.end
-
-.sub 'pop' :method
-    .param int idx      :optional
-    .param int has_idx  :opt_flag
-
-    unless has_idx goto no_idx
-    $P1 = self[idx]
-    delete self[idx]
-    .return($P1)
-
-no_idx:
-    $P1 = pop self
-    .return($P1)
-.end
-
-
-.sub 'remove' :method
-    .param pmc value
-    $I0 = self.'index'(value)
-    delete self[$I0]
-.end
-
-
-.sub 'reverse' :method
-    .local int i, j
-    .local pmc a, b
-
-    i = 0
-    j = elements self
-    dec j
-
-loop:
-    if i >= j goto done
-
-    a = self[i]
-    b = self[j]
-    self[i] = b
-    self[j] = a
-
-    inc i
-    dec j
-    goto loop
-
-done:
-.end
-
-
-.sub 'sort' :method
-    .param pmc key          :named :optional
-    .param pmc reverse      :named :optional
-    
-    $P0 = new 'Exception'
-    $P0 = 'NotImplementedError'      # XXX
-    throw $P0
-.end
-
-.namespace []

src/classes/pyniestr.pir

-.sub '' :anon :init :load
-    $P0 = subclass 'String', [ 'str' ]
-
-    $P1 = get_global [ 'type' ], 'wrap_class'
-    $P1('str', $P0)
-    
-    $P2 = get_class 'String'
-    $P1 = getinterp
-    $P1.'hll_map'($P2, $P0)
-.end
-
-
-.namespace [ 'str' ]
-
-
-=item str([object])
-
-Return a string containing a nicely printable representation of an object.
-For strings, this returns the string itself. The difference with
-repr(object) is that str(object) does not always attempt to return
-a string that is acceptable to eval(); its goal is to return a
-printable string. If no argument is given, returns the empty string, ''.
-
-=cut
-
-.sub '__init__' :method
-    .param pmc obj :optional
-    .param int has_obj :opt_flag
-    
-    unless has_obj goto done
-    $S0 = obj
-    self = $S0
-  done:
-.end
-
-.sub '__repr__' :method
-    .local string result
-    result = "'"
-    
-    # XXX escaping
-    $S0 = self
-    result .= $S0
-    
-    result .= "'"
-    .return (result)
-.end
-
-.sub 'split' :method
-    .param pmc sep          :optional :named('sep')
-    .param int has_sep      :opt_flag
-    .param int maxsplit     :optional :named('maxsplit')
-    .param int has_maxsplit :opt_flag
-
-    unless has_sep goto not_yet
-    if has_maxsplit goto not_yet
-
-    $S0 = sep
-    $S1 = self
-    $P0 = split $S0, $S1
-    # convert from ResizableStringArray to Pynie list
-    .tailcall 'listmaker'($P0 :flat)
-
-not_yet:
-    $P0 = new 'Exception'
-    $P0 = 'NotImplementedError'         # XXX
-    raise ($P0)
-.end
-
-.sub 'join' :method
-    .param pmc seq
-    $S0 = self
-    $S1 = join $S0, seq
-    .return ($S1)
-.end
-
-.namespace []

src/classes/pynietype.pir

-.sub '' :anon :init
-    # setup type Class
-    $P0 = newclass [ 'type' ]
-    addattribute $P0, '_class'
-
-    # XXX there should be a type object wrapping the type class
-.end
-
-.namespace [ 'type' ]
-
-.sub 'make_type_object'
-    .param pmc _class
-
-    .local pmc init_args
-    init_args = new 'Hash'
-    init_args['_class'] = _class
-
-    $P1 = new [ 'type' ], init_args
-
-    .return ($P1)
-.end
-
-.sub 'wrap_class'
-    .param string name
-    .param pmc _class
-    
-    .local pmc make_type_object
-    make_type_object = get_global 'make_type_object'
-    $P0 = make_type_object(_class)
-    
-    set_hll_global name, $P0
-.end
-
-.sub 'invoke' :vtable
-    .param pmc args :slurpy
-    .param pmc kwargs :named :slurpy
-
-    $P0 = getattribute self, '_class'
-    # XXX $P1 should be an instance of self
-    $P1 = new $P0
-
-    $I0 = can $P1, '__init__'
-    unless $I0 goto done
-    $P1.'__init__'(args :flat, kwargs :flat)
-
-done:
-    .return ($P1)
-.end
-
-.sub 'get_string' :vtable
-    $P0 = getattribute self, '_class'
-    $S0 = $P0.'name'()
-
-    $S1 = "<class '"
-    $S1 .= $S0
-    $S1 .= "'>"
-
-    .return ($S1)
-.end
-
-.namespace []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.