Anonymous avatar Anonymous committed c5d1644

use global speaker switch to simplify actions

Comments (0)

Files changed (2)

src/builtins/say.pir

 .sub 'onload' :anon :load :init
   $P0 = new 'ResizablePMCArray' 
   set_global 'the_cast', $P0
+
   $P0 = 0
   set_global 'the_condition', $P0
+
+  $P0 = new 'String' 
+  set_global 'the_speaker', $P0
 .end
 
 .sub 'say'
 
 .sub 'assign'
     .param int val
-    .param string speaker
-    $P0 = 'find_other'(speaker) 
+    $P0 = 'find_other'() 
     $P0['value'] = val
 .end
 
 .sub 'find_other'
-    .param string speaker
+    get_global $P0, 'the_speaker'
     .local int i, size, status
     .local string name
     .local pmc person
 
     unless status goto loop
     name = person['name']
-    if name == speaker goto loop
+    if name == $S0 goto loop
   end_loop:
     .return (person)
 .end
 
 
 .sub 'open_heart'
-    .param string speaker
-    $P0 = 'find_other'(speaker)
+    $P0 = 'find_other'()
     $I1 = $P0['value']
     print $I1
 .end
 
 .sub 'listen_heart'
-    .param string speaker
-    $P0 = 'find_other'(speaker)
+    $P0 = 'find_other'()
     $P1 = getstdin
     readline $S1, $P1
     $I1 = $S1
 .end
 
 .sub 'speak_mind'
-    .param string speaker
-    $P0 = 'find_other'(speaker)
+    $P0 = 'find_other'()
     $I1 = $P0['value']
     $S1 = chr $I1
     print $S1
 .end
 
 .sub 'open_mind'
-    .param string speaker
-    $P0 = 'find_other'(speaker)
+    $P0 = 'find_other'()
     $P1 = getstdin
     readline $S1, $P1
     $I1 = ord $S1

src/parser/actions.pm

 }
 
 sub mkcall($arg,$name) {
-return PAST::Op.new($arg,
-    :name($name),
-    :pasttype('call')
-    );
+return PAST::Op.new($arg, :name($name), :pasttype('call'));
+}
+sub mkcall0($name) {
+return PAST::Op.new(:name($name), :pasttype('call'));
 }
 
 method assignment($/) {
 
 method io($/,$k) {
   dbg("io:"~$k);
-  my $res := PAST::Op.new(:name($k),:pasttype('call'));
+  my $res := mkcall0($k);
   dbg("ok");
   make $res;
 }
 method line($/) {
     dbg("line:");
     my $past := PAST::Stmts.new( :node( $/ ) );
+    $past.push(
+      PAST::Op.new(
+        PAST::Var.new(
+          :name('the_speaker'),
+          :scope('package')
+        ),
+        PAST::Val.new(
+          :value($<character>), 
+          :returns('String')
+        ),
+        :pasttype('bind'),
+      )
+    );
     for $<sentence> {
-      if $_<assignment> || $_<io> {
-        my $op := $( $_ );
-        $op.push(PAST::Val.new(
-            :value($<character>), 
-            :returns('String'),
-            :node($_)) );
-        $past.push($op);
-      }
-      else      {
-        $past.push( $( $_ ) );
-      }
+      $past.push( $( $_ ) );
     }
     make $past;
 }
     :inline("goto "~$<roman>), 
     :node( $/ ) );
   make $res;
-  my $res := PAST::Op.new( :name( $key ), :pasttype('call'));
+  my $res := mkcall0( $key );
   for $<value> {
     $res.push( $( $_ ));
   }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.