Permalink
Browse files

add some abstract base classes

Was playing around, and tried to run this 007 program:

    my q = Q::Literal::Int { value: 42 };
    say(q ~~ Q::Literal)

But it came back saying that `Q::Literal` wasn't a thing, which
felt wrong. So I added them. Now the above program prints "1\n".

We might have to make some extra effort to make those abstract types
uninstantiable. But that can be a separate commit.
  • Loading branch information...
1 parent 37af96b commit 31b531946cc513476cbb9c8d966a08be35c6767c @masak committed Jun 9, 2016
Showing with 11 additions and 5 deletions.
  1. +5 −0 lib/_007/Runtime/Builtins.pm
  2. +6 −5 t/integration/val-q-classes.t
@@ -396,6 +396,8 @@ class _007::Runtime::Builtins {
Q::ArgumentList,
Q::Block,
Q::CompUnit,
+ Q::Declaration,
+ Q::Expr,
Q::Expr::StatementListAdapter,
Q::Identifier,
Q::Infix,
@@ -418,6 +420,7 @@ class _007::Runtime::Builtins {
Q::Infix::Replicate,
Q::Infix::ArrayReplicate,
Q::Infix::Cons,
+ Q::Literal,
Q::Literal::Int,
Q::Literal::None,
Q::Literal::Str,
@@ -433,6 +436,7 @@ class _007::Runtime::Builtins {
Q::Prefix::Upto,
Q::Property,
Q::PropertyList,
+ Q::Statement,
Q::Statement::BEGIN,
Q::Statement::Block,
Q::Statement::Constant,
@@ -446,6 +450,7 @@ class _007::Runtime::Builtins {
Q::Statement::Throw,
Q::Statement::While,
Q::StatementList,
+ Q::Term,
Q::Term::Array,
Q::Term::Object,
Q::Term::Quasi,
@@ -1,20 +1,21 @@
use v6;
use Test;
-my @classes = flat
+my @p6types = flat
qx[perl6 -ne 'say ~$0 if /^class \h+ ("Q::" \S+)/' lib/_007/Q.pm].lines,
@vendethiel
vendethiel Jun 9, 2016 edited Contributor

... Cute. Wouldn't there a better (i.e. introspection-based) way to find that?

@masak
masak Jun 9, 2016 edited Owner
<moritz> m: say X::.keys
<camelia> rakudo-moar d292d7: OUTPUT«(Method NoSuchSymbol NotEnoughDimensions OS InvalidType Pairup NYI 
             PseudoPackage EXPORTHOW IO Set Package Declaration Inheritance Redeclaration StubCode UnitScope 
             PoisonedAlias Placeholder IllegalOnFixedDimensionArray Temporal Proc InvalidTypeSmiley Numeri…»
* masak tries this

$ perl6 -e 'use _007; say Q::.keys'
(CompUnit Declaration StatementList Term Infix Trait Prefix Unquote Property Block Statement Literal Identifier Postfix ArgumentList Expr PropertyList TraitList Parameter ParameterList)

<masak> yay, that works
<moritz> note that it only gives you one level at first
<masak> nodnod
<moritz> m: say X::Proc::.keys
<camelia> rakudo-moar d292d7: OUTPUT«(Async Unsuccessful)␤»
<masak> so I need to tree-walk, no biggie
<moritz> .oO( let's do the tree-walk again)

Added low-hanging-fruit issue #141 for this.

@vendethiel
vendethiel Jun 9, 2016 Contributor

yay for Perl 6 :-).

+ qx[perl6 -ne 'say ~$0 if /^role \h+ ("Q::" \S+)/' lib/_007/Q.pm].lines,
qx[perl6 -ne 'say ~$0 if /^class \h+ ("Val::" \S+)/' lib/_007/Val.pm].lines;
my @builtins = qx!perl6 -ne 'say ~$0 if /^ \h+ ([Val|Q] "::" <-[,]>+) "," \h* $/' lib/_007/Runtime/Builtins.pm!.lines;
{
- my $missing-classes = (@builtins (-) @classes).keys.map({ "- $_" }).join("\n");
- is $missing-classes, "", "all built-in types are also classes";
+ my $missing-p6types = (@builtins (-) @p6types).keys.map({ "- $_" }).join("\n");
+ is $missing-p6types, "", "all built-in types are also p6 types";
}
{
- my $missing-builtins = (@classes (-) @builtins).keys.map({ "- $_" }).join("\n");
- is $missing-builtins, "", "all classes are also built-in types";
+ my $missing-builtins = (@p6types (-) @builtins).keys.map({ "- $_" }).join("\n");
+ is $missing-builtins, "", "all p6 types are also built-in types";
}
done-testing;

0 comments on commit 31b5319

Please sign in to comment.