Skip to content

Instantly share code, notes, and snippets.

@moritz
Created June 29, 2011 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/1053498 to your computer and use it in GitHub Desktop.
Save moritz/1053498 to your computer and use it in GitHub Desktop.
Trying to make 1/2 a Rat
diff --git a/src/Perl6/Metamodel/BOOTSTRAP.pm b/src/Perl6/Metamodel/BOOTSTRAP.pm
index c742fcf..941d3cf 100644
--- a/src/Perl6/Metamodel/BOOTSTRAP.pm
+++ b/src/Perl6/Metamodel/BOOTSTRAP.pm
@@ -412,6 +412,12 @@ my stub Num metaclass Perl6::Metamodel::ClassHOW { ... };
Num.HOW.add_parent(Num, Real);
Num.HOW.add_attribute(Num, BOOTSTRAPATTR.new(:name<$!value>, :type(num), :box_target
+# class Rat is Cool does Real {
+# ....
+# }
+my stub Rat metaclass Perl6::Metamodel::ClassHOW { ... };
+Rat.HOW.add_parent(Rat, Real);
+
# Stash these common types for box ops.
pir::perl6_set_types_ins__vPPP(Int, Num, Str);
diff --git a/src/core/Int.pm b/src/core/Int.pm
index 136b871..acf7d77 100644
--- a/src/core/Int.pm
+++ b/src/core/Int.pm
@@ -69,8 +69,7 @@ multi infix:<*>(Int \$a, Int \$b) {
}
multi infix:</>(Int \$a, Int \$b) {
- # XXX should really return a Rat
- $a.Num / $b.Num
+ Rat.new($a, $b)
}
multi infix:<div>(Int \$a, Int \$b) {
$ ./perl6 -e '1/2'
Could not find sub &Rat
current instr.: 'infix:</>' pc 226798 (src/gen/CORE.setting.pir:58105) (:897)
called from Sub '_block1002' pc 82 ((file unknown):72) (:1)
called from Sub '_block1000' pc 14 ((file unknown):20) (:1)
called from Sub 'nqp;HLL;Compiler;_block1782' pc 34185 (src/stage2/gen/NQPHLL.pir:10821)
called from Sub 'nqp;HLL;Compiler;eval' pc 34043 (src/stage2/gen/NQPHLL.pir:10776)
called from Sub 'nqp;HLL;Compiler;_block1864' pc 35410 (src/stage2/gen/NQPHLL.pir:0)
called from Sub 'nqp;HLL;Compiler;command_line' pc 35094 (src/stage2/gen/NQPHLL.pir:0)
called from Sub 'MAIN' pc 638 (src/gen/perl6.pir:230)
called from Sub '_block1000' pc 100 (src/gen/perl6.pir:67)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment