I ran into a problem trying to convert Leo's "Case 1" example so that it uses methods instead of subs. Here's how far I got:
.HLL 'Amber', 'amber_kernel' .sub main :main newclass $P0, 'FOO' $P1 = new 'FOO' $P1.main() .end .namespace [ "FOO" ] .sub main :method $P0 = self.do_add3(20) print $P0 print "\n" .end .sub do_add3 :method .param pmc arg .const .Sub add3sub = 'add3' #(1) .local pmc add3closure add3closure = newclosure add3sub #$P1 = self.add3sub(arg) #(2) $P1 = self.add3closure(arg) #(3) .return ($P1) .end .sub add3 :method :outer('do_add3') #(4) .param pmc arg $P0 = n_add arg, 3 #(5) .return($P0) .end This segfaults at #(3). Possibly, I need to specify the FOO namespace at #(1) and/or #(4). But how? It doesn't work to write 'FOO\0add3', for example. Now for the really strange thing: I can make this example work by doing any one of several apparently-unrelated things: - uncomment line #(2) - remove the ":outer('do_add3')" part of line #(4) - remove the .HLL declaration at the top of the program - replace line #(5) by "$P0 = n_neg arg" (the significance of this might be that 'n_neg' is redefined in the Amber_INTEGER PMC - other operations are inherited unchanged from the Integer PMC) Does anyone have any ideas where I can look for clues? Regards, Roger Browne Here's Leo's original example: > .pragma n_operators 1 # add creates new PMC result below > .sub do_add3 > .param pmc arg # looks nicer than get_params > .lex '$a', arg > .lex '&add3', $P1 > .const .Sub add3 = "add3" > $P1 = newclosure add3 > $P2 = $P1() # tailcall eventually - b0rked > .return ($P2) > .end > > .sub add3 :anon :outer(do_add3) :lex > $P0 = find_lex '$a' > $P1 = $P0 + 3 # create/return new value > .return ($P1) > .end > > .sub main :main > $P0 = do_add3(20) > print $P0 > print "\n" > $P1 = do_add3(21) > print $P1 > print "\n" > .end >