Permalink
Browse files

Merge remote branch 'origin/master' into serialize

  • Loading branch information...
sorear committed Sep 30, 2011
2 parents 8a35c4f + 5be99bf commit 94e9968941f9956fc37a72fb4981dcbc4a7240d3
View
@@ -1 +1 @@
-https://github.com/downloads/sorear/niecza/niecza-9.zip
+https://github.com/downloads/sorear/niecza/niecza-10.zip
View
@@ -7,7 +7,8 @@ RM=rm -f
CP=cp
cskernel=Kernel.cs Builtins.cs Cursor.cs JSYNC.cs NieczaCLR.cs Utils.cs \
- ObjModel.cs BigInteger.cs Printf.cs CodeGen.cs
+ ObjModel.cs BigInteger.cs Printf.cs CodeGen.cs \
+ GeneratedTrigFunctions.cs
# Tell make to regard the following targets as not being filenames
.PHONY: all aot test spectest clean realclean
@@ -51,6 +52,13 @@ obj/Kernel.dll: $(patsubst %,lib/%,$(cskernel))
$(CSC) /target:library /out:obj/Kernel.dll /lib:obj /unsafe+ \
$(patsubst %,lib/%,$(cskernel))
+perl5: obj/Perl5Interpreter.dll obj/p5embed.so
+obj/Perl5Interpreter.dll: obj/Kernel.dll lib/Perl5Interpreter.cs
+ gmcs /target:library /lib:obj /out:obj/Perl5Interpreter.dll /r:Kernel.dll lib/Perl5Interpreter.cs
+
+obj/p5embed.so: lib/p5embed.c
+ cc -shared -Wl,-soname,p5embed.so -o obj/p5embed.so lib/p5embed.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
+
aot: all
mono --aot run/*.dll run/Niecza.exe
View
@@ -0,0 +1,83 @@
+ Announce: Niecza Perl 6 v10
+
+This is the tenth release of Niecza Perl 6, as usual scheduled on
+the last Monday of the month.
+
+You can obtain a build of Niecza from [1]. This build contains a
+working compiler as a set of .exe and .dll files suitable for use with
+Mono or Microsoft .NET. If you wish to follow latest developments,
+you can obtain the source from [2]; however, you will still need a
+binary for bootstrapping, so you gain nothing from a "source is
+better" perspective.
+
+Niecza is a Perl 6 compiler project studying questions about the
+efficient implementability of Perl 6 features. It currently targets
+the Common Language Runtime; both Mono and Microsoft .NET are known to
+work. On Windows, Cygwin is required for source builds only; see the
+README for details.
+
+
+ List of changes
+
+
+
+[Major features]
+
+CLR interoperation is now fairly well supported! You can create
+objects, call methods, get and set fields and properties, create
+delegates, etc from Perl 6 code. See examples/ for usage ideas.
+(Examples by Martin Berends)
+
+The Mono.Posix dependency has been relaxed from load time to run
+time, meaning .NET support is back if you don't use file tests.
+
+
+
+[Minor new features]
+
+\qq[] syntax is now implemented.
+
+qp|| now returns a path object.
+
+New Test.pm6 methods succeeds_ok and fails_ok (and eval_ variants) to
+catch warnings. (Design by flussence)
+
+@foo? and %foo? in signatures are now correctly supported.
+
+Many more trig functions now implemented. (Solomon Foster)
+
+Standard grammar has been updated, in particular bringing the new
+concept of regex separators; x ** y is now spelled x+ % y. Do
+not expect other forms of % and %% to work just yet.
+
+
+
+[Selected bug fixes]
+
+sqrt now returns the correct value for arguments with a negative
+imaginary part. Also sqrt(0) returns Num not Complex now.
+
+
+
+[Other]
+
+docs/compiler.pod is more current. (Martin Berends)
+
+Prototyping has begun on Perl 5 interoperation. (Paweł Murias)
+
+
+ Getting involved
+
+Contact sorear in irc.freenode.net #perl6 or via the sender address of
+this mailing. Also check out the TODO file; whether you want to work
+on stuff on it, or have cool ideas to add to it, both are good.
+
+ Future directions
+
+I have an active branch (started this month) to unify compile-time and
+run-time metamodel representations, using serialization to bridge the
+gap. It doesn't work yet, but when it does it will enable many
+improvements, most importantly real support for BEGIN and roles.
+
+[1] https://github.com/downloads/sorear/niecza/niecza-10.zip
+[2] https://github.com/sorear/niecza
View
@@ -0,0 +1,86 @@
+# Main documentation: http://docs.go-mono.com, particularly
+# Gnome (for Gdk and Gtk) and Mono (for Cairo) libraries.
+# See also: The X-Windows Disaster at http://www.art.net/~hopkins/Don/unix-haters/handbook.html
+
+constant $GTK = "gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f";
+constant $GDK = "gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f";
+constant $GLIB = "glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f";
+# use 'gacutil -l' to look up similar module details
+
+constant Application = CLR::("Gtk.Application,$GTK");
+constant Window = CLR::("Gtk.Window,$GTK");
+constant GdkCairoHelper = CLR::("Gdk.CairoHelper,$GDK");
+constant GtkDrawingArea = CLR::("Gtk.DrawingArea,$GTK");
+constant GLibTimeout = CLR::("GLib.Timeout,$GLIB");
+
+Application.Init;
+my $window = Window.new("clock");
+my $windowSizeX = 200; my $windowSizeY = 200;
+$window.Resize($windowSizeX, $windowSizeY);
+my $drawingarea = GtkDrawingArea.new;
+$drawingarea.add_ExposeEvent: sub ($obj, $args) {
+ $args; # suppress 'declared but not used' warnings
+ my $cc = GdkCairoHelper.Create($obj.GdkWindow); # Cairo Context
+ # TODO: the following two lines pass parameters by value, need to pass by references to integers
+ my $windowX=0; my $windowY=0; my $windowWidth=0; my $windowHeight=0; my $windowDepth=0;
+ $obj.GdkWindow.GetGeometry($windowX, $windowY, $windowWidth, $windowHeight, $windowDepth);
+ $cc.SetSourceRGB(0.95.Num, 0.90.Num, 0.85.Num); $cc.Paint; # background color
+ ClockFace($cc, $windowWidth, $windowHeight);
+ # Calculate the parameters needed to draw the clock
+ my $hour = ((now.to-posix[0] % (12*3600))/3600); # there must be a more elegant way...
+ my $minute = ((now.to-posix[0] / 60) % 60);
+ my $maxRadius = ($windowWidth min $windowHeight)/2;
+ my $linewidth = ($maxRadius * 0.03).Int max 1;
+ my $radiusHour = $maxRadius * 0.5;
+ my $radiusMinute = $maxRadius * 0.7;
+ # Draw the hands of the clock
+ my $radiansHour = $hour / 12 * pi * 2;
+ my $radiansMinute = $minute / 60 * pi * 2;
+ my $xCenter = $windowWidth / 2; my $yCenter = $windowHeight / 2;
+ my $xHour = $xCenter + $radiusHour * sin($radiansHour);
+ my $yHour = $yCenter + $radiusHour * sin($radiansHour - pi / 2);
+ my $xMinute = $xCenter + $radiusMinute * sin($radiansMinute);
+ my $yMinute = $yCenter + $radiusMinute * sin($radiansMinute - pi / 2);
+ $cc.LineWidth = $linewidth;
+ $cc.MoveTo($xMinute.Int,$yMinute.Int);
+ $cc.LineTo($xCenter.Int,$yCenter.Int);
+ $cc.LineTo($xHour.Int,$yHour.Int);
+ $cc.Arc($xCenter.Int,$yCenter.Int,$linewidth.Int,0,7); # from 0 radians to more than 2*pi
+ $cc.Stroke;
+ $cc.Target.Dispose;
+ $cc.dispose-hack; # Should be $cc.Dispose but CLR interop cannot call that
+ # Tracked as https://github.com/sorear/niecza/issues/56
+};
+GLibTimeout.Add: 60000, sub () { # Update once per minute
+ $drawingarea.QueueDrawArea(0,0,$windowSizeX,$windowSizeY);
+ return True; # meaning please continue calling this timeout handler
+};
+$window.add_DeleteEvent: sub ($obj, $args) {
+ $obj; $args; # suppress "declared but not used" Potential difficulties
+ Application.Quit;
+};
+$window.Add($drawingarea);
+$window.ShowAll;
+Application.Run;
+
+sub ClockFace($cc, $width, $height)
+{
+ # Calculate dimensions relative to window size
+ my $maxRadius = ($width min $height) / 2;
+ my $centerX = $width / 2;
+ my $centerY = $height / 2;
+ my $lineWidth = ($maxRadius * 0.025).Int max 1;
+ # Draw the outer circle
+ $cc.SetSourceRGB(0.7.Num, 0, 0); # dark red
+ $cc.LineWidth = $lineWidth;
+ $cc.Arc($centerX.Int, $centerY.Int, ($maxRadius - $lineWidth).Int, 0, 7);
+ $cc.Stroke();
+ # Write the clock name on its face
+ my $clockName = "it's Niecza time!";
+ $cc.SetSourceRGB(0.7.Num, 0, 0); # dark red
+ $cc.SetFontSize(($maxRadius * 0.15).Int);
+ my $textWidth = $cc.TextExtents($clockName).Width;
+ $cc.MoveTo(($width/2 - $textWidth/2).Int, ($height * 0.85).Int);
+ $cc.ShowText($clockName);
+ $cc.Stroke();
+}
View
@@ -0,0 +1,80 @@
+# Main documentation: http://docs.go-mono.com, particularly
+# Gnome (for Gdk and Gtk) and Mono (for Cairo) libraries.
+# See also: The X-Windows Disaster at http://www.art.net/~hopkins/Don/unix-haters/handbook.html
+
+constant $GTK = "gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f";
+constant $GDK = "gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f";
+# use 'gacutil -l' to look up similar module details
+
+constant Application = CLR::("Gtk.Application,$GTK");
+constant Window = CLR::("Gtk.Window,$GTK");
+constant GdkCairoHelper = CLR::("Gdk.CairoHelper,$GDK");
+constant GtkDrawingArea = CLR::("Gtk.DrawingArea,$GTK");
+
+Application.Init;
+my $window = Window.new("sierpinski");
+my $windowSizeX = 640; my $windowSizeY = 560;
+$window.Resize($windowSizeX, $windowSizeY); # TODO: resize at runtime NYI
+my $drawingarea = GtkDrawingArea.new;
+$drawingarea.add_ExposeEvent(&ExposeEvent);
+$window.add_DeleteEvent(&DeleteEvent);
+$window.Add($drawingarea);
+$window.ShowAll;
+Application.Run; # end of main program, it's all over when this returns
+
+sub DeleteEvent($obj, $args) {
+ $obj; $args; # suppress "declared but not used" "Potential difficulties"
+ Application.Quit;
+};
+
+sub ExposeEvent($obj, $args)
+{
+ $args; # suppress "declared but not used" "Potential difficulties"
+ my $cc = GdkCairoHelper.Create($obj.GdkWindow); # Cairo Context
+ # TODO: the following two lines pass parameters by value, need to pass by references to integers
+ # my $windowX; my $windowY; my $windowWidth; my $windowHeight; my $windowDepth;
+ # $obj.GdkWindow.GetGeometry($windowX, $windowY, $windowWidth, $windowHeight, $windowDepth);
+ # Tracked as https://github.com/sorear/niecza/issues/57
+ # TODO: remove the following one line cheat that works around the above problem
+ my $windowWidth = $windowSizeX; my $windowHeight = $windowSizeY;
+ $cc.SetSourceRGB(0.6, 1, 0.6); $cc.Paint; # pale green background
+ # Start the recursive drawing process
+ my $x0=0; my $y0=0; my $x1=$windowWidth-1; my $y1=$windowHeight/2;
+ my $x2=0; my $y2=$windowHeight-1;
+ my $depth = Sierpinski($cc, $x0, $y0, $x1, $y1, $x2, $y2, True, 1);
+ my $text = sprintf("%d x %d, %d levels", $windowWidth, $windowHeight, $depth);
+ $cc.SetSourceRGB(0.6, 0.6, 1); # pale blue
+ $cc.SetFontSize($windowWidth * 0.07);
+ my $textWidth = $cc.TextExtents($text).Width;
+ my $textHeight = $cc.TextExtents($text).Height;
+ $cc.MoveTo($windowWidth*0.98 - $textWidth, $windowHeight*0.01 + $textHeight);
+ $cc.ShowText($text);
+ $cc.Target.Dispose;
+ $cc.dispose-hack; # Should be $cc.Dispose but CLR interop cannot call that
+ # Tracked as https://github.com/sorear/niecza/issues/56
+};
+
+sub Sierpinski($cc, $x0, $y0, $x1, $y1, $x2, $y2, $colorflag, $depth is copy)
+{
+ if $colorflag { $cc.SetSourceRGB(0.6, 0, 0.8); } # indigo
+ else { $cc.SetSourceRGB( 1, 1, 0.8); } # pale yellow
+ # First draw the entire main triangle in the one color
+ $cc.MoveTo($x0, $y0); $cc.LineTo($x1, $y1);
+ $cc.LineTo($x2, $y2); $cc.LineTo($x0, $y0);
+ $cc.Fill;
+ $cc.Stroke;
+ if (($x1-$x0)>2) && (($y2-$y0)>2) { # Prepare to recurse
+ ++$depth;
+ # Calculate the midpoints of the 3 edges of the triangle
+ # note - these .Int conversions make a very big speed difference
+ my $x01=(($x0+$x1)/2).Int; my $y01=(($y0+$y1)/2).Int;
+ my $x12=(($x1+$x2)/2).Int; my $y12=(($y1+$y2)/2).Int;
+ my $x20=(($x2+$x0)/2).Int; my $y20=(($y2+$y0)/2).Int;
+ # Recursively draw three smaller triangles in the other color
+ Sierpinski($cc, $x0, $y0, $x01,$y01, $x20,$y20, !$colorflag, $depth);
+ Sierpinski($cc, $x01,$y01, $x1, $y1, $x12,$y12, !$colorflag, $depth);
+ $depth =
+ Sierpinski($cc, $x20,$y20, $x12,$y12, $x2, $y2, !$colorflag, $depth);
+ }
+ $depth;
+}
View
@@ -0,0 +1,21 @@
+eval(q:to/PERL5/,:lang<perl5>);
+ print "Hel"."lo ";
+ PERL5
+eval(q:to/PERL5/,:lang<perl5>);
+ print "World\n";
+ PERL5
+
+eval(q:to/PERL5/,:lang<perl5>);
+use strict;
+use warnings;
+package Foo;
+sub baz {
+ my ($self,$arg) = @_;
+ print "Just another $arg\n";
+}
+sub new {
+ bless {},"Foo";
+}
+PERL5
+my $foo = eval(:lang<perl5>,'Foo->new');
+$foo.baz(eval(:lang<perl5>,'"Perl hacker"'));
View
@@ -7,6 +7,9 @@
using System.Runtime.CompilerServices;
namespace Niecza {
+ public interface IForeignInterpreter {
+ Variable Eval(string code);
+ }
class PosixWrapper {
static Assembly Mono_Posix;
static Type Syscall, AccessModes, Stat;
@@ -490,6 +493,10 @@ class SubstrLValue: Variable {
return Kernel.BoxAnyMO(str, Kernel.StrMO);
}
+ public static Variable MakeComplex(Complex z) {
+ return Kernel.BoxAnyMO<Complex>(z, Kernel.ComplexMO);
+ }
+
public static Variable MakeParcel(params Variable[] bits) {
return Kernel.NewRWListVar(Kernel.BoxRaw(bits, Kernel.ParcelMO));
}
@@ -878,22 +885,19 @@ class SubstrLValue: Variable {
}
}
- static Func<Variable,Variable> sin_d = sin;
- public static Variable sin(Variable a1) {
+ static Func<Variable,Variable,Variable> atan2_d = atan2;
+ public static Variable atan2(Variable a1, Variable a2) {
P6any o1 = a1.Fetch();
int r1;
- if (!o1.mo.is_any)
- return HandleSpecial1(a1,o1, sin_d);
P6any n1 = GetNumber(a1, o1, out r1);
+ P6any o2 = a2.Fetch();
+ int r2;
+ P6any n2 = GetNumber(a2, o2, out r2);
- if (r1 == NR_COMPLEX) {
- Complex v1 = PromoteToComplex(r1, n1);
- return MakeComplex(Math.Sin(v1.re) * Math.Cosh(v1.im),
- Math.Cos(v1.re) * Math.Sinh(v1.im));
- }
{
double v1 = PromoteToFloat(r1, n1);
- return MakeFloat(Math.Sin(v1));
+ double v2 = PromoteToFloat(r2, n2);
+ return MakeFloat(Math.Atan2(v1, v2));
}
}
@@ -940,6 +944,24 @@ class SubstrLValue: Variable {
return Kernel.NewROScalar(n1);
}
+ static Func<Variable,Variable> eval_perl5_d = eval_perl5;
+ static IForeignInterpreter p5_interpreter;
+ public static Variable eval_perl5(Variable v) {
+
+ // Cargo culted to get the string from the argument
+ P6any o1 = v.Fetch();
+ int r1;
+ if (!o1.mo.is_any)
+ return HandleSpecial1(v,o1, eval_perl5_d);
+ string r = o1.mo.mro_raw_Str.Get(v);
+
+ if (p5_interpreter == null) {
+ System.Reflection.Assembly a = System.Reflection.Assembly.Load("Perl5Interpreter");
+ p5_interpreter = (IForeignInterpreter) a.CreateInstance("Perl5Interpreter");
+ }
+ return p5_interpreter.Eval(r);
+ }
+
// we don't need to do nominal checking stuff here because this
// is in a method, never inlined, and as such the binder had to
// already have been called.
Oops, something went wrong.

0 comments on commit 94e9968

Please sign in to comment.