Changeset 22593 for misc

Show
Ignore:
Timestamp:
10/13/08 03:16:56 (3 months ago)
Author:
putter
Message:

[elfish/STD_blue] Dropped in STD_red elf_h IRx1_FromAST constructors. Currently adapting them to the STD_blue/gimme5 ast. -e 'say 3' works, but little else yet.

Location:
misc/elfish/STD_blue
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • misc/elfish/STD_blue/IRx1_FromAST2_create.pl

    r22589 r22593  
    1212 
    1313statement 
    14 $m<EXPR> 
     14my $labels = $m<label>; 
     15my $result = $m<EXPR> || $m<control>; 
     16if $o<EXPR> && ($o<mod_loop> || $o<mod_cond>) { 
     17  temp $blackboard::statement_expr = $result; 
     18  $result = $m<mod_loop> || $m<mod_cond>; 
     19  if $o<mod_condloop> { 
     20    $blackboard::statement_expr = $result; 
     21    $result = $m<mod_condloop>; 
     22  } 
     23} 
     24if $labels { 
     25  Label.newp($labels,$result); 
     26} else { 
     27  $result; 
     28} 
    1529 
    1630EXPR 
    17 $m<noun> 
     31if $m<infix> { 
     32  my $op = $m<infix><sym_name>; 
     33  my $args = [$m<left>,$m<right>]; 
     34  if $op eq '=>' { 
     35    if $args[2] { die "chained => unimplemented" } 
     36    Pair.newp($args[0],$args[1]) 
     37  } else { 
     38    Apply.newp("infix:"~$op,Capture.newp1($args)) 
     39  } 
     40} 
     41else { 
     42  temp $blackboard::expect_term_base = $m<noun>; 
     43  my $ops = []; 
     44  if $o<pre>  { $ops.push($o<pre>.flatten) }; 
     45  if $o<post> { $ops.push($o<post>.flatten) }; 
     46  for $ops { 
     47    $blackboard::expect_term_base = ir($_) 
     48  } 
     49  $blackboard::expect_term_base 
     50} 
     51 
     52pre 
     53$m<prefix> 
     54 
     55post 
     56$m<postop> || $m<dotty> 
     57 
     58postop 
     59$m<postfix> || $m<postcircumfix> 
     60 
     61prefix 
     62my $op = *text*; 
     63Apply.newp("prefix:"~$op,Capture.newp1([$blackboard::expect_term_base])) 
     64 
     65postfix 
     66my $op = *text*; 
     67Apply.newp("postfix:"~$op,Capture.newp1([$blackboard::expect_term_base])) 
     68 
     69postcircumfix 
     70my $name = $m<sym_name>; 
     71my $ident = "postcircumfix:"~$name; 
     72my $args = $m<semilist>; 
     73if $args && ($args.WHAT ne 'Array')  { $args = [$args] } 
     74Call.newp($blackboard::expect_term_base,$ident,Capture.newp1($args||[])) 
     75 
     76semilist 
     77$m<statement> 
     78 
     79dotty 
     80#temp $blackboard::dottyop = $m<sym_name>; 
     81$m<dottyop> 
     82 
     83dottyop 
     84$m<methodop> || $m<postop> 
     85 
     86methodop 
     87Call.newp($blackboard::expect_term_base,$m<longname>,Capture.newp1($m<semilist>||[])) 
     88 
     89term 
     90my $text = $m<sym_name>; 
     91if $text eq '*' { 
     92  Apply.newp('whatever',Capture.newp1([])) 
     93} else { 
     94  Apply.newp($text,Capture.newp1([])) 
     95} 
    1896 
    1997noun 
    20 $m<term> || $m<value> 
     98#Should just be *1*, but all versions of node contain a colonpair too. 
     99$m<fatarrow> || $m<variable> || $m<package_declarator> || $m<scope_declarator> || $m<multi_declarator> || $m<routine_declarator> || $m<regex_declarator> || $m<type_declarator> || $m<circumfix> || $m<dotty> || $m<value> || $m<capterm> || $m<sigterm> || $m<term> || $m<statement_prefi> || $m<colonpair> 
     100 
     101longname 
     102$m<name> 
     103 
     104name 
     105my $parts = [$m<identifier>]; 
     106if $m<morename> { $parts.push($m<morename>.flatten) } 
     107$parts.join("::"); 
     108 
     109morename 
     110$m<identifier>[0] 
     111 
     112identifier 
     113*text* 
     114 
    21115 
    22116value 
     
    27121 
    28122integer 
    29 NumInt.newp(*text*) 
    30  
    31 term 
    32 if $o<args> { 
    33   my $ident = 'sub_name_missing_from_STD_ast'; #XXX :( 
    34   my $args = $m<args>; 
    35   Apply.newp($ident,Capture.newp($args||[])) 
    36 } 
    37  
    38 args 
    39 $m<in> || $m<arglist> 
    40  
    41 arglist 
    42 # Actually an arg :/ 
    43 $m<EXPR> 
    44  
    45 in 
     123NumInt.newp(*text*,10) 
     124 
     125fatarrow 
     126Pair.newp($m<key>,$m<val>) 
     127 
     128 
     129term:identifier 
     130my $args = $m<args><semilist>; 
     131if not($args) && $o<args><arglist>[0]<EXPR> { 
     132  $args = [ irbuild_ir($o<args><arglist>[0]<EXPR>) ]; 
     133} 
     134Apply.newp($m<identifier>,Capture.newp1($args||[])) 
     135 
     136 
     137statement_control:use 
     138Use.newp('use',$m<module_name>,$m<EXPR>) 
     139 
     140module_name:depreciated 
     141*text* 
     142 
     143module_name:normal 
     144*text* 
     145 
     146role_name 
     147*text* 
     148 
     149 
     150circumfix 
     151my $s = *text*; 
     152my $name = substr($s,0,1)~' '~substr($s,-1,1); # XXX :( 
     153my $args = $m<kludge_name>; 
     154if $args && ($args.WHAT ne 'Array')  { $args = [$args] } 
     155Apply.newp("circumfix:"~$name,Capture.newp1($args||[])) 
     156 
     157 
     158quote 
     159my $nibs = $m<nibble><nibbles>; 
     160my $args = $nibs.map(sub($x){if $x.WHAT eq 'Str' {Buf.newp($x);} else {$x}}); 
     161Apply.newp('infix:~',Capture.newp1($args||[])) 
     162 
     163nibbles:\ 
     164my $which = $m<item><sym_name>; 
     165if $which eq 'n' { "\n" } 
     166if $which eq 't' { "\t" } 
     167else { $which } 
     168 
     169 
     170scope_declarator:my 
     171temp $blackboard::scope = 'my'; 
     172$m<scoped> 
     173 
     174scope_declarator:has 
     175temp $blackboard::scope = 'has'; 
     176$m<scoped> 
     177 
     178scope_declarator:our 
     179temp $blackboard::scope = 'our'; 
     180$m<scoped> 
     181 
     182scope_declarator:temp 
     183temp $blackboard::scope = 'temp'; 
     184$m<scoped> 
     185 
     186scoped 
     187temp $blackboard::typenames = $m<fulltypename>; 
     188$m<declarator> 
     189 
     190declarator 
     191$m<variable_declarator> || $m<signature> || $m<plurality_declarator> || $m<routine_declarator>  || $m<type_declarator> 
     192 
     193variable_declarator 
     194my $scope = $blackboard::scope; temp $blackboard::scope; 
     195my $typenames = $blackboard::typenames; temp $blackboard::typenames = undef; 
     196VarDecl.newp($scope,$typenames,undef,$m<variable>,undef,$m<traits>,'=',$m<default_value>) 
     197#XXX default_value is going to take some non-local work. 
     198 
     199variable 
     200my $tw = $m<twigil>; 
     201if $o<postcircumfix> { 
     202  if $tw eq "." { 
     203    my $slf = Apply.newp('self',Capture.newp1([])); 
     204    my $args = $m<postcircumfix><kludge_name>; 
     205    if $args && ($args.WHAT ne 'Array')  { $args = [$args] } 
     206    Call.newp($slf,$m<desigilname>,Capture.newp1($args||[])) 
     207  } else { 
     208    my $v = Var.newp($m<sigil>,$tw,$m<desigilname>); 
     209    temp $blackboard::expect_term_base = $v; 
     210    $m<postcircumfix>; 
     211  } 
     212} else { 
     213  Var.newp($m<sigil>,$tw,$m<desigilname>); 
     214} 
     215 
     216sigil 
     217*text* 
     218 
     219twigil 
     220*text* 
     221 
     222special_variable 
     223my $v = *text*; 
     224my $s = substr($v,0,1); 
     225my $n = substr($v,1,$v.chars); 
     226Var.newp($s,undef,$n) 
     227 
     228 
     229statement_control:BEGIN 
     230ClosureTrait.newp('BEGIN',$m<block>) 
     231 
     232statement_control:for 
     233For.newp($m<EXPR>,$m<xblock>) 
     234 
     235statement_mod_loop:for 
     236For.newp($m<modifier_expr>,$blackboard::statement_expr) 
     237 
     238statement_control:while 
     239Loop.newp($m<EXPR>,$m<block>,undef,undef) 
     240 
     241statement_mod_loop:while 
     242Loop.newp($m<modifier_expr>,$blackboard::statement_expr,undef,undef) 
     243 
     244statement_control:until 
     245my $test = Apply.newp("not",Capture.newp1([$m<EXPR>])); 
     246Loop.newp($test,$m<block>,undef,undef) 
     247 
     248statement_mod_loop:until 
     249my $test = Apply.newp("not",Capture.newp1([$m<modifier_expr>])); 
     250Loop.newp($test,$blackboard::statement_expr,undef,undef) 
     251 
     252statement_control:loop 
     253my $e1 = $m<loop_eee><loop_e1>; 
     254my $e2 = $m<loop_eee><loop_e2>; 
     255my $e3 = $m<loop_eee><loop_e3>; 
     256my $block = $m<loop_block>; 
     257my $body = Loop.newp($e2,Block.newp([$block,$e3]),undef,undef); 
     258Block.newp([$e1,$body]) 
     259 
     260statement_control:if 
     261my $els = $m<else>; 
     262if $els { $els = $els[0] } 
     263Cond.newp([[$m<if_expr>,$m<if_block>]].push($m<elsif>.flatten),$els,undef) 
     264 
     265elsif 
     266[$m<elsif_expr>,$m<elsif_block>] 
     267 
     268if__else 
    46269*1* 
    47270 
    48 semilist 
    49 $m<statement> # actuall a statement list :( 
    50  
     271statement_mod_cond:if 
     272Cond.newp([[$m<modifier_expr>,$blackboard::statement_expr]],undef,undef) 
     273 
     274statement_control:unless 
     275Cond.newp([[$m<EXPR>,$m<block>]],undef,1) 
     276 
     277statement_mod_cond:unless 
     278Cond.newp([[$m<modifier_expr>,$blackboard::statement_expr]],undef,1) 
     279 
     280 
     281statement_control:given 
     282Given.newp($m<EXPR>,$m<block>) 
     283 
     284statement_mod_loop:given 
     285Given.newp($m<modifier_expr>,$blackboard::statement_expr) 
     286 
     287statement_control:when 
     288When.newp($m<EXPR>,$m<block>) 
     289 
     290statement_mod_cond:when 
     291When.newp($m<modifier_expr>,$blackboard::statement_expr) 
     292 
     293statement_control:default 
     294When.newp(undef,$m<block>) 
     295 
     296 
     297statement_prefix:do 
     298Apply.newp("statement_prefix:do",Capture.newp1([$m<statement>])) 
     299 
     300statement_prefix:try 
     301Apply.newp("statement_prefix:try",Capture.newp1([$m<statement>])) 
     302 
     303statement_prefix:gather 
     304Apply.newp("statement_prefix:gather",Capture.newp1([$m<statement>])) 
     305 
     306statement_prefix:contend 
     307Apply.newp("statement_prefix:contend",Capture.newp1([$m<statement>])) 
     308 
     309statement_prefix:async 
     310Apply.newp("statement_prefix:async",Capture.newp1([$m<statement>])) 
     311 
     312statement_prefix:lazy 
     313Apply.newp("statement_prefix:lazy",Capture.newp1([$m<statement>])) 
     314 
     315 
     316pblock 
     317if $o<signature> { 
     318  SubDecl.newp(undef,undef,undef,undef,$m<signature>,undef,$m<block>) 
     319} else { 
     320  $m<block> 
     321} 
     322 
     323block 
     324Block.newp($m<statementlist>) 
     325 
     326xblock 
     327$m<pblock> 
     328 
     329plurality_declarator:multi 
     330temp $blackboard::plurality = 'multi'; 
     331$m<pluralized> || $m<routine_def> 
     332 
     333routine_declarator:routine_def 
     334my $scope = $blackboard::scope; temp $blackboard::scope; 
     335my $plurality = $blackboard::plurality; temp $blackboard::plurality; 
     336my $ident = ""; 
     337if $o<ident> { $ident = $m<ident>  }; 
     338if ($o<ident> && not($scope)) { $scope = "our" }; 
     339my $sig = Signature.newp([],undef); 
     340if $m<multisig> { $sig = $m<multisig>.[0] }; 
     341SubDecl.newp($scope,undef,$plurality,$ident,$sig,$m<trait>,$m<block>) 
     342 
     343# routine_def is the same as routine_declarator:routine_def 
     344# This is a workaround for STD.pm not recognizing  multi f(){} . 
     345routine_def 
     346my $scope = $blackboard::scope; temp $blackboard::scope; 
     347my $plurality = $blackboard::plurality; temp $blackboard::plurality; 
     348my $ident = ""; 
     349if $o<ident> { $ident = $m<ident>  }; 
     350if ($o<ident> && not($scope)) { $scope = "our" }; 
     351my $sig = Signature.newp([],undef); 
     352if $m<multisig> { $sig = $m<multisig>.[0] }; 
     353SubDecl.newp($scope,undef,$plurality,$ident,$sig,$m<trait>,$m<block>) 
     354 
     355routine_declarator:method_def 
     356my $plurality = $blackboard::plurality; temp $blackboard::plurality; 
     357my $multisig = $m<multisig>; 
     358if not($multisig) { $multisig = [Signature.newp([],undef)]; } 
     359MethodDecl.newp(undef,undef,$plurality,$m<ident>,$multisig.[0],$m<trait>,$m<block>,undef,undef) 
     360 
     361signature 
     362Signature.newp($m<parsep>,undef) 
     363 
     364parameter 
     365Parameter.newp($m<type_constraint>,$m<quantchar>,$m<param_var>,undef,undef,undef,undef) 
     366 
     367param_var 
     368ParamVar.newp($m<sigil>,$m<twigil>,$m<ident>) 
     369 
     370capture 
     371if not($o<EXPR>) { 
     372  Capture.newp1([]) 
     373} 
     374elsif $o<EXPR><noun> { 
     375  Capture.newp1([$m<EXPR><noun>]) 
     376} 
     377elsif $o<EXPR><sym> && $o<EXPR><sym> eq ':' { 
     378  my $args = $m<EXPR><args>; 
     379  my $inv = $args.shift; 
     380  Capture.newp($args||[],$inv) 
     381} 
     382elsif $o<EXPR><sym> && $o<EXPR><sym> eq ',' { 
     383  my $args = $o<EXPR><args>; 
     384  my $arg0 = $args && $args[0]; 
     385  my $inv = undef; 
     386  if $arg0 && $arg0<sym> && $arg0<sym> eq ':' { 
     387    $args.shift; 
     388    $inv = $arg0<args>[0]; 
     389    if $arg0<args>[1] { 
     390      $args.unshift($arg0<args>[1]); 
     391    } 
     392  } 
     393  Capture.newp(ir($args)||[],ir($inv)) 
     394} 
     395else { die "capture AST form not recognized" } 
     396 
     397colonpair 
     398*1* 
     399 
     400colonpair__false 
     401Pair.newp($m<ident>,NumInt.newp(0)) 
     402 
     403colonpair__value 
     404my $value; 
     405if $o<postcircumfix> { 
     406  $value = $m<postcircumfix><kludge_name>; 
     407} else { 
     408  $value = NumInt.newp(1); 
     409} 
     410Pair.newp($m<ident>,$value) 
     411 
     412quotepair 
     413*1* 
     414 
     415quotepair__false 
     416Pair.newp($m<ident>,NumInt.newp(0)) 
     417 
     418quotepair__value 
     419my $value; 
     420if $o<postcircumfix> { 
     421  $value = $m<postcircumfix><kludge_name>; 
     422} else { 
     423  $value = NumInt.newp(1); 
     424} 
     425Pair.newp($m<ident>,$value) 
     426 
     427quotepair__nth 
     428Pair.newp('nth',$m<n>) 
     429 
     430 
     431package_declarator:role 
     432temp $blackboard::package_declarator = 'role'; 
     433$m<package_def> 
     434 
     435package_declarator:class 
     436temp $blackboard::package_declarator = 'class'; 
     437$m<package_def> 
     438 
     439package_declarator:module 
     440temp $blackboard::package_declarator = 'module'; 
     441$m<package_def> 
     442 
     443package_declarator:package 
     444temp $blackboard::package_declarator = 'package'; 
     445$m<package_def> 
     446 
     447package_declarator:grammar 
     448temp $blackboard::package_declarator = 'grammar'; 
     449$m<package_def> 
     450 
     451package_def 
     452PackageDecl.newp(undef,undef,$blackboard::package_declarator,$m<module_name>.[0],$m<traits>,$m<block>) 
     453 
     454fulltypename 
     455$m<typename>.join("::") 
     456 
     457typename 
     458*text* # $m<name> 
     459 
     460trait_verb:is 
     461Trait.newp('is',$m<ident>) 
     462 
     463trait_verb:does 
     464Trait.newp('does',$m<role_name>) 
     465 
     466 
     467circumfix:pblock 
     468if $o<block><statementlist>.elems == 0 or $o<block><statementlist>[0].match_string.re_matchp('^:') { 
     469  Hash.newp($m<block><statementlist>) 
     470} elsif $o<block><statementlist>[0]<EXPR> and $o<block><statementlist>[0]<EXPR><sym> and $o<block><statementlist>[0]<EXPR><sym> eq "," { # XXX Not p6.  Remove once off elf_e, and Match updated. 
     471  Hash.newp($m<block><statementlist>) 
     472} elsif $o<block><statementlist>[0]<EXPR> and $o<block><statementlist>[0]<EXPR><sym> and $o<block><statementlist>[0]<EXPR><sym> eq "=>" { 
     473  Hash.newp($m<block><statementlist>) 
     474} elsif not($m<lambda>) and not($m<signature>) { 
     475  $m<block> 
     476} else { 
     477  die "AST handler circumfix:pblock partially unimplemented"; 
     478} 
     479 
     480 
     481quote:regex 
     482my $s = $m<text> || $m<quotesnabber><text>; 
     483Rx.newp($s,$m<quotepair>) 
     484 
     485regex_declarator:regex_def 
     486RegexDef.newp($m<ident>,$m<regex_block>) 
     487 
     488regex_block 
     489$m<regex> 
     490 
     491regex 
     492Regex.newp($m<pattern>) 
     493 
     494regex_first 
     495RxFirst.newp($m<patterns>) 
     496 
     497regex_every 
     498RxEvery.newp($m<patterns>) 
     499 
     500regex_submatch 
     501RxSubmatch.newp($m<patterns>) 
     502 
     503regex_any 
     504RxAny.newp($m<patterns>) 
     505 
     506regex_all 
     507RxAll.newp($m<patterns>) 
     508 
     509regex_sequence 
     510RxSequence.newp($m<patterns>) 
     511 
     512regex_quantified_atom 
     513RxQuantifiedAtom.newp($m<regex_atom>,$m<regex_quantifier>) 
     514 
     515regex_quantifier 
     516*text* 
     517 
     518regex_atom 
     519if $m<char> { RxLiteral.newp($m<char>,"'") } else { *1* } 
     520 
     521regex_metachar:regex_backslash 
     522RxBackslash.newp(*text*) 
     523 
     524regex_metachar:regex_mod_internal 
     525RxModInternal.newp(*text*) 
     526 
     527regex_assertion:ident 
     528RxAssertion.newp($m<ident>) 
     529 
     530regex_metachar:capture 
     531RxCapture.newp($m<regex><pattern>) 
     532 
     533regex_metachar:group 
     534RxGroup.newp($m<regex><pattern>) 
     535 
     536regex_metachar:block 
     537RxBlock.newp($m<block>) 
     538 
     539regex_metachar:var 
     540RxBind.newp($m<variable>,$m<binding>) 
     541 
     542regex_metachar:q 
     543RxLiteral.newp($m<text>,"'") 
     544 
     545regex_metachar:qq 
     546RxLiteral.newp($m<text>,'"') 
     547 
     548regex_metachar 
     549RxSymbol.newp(*text*) 
    51550 
    52551 
     
    77576        $constructor.($m); 
    78577      } else { 
    79         die "Unknown rule: "~$rule~"\nIt needs to be added to ast_handlers.\n"; 
     578        die "Unknown rule: "~$rule~"\nIt needs to be added to ast_handlers .\n"; 
    80579      } 
    81580    } 
     
    167666    my $fname = $name; 
    168667    $fname =~ s/(\W)/"_".ord($1)/eg; 
     668    my $qname = $name; 
     669    $qname =~ s/([\\'])/\\$1/g; 
    169670    $code .= "\n".unindent(<<"    END","    "); 
    170671      my \$construct_$fname = sub (\$m) { 
     
    173674    END 
    174675    $init .= "".unindent(<<"    END","    "); 
    175       \$.add_constructor('$name', \$construct_$fname); 
     676      \$.add_constructor('$qname', \$construct_$fname); 
    176677    END 
    177678 
     
    190691  $code .= unindent(<<'  END'); 
    191692 
    192   if not($*ast2ir_0) { $*ast2ir_0 = IRx1_Build.new.init; } 
    193   $*ast2ir_1 = IRx1_Build.new.init; 
     693  if not($*ast2ir_0) { $*ast2ir_0 = IRx1_Build2.new.init; } 
     694  $*ast2ir_1 = IRx1_Build2.new.init; 
    194695 
    195696  END 
  • misc/elfish/STD_blue/Makefile

    r22589 r22593  
    11 
    22elfx:: 
     3        ./IRx1_FromAST2_create.pl 
    34        ../../elf/elf_h -x -o ./elfx -I ../../elf/elf_h_src -e 'use Elf_wo_main' IRx1_FromAST2.pm Parser2.pm -e elf_main 
  • misc/elfish/STD_blue/STD_blue_run

    r22589 r22593  
    7171 
    7272  my($cache_file,$output) = cached_output_for($code, $format); 
     73  $output = undef; #XXX disable cache 
    7374  if($output && !$dash_e){print $output; exit;} 
    7475 
     
    133134  sub condition_sym { 
    134135    my($o,$sym)=@_; 
    135     if ($sym !~ /^sym/) { $sym } 
     136    if (ref $sym) { join(" ",@$sym) } 
     137    elsif ($sym !~ /^sym/) { $sym } 
    136138    elsif ($sym =~ /\Asym<\s*(.+?)\s*>\z/) { $1 } 
    137139    elsif ($sym =~ /\Asym«\s*(.+?)\s*»\z/) { $1 } 
     
    141143  our $category = 'comp_unit'; 
    142144  our %seen; 
    143   our $max_repetition = 3; 
     145  our $max_repetition = 20; 
    144146  sub to_dump0 { 
    145147    my($o)=@_; 
    146148    local $seen{$o} = $seen{$o}; 
    147149    if($seen{$o}++ > $max_repetition) { return "LOOP:$o"->to_dump0 } 
     150    my $rule = $category; 
     151    if($rule =~ /\A(chain|list|arg|left|right)\z/) { $rule = 'EXPR' } 
     152    my $sym = $o->{sym}; 
     153    if($sym) { 
     154      my $normalized = $o->condition_sym($sym); 
     155      $o->{sym_name} = $normalized; 
     156      $rule .= ":".$normalized if $sym ne $rule && $rule ne 'EXPR'; 
     157    } 
     158    my $rule_str = $rule->to_dump0; 
    148159    my $f = $o->{_from}; 
    149160    my $t = $o->{_to}; 
     
    161172      } 
    162173    }keys(%$o)); 
    163     my $rule = $category; 
    164     my $sym = $o->{sym}; 
    165     if($sym) { 
    166       my $normalized = $o->condition_sym($sym); 
    167       $rule .= ":".$normalized if $sym ne $rule; 
    168     } 
    169     my $rule_str = $rule->to_dump0; 
    170174    "match($rule_str,$s,$f,$t,{$h})" 
    171175  }