Various people have bugged me about this for a long time so I figured
it was time, since it was the logical next step in hiding the Parrot
calling convention implementation details.

I've patched in initial support for IMCC to compile high level sub calls.

0, 1 and multiple return values are supported, but I didn't add flattening
support yet as I'm not sure what syntax to use.

The following works:

_foo()
var = _foo()
var = _foo(a, b)
(var1, var2) = _foo(a, b)
(var1) = _foo(a, b)         # redundant but supported


Notes:


* Since this is intermediate language, not HL, arguments to the
subs must be either variables or single constants, NOT expressions.

* Currently this syntax expects the sub name to be an IDENTIFIER.
I'll add a syntax for calling a sub in a variable and possible
by name (string constant).

* IMCC will default the subs calls to prototyped for now. Currently
our calling convention code is a bit broken, but the prototyped
version works well.

I've attached a couple of working samples.

Cheers,

-Melvin



# Sample 1
.sub _main
  .local int i
  .local int j
  .local string s
  i = 7
  $I1 = 8
  s = "nine"
  I0 = _foo(7, 8, "nine")
  print "return: "
  print I0
  print "\n"
  end
.end

.sub _foo
  .param int i
  .param int j
  .param string s
  print i
  print " "
  print j
  print " "
  print s
  print "\n"
  .pcc_begin_return
  .return 10
  .pcc_end_return
.end


# Sample 2, multiple return values .sub _main .local int i .local int j .local string s i = 7 $I1 = 8 s = "nine" (I0, I1) = _foo(7, 8, "nine") print "return: " print I0 print " " print I1 print "\n" end .end

.sub _foo
  .param int i
  .param int j
  .param string s
  print i
  print " "
  print j
  print " "
  print s
  print "\n"
  .pcc_begin_return
  .return 10
  .return 11
  .pcc_end_return
.end




Reply via email to