Melt the butter in a small pot over medium heat and add the onions. Sweat the onions over medium heat for 5 minutes or until they are translucent. Add the flour and stir over medium heat for 2 minutes. Stir in the sugar, cinnamon, allspice, nutmeg, salt, pepper, and diced pumpkin; saute another minute. Add the stock and simmer for 15-20 minutes, or until the squash is very tender. Add the cream and simmer for 1 or 2 minutes longer. Puree in a blender or food processor. After ladling the soup into warm bowls, garnish it with the toasted walnuts and diced apple.