Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: everything is an object #242

Open
wants to merge 91 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
a46a974
asset-capture Val::Int
Aug 19, 2017
885f903
remove Val::Int
Aug 19, 2017
e53099c
Turn TYPE into a hash
Aug 19, 2017
2fc4d1d
asset-capture Val::Str
Aug 19, 2017
450d49f
remove Val::Str
Aug 19, 2017
317d4ea
asset-capture Val::Array
Aug 21, 2017
f4af823
remove Val::Array
Aug 21, 2017
c19c130
de-duplicate code that creates TYPE
Aug 26, 2017
29c9d46
asset-capture Val::NoneType
Aug 26, 2017
ae4f76f
remove Val::NoneType
Aug 26, 2017
97a8bcf
asset-capture Val::Bool
Aug 26, 2017
e0aec7c
remove Val::Bool
Aug 26, 2017
eb2f5b1
demote NoneType and Bool to enum types
Aug 27, 2017
3816fa6
asset-capture Val::Exception
Aug 27, 2017
e7d9169
remove Val::Exception
Aug 27, 2017
6182b03
asset-capture Val::Object
Aug 30, 2017
383cf08
remove Val::Object
Aug 30, 2017
1f610aa
remove unuser &wrap subroutine
Aug 31, 2017
118e6d2
rename s/sevenize/wrap/g
Aug 31, 2017
8f369ff
check for properties that they are declared as fields
Sep 3, 2017
30599b4
Move .call from Runtime to Val::Sub
Sep 4, 2017
a96c4d6
Switch from &.hook mechanism to NativeSub
Sep 4, 2017
caf3db1
asset-capture Val::Sub
Sep 7, 2017
1c5b201
remove Val::Sub
Sep 7, 2017
199d152
eliminate NativeSub
Sep 7, 2017
be4e43f
move wrapped sub check inside internal-call
Sep 7, 2017
59ebf73
asset-capture Val::Macro
Sep 7, 2017
93fc6c6
remove Val::Macro
Sep 7, 2017
817e08d
asset-capture Val::Regex
Sep 7, 2017
3c8c9f0
remove Val::Regex
Sep 7, 2017
22f6c24
quarantine t/features/expr.t for now
Sep 8, 2017
976aece
Split up TYPE declaration and initialization
Sep 8, 2017
88e6c4e
move TYPE above _007::Type
Sep 8, 2017
1aeed9d
introduce _007::Type.base
Sep 9, 2017
95a4d7a
implement Object.isa
Sep 9, 2017
5d11baf
check for Sub/Macro using subtyping check
Sep 9, 2017
d7c817b
Do subtyping checks instead of exact typechecks
Sep 9, 2017
a3213c0
Compare with None directly
Sep 9, 2017
79edb9d
field declarations are inherited
Sep 10, 2017
221d534
remove comment
Sep 10, 2017
b6b2dd1
asset-capture the Q hierarchy
Sep 16, 2017
2f2e0e4
move a few exception types to where they belong
Sep 16, 2017
31b84e7
remove Q.pm
Sep 16, 2017
92d1a13
asset-capture Val::Type
Sep 16, 2017
01e8722
remove Val::Type
Sep 16, 2017
14babac
remove Val
Sep 16, 2017
66eb8d7
rename Val.pm -> Object.pm
Sep 16, 2017
e55daa7
remove MONKEY-SEE-NO-EVAL imports
Sep 16, 2017
6df3130
remove unnecessary exception for Subs
Sep 16, 2017
234b2aa
Sort out some Dict/property confusion
Sep 16, 2017
4278daa
Turn _007::Type.create into a sub
Sep 16, 2017
8966922
remove some obsolete/redundant code
Sep 16, 2017
0e83895
Simplify Helper::Str a bit
Sep 16, 2017
421eaad
move Helper up
Sep 16, 2017
9f7e027
separate Type.pm from Object.pm
Sep 16, 2017
b6f1a23
demote Helper from class to sub
Sep 16, 2017
0917b3a
remove a lot of unnecessary typechecks
Sep 16, 2017
5373115
get rid of type-of sub
Sep 16, 2017
2ed8c5e
Put back the API documentation the way it was.
Sep 17, 2017
c43a515
sort out Object/Dict in the documentation
Sep 17, 2017
8d4d209
document Q::Term::Dict
Sep 17, 2017
41b5c8d
simplify the lookup for prefixes/infixes
Sep 18, 2017
2838b0a
add count-builtins script
Sep 18, 2017
a0b03b8
put back the type information in X::Type exceptions
Sep 18, 2017
1b7566f
define Str and repr as built-in methods
Sep 18, 2017
f501134
remove obsolete method
Sep 18, 2017
8864baa
defined Bool as built-in method
Sep 18, 2017
636903e
Revert "quarantine t/features/expr.t for now"
Sep 18, 2017
bca5a8d
abstract &stringify
Sep 19, 2017
71e6b62
abstract &reprify
Sep 19, 2017
7d0b4f2
abstract &boolify
Sep 19, 2017
36d3e86
Use .is-a, not .isa
Sep 19, 2017
ceaa029
re-introduce parts of object.t as dict.t
Sep 19, 2017
6df9fdb
re-introduce the rest of objects.t as objects.t
Sep 19, 2017
2f525da
No more .property in Runtime; hello bound-method
Sep 19, 2017
379b8e6
remove 'runtime' parameter on all Qtypes
Sep 20, 2017
7d53b56
Document .size() and .keys() on Dict
Sep 20, 2017
8bee671
get rid of _007::Object::Enum
Sep 20, 2017
b69ad14
Make fields hashes, not just strings
Sep 20, 2017
5dc3031
Give Type a $.type
Sep 20, 2017
7184e08
Extract common role
Sep 20, 2017
c6fb067
Typecheck during object creation
Sep 20, 2017
da44664
Allow checking of type unions
Sep 20, 2017
d37597f
Lift some common code into wrap-fn
Sep 21, 2017
819aaaa
Comment &wrap, internally documenting it
Sep 21, 2017
a2b153a
Allow fields to be optional
Oct 2, 2017
311cff9
Make Q::Identifier's .frame field optional
Oct 7, 2017
31b0fe6
Make Q::Statement::My's .expr field optional
Oct 7, 2017
f2f25fa
Add a long-missed `new` in the tutorial
Oct 7, 2017
b79e0be
Make Q::Statement::If's .else field optional
Oct 7, 2017
dd967dd
Make Q::Statement::Return's .expr field optional
Oct 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"_007::Parser::Actions" : "lib/_007/Parser/Actions.pm",
"_007::Parser::Syntax" : "lib/_007/Parser/Syntax.pm",
"_007::Precedence" : "lib/_007/Precedence.pm",
"_007::Q" : "lib/_007/Q.pm",
"_007::Runtime" : "lib/_007/Runtime.pm",
"_007::Builtins" : "lib/_007/Builtins.pm",
"_007::Test" : "lib/_007/Test.pm",
"_007::Val" : "lib/_007/Val.pm"
"_007::Object" : "lib/_007/Object.pm",
"_007::Type" : "lib/_007/Type.pm"
},
"support" : { "source" : "git://github.com/masak/007.git" }
}
74 changes: 74 additions & 0 deletions bin/count-builtins
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env perl6
use v6;

