Permalink
Browse files

[cardinal] Adding initial support for Range, Time, Math, GC, and Kern…

…el classes. Much more to come :-)

git-svn-id: https://svn.parrot.org/parrot/trunk/languages/cardinal@31774 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 0f17d8e commit 3356e2341d7e1cf3d583f5528d4d624205a25c54 @damianknopp damianknopp committed Oct 8, 2008
View
@@ -37,7 +37,8 @@ object.
.namespace [ 'cardinal::Compiler' ]
-.loadlib 'cardinal_group'
+#no caridinal_group found on my machine
+#.loadlib 'cardinal_group'
.sub 'onload' :anon :load :init
load_bytecode 'PCT.pbc'
View
@@ -55,7 +55,13 @@ BUILTINS_PIR = \
src/classes/Integer.pir \
src/classes/Array.pir \
src/classes/Hash.pir \
+ src/classes/Any.pir \
+ src/classes/Range.pir \
src/classes/Bool.pir \
+ src/classes/Kernel.pir \
+ src/classes/Time.pir \
+ src/classes/Math.pir \
+ src/classes/GC.pir \
src/builtins/globals.pir \
src/builtins/eval.pir \
View
@@ -61,6 +61,14 @@ src/builtins/control.pir - Cardinal Control functions
throw e
.end
+=item sleep(num)
+Sleep for number of seconds.
+=cut
+.sub 'sleep'
+ .param num a
+ sleep a
+.end
+
# Local Variables:
# mode: pir
# fill-column: 100
View
@@ -121,7 +121,6 @@ such as C<eval>, C<require>, and C<use>.
$P0 = 'require'(file, 'file'=>1)
.end
-
=back
=cut
View
@@ -29,6 +29,29 @@ src/builtins/globals.pir - initialize miscellaneous global variables
## set up %*INC
$P0 = new 'CardinalHash'
set_hll_global '%INC', $P0
+
+ ## global record separator
+ #$P1 = new 'CardinalString'
+ #$P1 = "\n"
+ $P1 = get_hll_global ['NilClass'], '!CARDINALMETA'
+ set_hll_global '$/', $P1
+
+ $P2 = new 'CardinalString'
+ $P2 = "parrot"
+ set_hll_global 'RUBY_PLATFORM', $P2
+
+ $P3 = new 'CardinalString'
+ $P3 = "1.9"
+ set_hll_global 'RUBY_VERSION', $P3
+.end
+
+=item
+ Uses Parrot builtin Random type, doesnt seem to be working
+=cut
+.sub 'rand'
+ $P0 = new 'Random'
+ $I0 = $P0
+ .return ($I0)
.end
# Local Variables:
View
@@ -136,6 +136,23 @@ src/builtins/op.pir - Cardinal ops
.end
+## autoincrement
+.sub 'postfix:++' :multi(_)
+ .param pmc a
+ $P0 = clone a
+ inc a
+ .return ($P0)
+ #.return (a)
+.end
+
+.sub 'postfix:--' :multi(_)
+ .param pmc a
+ $P0 = clone a
+ dec a
+ .return ($P0)
+.end
+
+
=back
=cut
View
@@ -33,6 +33,28 @@ builtin functions for Ruby.
'print'($S0, "\n")
.end
+.sub 'readline'
+ #.param pmc sep :optional #record sep
+ $P0 = getstdin
+ $S0 = $P0.readline('')
+ .return($S0)
+.end
+
+.sub 'printf'
+ .param pmc fmt
+ .param pmc args :slurpy
+ $P0 = get_hll_global ['Kernel'], '!CARDINALMETA'
+ $P0.'printf'(fmt, args :flat)
+.end
+
+.sub 'sprintf'
+ .param pmc fmt
+ .param pmc args :slurpy
+ $P0 = get_hll_global ['Kernel'], '!CARDINALMETA'
+ $P1 = $P0.'sprintf'(fmt, args :flat)
+ .return ($P1)
+.end
+
# Local Variables:
# mode: pir
# fill-column: 100
View
@@ -0,0 +1,54 @@
+## $Id: Any.pir 29590 2008-07-18 16:46:36Z jonathan $
+
+=head1 TITLE
+
+Any - Perl 6 Any class
+
+=head1 DESCRIPTION
+
+This file implements the Any class.
+
+=head2 Basic C<Any> methods
+
+=over 4
+
+=cut
+
+.namespace []
+.sub 'onload' :anon :init :load
+ .local pmc meta
+ meta = get_hll_global ['CardinalObject'], '!CARDINALMETA'
+ meta.'new_class'('CardinalAny', 'parent'=>'CardinalObject')
+.end
+
+
+=item can($x)
+
+=cut
+
+.namespace ['CardinalAny']
+.sub 'can' :method
+ .param pmc x
+ $P0 = self.'HOW'()
+ .return $P0.'can'(self, x)
+.end
+
+=item isa($x)
+
+=cut
+
+.sub 'isa' :method
+ .param pmc x
+ $P0 = self.'HOW'()
+ .return $P0.'isa'(self, x)
+.end
+
+=back
+
+=cut
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
View
@@ -26,7 +26,6 @@ Stolen from Rakudo
.end
-
=item get_string() (vtable method)
Return the elements of the list concatenated.
@@ -40,6 +39,23 @@ Return the elements of the list concatenated.
.return ($S0)
.end
+.sub 'initialize' :method :multi(_)
+ noop
+.end
+
+.include "hllmacros.pir"
+.sub 'initialize' :method :multi(_,CardinalInteger)
+ .param pmc size
+ .local pmc i
+ i = new 'CardinalInteger'
+ i = 0
+ $P0 = get_hll_global 'nil'
+ .DoWhile( {
+ self[i] = $P0
+ inc i
+ }, i < size)
+.end
+
=item to_s() (method)
Return a CardinalString representing the Array.
@@ -74,6 +90,35 @@ Removes all elements from the array.
self = 0
.end
+=item fill(value)
+
+Fill C<self> with C<value>
+Doesnt work, but it should be close...
+
+=cut
+
+.sub 'fill' :method
+ .param pmc value
+ .param int offset :optional
+ .param int end_index :optional
+
+ unless end_index goto set_index
+ unless offset goto set_offset
+ goto do_fill
+
+ set_index:
+ end_index = self.'length'()
+ unless offset goto set_offset
+ goto do_fill
+ set_offset:
+ offset = 0
+ goto do_fill
+ do_fill:
+ $P0 = new 'CardinalString'
+ $P0 = value
+ splice self, value, offset, end_index
+ .return (self)
+.end
=item ACCEPTS(topic)
@@ -128,6 +173,16 @@ Return the number of elements in the list.
.return ($I0)
.end
+=item
+
+Return the class name
+
+=cut
+
+.sub 'class' :method
+ .return self.'WHAT'()
+.end
+
=item sort()
Return a sorted copy of the list
@@ -227,6 +282,15 @@ Return a sorted copy of the list
self.append($P0)
.end
+.sub 'max' :method
+ $P0 = 'infix:max'(self)
+ .return($P0)
+.end
+
+.sub 'min' :method
+ $P0 = 'infix:min'(self)
+ .return($P0)
+.end
=item include?(ELEMENT)
@@ -250,6 +314,21 @@ Return true if self contains ELEMENT
.return($P0)
.end
+=item
+Return true is C<self> is of size 0
+=cut
+.sub 'empty?' :method
+ .local int len
+ len = self.'length'()
+ if len == 0 goto empty
+ goto not_empty
+ empty:
+ $P0 = get_hll_global ['Bool'], 'True'
+ .return ($P0)
+ not_empty:
+ $P0 = get_hll_global ['Bool'], 'False'
+ .return ($P0)
+.end
=item unshift(ELEMENTS)
@@ -657,8 +736,8 @@ Checks to see if the specified index or indices have been assigned to. Returns
.sub grep :method
.param pmc test
+ .param pmc block :named('!BLOCK')
.local pmc retv
- .local pmc block
.local pmc block_res
.local pmc block_arg
.local int narg
@@ -671,15 +750,14 @@ Checks to see if the specified index or indices have been assigned to. Returns
loop:
if i == narg goto done
block_arg = self[i]
-
- newclosure block, test
+ $P0 = 'infix:=~'(block_arg, test)
+ unless $P0 goto next
block_res = block(block_arg)
-
if block_res goto grepped
goto next
grepped:
- retv.'push'(block_arg)
+ retv.'push'(block_res)
goto next
next:
@@ -1176,7 +1254,7 @@ The min operator.
=cut
.sub 'infix:min'
- .param pmc args :slurpy
+ .param pmc args
# If we have no arguments, undefined.
.local int elems
@@ -1191,11 +1269,14 @@ have_args:
.local int i
cur_min = args[0]
i = 1
+ .local pmc compare
+ compare = get_hll_global 'infix:<=>'
find_min_loop:
if i >= elems goto find_min_loop_end
$P0 = args[i]
- $I0 = 'infix:cmp'($P0, cur_min)
- if $I0 != -1 goto not_min
+ #$I0 = cur_min.'infix:cmp'($P0)
+ $I0 = cur_min.compare($P0)
+ if $I0 != 1 goto not_min
set cur_min, $P0
not_min:
inc i
@@ -1213,7 +1294,7 @@ The max operator.
=cut
.sub 'infix:max'
- .param pmc args :slurpy
+ .param pmc args
# If we have no arguments, undefined.
.local int elems
@@ -1228,11 +1309,14 @@ have_args:
.local int i
cur_max = args[0]
i = 1
+ .local pmc compare
+ compare = get_hll_global 'infix:<=>'
find_max_loop:
if i >= elems goto find_max_loop_end
$P0 = args[i]
- $I0 = 'infix:cmp'($P0, cur_max)
- if $I0 != 1 goto not_max
+ #$I0 = 'infix:<=>'($P0, cur_max)
+ $I0 = cur_max.compare($P0)
+ if $I0 != -1 goto not_max
set cur_max, $P0
not_max:
inc i
Oops, something went wrong.

0 comments on commit 3356e23

Please sign in to comment.