Changeset 22563
- Timestamp:
- 10/10/08 16:19:09 (6 weeks ago)
- Location:
- v6/mildew
- Files:
-
- 2 modified
-
mildew (modified) (11 diffs)
-
src/AST/Helpers.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
v6/mildew/mildew
r22541 r22563 1 1 #!/usr/local/bin/perl 2 3 2 use lib '../../src/perl6'; 4 3 use lib 'src'; 5 4 use STD; 5 package Mildew; 6 require 'viv'; 6 7 use AST; 7 8 use AST::Helpers; … … 15 16 use Carp 'confess'; 16 17 17 $::ACTIONS = 'Actions';18 {package Actions;19 our $AUTOLOAD;20 sub AUTOLOAD {21 my $self=shift;22 my $match=shift;23 if ($AUTOLOAD =~ /^Actions::scope_declarator.*my/) {24 warn "action $AUTOLOAD\n";25 $match->{''} = 'my';26 }27 }28 }29 18 my ($debug,$file); 30 19 GetOptions("file=s"=>\$file,"debug"=>\$debug); … … 33 22 confess 'unimplemented' 34 23 } 35 sub integer_{24 sub VAST::integer::emit_m0ld { 36 25 my $m = shift; 37 26 #XXX non-base 10 38 integer $m->text; 39 } 40 sub scope_declarator { 41 my $m = shift; 27 integer($m->{TEXT}); 28 } 29 sub VAST::scope_declarator::emit_m0ld { 30 my $m = shift; 31 die 'not implemented yet'; 42 32 if ($m->{''} eq 'my') { 43 33 if (my $decl = $m->{scoped}{declarator}) { … … 64 54 } 65 55 } 66 sub noun{56 sub VAST::noun::emit_m0ld { 67 57 my $m = shift; 68 58 if ($m->{variable}) { 69 variable($m->{variable});59 $m->{variable}->emit_m0ld; 70 60 } elsif ($m->{value}) { 71 value($m->{value});61 $m->{value}->emit_m0ld; 72 62 } elsif ($m->{routine_declarator}) { 73 63 if ($m->{routine_declarator}{routine_def}) { 74 routine_def($m->{routine_declarator}{routine_def});64 $m->{routine_declarator}{routine_def}->emit_m0ld; 75 65 } else { 76 66 XXX; 77 67 } 78 68 } elsif ($m->{term}) { 79 term($m->{term});69 $m->{term}->emit_m0ld; 80 70 } elsif ($m->{scope_declarator}) { 81 scope_declarator($m->{scope_declarator});82 } else { 83 XXX; 84 } 85 } 86 sub term{71 $m->{scope_declarator}->emit_m0ld; 72 } else { 73 XXX; 74 } 75 } 76 sub VAST::term::emit_m0ld { 87 77 my $m = shift; 88 78 if ($m->{identifier} && $m->{args}) { 89 79 my $func = AST::Call->new( 90 80 identifier=>string 'lookup', 91 capture=>AST::Capture->new(invocant=>reg 'scope',positional=>[string '&'.$m->{identifier} ->text],named=>[]),81 capture=>AST::Capture->new(invocant=>reg 'scope',positional=>[string '&'.$m->{identifier}{TEXT}],named=>[]), 92 82 ); 93 AST::Call->new(identifier=>string 'postcircumfix:( )',capture=>AST::Capture->new(invocant=>$func,positional=>args($m->{args}))); 94 } 95 } 96 sub args { 97 my $m = shift; 98 return [map {EXPR($_->{EXPR})} @{$m->{arglist}}]; 99 } 100 sub routine_def { 83 AST::Call->new(identifier=>string 'postcircumfix:( )',capture=>AST::Capture->new(invocant=>$func,positional=>$m->{args}->emit_m0ld)); 84 } 85 } 86 sub VAST::Terminator::emit_m0ld { 87 my $m = shift; 88 if ($m->{noun}) { 89 $m->{noun}->emit_m0ld; 90 } else { 91 XXX; 92 } 93 } 94 sub VAST::args::emit_m0ld { 95 my $m = shift; 96 return [map {$_->{EXPR}->emit_m0ld} @{$m->{arglist}}]; 97 } 98 sub VAST::routine_def::emit_m0ld { 101 99 my $m = shift; 102 100 AST::Call->new(identifier=>string 'new', … … 111 109 ); 112 110 } 113 sub block{111 sub VAST::block::emit_m0ld { 114 112 my $m = shift; 115 113 AST::Block->new(regs=>['interpreter','scope'],stmts=>statementlist($m->{in}{statementlist})); 116 114 } 117 sub value{115 sub VAST::value::emit_m0ld { 118 116 my $m = shift; 119 117 if ($m->{number}) { 120 number($m->{number});118 $m->{number}->emit_m0ld; 121 119 } elsif ($m->{quote}) { 122 quote($m->{quote}); 123 } else { 124 warn Dump($m->{number}); 120 $m->{quote}->emit_m0ld; 121 } else { 125 122 warn Dump($m); 126 123 XXX; 127 124 } 128 125 } 129 sub quote { 130 my $m = shift; 131 #XXX 132 my $text = $m->{nibble}->text; 133 string $text; 134 } 135 sub number { 126 sub VAST::quote::emit_m0ld { 127 my $m = shift; 128 # XXX escapes 129 string $m->{nibble}{nibbles}[0]; 130 } 131 sub VAST::number::emit_m0ld { 136 132 my $m = shift; 137 133 if ($m->{integer}) { 138 integer_($m->{integer}); 139 } else { 140 XXX; 141 } 142 } 143 sub variable { 144 my $m = shift; 134 $m->{integer}->emit_m0ld; 135 } else { 136 XXX; 137 } 138 } 139 sub VAST::variable::emit_m0ld { 140 my $m = shift; 141 my $varname = $m->{desigilname}{longname}{name}{identifier}{TEXT}; 145 142 AST::Call->new( 146 143 identifier=>string 'lookup', 147 capture=>AST::Capture->new(invocant=>reg 'scope',positional=>[string $ m->text],named=>[]),144 capture=>AST::Capture->new(invocant=>reg 'scope',positional=>[string $varname],named=>[]), 148 145 ); 149 146 } 150 sub dottyop{147 sub VAST::dottyop::emit_m0ld { 151 148 my ($noun,$m) = @_; 152 149 if ($m->{methodop}) { … … 156 153 } 157 154 } 158 sub dotty{155 sub VAST::dotty::emit_m0ld { 159 156 my ($noun,$m) = @_; 160 157 #XXX .*foo … … 165 162 } 166 163 } 167 sub FETCH{164 sub VAST::FETCH::emit_m0ld { 168 165 my $arg = shift; 169 166 AST::Call->new(capture=>AST::Capture->new(invocant=>$arg),identifier=>string 'FETCH'); 170 167 } 171 sub methodop{168 sub VAST::methodop::emit_m0ld { 172 169 my ($noun,$m) = @_; 173 170 if ($m->{longname}) { … … 175 172 AST::Call->new( 176 173 identifier=>string $m->{longname}->text, 177 capture=>AST::Capture->new(invocant=>FETCH($noun),positional=>[FETCH( EXPR($pos0->{EXPR}))],named=>[]),174 capture=>AST::Capture->new(invocant=>FETCH($noun),positional=>[FETCH($pos0->{EXPR}->emit_m0ld)],named=>[]), 178 175 179 176 ); … … 182 179 } 183 180 } 184 sub EXPR{181 sub VAST::TERM::emit_m0ld { 185 182 my $m = shift; 186 183 if ($m->{noun}) { 187 my $noun = noun($m->{noun});184 my $noun = $m->{noun}->emit_m0ld; 188 185 if ($m->{post}) { 189 186 for (@{$m->{post}}) { 190 187 if ($_->{dotty}) { 191 $noun = dotty($noun,$_->{dotty});188 $noun = $_->{dotty}->emit_m0ld($noun); 192 189 } else { 193 190 XXX … … 200 197 } 201 198 } 202 sub statement{199 sub VAST::statement::emit_m0ld { 203 200 my $m = shift; 204 201 if ($m->{label}) { … … 206 203 } elsif ($m->{statement_control}) { 207 204 } elsif ($m->{EXPR}) { 208 EXPR($m->{EXPR});209 } else { 210 } 211 } 212 sub comp_unit{213 my $m = shift; 214 AST::Block->new(regs=>['interpreter','scope'],stmts=> statementlist($m->{statementlist}));215 } 216 sub statementlist{217 my $m = shift; 218 [map { statement $_} @{$m->{statement}}]205 $m->{EXPR}->emit_m0ld; 206 } else { 207 } 208 } 209 sub VAST::comp_unit::emit_m0ld { 210 my $m = shift; 211 AST::Block->new(regs=>['interpreter','scope'],stmts=>$m->{statementlist}->emit_m0ld); 212 } 213 sub VAST::statementlist::emit_m0ld { 214 my $m = shift; 215 [map {$_->emit_m0ld} @{$m->{statement}}] 219 216 } 220 217 unless ($file) { 221 218 die "usage [--debug] --file filename\n" 222 219 } 223 my $r = STD->parsefile($file,'comp_unit'); 224 print dump_match('comp_unit'=>$r,{vertical=>1,mark_arrays=>1,visit_twice=>1}),"\n" if $debug; 225 my $mold = comp_unit($r); 220 my $r = STD->parsefile($file,'comp_unit')->item; 221 print Dump($r) if $debug; 222 #print dump_match('comp_unit'=>$r,{vertical=>1,mark_arrays=>1,visit_twice=>1}),"\n" if $debug; 223 my $mold = $r->emit_m0ld; 226 224 use YAML::XS; 227 225 print Dump($mold) if $debug; -
v6/mildew/src/AST/Helpers.pm
r22542 r22563 1 1 package AST::Helpers; 2 2 use Exporter 'import'; 3 our @EXPORT = qw(string reg inte rger);3 our @EXPORT = qw(string reg integer); 4 4 use AST; 5 5 sub string($) {
