###
# [set]
# Copyright (c) 2002-2003 by William J. Coleda

.pcc_sub __cmd_set prototyped
  .param PerlArray argv
  
  .include "lib/macros/debug.imc"
  .local int debug
  debug = 0

  .local int argc 
  argc = argv

  .local PerlString value
  .local string retval
 
  if argc == 0 goto error

  $S1 = argv[0] 
  if argc == 2 goto setting
  if argc == 1 goto getting
  if argc > 2 goto error

getting:
  find_lex $P1, $S1
  retval = $P1
  .debug("Trying to get value of: ")
  .debug(S1)
  .debug("\n")
  goto done

setting:
  new value, .PerlString
  value = argv[1]
  .debug("Trying to save value of: ")
  .debug(value)
  .debug("\ninto")
  .debug($S1)
  .debug("\n")
  store_lex 0, $S1, value
  retval = value

  goto done 

  # fall through to a bad call.

error:
  print "wrong # args: should be \"set varName ?newValue?\"\n"

done:
  .pcc_begin_return
  .return retval
  .pcc_end_return
.end
