Browse files

Merge branch 'master' of

  • Loading branch information...
Whiteknight committed Jan 27, 2010
2 parents ef9b28f + d3bf9ad commit 8a7ba1399dce9e0d535b3f236566b15bad9f40b2
Showing with 446 additions and 246 deletions.
  1. +4 −1 matrixy.pir
  2. +23 −0 src/internals/aggregates.pir
  3. +116 −20 src/internals/dispatch.pir
  4. +239 −159 src/parser/
  5. +30 −43 src/parser/
  6. +1 −18 t/2-function.t
  7. +2 −2 t/functions/cell.t
  8. +6 −0 t/functions/columns.t
  9. +6 −0 t/functions/rows.t
  10. +16 −0 t/syntax/cell.t
  11. +3 −3 t/syntax/varargin.t
@@ -73,6 +73,9 @@ object.
$P0 = box 0
set_hll_global ['Matrixy';'Grammar';'Actions'], '$?MATRIXSQUARE', $P0
$P0 = box 0
set_hll_global ['Matrixy';'Grammar';'Actions'], '$?LVALUECELL', $P0
# list of functions that we've compiled. We cache them to prevent needing
# to recompile.
# TODO: This isn't part of the parser, find a better namespace to hold this
@@ -132,7 +135,7 @@ to the Matrixy compiler.
# TODO: We might want to add this sequence as a method on the compiler
# object, so we can call it from a library load too.
# load start up file
$P0 = null
@@ -11,6 +11,11 @@
.sub '!cell'
$P0 = new ['PMCMatrix2D']
.sub '!matrix_from_rows'
.param pmc ary :slurpy
.local pmc lengths
@@ -78,6 +83,7 @@
row = shift myiter
$I1 = row
if $I1 != length goto lengths_not_equal
inc $I0
goto loop_top
@@ -233,3 +239,20 @@
.sub '_is_defined'
.param pmc item
if null item goto not_defined
$S0 = typeof item
if $S0 == "Undef" goto not_defined
.sub '_integer_copy'
.param int i
$P0 = new 'Integer'
$P0 = i
@@ -18,10 +18,21 @@ C<(5)>.
retrieve a value using the following syntax:
foo = bar(1, 2)
bar ...
These are r-values only, not l-value assignment forms. bar could be
a matrix, a cell array, a func handle, or a subroutine call. We will take
the name of the variable and it's current value. Some rules:
1) functions are stored in the Matrixy::builtins namespace and "var" will
be null here. Look up the function in the namespace and dispatch it
2) matrices and cells will have non-null values here. They must be vivified
somewhere else.
bar could be either a matrix or a subroutine. Handles all the idiosyncratic
rules for these kinds of things in M.
@@ -39,14 +50,14 @@ rules for these kinds of things in M.
if null var goto not_a_var
.tailcall '!index_variable'(var, nargout, nargin, parens, args)
# if it's not a variable, treat it like a sub and look that up.
# if it's not a pre-existing variable, see if we have a function
sub_obj = '!lookup_function'(name)
unless null sub_obj goto found_sub
_error_all("'", name, "' undefined")
if null sub_obj goto error_var_undefined
.tailcall sub_obj(nargout, nargin, args :flat)
_error_all("'", name, "' undefined")
=item !lookup_function(name)
@@ -68,7 +79,8 @@ found, null otherwise.
if $I0 goto _dispatch_found_sub
# Second, look for a locally-defined function
sub_obj = get_hll_global ["Matrixy::functions"], name
# TODO: Fix this to be "Matrixy";"functions" instead
sub_obj = get_hll_global ["Matrixy";"functions"], name
$I0 = defined sub_obj
if $I0 goto _dispatch_found_sub
@@ -108,7 +120,13 @@ Handles equations of the following types:
a = var(b, ...)
Returns the value
Returns the value. Matrices can be indexed with foo(...) style, which returns
the scalar item at that position. Cells can be indexed with foo{...} to return
the item, or with foo(...) to return another cell containing those items.
foo parens == 0
foo(...) parens == 1
foo{...} parens == 2
@@ -119,24 +137,69 @@ Returns the value
.param int parens
.param pmc args
# TODO: We don't handle slices yet.
# Figure out which type it is, to determine where to go
$S0 = typeof var
# If it's a function handle variable, dispatch it.
unless $S0 == 'Sub' goto its_a_variable
if parens == 1 goto execute_sub_handle
if $S0 == 'Sub' goto have_func_handle
if $S0 == 'PMCMatrix2D' goto have_cell_array
$I0 = does var, "matrix"
if $I0 == 1 goto have_matrix_type
$I0 = args
if $I0 != 0 goto error_index_scalar
# For Subs, if we have parens execute it. Otherwise it's an error. If we
# want a sub reference, need to use the @ operator
if parens == 0 goto assign_func_handle
if parens == 2 goto error_func_not_cell
.tailcall var(nargout, nargin, args :flat)
# If it's an ordinary variable, do the indexing
# For cell arrays the indexing is different depending on which brackets
# we use.
if parens == 1 goto index_cell_as_cell
if parens == 2 goto index_cell_as_matrix
.tailcall '!scalar_indexing'(var, args)
# TODO: Do this right!
$P0 = '!scalar_indexing'(var, args)
$P1 = new ['PMCMatrix2D']
$P1[0;0] = $P0
# Matrices can be indexed by () but not {}.
if parens == 1 goto index_matrix_as_matrix
if parens == 2 goto error_matrix_not_cell
.tailcall '!scalar_indexing'(var, args)
_error_all("Cannot index a scalar")
_error_all("Cannot index function with {}")
_error_all("Cannot index matrix with {}")
.sub '!scalar_indexing'
.param pmc var
.param pmc args
# If we only have a 1-ary index, we need to use a separate vector indexing
# algorithm instead of the nested matrix indexing.
$I0 = args
if $I0 == 0 goto non_indexing
if $I0 == 1 goto vector_indexing
if $I0 == 2 goto matrix_indexing
_error_all("Only 0, 1, 2 indexes are supported")
_error_all("Only 0, 1, 2 indexes are currently supported")
@@ -153,8 +216,6 @@ Returns the value
dec $I1
$P0 = var[$I0;$I1]
_error_all("invalid index")
=item !is_scalar
@@ -186,12 +247,42 @@ Returns the modified variable.
# TODO: What is the difference between foo() and foo{}, besides the later
# not working for non-cells? At the moment we do basic type checking and
# Then redirect to normal indexed assignment.
# TODO: We can refactor these two assignment functions to both call a common
# indexing kernel, I think
.sub '!indexed_assign_cell'
.param pmc var
.param pmc value
.param pmc indices :slurpy
if null var goto autovivify_cell
$S0 = typeof var
if $S0 != "PMCMatrix2D" goto error_not_a_cell
.tailcall '!indexed_assign'(var, value, indices :flat)
var = new ['PMCMatrix2D']
.tailcall '!indexed_assign'(var, value, indices :flat)
_error_all("Cannot use {} indexing on a ", $S0)
.sub '!indexed_assign'
.param pmc var
.param pmc value
.param int idx
.param int array_assign
.param pmc indices :slurpy
# TODO: Handle block assignments for matrices.
# If array_assign == 1, value is a regular scalar value. Otherwise, it's an
# aggregate and idx is the index of the value
if array_assign == 0 goto have_final_value
if null value goto have_final_value
value = value[idx]
$I0 = elements indices
if $I0 == 0 goto assign_scalar
@@ -357,6 +448,11 @@ file.
.sub '!unpack_return_array'
.param pmc args
.return(args :flat)
.namespace []
Oops, something went wrong.

0 comments on commit 8a7ba13

Please sign in to comment.