Skip to content

Commit

Permalink
Fixing up little grammar things; found more issues surrounding my
Browse files Browse the repository at this point in the history
design choice (perhaps ill-advised) to only store objects of my
HLL in Fixed*Array objects (not allowing literals).  There may be
arguments each way.  I may have chosen the better but more challenging
route.
  • Loading branch information
jayemerson committed Jul 18, 2011
1 parent 0e7a416 commit 7e11dd4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 38 deletions.
16 changes: 9 additions & 7 deletions src/nqr/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ method block($/) {
make $past;
}

# Check when this is used. Might need to wrap the returned
# value if on the right side. If on the left? Hmm...
method primary($/) {
my $past := $<identifier>.ast;

Expand All @@ -310,13 +312,13 @@ method primary($/) {
}


### !!! need to consider this, not exactly sure when/how it is
### used, and might be related to the performance issue? Also
### consider whether we need to check to see if a variable already
### exists as part of the assignment? Think about copy generation,
### and so on.
### Modifed by JWE to strip out the literal. But we really
### want this to extract many values at a time, potentially.
method postfix_expression:sym<index>($/) {
my $index := $<EXPR>.ast;
print("In postfix_expression:index");
my $index := PAST::Op.new( :pirop<set__iQi>, ## NEW
$<EXPR>.ast, 0 );
#my $index := $<EXPR>.ast;
my $past := PAST::Var.new( $index,
:scope('keyed'),
:viviself('Undef'),
Expand Down Expand Up @@ -429,7 +431,7 @@ method named_field($/) {
make $past;
}

### JAY: Figure this out. Probably part of some issue:
### JAY: Probably not supported at all:
method circumfix:sym<[ ]>($/) {
## use the parrot calling conventions to
## create an array,
Expand Down
75 changes: 48 additions & 27 deletions src/nqr/Runtime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@


# Use of the ! in this way prevents NQR from being able
# to call these directly.
# to call these directly. Probably get rid of array, and
# at least change hash.
Q:PIR {
$P0 = find_lex 'array'
set_global '!array', $P0
Expand All @@ -43,7 +44,7 @@
# say(): do not modify this!
# The following was from Squaak, but I changed it to 'say' and
# changed all the tests as a result; should only be used internally
# if at all.
# if at all, but let's leave it for now.

sub say(*@args) {
pir::say(pir::join('', @args));
Expand All @@ -54,17 +55,11 @@ sub say(*@args) {
########################################
# length()

# Accepts an array, hash, or literal (incomplete checking),
# though checking a literal shouldn't be needed unless the
# query is length(5), perhaps? Not sure even then...

# Simple if we always have a Resizable*Array, right?
# Wouldn't work if we had literals, so be careful when you
# use this internally.
sub length($arg) {
return pir::elements($arg);
#if (pir::does($arg, "array") || pir::does($arg, "hash")) {
# return pir::elements($arg);
#}
#return 1;
}

#################################################################
Expand All @@ -73,11 +68,11 @@ sub length($arg) {

# Accepts an array, hash, or literal (incomplete checking)
# Could be simplified if all my NQR objects are some *Array
# objects, anyway?
# objects, anyway? Except it's nice for internal usage.
sub print(*@args) {
my $len := length(@args);
if ($len > 1) {
say("Warning: only first argument is printed.");
warning("only first argument is printed.");
}
my $arg := @args[0];
if (pir::does($arg, "array") || pir::does($arg, "hash")) {
Expand All @@ -97,7 +92,7 @@ sub warning($msg) {
# in SCRATCH.

# Modified for Resizable(Float_or_Integer)Array
# Looping starts at the end to avoid resizing, rathe
# Looping starts at the end to avoid resizing, rather
# than starting at 0.
sub seq($from, $to, $by) {
my $f := $from[0];
Expand Down Expand Up @@ -128,11 +123,8 @@ sub paste(*@args) {
for @args -> $arg {
if (pir::does($arg, "array")) { $arg := $arg[0]; }
@sargs[@sargs] := ~$arg;
#if (pir::typeof($arg) ne 'String') {
# Could also have been used:
# @sargs[@sargs] := pir::set__sN($arg);
#} else {
# @sargs[@sargs] := $arg;
#}
}
@ans[0] := pir::join(' ', @sargs);
return @ans;
Expand All @@ -142,7 +134,9 @@ sub paste(*@args) {
# c():

# Modified for Resizable(Float_or_Integer)Array, but no
# longer uses strings.
# longer uses strings. Benchmarks indicated this was
# pretty slow. It was one of my first, and could have
# lots of resizing.
sub c(*@args) {
my @ans;
my @arg;
Expand Down Expand Up @@ -174,21 +168,48 @@ sub c(*@args) {
}



# Was very inefficient using c(), rebuilt for Float only,
# still could be better.
sub rep($arg, $times) {
my $len := length($arg); # Eventually might be a PMC
my $i := 0;
my $j;
my @ans := pir::new("ResizableFloatArray");
while ($i < $times[0]) {
$j := 0;
while ($j < $len) {
@ans[$i*$len+$j] := $arg[$j];
$j++;
if (pir::typeof($arg[0]) eq 'Float') {
my @ans := pir::new("ResizableFloatArray");
while ($i < $times[0]) {
$j := 0;
while ($j < $len) {
@ans[$i*$len+$j] := $arg[$j];
$j++;
}
$i++;
}
$i++;
return @ans;
}
if (pir::typeof($arg[0]) eq 'Integer') {
my @ans := pir::new("ResizableIntegerArray");
while ($i < $times[0]) {
$j := 0;
while ($j < $len) {
@ans[$i*$len+$j] := $arg[$j];
$j++;
}
$i++;
}
return @ans;
}
if (pir::typeof($arg[0]) eq 'String') {
my @ans := pir::new("ResizableStringArray");
while ($i < $times[0]) {
$j := 0;
while ($j < $len) {
@ans[$i*$len+$j] := $arg[$j];
$j++;
}
$i++;
}
return @ans;
}
return @ans;
}


Expand Down
11 changes: 7 additions & 4 deletions t/00-sanity.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

say("1..19")
say("1..20")

# Basic assignment
a <- 1
print(paste("ok", a))


# Array indexing and length (note: indexing starts at 0)
a <- rep(2,3)
print(paste("ok", a[1]))
a <- rep(100,100)
print(paste("ok", a[0]-a[99]+a[50]-98))
print(paste("ok", length(a)))

# A function
Expand Down Expand Up @@ -53,7 +54,9 @@ while (j < 2) {
j = j + 1
}

# for-statement
# seq()
a <- seq(1, 20, 2)
print(paste("ok", a[length(a)-1]))



0 comments on commit 7e11dd4

Please sign in to comment.