Skip to content

Commit

Permalink
Ruby backend - runtime tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jul 24, 2010
1 parent b3f565f commit b934ec1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions lib/MiniPerl6/Ruby/Runtime.rb
Expand Up @@ -21,7 +21,7 @@ class Mp6_Array < Array
end

def mp6_to_num (v)
if v.class == "".class
if v.class == String
if v.index(".")
return v.to_f
end
Expand All @@ -34,13 +34,13 @@ def mp6_to_num (v)
end

def mp6_to_bool (v)
if v.class == "".class
if v.class == String
return v != "0" && v != ""
end
if v.class == 1.class
if v.class == Fixnum || v.class == Float || v.class == Bignum
return v != 0
end
if v.class == [].class || v.class == Mp6_Array
if v.class == Array || v.class == Mp6_Array
return v.length != 0
end
if v.class == C_MiniPerl6__Match
Expand All @@ -53,7 +53,7 @@ def mp6_to_scalar (v)
if v.class == C_MiniPerl6__Match
return v.f_scalar()
end
if v.class == Array
if v.class == Array || v.class == Mp6_Array
return v.length
end
return v
Expand Down Expand Up @@ -101,7 +101,7 @@ class C_MiniPerl6__Grammar
$MiniPerl6__Grammar = C_MiniPerl6__Grammar.new()
namespace = $MiniPerl6__Grammar
def f_word(s, pos)
/^\w/.match(s[pos..-1])
/^\w/.match(s[pos,1])
m = C_MiniPerl6__Match.new
if $~
m.v_str = s
Expand All @@ -114,7 +114,7 @@ def f_word(s, pos)
return m
end
def f_digit(s, pos)
/^\d/.match(s[pos..-1])
/^\d/.match(s[pos,1])
m = C_MiniPerl6__Match.new
if $~
m.v_str = s
Expand All @@ -127,20 +127,21 @@ def f_digit(s, pos)
return m
end
def f_space(s, pos)
/^\s/.match(s[pos..-1])
/^(\s)/.match(s[pos,1])
m = C_MiniPerl6__Match.new
if $~
puts(" -- f_space " + pos.to_s + " " + ($~.end(1) + pos).to_s + "[" + s[pos..$~.end(1) + pos] + "]")
m.v_str = s
m.v_from = pos
m.v_to = $~.end(0) + pos
m.v_to = $~.end(1) + pos
m.v_bool = true
else
m.v_bool = false
end
return m
end
def f_is_newline(s, pos)
/^(\r\n?|\n\r?)/.match(s[pos..-1])
/^(\r\n?|\n\r?)/.match(s[pos,2])
m = C_MiniPerl6__Match.new
if $~
m.v_str = s
Expand All @@ -153,7 +154,7 @@ def f_is_newline(s, pos)
return m
end
def f_not_newline(s, pos)
/^(\r|\n)/.match(s[pos..-1])
/^(\r|\n)/.match(s[pos,1])
m = C_MiniPerl6__Match.new
if $~
m.v_str = s
Expand Down
2 changes: 1 addition & 1 deletion lib5/MiniPerl6/Ruby/Emitter.pm
Expand Up @@ -195,7 +195,7 @@ sub hyper { $_[0]->{hyper} };
sub method { $_[0]->{method} };
sub arguments { $_[0]->{arguments} };
sub emit_ruby { my $self = $_[0]; $self->emit_ruby_indented(0) };
sub emit_ruby_indented { my $self = $_[0]; my $level = $_[1]; (my $invocant = $self->{invocant}->emit_ruby()); if (Main::bool((($self->{method} eq 'perl') || (($self->{method} eq 'yaml') || (($self->{method} eq 'say') || (($self->{method} eq 'join') || ($self->{method} eq 'isa'))))))) { if (Main::bool($self->{hyper})) { return($invocant . '.map {|x| x.' . $self->{method} . '(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')}') } else { return('Mp6_' . $self->{method} . '(' . Main::join([ map { $_->emit_ruby() } @{ [$self->{invocant}, @{$self->{arguments}}] } ], ', ') . ')') } } else { }; (my $meth = $self->{method}); if (Main::bool(($meth eq 'postcircumfix:<( )>'))) { return(Ruby::tab($level) . $invocant . '.call(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')') } else { }; if (Main::bool((($meth eq 'values') || (($meth eq 'keys') || (($meth eq 'push') || ($meth eq 'concat')))))) { return(Ruby::tab($level) . $invocant . '.' . $meth . '(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')') } else { }; if (Main::bool(($meth eq 'chars'))) { return(Ruby::tab($level) . 'len(' . $invocant . ')') } else { }; (my $call = 'f_' . $meth . '(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')'); if (Main::bool($self->{hyper})) { Ruby::tab($level) . $invocant . '.map {|x| x.' . $call . '}' } else { Ruby::tab($level) . $invocant . '.' . $call } }
sub emit_ruby_indented { my $self = $_[0]; my $level = $_[1]; (my $invocant = $self->{invocant}->emit_ruby()); if (Main::bool((($self->{method} eq 'perl') || (($self->{method} eq 'yaml') || (($self->{method} eq 'say') || (($self->{method} eq 'join') || ($self->{method} eq 'isa'))))))) { if (Main::bool($self->{hyper})) { return($invocant . '.map {|x| x.' . $self->{method} . '(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')}') } else { return('mp6_' . $self->{method} . '(' . Main::join([ map { $_->emit_ruby() } @{ [$self->{invocant}, @{$self->{arguments}}] } ], ', ') . ')') } } else { }; (my $meth = $self->{method}); if (Main::bool(($meth eq 'postcircumfix:<( )>'))) { return(Ruby::tab($level) . $invocant . '.call(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')') } else { }; if (Main::bool((($meth eq 'values') || (($meth eq 'keys') || (($meth eq 'push') || ($meth eq 'concat')))))) { return(Ruby::tab($level) . $invocant . '.' . $meth . '(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')') } else { }; if (Main::bool(($meth eq 'chars'))) { return(Ruby::tab($level) . 'len(' . $invocant . ')') } else { }; (my $call = 'f_' . $meth . '(' . Main::join([ map { $_->emit_ruby() } @{ $self->{arguments} } ], ', ') . ')'); if (Main::bool($self->{hyper})) { Ruby::tab($level) . $invocant . '.map {|x| x.' . $call . '}' } else { Ruby::tab($level) . $invocant . '.' . $call } }
}

{
Expand Down

0 comments on commit b934ec1

Please sign in to comment.