Skip to content

Commit

Permalink
add some functions to manipulate parrot objects better without descen…
Browse files Browse the repository at this point in the history
…ding into inline PIR
  • Loading branch information
Whiteknight committed Dec 8, 2009
1 parent 95a1beb commit c58eecd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/builtins/parrot_method.pir
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.namespace ["_Matrixy";"builtins"]

.sub parrot_method
.param int nargout
.param int nargin
.param pmc obj
.param pmc method
.param pmc args :slurpy

$S0 = typeof method
if $S0 == "String" goto have_string
if $S0 == "CharMatrix2D" goto have_string_array
error("method must be a string")
have_string:
$S0 = method
goto have_method_str
have_string_array:
$S0 = method[0]
have_method_str:
$P1 = new ['PMCMatrix2D']
($P0 :slurpy) = obj.$S0(args :flat)
if null $P0 goto just_return
$P1.'initialize_from_array'($P0)
just_return:
.return($P1)
.end
27 changes: 27 additions & 0 deletions src/builtins/parrot_new.pir
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.namespace ["_Matrixy";"builtins"]

.sub parrot_new
.param int nargout
.param int nargin
.param pmc type
.param pmc init :optional
.param int has_init :opt_flag

$S0 = typeof type
if $S0 == "String" goto have_string
if $S0 == "CharMatrix2D" goto have_string_array
error("type must be a string")
have_string:
$S0 = type
goto have_type_str
have_string_array:
$S0 = type[0]
have_type_str:
if has_init goto use_initializer
$P0 = new [$S0]
.return($P0)
use_initializer:
$P0 = new [$S0], init
.return($P0)
.end

0 comments on commit c58eecd

Please sign in to comment.