my $type_count = 0;
my $bound_method_count = 0;
my $runtime_builtin_method_count = 0;
my $built_in_subs = 0;
my $exception_types_in_007 = 0;
my $exception_types_in_perl6 = 0;

for <lib/_007/Type.pm> -> $file {
for $file.IO.lines {
if /^ "TYPE<" (<-[>]>+) ">" \h* "=" \h* "_007::Type.new(" / {
$type_count++;
if $0 eq "Exception" || $0.starts-with("X::") {
$exception_types_in_007++;
}
}
}
}

for <lib/_007/Object.pm> -> $file {
for $file.IO.lines {
if /^ "sub bound-method(" / ff /^ "}" / {
if /^ " " ** 4 \S / {
if /^ \h* "if \$object.isa" / {
$bound_method_count++;
}
elsif /^ \h* "}" / {
# do nothing
}
elsif /^ \h* "die " / {
# do nothing
}
else {
die "Unexpected line: `$_`";
}
}
}
}
}

for <lib/_007/Runtime.pm> -> $file {
for $file.IO.lines {
if /^ \h* "return builtin(" / {
$runtime_builtin_method_count++;
}
}
}

for <lib/_007/Builtins.pm> -> $file {
for $file.IO.lines {
if /^ \h* "my @builtins ="/ ff /^ \h* ";" \h* $/ {
if /^ \h* \S+ \h* "=>" \h* ["->" | "sub" | "macro-op" | "op"] / {
$built_in_subs++;
}
}
}
}

