From 264840db00dc2565041af39971d14b593e3392f4 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Tue, 20 Oct 2009 21:10:46 -0400 Subject: [PATCH] move helper functions out of the matrixy.pir driver file and into src/internals/* --- matrixy.pir | 32 -------------------------------- src/internals/aggregates.pir | 12 ++++++++++++ src/internals/matrix.pir | 17 +++++++++++++++++ src/internals/parser.pir | 10 ++++++++++ 4 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 src/internals/aggregates.pir create mode 100644 src/internals/parser.pir diff --git a/matrixy.pir b/matrixy.pir index 622627f..e31c9be 100644 --- a/matrixy.pir +++ b/matrixy.pir @@ -89,38 +89,6 @@ to the Matrixy compiler. .include 'src/gen_grammar.pir' .include 'src/gen_actions.pir' -.namespace [] - -.sub '!hash' - .param pmc fields :slurpy :named - .return (fields) -.end - -.sub '_new_empty_array' - $P0 = new 'ResizablePMCArray' - .return($P0) -.end - -# TODO: Move this to somewhere in src/internals/* -.sub '_terminator_has_semicolon' - .param string term - $S0 = substr term, 0, 1 - if $S0 == ';' goto has_semicolon - .return(0) - has_semicolon: - .return(1) -.end - -.sub '!get_first_array_row' - .param pmc m - $S0 = typeof m - if $S0 == 'ResizablePMCArray' goto have_matrix - .return(m) - have_matrix: - $P0 = m[0] - .return($P0) -.end - =back =cut diff --git a/src/internals/aggregates.pir b/src/internals/aggregates.pir new file mode 100644 index 0000000..335f811 --- /dev/null +++ b/src/internals/aggregates.pir @@ -0,0 +1,12 @@ + +.namespace [] + +.sub '!hash' +.param pmc fields :slurpy :named +.return (fields) +.end + +.sub '_new_empty_array' +$P0 = new 'ResizablePMCArray' +.return($P0) +.end diff --git a/src/internals/matrix.pir b/src/internals/matrix.pir index 647ea2c..ad47a84 100644 --- a/src/internals/matrix.pir +++ b/src/internals/matrix.pir @@ -526,6 +526,23 @@ Can only dispatch over an internal function, not a builtin or a library routine. # TODO: Implement this. .end +=item !get_first_array_row + +Get the first row from a matrix. If it's not a matrix/vector, just return +the PMC itself + +=cut + +.sub '!get_first_array_row' + .param pmc m + $S0 = typeof m + if $S0 == 'ResizablePMCArray' goto have_matrix + .return(m) + have_matrix: + $P0 = m[0] + .return($P0) +.end + =back =cut diff --git a/src/internals/parser.pir b/src/internals/parser.pir new file mode 100644 index 0000000..e229504 --- /dev/null +++ b/src/internals/parser.pir @@ -0,0 +1,10 @@ +.namespace [] + +.sub '_terminator_has_semicolon' + .param string term + $S0 = substr term, 0, 1 + if $S0 == ';' goto has_semicolon + .return(0) + has_semicolon: + .return(1) +.end