Computation of three-dimensional tokamak and spherical torus equilibria