for <lib/_007/Object.pm lib/_007/OpScope.pm lib/_007/Parser/Actions.pm lib/_007/Runtime.pm> -> $file {
for $file.IO.lines {
if /^ "class X::" / {
$exception_types_in_perl6++;
}
}
}

say "Types: $type_count";
say "Bound methods: $bound_method_count";
say "Built-in methods in Runtime.pm: $runtime_builtin_method_count";
say "Built-in subs: $built_in_subs";
say "Exception types in 007: $exception_types_in_007";
say "Exception types in Perl 6: $exception_types_in_perl6";
2 changes: 1 addition & 1 deletion examples/hanoi.007
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ constant DISK = {
};

my state = [
[DISK.huge, DISK.large, DISK.small, DISK.tiny],
[DISK["huge"], DISK["large"], DISK["small"], DISK["tiny"]],
[],
[]
];
Expand Down
65 changes: 33 additions & 32 deletions lib/_007/Backend/JavaScript.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use _007::Val;
use _007::Q;
use _007::Object;

my %builtins =
"say" => q:to '----',
Expand All @@ -10,14 +9,14 @@ my %builtins =
;

class _007::Backend::JavaScript {
method emit(Q::CompUnit $compunit) {
method emit(_007::Object $compunit) {
return ""
unless $compunit.block.statementlist.statements.elements;
unless $compunit.properties<block>.properties<statementlist>.properties<statements>.value;

my @builtins;
my @main;

for $compunit.block.statementlist.statements.elements -> $stmt {
for $compunit.properties<block>.properties<statementlist>.properties<statements>.value -> $stmt {
emit-stmt($stmt);
}

Expand All @@ -29,38 +28,40 @@ class _007::Backend::JavaScript {
\})();
PROGRAM

multi emit-stmt(Q::Statement $stmt) {
die "Cannot handle {$stmt.^name}";
}
sub emit-stmt(_007::Object $stmt) {
if $stmt.isa("Q::Statement::Expr") {
my $expr = $stmt.properties<expr>;
when $expr.isa("Q::Postfix::Call")
&& $expr.properties<operand>.isa("Q::Identifier")
&& $expr.properties<operand>.properties<name>.value eq "say" {

multi emit-stmt(Q::Statement::Expr $stmt) {
my $expr = $stmt.expr;
when $expr ~~ Q::Postfix::Call
&& $expr.operand ~~ Q::Identifier
&& $expr.operand.name.value eq "say" {
@builtins.push(%builtins<say>);
my @arguments = $expr.properties<argumentlist>.properties<arguments>.value.map: {
die "Cannot handle non-literal-Str arguments just yet!"
unless .isa("Q::Literal::Str");
# XXX: should really type-check the result of the .repr() call
bound-method(.properties<value>, "repr")().value;
};
@main.push("say({@arguments.join(", ")});");
}

@builtins.push(%builtins<say>);
my @arguments = $expr.argumentlist.arguments.elements.map: {
die "Cannot handle non-literal-Str arguments just yet!"
unless $_ ~~ Q::Literal::Str;
.value.quoted-Str;
};
@main.push("say({@arguments.join(", ")});");
die "Cannot handle this type of Q::Statement::Expr yet!";
}

die "Cannot handle this type of Q::Statement::Expr yet!";
}

multi emit-stmt(Q::Statement::My $stmt) {
my $name = $stmt.identifier.name.value;
if $stmt.expr !~~ NONE {
die "Cannot handle non-literal-Int rhs just yet!"
unless $stmt.expr ~~ Q::Literal::Int;
my $expr = $stmt.expr.value.Str;
@main.push("let {$name} = {$expr};");
elsif $stmt.isa("Q::Statement::My") {
my $name = $stmt.properties<identifier>.properties<name>.value;
if $stmt.properties<expr> !=== NONE {
die "Cannot handle non-literal-Int rhs just yet!"
unless $stmt.properties<expr>.isa("Q::Literal::Int");
# XXX: should really type-check the result of the .Str() call
my $expr = bound-method($stmt.properties<expr>.properties<value>, "Str")().value;
@main.push("let {$name} = {$expr};");
}
else {
@main.push("let {$name};");
}
}
else {
@main.push("let {$name};");
die "Cannot handle {$stmt.type.name}";
}
}
}
Expand Down
Loading