Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 150 lines (107 sloc) 3.019 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
=head1 NAME

F<src/builtins/stdio.pir> - built-in stdio functions

=head1 DESCRIPTION

This file contains some of the basic functions for I/O on
the console and in files.

=head1 Functions

=over 4

=cut

.namespace []

=item _disp_all(PMC args :slurpy)

This is similar to the disp() function above, accept that
it prints out a slurpy list of arguments to the terminal.

This is non-standard, so it begins with an underscore.

=cut

.sub '_disp_all'
    .param pmc args :slurpy
    # TODO: Update this to call '!get_matrix_string'
    .local pmc myiter
    myiter = iter args
  iter_loop:
    unless myiter goto iter_end
    $S0 = shift myiter
    print $S0
    goto iter_loop
  iter_end:
    print "\n"
    .return (1)
.end


=item _error_all(PMC args :slurpy)

raises an exception with the message which is given
piecewise. The arguments are stringified and concatinated,
and the resulting message is used to raise an exception.

=cut

.sub '_error_all'
    .param pmc args :slurpy
    .local pmc myiter
    # TODO: Update this to call '!get_matrix_string'
    myiter = iter args
    $S0 = ''
  iter_loop:
    unless myiter goto iter_end
    $S1 = shift myiter
    $S0 = $S0 . $S1
    goto iter_loop
  iter_end:
    $P1 = new 'Exception'
    $P1['message'] = $S0
    throw $P1
    .return()
.end

=item _print_result_a(PMC name, PMC value, STRING term)

Handles the MATLAB/Octave behavior where the value of an
assigment is printed to the terminal, unless the statement
is postfixed with a ';'. If the ';' exists, nothing is
printed. Otherwise, the name of the variable and the value
that has been assigned to it is printed.

For example, typing C<x = 5> at the prompt without a
semicolor will cause Octave to print:

    x =

        5

=item _print_result_e(PMC value, STRING term)

Handles the MATLAB/Octave behavior where the value of an
expression is printed to the terminal unless the statement
is postfixed with a ';'. If the ';' exists, nothing is
printed. Otherwise, the value of the expression is assigned
to the C<ans> variable, and it is printed to the terminal.

For example, typing C<5 + 4> at the prompt without a
semicolon will cause Octave to print

    ans =

        9

In this way, Matrixy can be used as a sort of desk calculator.

=item _print_result_a(PMC value, STRING term)

Prints the value of a bare variable or subroutine call name. So writing

  x(5)

Will print out

  ans =

      9

if the result of the variable x, or the subroutine call x() returns the value
"9" with argument "5".

=cut

.sub '!print_result_a'
    .param pmc name
    .param pmc value
    print name
    say " = "
    $S0 = value
    say $S0
    set_hll_global "ans", value
    .return()
.end

.sub '!print_result_e'
    .param pmc value
    $I0 = defined value
    unless $I0 goto end_print_result
    print "ans = "
    $S0 = value
    say $S0
    set_hll_global "ans", value
  end_print_result:
    .return()
.end

.sub '!store_last_ans'
    .param pmc value
    set_hll_global "ans", value
.end

=back

=cut

Something went wrong with that request. Please try again.