The French government today suspended stock market trading in companies about to be nationalized and moved swiftly to rewrite portions of its takeover program that were rejected as unconstitutional by the nation's highest court.

The freeze was designed to prevent an avalanche of buy orders on the affected companies, whose stockholders stand to receive substantially higher compensation as a result of the court's decision Saturday attacking the Socialist government's reimbursement plan as unfair.

Prime Minister Pierre Mauroy called in several ministers and their chief aides for two urgent sessions to work out new legislation to meet the court's objections. Despite his determination to get the changes passed speedily, however, the ruling has imposed at least three weeks' delay in promulgation of nationalization laws that are the mainstay of President Francois Mitterrand's economic platform.

This setback was accompanied by the loss yesterday of four by-elections to the conservative opposition. Mitterrand's Socialists still enjoy an absolute majority--with 284 seats, including 19 affiliated members, in the 491-seat National Assembly. But the defeats in the first electoral test since its rise to power marked a highly visible loss of face for a government that had been riding high since presidential and legislative sweeps last May and June.

In what was seen as a measure of the embarrassment, Mauroy and his ministers remained uncharacteristically silent. The conservative opposition, on the other hand, issued a number of statements interpreting the results as a disavowal of Mitterrand's policies.

Some political analysts suggested the court decision Saturday night could have played a role in yesterday's vote. By finding fault with the government's nationalization program, the court, the Constitutional Council, seemed to bolster opposition arguments that the Socialists are proceeding recklessly into an economic adventure that will end up costing the country dearly, they said.

Claude Estier, a spokesman for the Socialist Party, suggested in a television interview tonight that the council may have timed its decision to give the opposition an advantage.

Whatever the connection between the court decision and the electoral losses, however, the two combined raised the danger of slowing the government's momentum at a time when Socialist politicians say they already are hearing complaints from constituents that the practical effects of Mitterrand's policies seem slow in coming.

Some Socialist officials have told French political reporters in private of fears that such impatience could cost them votes in cantonal elections scheduled for March. These elections, for local assemblies, will be the first nationwide test of political sentiment--far more meaningful than yesterday--since Mitterrand took over.

By decree, Mauroy has reduced the legal workweek from 40 to 39 hours and increased the legal vacation period from four to five weeks a year. These changes are due to take effect in the coming months, particularly at vacation time next summer.

But with unemployment having climbed several hundred thousand over 2 million and with inflation slightly up at 14 percent, the nationalizations were to become the most spectacular change flowing from the Socialist victory. Mauroy had planned to have the laws promulgated Wednesday and simultaneously announce names of new presidents for the banks and firms taken over.

Secretary of State Jean Le Garrec, in direct charge of nationalizations, said these plans now will have to be put back by more than a month, although other officials predicted the laws could be revised and contested sections pushed through parliament again in three weeks.

The most complicated change involves compensation for stockholders in companies and banks being taken over. The court ruled Mauroy's plan was unfair on this point mainly because it failed to take into account dividends for profits in 1981, but also because of other features of the way stocks were evaluated.

Preliminary estimates today said addition of the 1981 dividends alone could cost the government $360 million, with recalculation of stocks' value another costly addition to the total compensation bill of about $5.6 billion. It was this perspective that led Finance Minister Jacques Delors to order trading suspended for affected companies until the new payback system is worked out.

Stung by the delay, National Assembly President Louis Mermaz charged that the court's decision will cost the country time and money. He vowed to accelerate parliamentary procedure to get revised laws passed and suggested the court may have had politics in mind as well as law in making its ruling.

The court is not "intemporal and neutral," he said, referring to the fact most of its nine members were named by conservative political leaders under presidents Georges Pompidou and Valery Giscard d'Estaing.