Hi, attached a patch with a start on the implementation of flush.pir

Note that ParrotIO.pmc doesn't seem to have a method to find out what mode it is opened in, so that check cannot be done.

regards,
kj

Will Coleda (via RT) wrote:

# New Ticket Created by Will Coleda # Please include the string: [perl #37815] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37815 >



File:
  languages/tcl/lib/builtins/flush.pir (exists, stub)
Spec:
  http://www.tcl.tk/man/tcl8.5/TclCmd/flush.htm
Tests:
  languages/tcl/t/cmd_flush.t (doesn't exist)
Implementation:
lookup the named channel in _Tcl::channels and use the flush method on the ParrotIO pmc.
See Also:
 languages/tcl/lib/builtins/howto.pod



--- flush.pir   2005-12-02 19:44:27.000000000 +0100
+++ flushpatch.pir      2005-12-02 19:33:39.000000000 +0100
@@ -7,6 +7,93 @@
   .param int register_num
   .param pmc argv
 
-  .return(register_num,'')
+  .local string pir_code, temp_code
+  pir_code = ""
+  temp_code = ""
+  
+  # get number of arguments and check
+  .local int argc
+   argc = argv
+  if argc != 1 goto args_miscount
+
+  # number of args is ok
+
+  # generate code that checks for the specified channel:
+  # get the channel specified to be flushed
+
+  .local pmc compiler, value
+  compiler = find_global "_Tcl", "compile_dispatch"
+  .local int value_num
+  value = argv[0]
+  (value_num, temp_code) = compiler(value, register_num)
+  pir_code .= temp_code
+  register_num = value_num + 1
+  $S0 = register_num
+  pir_code .= "$P"
+  pir_code .= $S0
+  pir_code .= "=$P"
+  $S0 = value_num
+  pir_code .= $S0
+  pir_code .= "\n"
+  temp_code = ".local string channel_id\n"
+  temp_code .= "channel_id = $P"
+  $S0 = register_num
+  temp_code .= $S0
+  pir_code .= temp_code
+
+  
+  pir_code .= <<"END_PIR"
+  # keep this comment, we need a newline!
+  # generate code for accessing the "channels" variable in ParTcl 
+  .local pmc channels, channel
+  channels = find_global "_Tcl", "channels"
+
+  # find the specified channel
+  channel = channels[channel_id]
+
+  # check whether the channel is found
+  unless_null channel, do_flush
+  #
+  # channel is not found;
+  # throw an exception
+  .local string msg
+  msg = "can not find channel named \\\""
+  msg .= channel_id
+  msg .= "\\\""
+  .throw(msg)
+END_PIR
+
+  pir_code .=<<"END_PIR"  
+do_flush:
+  # check whether it was opened for writing
+  # XXX TODO -- Seems like ParrotIO.pmc doesn't have support for this
+
+  # everything ok, flush it
+  channel."flush"()
+
+  # return an empty string
+  .local pmc retval
+  retval = new .TclString
+  retval = ""
+  .return(retval)
+END_PIR
+
+  .return(register_num, pir_code)
+
+channel_not_write_mode:
+  pir_code=<<"END_PIR"
+  .local string msg
+  msg = "channel \""
+  msg .= channel_id
+  msg .= "\" wasn't opened for writing"
+  .throw(msg)
+END_PIR
+
+.return(register_num, pir_code)
+
+args_miscount:
+  pir_code = ".throw(\"wrong # args: should be flush \\\"channelId\\\"\")\n"
+  .return(register_num, pir_code)
+
 .end
 

Reply via email to