[Patch] math.ops
I've added a couple of functions to math.ops now. What do you think about adding complex functions? ( complex.h ) /josef diff -urN parrot.orig/MANIFEST parrot/MANIFEST --- parrot.orig/MANIFESTThu Jun 13 00:12:15 2002 +++ parrot/MANIFEST Thu Jun 13 09:31:56 2002 @@ -354,6 +354,7 @@ lib/Test/Simple.pm lib/Text/Balanced.pm make.pl +math.ops memory.c misc.c obscure.ops diff -urN parrot.orig/math.ops parrot/math.ops --- parrot.orig/math.opsThu Jan 1 01:00:00 1970 +++ parrot/math.ops Thu Jun 13 09:31:10 2002 @@ -0,0 +1,161 @@ +/* +** math.ops +*/ + +VERSION = PARROT_VERSION; + +=head1 NAME + +math.ops + +=cut + +=head1 DESCRIPTION + +Parrot's library of math ops. + +=cut + + + + +=head2 Other mathematical operations + +Implementations of various mathematical operations + +=over 4 + +=cut + + + + +=item B(out INT, in INT, in INT) + +=item B(out INT, in NUM, in NUM) + +Greatest Common divisor of $2 and $3. + +=cut + +inline op gcd(out INT, in INT, in INT) { + +UINTVAL q = 0; +UINTVAL c = 0; + while ($3 != 0) { +q = floor( (FLOATVAL)$2/$3 ); +c = $2 - $3*q; +$2 = $3; +$3 = c; + } + $1 = $2; + goto NEXT(); +} + +inline op gcd(out INT, in NUM, in NUM){ + +UINTVAL q = 0; +UINTVAL c = 0; + while ($3 != 0) { +q = floor( (FLOATVAL)$2/$3 ); +c = $2 - $3*q; +$2 = $3; +$3 = c; + } + $1 = $2; + goto NEXT(); +} + + + +=item B(out INT, in INT, in INT) + +=item B(out NUM, in INT, in INT) + +Least Common Multiple + +=cut + +inline op lcm(out INT, in INT, in INT) { + +UINTVAL q = 0; +UINTVAL c = 0; +INTVAL saved_var2 = $2; +INTVAL saved_var3 = $3; + while ($3 != 0) { +q = floor( (FLOATVAL)$2/$3 ); +c = $2 - $3*q; +$2 = $3; +$3 = c; + } + saved_var2 = saved_var2/$2; + $1 = saved_var2*saved_var3; + goto NEXT(); +} + +inline op lcm(out NUM, in INT, in INT) { + +UINTVAL q = 0; +UINTVAL c = 0; +INTVAL saved_var2 = $2; +INTVAL saved_var3 = $3; + while ($3 != 0) { +q = floor( (FLOATVAL)$2/$3 ); +c = $2 - $3*q; +$2 = $3; +$3 = c; + } + saved_var2 = saved_var2/$2; + $1 = (FLOATVAL)saved_var2*saved_var3; + goto NEXT(); +} + + + + +=item B(out INT, in INT) + +=item B(out NUM, in INT) + +Factorial, n!. Calculates the product of 1 to N. + +=cut + +inline op fact(out INT, in INT) { + +UINTVAL i = $2; +UINTVAL q = 1; + while(i>0) { +q = q*i; +i--; + } + $1 = q; + goto NEXT(); +} + +inline op fact(out NUM, in INT) { + +UINTVAL i = $2; +UINTVAL q = 1; + while(i>0) { +q = q*i; +i--; + } + $1 = q; + goto NEXT(); +} + + + + + +=head1 COPYRIGHT + +Copyright (C) 2001-2002 Yet Another Society. All rights reserved. + +=head1 LICENSE + +This program is free software. It is subject to the same license +as the Parrot interpreter itself. + +=cut
[Oscon] Lightning Talks
If you are going to attend the Open Source Convention; please consider putting in a lightning talk. From: Nathan Torkington Subject: [Oscon] Lightning Talks Please pass the word around that we need more lightning talk proposals: http://conferences.oreillynet.com/cs/os2002/create/e_sess?x-t=os2002_lt.create.form Lightning talks are for works-in-progress, ideas you think others could implement, explanations of neat things you've discovered, philosophical arguments, success stories, or anything else you can fit in five minutes. They're fun for the audience (it's like channel-surfing at a conference!) and fun for the speakers. Thanks, Nat If you don't know how they work, then there is also a page written by Mark-Jason Dominus here: http://perl.plover.com/lt/ (mjd coordinated most of the previous lightning talk sessions). -- ask bjoern hansen, http://askbjoernhansen.com/ !try; do();
Globals!
Folks, We have global variables. (And have for some time, according to the commit logs) I've tweaked core.ops a little, made sure the global symbol table is part of the root set for the GC, and added in a test for it. Anyone got anything else on the todo list that's actually done? :) -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
lex behavior
I'm still unclear as to how you implement lex-like longest token rule with P6 regexes. If the | operator grabs the first one it matches, how do I match "bacamus" out of this?: "bacamus" =~ / b.*a | b.*s / Luke
Re: lex behavior
> I'm still unclear as to how you implement lex-like longest token rule with > P6 regexes. If the | operator grabs the first one it matches, how do I > match "bacamus" out of this?: > > "bacamus" =~ / b.*a | b.*s / Borrow this trick from Parse::RecDescent: rule max (*@candidates) {{ my $best; my $startpos = .pos; for @candidates -> $next { .pos = $startpos; $best = $0 if /<$next>/ && $best && $0.length < $best.length { } fail unless $best; let $0 := $best; .pos = $best.pos; }} then: "bacamus" =~ / /; Damian
RE: lex behavior
Damian Conway: # > I'm still unclear as to how you implement lex-like longest # token rule # > with P6 regexes. If the | operator grabs the first one it matches, # > how do I match "bacamus" out of this?: # > # > "bacamus" =~ / b.*a | b.*s / # # Borrow this trick from Parse::RecDescent: # # rule max (*@candidates) {{ # my $best; # my $startpos = .pos; # for @candidates -> $next { # .pos = $startpos; # $best = $0 if /<$next>/ && $best && # $0.length < $best.length { # } # fail unless $best; # let $0 := $best; # .pos = $best.pos; # }} # # then: # # "bacamus" =~ / /; Will that handle captures correctly? Maybe you should temporize $0... --Brent Dax <[EMAIL PROTECTED]> @roles=map {"Parrot $_"} qw(embedding regexen Configure) Early in the series, Patrick Stewart came up to us and asked how warp drive worked. We explained some of the hypothetical principles . . . "Nonsense," Patrick declared. "All you have to do is say, 'Engage.'" --Star Trek: The Next Generation Technical Manual
Re: lex behavior
I figured that (I actually did it, in a less-pretty form, in my early Perl days when I wrote a syntax highlighter for my website). So there's no elegant way the new regexes support it? That's a shame. But I see now how state objects are a very cool idea. Oh, and I'd just thought I'd let everyone know: I'm writing a vim syntax highlighting file for Perl 6 at the moment. I'll post it when it's in an acceptable state. > Borrow this trick from Parse::RecDescent: > > rule max (*@candidates) {{ > my $best; > my $startpos = .pos; > for @candidates -> $next { > .pos = $startpos; > $best = $0 if /<$next>/ && $best && $0.length < $best.length { > } > fail unless $best; > let $0 := $best; > .pos = $best.pos; > }} > > then: > > "bacamus" =~ / /; > > > Damian Luke -- Base 8 is just like base 10 really... if you're missing two fingers. --Tom Lehrer, "New Math"
RE: lex behavior
Luke Palmer wrote: > So there's no elegant way the new regexes support it? > That's a shame. seems fairly elegant to me, with 2 caveats: First, we need assertions as part of the default library. I.e. we shouldn't need a C for things like min and max. Second, we should eliminate as much of the syntactic noise as possible: would be nice -- with parenthesis, or the like, needed only when things become ambiguous. I think, though am not sure, that having whitespace act as an arglist separator in assertions makes it cleaner. There are definitely strong counter-arguments. But I would like to minimize the clutter: and the baseline is that alternation requires only one character. Dave.
RE: lex behavior
On Thu, 13 Jun 2002, David Whipp wrote: : Second, we should eliminate as much of the syntactic noise as possible: : : : : would be nice -- with parenthesis, or the like, needed only when things : become ambiguous. I think, though am not sure, that having whitespace act as : an arglist separator in assertions makes it cleaner. There are definitely : strong counter-arguments. But I would like to minimize the clutter: and the : baseline is that alternation requires only one character. That would be problematic as a default rule. You wouldn't be able to write assertions like: To get more syntactic control would take something like a macro facility. But that has its own problems. Regexes will be tough to debug even without that. I think the biggest drawback is that it goes against the shiny new policy about (in)significant whitespace. On the other hand, it might be possible with regex introspection to dissect the alternatives of and evaluate them separately. But the most straightforward way to match longest is probably to use :any to get a superposition of matches, and then pull out the longest match. Perhaps there could be a :longest that does that internally, and could optimize away cases that couldn't possibly be longest. (And possibly even invoke a DFA optimizer to make it one pass, in the absence of internal captures.) Larry
Assembler bug
I'll put this into RT tracker. I noticed this while integrating some code from Angel Faus for the IMCC compiler. The assembler currently does not check if your register is in the correct range. So it allows: set I11, -1 At least I don't think we've implemented unlimited register file size. :) I'm sure this is an easy fix, I'll look at it after dinner if someone else doesn't snag it. -Melvin
IMCC 0.0.3 beefs up
I've just committed the 3rd revision of the Parrot intermediate compiler. Angel Faus has added register spilling to work with the graph-coloring allocator. Currently we spill regs to an array in P31. Given that we don't have random access stacks, this is the only fast way to do this. Much thanks to Angel; anyone who has written a register allocator knows the spiller is the ugliest part to get right, and he stepped in just when I was getting swamped at work. I do not like the fact that we have to use keyed access at a low level to accomplish this, so I hope we consider adding random access to stacks. If you haven't looked at IMCC, we've written a complete register allocator that you can map symbolic variables to. This means that anyone that wishes to write a compiler for Parrot can just emit code for IMCC and let it handle the dirty work of VM register allocation, spillage, peephole optimization, constant expression evaluation, etc. -Melvin
Re: Assembler bug
Melvin Smith wrote: > > I'll put this into RT tracker. > > I noticed this while integrating some code from Angel Faus for > the IMCC compiler. The assembler currently does not check > if your register is in the correct range. So it allows: > > set I11, -1 > > At least I don't think we've implemented unlimited register file size. :) > > I'm sure this is an easy fix, I'll look at it after dinner if someone > else doesn't snag it. > > -Melvin Implied patch applied, thanks. -- Jeff <[EMAIL PROTECTED]>
m:foobar syntax
I came across this problem when writing the vim syntax file: How can we tell the difference between these?: m:option(pattern) m:option(argument)/pattern/ Luke
RE: foobar syntax
Luke Palmer: # I came across this problem when writing the vim syntax file: # # How can we tell the difference between these?: # # m:option(pattern) # m:option(argument)/pattern/ The difference is that the first is a syntax error. :^) I think it says that '(' is no longer a valid delimiter, and if you want a balanced one '[' is usually ideal. --Brent Dax <[EMAIL PROTECTED]> @roles=map {"Parrot $_"} qw(embedding regexen Configure) Early in the series, Patrick Stewart came up to us and asked how warp drive worked. We explained some of the hypothetical principles . . . "Nonsense," Patrick declared. "All you have to do is say, 'Engage.'" --Star Trek: The Next Generation Technical Manual
Re: m:foobar syntax
> I came across this problem when writing the vim syntax file: > > How can we tell the difference between these?: > > m:option(pattern) > m:option(argument)/pattern/ Easy. As A5 states, (...) are no longer leagal regex delimiters. So the first is a syntax error. :-) Damian
parrot 0.0.6 on win2k
hi i am under win 2k perl 5.6.1 i have dowloaded and tried 0.0.6 there is a pb to compile (that is easely catched) is it the place to give the patch ? after that parrot .exe cannot run any program, the message is : segfault for the fact.pasm given in examples directory or pack_file_unpack : illegal bytecode table segment size 3082 (must be multiple of 4) parrot.vm : cannot unpack essai.pbc for a simple parrot.pasm (that has been assembled with perl assemble.pl essai.pasm essai.pbc essai.pasm: print "The first 20 fibonacci numbers are:\n" end is it the place to send bug reports ? pascal
Re: IMCC 0.0.3 beefs up
At 7:45 PM -0400 6/13/02, Melvin Smith wrote: >I do not like the fact that we have to use keyed access at a low level >to accomplish this, so I hope we consider adding random access >to stacks. It's on the list--it's just never gotten implemented. Time to fix that, I think. We've added (or are working on adding) real integer access to arrays without keys, but that's not in, and this will likely be faster. >If you haven't looked at IMCC, we've written a complete >register allocator that you can map symbolic variables to. This means >that anyone that wishes to write a compiler for Parrot can just >emit code for IMCC and let it handle the dirty work of VM register >allocation, spillage, peephole optimization, constant expression >evaluation, etc. And Yay, Melvin! (And Angel!) -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
[Proposal] new pmc class: matrix
What do you all think about adding a matrix class. It would be really usefull to have it as a class.. Pseudo code: new P0, Matrix, 3, 3 set P0, 0, 0, 1 set P0, 0, 1, 3 set P0, 0, 2, 1 set P0, 1, 0, 2 set P0, 1, 1, 2 set P0, 1, 2, 2 set P0, 2, 0, 3 set P0, 2, 0, 1 set P0, 2, 0, 3 print P0 would then give: 1 2 3 3 2 1 1 2 3 Or another way could be using matlab like syntax (treated as a string): new P0, Matrix, 3, 3 set P0, "[1 2 3; 3 2 1; 1 2 3]" A third option maybe (if its possible) would be to actually adding above syntax to the assembler but that would probably look to ugly new P0, Matrix, 3, 3 set P0, [1 2 3; 3 2 1; 1 2 3] Maybe one could use (...) and "## args" in c to possible create a syntax like : new P0, Matrix, 3, 3 set P0, 1,2,3,,3,2,1,,1,2,3 What do you all think about this.. It would be really usefull to have builtin vector operations like transpose eigevects etc... /josef