[m-rev.] diff: rename some function symbols in the MLDS

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Aug 22 01:53:27 AEST 2007


Estimated hours taken: 1
Branches: main

Rename some function symbols in the MLDS in order avoid ambiguities.

Fix an omission in the MLDS backend's handling of switches on foreign
enumerations.

compiler/mlds.m:
 	Add the prefix `ml_stmt_' to the constructors of the mlds_stmt/0 type.
 	The current names conflict with those in the HLDS and LLDS.

compiler/ml_simplify_switch.m:
 	Fix the above omission.

 	Try to avoid something similar occurring again by change the semidet
 	predicate is_integral_type/1 into a boolean function that switches
 	on the type mlds_type/0.

compiler/ml_elim_nested.m:
 	Turn some if-then-elses into the switches.

compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
 	Conform to the above change.

Julien.


Index: compiler/ml_call_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.77
diff -u -r1.77 ml_call_gen.m
--- compiler/ml_call_gen.m	19 Jan 2007 07:04:19 -0000	1.77
+++ compiler/ml_call_gen.m	21 Aug 2007 15:06:35 -0000
@@ -484,7 +484,7 @@
      ;
          CallKind = ordinary_call
      ),
-    Stmt = mlcall(Signature, FuncRval, ObjectRval, ArgRvals, RetLvals,
+    Stmt = ml_stmt_call(Signature, FuncRval, ObjectRval, ArgRvals, RetLvals,
          CallKind),
      Statement = statement(Stmt, mlds_make_context(Context)),
      Statements = [Statement].
Index: compiler/ml_closure_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_closure_gen.m,v
retrieving revision 1.51
diff -u -r1.51 ml_closure_gen.m
--- compiler/ml_closure_gen.m	13 Aug 2007 01:27:43 -0000	1.51
+++ compiler/ml_closure_gen.m	21 Aug 2007 15:06:35 -0000
@@ -1100,7 +1100,7 @@
              target_code_input(lval(ClosureArgLval)),
              raw_target_code(")->MR_closure_layout;\n", [])
          ],
-        ClosureLayoutPtrGCInit = statement(atomic(
+        ClosureLayoutPtrGCInit = statement(ml_stmt_atomic(
              inline_target_code(ml_target_c,
              ClosureLayoutPtrGCInitFragments)), MLDS_Context),
          TypeParamsGCInitFragments = [
@@ -1116,9 +1116,9 @@
              ClosureLayoutRval, ClosureLayoutType,
              ClosureLayoutDefns, !Info),
          ClosureLayoutPtrGCInit = statement(
-            block(
+            ml_stmt_block(
                  ClosureLayoutDefns,
-                [statement(atomic(
+                [statement(ml_stmt_atomic(
                      assign(ClosureLayoutPtrLval,
                      unop(box(ClosureLayoutType), ClosureLayoutRval)
                  )), MLDS_Context)]
@@ -1138,7 +1138,7 @@
          unexpected(this_file, "ml_gen_closure_wrapper_gc_decls: special_pred")

      ),
-    TypeParamsGCInit = statement(atomic(inline_target_code(
+    TypeParamsGCInit = statement(ml_stmt_atomic(inline_target_code(
          ml_target_c, TypeParamsGCInitFragments)), MLDS_Context),
      GC_Decls = [ClosureLayoutPtrDecl, TypeParamsDecl].

@@ -1194,7 +1194,7 @@
          ;
              GCStatement0 = gc_initialiser(CallTraceFuncCode)
          ),
-        MakeTypeInfoCode = atomic(inline_target_code(ml_target_c, [
+        MakeTypeInfoCode = ml_stmt_atomic(inline_target_code(ml_target_c, [
              raw_target_code("{\n", []),
              raw_target_code("MR_MemoryList allocated_mem = NULL;\n", []),
              target_code_output(TypeInfoLval),
@@ -1208,11 +1208,11 @@
                  "NULL, NULL, &allocated_mem);\n",
                  [i(ArgNum)]), [])
          ])),
-        DeallocateCode = atomic(inline_target_code(ml_target_c, [
+        DeallocateCode = ml_stmt_atomic(inline_target_code(ml_target_c, [
              raw_target_code("MR_deallocate(allocated_mem);\n", []),
              raw_target_code("}\n", [])
          ])),
-        GCTraceCode = block([TypeInfoDecl], [
+        GCTraceCode = ml_stmt_block([TypeInfoDecl], [
              statement(MakeTypeInfoCode, MLDS_Context),
              CallTraceFuncCode,
              statement(DeallocateCode, MLDS_Context)
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.204
diff -u -r1.204 ml_code_gen.m
--- compiler/ml_code_gen.m	13 Aug 2007 03:01:42 -0000	1.204
+++ compiler/ml_code_gen.m	21 Aug 2007 15:06:35 -0000
@@ -1787,7 +1787,7 @@
      %
      ml_gen_test_success(!.Info, Succeeded),
      ml_gen_call_current_success_cont(Context, CallCont, !Info),
-    IfStmt = if_then_else(Succeeded, CallCont, no),
+    IfStmt = ml_stmt_if_then_else(Succeeded, CallCont, no),
      IfStatement = statement(IfStmt, mlds_make_context(Context)),
      !:Statements = !.Statements ++ [IfStatement].

@@ -1870,9 +1870,9 @@
              [i(CommitLabelNum)]), no),
          ml_gen_var_lval(!.Info, CommitRef, mlds_commit_type, CommitRefLval),
          CommitRefDecl = ml_gen_commit_var_decl(MLDS_Context, CommitRef),
-        DoCommitStmt = do_commit(lval(CommitRefLval)),
+        DoCommitStmt = ml_stmt_do_commit(lval(CommitRefLval)),
          DoCommitStatement = statement(DoCommitStmt, MLDS_Context),
-        % pop nesting level
+        % Pop nesting level.
          ml_gen_nondet_label_func(!.Info, SuccessFuncLabel, Context,
              DoCommitStatement, SuccessFunc),

@@ -1890,7 +1890,7 @@
              SetSuccessFalse),
          ml_gen_set_success(!.Info, const(mlconst_true), Context,
              SetSuccessTrue),
-        TryCommitStmt = try_commit(CommitRefLval,
+        TryCommitStmt = ml_stmt_try_commit(CommitRefLval,
              ml_gen_block([], [GoalStatement, SetSuccessFalse], Context),
              ml_gen_block([], list.append(CopyLocalsToOutputArgs,
                  [SetSuccessTrue]), Context)),
@@ -1949,7 +1949,7 @@
              string.format("commit_%d", [i(CommitLabelNum)]), no),
          ml_gen_var_lval(!.Info, CommitRef, mlds_commit_type, CommitRefLval),
          CommitRefDecl = ml_gen_commit_var_decl(MLDS_Context, CommitRef),
-        DoCommitStmt = do_commit(lval(CommitRefLval)),
+        DoCommitStmt = ml_stmt_do_commit(lval(CommitRefLval)),
          DoCommitStatement = statement(DoCommitStmt, MLDS_Context),
          % pop nesting level
          ml_gen_nondet_label_func(!.Info, SuccessFuncLabel, Context,
@@ -1966,7 +1966,7 @@
              GoalContext),
          ml_gen_info_pop_success_cont(!Info),

-        TryCommitStmt = try_commit(CommitRefLval, GoalStatement,
+        TryCommitStmt = ml_stmt_try_commit(CommitRefLval, GoalStatement,
              ml_gen_block([], CopyLocalsToOutputArgs, Context)),
          TryCommitStatement = statement(TryCommitStmt, MLDS_Context),
          CommitFuncLocalDecls = [CommitRefDecl, SuccessFunc | GoalStaticDecls],
@@ -2046,8 +2046,8 @@
          RetTypes = [],
          Signature = mlds_func_signature(ArgTypes, RetTypes),
          CallKind = ordinary_call,
-        CallStmt = mlcall(Signature, CommitFuncLabelRval, no, ArgRvals, [],
-            CallKind),
+        CallStmt = ml_stmt_call(Signature, CommitFuncLabelRval, no, ArgRvals,
+            [], CallKind),
          CallStatement = statement(CallStmt, mlds_make_context(Context)),
          % Package it all up.
          Statements = [CallStatement],
@@ -2445,10 +2445,10 @@
      ],
      Starting_C_Code_Stmt = inline_target_code(ml_target_c, Starting_C_Code),
      Starting_C_Code_Statement = statement(
-        atomic(Starting_C_Code_Stmt), mlds_make_context(Context)),
+        ml_stmt_atomic(Starting_C_Code_Stmt), mlds_make_context(Context)),
      Ending_C_Code_Stmt = inline_target_code(ml_target_c, Ending_C_Code),
      Ending_C_Code_Statement = statement(
-        atomic(Ending_C_Code_Stmt), mlds_make_context(Context)),
+        ml_stmt_atomic(Ending_C_Code_Stmt), mlds_make_context(Context)),
      Statements = list.condense([
          [Starting_C_Code_Statement],
          ConvStatements,
@@ -2467,7 +2467,8 @@
      MLDSContext = mlds_make_context(Context),
      ml_success_lval(!.Info, SuccessLval),
      ml_generate_runtime_cond_code(TraceRuntimeCond, CondRval, !Info),
-    Statement = statement(atomic(assign(SuccessLval, CondRval)), MLDSContext),
+    Statement = statement(ml_stmt_atomic(assign(SuccessLval, CondRval)),
+        MLDSContext),
      Statements = [Statement].

  :- pred ml_generate_runtime_cond_code(trace_expr(trace_runtime)::in,
@@ -2595,7 +2596,7 @@
      ]),
      Java_Code_Stmt = inline_target_code(ml_target_java, Java_Code),
      Java_Code_Statement = statement(
-        atomic(Java_Code_Stmt),
+        ml_stmt_atomic(Java_Code_Stmt),
          mlds_make_context(Context)),
      Statements = list.condense([
          [Java_Code_Statement],
@@ -2665,7 +2666,7 @@
      ),

      Statements = [
-        statement(atomic(OutlineStmt), MLDSContext) |
+        statement(ml_stmt_atomic(OutlineStmt), MLDSContext) |
          SuccessIndicatorStatements
          ],
      Decls = SuccessVarLocals.
@@ -2771,8 +2772,8 @@
                  get_extra_attributes(Attributes)))
          ]),

-    ILCodeFragment = statement(atomic(OutlineStmt), MLDSContext),
-    Statements = [statement(block(VarLocals,
+    ILCodeFragment = statement(ml_stmt_atomic(OutlineStmt), MLDSContext),
+    Statements = [statement(ml_stmt_block(VarLocals,
          [ILCodeFragment] ++ ByRefAssignStatements ++ CopiedOutputStatements),
          mlds_make_context(Context))],
      Decls = [].
@@ -3029,8 +3030,8 @@
      Starting_C_Code_Stmt = inline_target_code(ml_target_c, Starting_C_Code),
      Ending_C_Code_Stmt = inline_target_code(ml_target_c, Ending_C_Code),
      Starting_C_Code_Statement = statement(
-        atomic(Starting_C_Code_Stmt), mlds_make_context(Context)),
-    Ending_C_Code_Statement = statement(atomic(Ending_C_Code_Stmt),
+        ml_stmt_atomic(Starting_C_Code_Stmt), mlds_make_context(Context)),
+    Ending_C_Code_Statement = statement(ml_stmt_atomic(Ending_C_Code_Stmt),
          mlds_make_context(Context)),
      Statements = list.condense([
          [Starting_C_Code_Statement],
@@ -3514,7 +3515,8 @@
          ml_gen_test_success(!.Info, Succeeded),
          ml_gen_goal(CodeModel, Then, ThenStatement, !Info),
          ml_gen_goal(CodeModel, Else, ElseStatement, !Info),
-        IfStmt = if_then_else(Succeeded, ThenStatement, yes(ElseStatement)),
+        IfStmt = ml_stmt_if_then_else(Succeeded, ThenStatement,
+            yes(ElseStatement)),
          IfStatement = statement(IfStmt, mlds_make_context(Context)),
          Decls = CondDecls,
          Statements = CondStatements ++ [IfStatement]
@@ -3579,7 +3581,8 @@
          % Generate `if (!cond_<N>) { <Else> }'.
          ml_gen_test_cond_var(!.Info, CondVar, CondSucceeded),
          ml_gen_goal(CodeModel, Else, ElseStatement, !Info),
-        IfStmt = if_then_else(unop(std_unop(logical_not), CondSucceeded),
+        IfStmt = ml_stmt_if_then_else(
+            unop(std_unop(logical_not), CondSucceeded),
              ElseStatement, no),
          IfStatement = statement(IfStmt, MLDS_Context),

@@ -3756,8 +3759,8 @@
              ml_gen_disj(Rest, CodeModel, Context,
                  RestDecls, RestStatements, !Info),
              RestStatement = ml_gen_block(RestDecls, RestStatements, Context),
-            IfStmt = if_then_else(unop(std_unop(logical_not), Succeeded),
-                RestStatement, no),
+            IfStmt = ml_stmt_if_then_else(
+                unop(std_unop(logical_not), Succeeded), RestStatement, no),
              IfStatement = statement(IfStmt, mlds_make_context(Context)),
              Decls = FirstDecls,
              Statements = FirstStatements ++ [IfStatement]
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.126
diff -u -r1.126 ml_code_util.m
--- compiler/ml_code_util.m	20 Aug 2007 03:35:59 -0000	1.126
+++ compiler/ml_code_util.m	21 Aug 2007 15:06:35 -0000
@@ -771,7 +771,7 @@

  ml_gen_assign(Lval, Rval, Context) = Statement :-
      Assign = assign(Lval, Rval),
-    Stmt = atomic(Assign),
+    Stmt = ml_stmt_atomic(Assign),
      Statement = statement(Stmt, mlds_make_context(Context)).

  ml_append_return_statement(Info, CodeModel, CopiedOutputVarLvals, Context,
@@ -782,7 +782,7 @@
          ml_gen_test_success(Info, Succeeded),
          CopiedOutputVarRvals = list.map(func(Lval) = lval(Lval),
              CopiedOutputVarLvals),
-        ReturnStmt = return([Succeeded | CopiedOutputVarRvals]),
+        ReturnStmt = ml_stmt_return([Succeeded | CopiedOutputVarRvals]),
          ReturnStatement = statement(ReturnStmt,
              mlds_make_context(Context)),
          !:Statements = !.Statements ++ [ReturnStatement]
@@ -792,7 +792,7 @@
      ->
          CopiedOutputVarRvals = list.map(func(Lval) = lval(Lval),
              CopiedOutputVarLvals),
-        ReturnStmt = return(CopiedOutputVarRvals),
+        ReturnStmt = ml_stmt_return(CopiedOutputVarRvals),
          ReturnStatement = statement(ReturnStmt,
              mlds_make_context(Context)),
          !:Statements = !.Statements ++ [ReturnStatement]
@@ -807,7 +807,7 @@
      ->
          SingleStatement
      ;
-        statement(block(VarDecls, Statements),
+        statement(ml_stmt_block(VarDecls, Statements),
              mlds_make_context(Context))
      ).

@@ -860,7 +860,7 @@
          ml_gen_test_success(!.Info, Succeeded),
          DoGenRest(RestDecls, RestStatements, !Info),
          IfBody = ml_gen_block([], RestStatements, Context),
-        IfStmt = if_then_else(Succeeded, IfBody, no),
+        IfStmt = ml_stmt_if_then_else(Succeeded, IfBody, no),
          IfStatement = statement(IfStmt, mlds_make_context(Context)),
          Decls = FirstDecls ++ RestDecls,
          Statements = FirstStatements ++ [IfStatement]
@@ -1751,7 +1751,7 @@
      ObjectRval = no,
      RetLvals = [],
      CallKind = ordinary_call,
-    Stmt = mlcall(Signature, FuncRval, ObjectRval, ArgRvals, RetLvals,
+    Stmt = ml_stmt_call(Signature, FuncRval, ObjectRval, ArgRvals, RetLvals,
          CallKind),
      Statement = statement(Stmt, mlds_make_context(Context)).

@@ -1819,7 +1819,7 @@
          PassedContVarName), InnerFuncArgType)),
      InnerFuncParams = mlds_func_params([PassedContArg | InnerArgs0], Rets),

-    InnerStmt = mlcall(Signature, InnerFuncRval, ObjectRval,
+    InnerStmt = ml_stmt_call(Signature, InnerFuncRval, ObjectRval,
          InnerArgRvals, RetLvals, CallKind),
      InnerStatement = statement(InnerStmt, MLDS_Context),

@@ -1841,10 +1841,10 @@
              code_addr_internal(QualProcLabel, SeqNum, ProxySignature))),

          % Put it inside a block where we call it.
-        Stmt = mlcall(ProxySignature, ProxyFuncRval, ObjectRval,
+        Stmt = ml_stmt_call(ProxySignature, ProxyFuncRval, ObjectRval,
              ProxyArgRvals, RetLvals, CallKind),
-        Statement = statement(
-            block([Defn], [statement(Stmt, MLDS_Context)]), MLDS_Context)
+        BlockStmt = ml_stmt_block([Defn], [statement(Stmt, MLDS_Context)]),
+        Statement = statement(BlockStmt, MLDS_Context)
      ;
          unexpected(this_file,
              "success continuation generated was not a function")
@@ -2126,7 +2126,7 @@
      % `private_builtin.gc_trace(TypeInfo, (MR_C_Pointer) &Var);'.
      CastVarAddr = unop(cast(CPointerType), mem_addr(VarLval)),
      TraceStatement = statement(
-        mlcall(Signature, FuncAddr, no,
+        ml_stmt_call(Signature, FuncAddr, no,
              [TypeInfoRval, CastVarAddr], [], ordinary_call
          ), mlds_make_context(Context)).

@@ -2207,49 +2207,49 @@

  fixup_newobj_in_stmt(Stmt0, Stmt, !Fixup) :-
      (
-        Stmt0 = block(Defns, Statements0),
+        Stmt0 = ml_stmt_block(Defns, Statements0),
          list.map_foldl(fixup_newobj_in_statement,
              Statements0, Statements, !Fixup),
-        Stmt = block(Defns, Statements)
+        Stmt = ml_stmt_block(Defns, Statements)
      ;
-        Stmt0 = while(Rval, Statement0, Once),
+        Stmt0 = ml_stmt_while(Rval, Statement0, Once),
          fixup_newobj_in_statement(Statement0, Statement, !Fixup),
-        Stmt = while(Rval, Statement, Once)
+        Stmt = ml_stmt_while(Rval, Statement, Once)
      ;
-        Stmt0 = if_then_else(Cond, Then0, MaybeElse0),
+        Stmt0 = ml_stmt_if_then_else(Cond, Then0, MaybeElse0),
          fixup_newobj_in_statement(Then0, Then, !Fixup),
          fixup_newobj_in_maybe_statement(MaybeElse0, MaybeElse, !Fixup),
-        Stmt = if_then_else(Cond, Then, MaybeElse)
+        Stmt = ml_stmt_if_then_else(Cond, Then, MaybeElse)
      ;
-        Stmt0 = switch(Type, Val, Range, Cases0, Default0),
+        Stmt0 = ml_stmt_switch(Type, Val, Range, Cases0, Default0),
          list.map_foldl(fixup_newobj_in_case, Cases0, Cases, !Fixup),
          fixup_newobj_in_default(Default0, Default, !Fixup),
-        Stmt = switch(Type, Val, Range, Cases, Default)
+        Stmt = ml_stmt_switch(Type, Val, Range, Cases, Default)
      ;
-        Stmt0 = label(_),
+        Stmt0 = ml_stmt_label(_),
          Stmt = Stmt0
      ;
-        Stmt0 = goto(_),
+        Stmt0 = ml_stmt_goto(_),
          Stmt = Stmt0
      ;
-        Stmt0 = computed_goto(Rval, Labels),
-        Stmt = computed_goto(Rval, Labels)
+        Stmt0 = ml_stmt_computed_goto(Rval, Labels),
+        Stmt = ml_stmt_computed_goto(Rval, Labels)
      ;
-        Stmt0 = mlcall(_Sig, _Func, _Obj, _Args, _RetLvals, _TailCall),
+        Stmt0 = ml_stmt_call(_Sig, _Func, _Obj, _Args, _RetLvals, _TailCall),
          Stmt = Stmt0
      ;
-        Stmt0 = return(_Rvals),
+        Stmt0 = ml_stmt_return(_Rvals),
          Stmt = Stmt0
      ;
-        Stmt0 = do_commit(_Ref),
+        Stmt0 = ml_stmt_do_commit(_Ref),
          Stmt = Stmt0
      ;
-        Stmt0 = try_commit(Ref, Statement0, Handler0),
+        Stmt0 = ml_stmt_try_commit(Ref, Statement0, Handler0),
          fixup_newobj_in_statement(Statement0, Statement, !Fixup),
          fixup_newobj_in_statement(Handler0, Handler, !Fixup),
-        Stmt = try_commit(Ref, Statement, Handler)
+        Stmt = ml_stmt_try_commit(Ref, Statement, Handler)
      ;
-        Stmt0 = atomic(AtomicStmt0),
+        Stmt0 = ml_stmt_atomic(AtomicStmt0),
          fixup_newobj_in_atomic_statement(AtomicStmt0, Stmt, !Fixup)
      ).

@@ -2327,11 +2327,11 @@
          % Generate code to assign the address of the new local variable
          % to the Lval.
          TaggedPtrRval = maybe_tag_rval(MaybeTag, PointerType, PtrRval),
-        AssignStmt = atomic(assign(Lval, TaggedPtrRval)),
+        AssignStmt = ml_stmt_atomic(assign(Lval, TaggedPtrRval)),
          AssignStatement = statement(AssignStmt, Context),
-        Stmt = block([], ArgInitStatements ++ [AssignStatement])
+        Stmt = ml_stmt_block([], ArgInitStatements ++ [AssignStatement])
      ;
-        Stmt = atomic(AtomicStatement0)
+        Stmt = ml_stmt_atomic(AtomicStatement0)
      ).

  :- pred init_field_n(mlds_type::in, mlds_rval::in, mlds_context::in,
@@ -2344,7 +2344,7 @@
      FieldType = mlds_generic_type,
      MaybeTag = yes(0),
      Field = field(MaybeTag, PointerRval, FieldId, FieldType, PointerType),
-    AssignStmt = atomic(assign(Field, ArgRval)),
+    AssignStmt = ml_stmt_atomic(assign(Field, ArgRval)),
      Statement = statement(AssignStmt, Context).

  :- func maybe_tag_rval(maybe(mlds_tag), mlds_type, mlds_rval) = mlds_rval.
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.92
diff -u -r1.92 ml_elim_nested.m
--- compiler/ml_elim_nested.m	25 Jul 2007 06:12:21 -0000	1.92
+++ compiler/ml_elim_nested.m	21 Aug 2007 15:06:35 -0000
@@ -622,7 +622,7 @@
                  % struct variable at the start of the top-level function's
                  % body, and append the final unlink statement (if any)
                  % at the end.
-                FuncBody = ml_block(EnvDecls,
+                FuncBody = make_block_stmt(EnvDecls,
                      InitEnv ++ CodeToCopyArgs ++ [FuncBody2] ++ UnchainFrame,
                      Context),
                  % Insert the environment struct type at the start of the list
@@ -718,7 +718,7 @@
          EnvArgLval = field(Tag, EnvPtr, FieldName, FieldType, EnvPtrTypeName),
          ArgRval = lval(var(QualVarName, FieldType)),
          AssignToEnv = assign(EnvArgLval, ArgRval),
-        CodeToCopyArg = statement(atomic(AssignToEnv), Context),
+        CodeToCopyArg = statement(ml_stmt_atomic(AssignToEnv), Context),

          ArgsToCopy = [ArgToCopy | ArgsToCopy0],
          CodeToCopyArgs = [CodeToCopyArg | CodeToCopyArgs0]
@@ -810,22 +810,25 @@

      % Extract the GC tracing code from the fields.
      list.map3(extract_gc_statements, Fields0, Fields1,
-        GC_InitStatements,GC_TraceStatements),
-    list.append(GC_InitStatements,GC_TraceStatements,GC_Statements0),
+        GC_InitStatements, GC_TraceStatements),
+    list.append(GC_InitStatements, GC_TraceStatements, GC_Statements0),
      GC_Statements = list.condense(GC_Statements0),

-    ( Action = chain_gc_stack_frames ->
+    (
+        Action = chain_gc_stack_frames,
          ml_chain_stack_frames(Fields1, GC_Statements, EnvTypeName,
              Context, FuncName, ModuleName, Globals, Fields, EnvInitializer,
              LinkStackChain, GCTraceFuncDefns),
          GCStatementEnv = gc_no_stmt
      ;
+        Action = hoist_nested_funcs,
          (
              GC_Statements = [],
              GCStatementEnv = gc_no_stmt
          ;
              GC_Statements = [_ | _],
-            GCStatementEnv = gc_trace_code(ml_block([], GC_Statements, Context))
+            GC_Block = make_block_stmt([], GC_Statements, Context),
+            GCStatementEnv = gc_trace_code(GC_Block)
          ),
          Fields = Fields1,
          EnvInitializer = no_initializer,
@@ -867,7 +870,7 @@
          % the value of MayUseAtomic is immaterial.
          MayUseAtomic = may_not_use_atomic_alloc,
          NewObj = [statement(
-            atomic(new_object(var(EnvVar, EnvTypeName),
+            ml_stmt_atomic(new_object(var(EnvVar, EnvTypeName),
                  no, no, EnvTypeName, no, no, [], [], MayUseAtomic)),
              Context)]
      ;
@@ -963,7 +966,7 @@
      EnvPtr = lval(var(qual(ModuleName, module_qual,
          mlds_var_name("frame_ptr", no)), EnvPtrTypeName)),
      AssignToStackChain = assign(StackChain, EnvPtr),
-    LinkStackChain = [statement(atomic(AssignToStackChain), Context)].
+    LinkStackChain = [statement(ml_stmt_atomic(AssignToStackChain), Context)].

  :- pred gen_gc_trace_func(mlds_entity_name::in, mlds_module_name::in,
      mlds_defn::in, list(statement)::in, mlds_context::in,
@@ -1009,7 +1012,7 @@
      ),

      % Construct the function definition.
-    Statement = statement(block([FramePointerDecl], GCTraceStatements),
+    Statement = statement(ml_stmt_block([FramePointerDecl], GCTraceStatements),
          Context),
      DeclFlags = ml_gen_gc_trace_func_decl_flags,
      MaybePredProcId = no,
@@ -1126,7 +1129,7 @@

          ml_init_env(Action, TypeName, CastEnvPtrVal, Context,
              ModuleName, Globals, EnvPtrDecl, InitEnvPtr),
-        FuncBody = statement(block([EnvPtrDecl],
+        FuncBody = statement(ml_stmt_block([EnvPtrDecl],
              [InitEnvPtr, FuncBody0]), Context),
          DefnBody = mlds_function(PredProcId, Params,
              body_defined_here(FuncBody), Attributes, EnvVarNames),
@@ -1185,7 +1188,7 @@
      %
      EnvPtrVar = qual(ModuleName, module_qual, EnvPtrVarName),
      AssignEnvPtr = assign(var(EnvPtrVar, EnvPtrVarType), EnvPtrVal),
-    InitEnvPtr = statement(atomic(AssignEnvPtr), Context).
+    InitEnvPtr = statement(ml_stmt_atomic(AssignEnvPtr), Context).

      % Given the declaration for a function parameter, produce a declaration
      % for a corresponding local variable or environment struct field.
@@ -1220,17 +1223,17 @@
      % But if the block consists only of a single statement with no
      % declarations, then just return that statement.
      %
-:- func ml_block(mlds_defns, statements, mlds_context)
+:- func make_block_stmt(mlds_defns, statements, mlds_context)
      = statement.

-ml_block(VarDecls, Statements, Context) =
+make_block_stmt(VarDecls, Statements, Context) =
      (
          VarDecls = [],
          Statements = [SingleStatement]
      ->
          SingleStatement
      ;
-        statement(block(VarDecls, Statements), Context)
+        statement(ml_stmt_block(VarDecls, Statements), Context)
      ).

  :- func ml_stack_chain_var = mlds_lval.
@@ -1383,69 +1386,71 @@

  flatten_stmt(Stmt0, Stmt, !Info) :-
      (
-        Stmt0 = block(Defns0, Statements0),
+        Stmt0 = ml_stmt_block(Defns0, Statements0),
          flatten_nested_defns(Defns0, Statements0, Defns, InitStatements,
              !Info),
          flatten_statements(InitStatements ++ Statements0, Statements, !Info),
-        Stmt = block(Defns, Statements)
+        Stmt = ml_stmt_block(Defns, Statements)
      ;
-        Stmt0 = while(Rval0, Statement0, Once),
+        Stmt0 = ml_stmt_while(Rval0, Statement0, Once),
          fixup_rval(Rval0, Rval, !Info),
          flatten_statement(Statement0, Statement, !Info),
-        Stmt = while(Rval, Statement, Once)
+        Stmt = ml_stmt_while(Rval, Statement, Once)
      ;
-        Stmt0 = if_then_else(Cond0, Then0, MaybeElse0),
+        Stmt0 = ml_stmt_if_then_else(Cond0, Then0, MaybeElse0),
          fixup_rval(Cond0, Cond, !Info),
          flatten_statement(Then0, Then, !Info),
          flatten_maybe_statement(MaybeElse0, MaybeElse, !Info),
-        Stmt = if_then_else(Cond, Then, MaybeElse)
+        Stmt = ml_stmt_if_then_else(Cond, Then, MaybeElse)
      ;
-        Stmt0 = switch(Type, Val0, Range, Cases0, Default0),
+        Stmt0 = ml_stmt_switch(Type, Val0, Range, Cases0, Default0),
          fixup_rval(Val0, Val, !Info),
          list.map_foldl(flatten_case, Cases0, Cases, !Info),
          flatten_default(Default0, Default, !Info),
-        Stmt = switch(Type, Val, Range, Cases, Default)
+        Stmt = ml_stmt_switch(Type, Val, Range, Cases, Default)
      ;
-        Stmt0 = label(_),
+        Stmt0 = ml_stmt_label(_),
          Stmt = Stmt0
      ;
-        Stmt0 = goto(_),
+        Stmt0 = ml_stmt_goto(_),
          Stmt = Stmt0
      ;
-        Stmt0 = computed_goto(Rval0, Labels),
+        Stmt0 = ml_stmt_computed_goto(Rval0, Labels),
          fixup_rval(Rval0, Rval, !Info),
-        Stmt = computed_goto(Rval, Labels)
+        Stmt = ml_stmt_computed_goto(Rval, Labels)
      ;
-        Stmt0 = mlcall(Sig, Func0, Obj0, Args0, RetLvals0, TailCall),
+        Stmt0 = ml_stmt_call(Sig, Func0, Obj0, Args0, RetLvals0, TailCall),
          fixup_rval(Func0, Func, !Info),
          fixup_maybe_rval(Obj0, Obj, !Info),
          fixup_rvals(Args0, Args, !Info),
          fixup_lvals(RetLvals0, RetLvals, !Info),
-        Stmt = mlcall(Sig, Func, Obj, Args, RetLvals, TailCall)
+        Stmt = ml_stmt_call(Sig, Func, Obj, Args, RetLvals, TailCall)
      ;
-        Stmt0 = return(Rvals0),
+        Stmt0 = ml_stmt_return(Rvals0),
          fixup_rvals(Rvals0, Rvals, !Info),
-        Stmt = return(Rvals)
+        Stmt = ml_stmt_return(Rvals)
      ;
-        Stmt0 = do_commit(Ref0),
+        Stmt0 = ml_stmt_do_commit(Ref0),
          fixup_rval(Ref0, Ref, !Info),
-        Stmt = do_commit(Ref)
+        Stmt = ml_stmt_do_commit(Ref)
      ;
-        Stmt0 = try_commit(Ref0, Statement0, Handler0),
+        Stmt0 = ml_stmt_try_commit(Ref0, Statement0, Handler0),
          fixup_lval(Ref0, Ref, !Info),
          flatten_statement(Statement0, Statement1, !Info),
          flatten_statement(Handler0, Handler1, !Info),
-        Stmt1 = try_commit(Ref, Statement1, Handler1),
+        Stmt1 = ml_stmt_try_commit(Ref, Statement1, Handler1),
          Action = !.Info ^ action,
-        ( Action = chain_gc_stack_frames ->
+        (
+            Action = chain_gc_stack_frames,
              save_and_restore_stack_chain(Stmt1, Stmt, !Info)
          ;
+            Action = hoist_nested_funcs,
              Stmt = Stmt1
          )
      ;
-        Stmt0 = atomic(AtomicStmt0),
+        Stmt0 = ml_stmt_atomic(AtomicStmt0),
          fixup_atomic_stmt(AtomicStmt0, AtomicStmt, !Info),
-        Stmt = atomic(AtomicStmt)
+        Stmt = ml_stmt_atomic(AtomicStmt)
      ).

  :- pred flatten_case(mlds_switch_case::in, mlds_switch_case::out,
@@ -1484,29 +1489,29 @@
      %       }
      %   }
      %
-:- inst try_commit ---> try_commit(ground, ground, ground).
+:- inst try_commit
+    --->    ml_stmt_try_commit(ground, ground, ground).

  :- pred save_and_restore_stack_chain(mlds_stmt::in(try_commit),
-    mlds_stmt::out,
-    elim_info::in, elim_info::out) is det.
+    mlds_stmt::out, elim_info::in, elim_info::out) is det.

  save_and_restore_stack_chain(Stmt0, Stmt, ElimInfo0, ElimInfo) :-
      ModuleName = ElimInfo0 ^ module_name,
      counter.allocate(Id, ElimInfo0 ^ saved_stack_chain_counter, NextId),
      ElimInfo = (ElimInfo0 ^ saved_stack_chain_counter := NextId),
-    Stmt0 = try_commit(Ref, Statement0, Handler0),
+    Stmt0 = ml_stmt_try_commit(Ref, Statement0, Handler0),
      Statement0 = statement(_, StatementContext),
      Handler0 = statement(_, HandlerContext),
      SavedVarDecl = gen_saved_stack_chain_var(Id, StatementContext),
      SaveStatement = gen_save_stack_chain_var(ModuleName, Id, StatementContext),
      RestoreStatement = gen_restore_stack_chain_var(ModuleName, Id,
          HandlerContext),
-    Statement = statement(block([], [SaveStatement, Statement0]),
+    Statement = statement(ml_stmt_block([], [SaveStatement, Statement0]),
          HandlerContext),
-    Handler = statement(block([], [RestoreStatement, Handler0]),
+    Handler = statement(ml_stmt_block([], [RestoreStatement, Handler0]),
          HandlerContext),
-    TryCommit = try_commit(Ref, Statement, Handler),
-    Stmt = block(
+    TryCommit = ml_stmt_try_commit(Ref, Statement, Handler),
+    Stmt = ml_stmt_block(
          [SavedVarDecl],
          [statement(TryCommit, StatementContext)]
      ).
@@ -1617,7 +1622,7 @@
                  VarLval = var(qual(!.Info ^ module_name, module_qual, VarName),
                      Type),
                  InitStatements = [statement(
-                    atomic(assign(VarLval, Rval)), Context)]
+                    ml_stmt_atomic(assign(VarLval, Rval)), Context)]
              ;
                  Defn1 = Defn0,
                  InitStatements = []
@@ -2082,48 +2087,48 @@

  stmt_contains_defn(Stmt, Defn) :-
      (
-        Stmt = block(Defns, Statements),
+        Stmt = ml_stmt_block(Defns, Statements),
          ( defns_contains_defn(Defns, Defn)
          ; statements_contains_defn(Statements, Defn)
          )
      ;
-        Stmt = while(_Rval, Statement, _Once),
+        Stmt = ml_stmt_while(_Rval, Statement, _Once),
          statement_contains_defn(Statement, Defn)
      ;
-        Stmt = if_then_else(_Cond, Then, MaybeElse),
+        Stmt = ml_stmt_if_then_else(_Cond, Then, MaybeElse),
          ( statement_contains_defn(Then, Defn)
          ; maybe_statement_contains_defn(MaybeElse, Defn)
          )
      ;
-        Stmt = switch(_Type, _Val, _Range, Cases, Default),
+        Stmt = ml_stmt_switch(_Type, _Val, _Range, Cases, Default),
          ( cases_contains_defn(Cases, Defn)
          ; default_contains_defn(Default, Defn)
          )
      ;
-        Stmt = label(_Label),
+        Stmt = ml_stmt_label(_Label),
          fail
      ;
-        Stmt = goto(_),
+        Stmt = ml_stmt_goto(_),
          fail
      ;
-        Stmt = computed_goto(_Rval, _Labels),
+        Stmt = ml_stmt_computed_goto(_Rval, _Labels),
          fail
      ;
-        Stmt = mlcall(_Sig, _Func, _Obj, _Args, _RetLvals, _TailCall),
+        Stmt = ml_stmt_call(_Sig, _Func, _Obj, _Args, _RetLvals, _TailCall),
          fail
      ;
-        Stmt = return(_Rvals),
+        Stmt = ml_stmt_return(_Rvals),
          fail
      ;
-        Stmt = do_commit(_Ref),
+        Stmt = ml_stmt_do_commit(_Ref),
          fail
      ;
-        Stmt = try_commit(_Ref, Statement, Handler),
+        Stmt = ml_stmt_try_commit(_Ref, Statement, Handler),
          ( statement_contains_defn(Statement, Defn)
          ; statement_contains_defn(Handler, Defn)
          )
      ;
-        Stmt = atomic(_AtomicStmt),
+        Stmt = ml_stmt_atomic(_AtomicStmt),
          fail
      ).

@@ -2177,50 +2182,49 @@

  add_unchain_stack_to_stmt(Stmt0, Context, Stmt, !Info) :-
      (
-        Stmt0 = block(Defns, Statements0),
+        Stmt0 = ml_stmt_block(Defns, Statements0),
          add_unchain_stack_to_statements(Statements0, Statements, !Info),
-        Stmt = block(Defns, Statements)
+        Stmt = ml_stmt_block(Defns, Statements)
      ;
-        Stmt0 = while(Rval, Statement0, Once),
+        Stmt0 = ml_stmt_while(Rval, Statement0, Once),
          add_unchain_stack_to_statement(Statement0, Statement, !Info),
-        Stmt = while(Rval, Statement, Once)
+        Stmt = ml_stmt_while(Rval, Statement, Once)
      ;
-        Stmt0 = if_then_else(Cond, Then0, MaybeElse0),
+        Stmt0 = ml_stmt_if_then_else(Cond, Then0, MaybeElse0),
          add_unchain_stack_to_statement(Then0, Then, !Info),
          add_unchain_stack_to_maybe_statement(MaybeElse0, MaybeElse, !Info),
-        Stmt = if_then_else(Cond, Then, MaybeElse)
+        Stmt = ml_stmt_if_then_else(Cond, Then, MaybeElse)
      ;
-        Stmt0 = switch(Type, Val, Range, Cases0, Default0),
-        list.map_foldl(add_unchain_stack_to_case, Cases0, Cases,
-            !Info),
+        Stmt0 = ml_stmt_switch(Type, Val, Range, Cases0, Default0),
+        list.map_foldl(add_unchain_stack_to_case, Cases0, Cases, !Info),
          add_unchain_stack_to_default(Default0, Default, !Info),
-        Stmt = switch(Type, Val, Range, Cases, Default)
+        Stmt = ml_stmt_switch(Type, Val, Range, Cases, Default)
      ;
-        Stmt0 = label(_),
+        Stmt0 = ml_stmt_label(_),
          Stmt = Stmt0
      ;
-        Stmt0 = goto(_),
+        Stmt0 = ml_stmt_goto(_),
          Stmt = Stmt0
      ;
-        Stmt0 = computed_goto(_Rval, _Labels),
+        Stmt0 = ml_stmt_computed_goto(_Rval, _Labels),
          Stmt = Stmt0
      ;
-        Stmt0 = mlcall(_Sig, _Func, _Obj, _Args, RetLvals, CallKind),
+        Stmt0 = ml_stmt_call(_Sig, _Func, _Obj, _Args, RetLvals, CallKind),
          add_unchain_stack_to_call(Stmt0, RetLvals, CallKind, Context,
              Stmt, !Info)
      ;
-        Stmt0 = return(_Rvals),
+        Stmt0 = ml_stmt_return(_Rvals),
          Stmt = prepend_unchain_frame(Stmt0, Context, !.Info)
      ;
-        Stmt0 = do_commit(_Ref),
+        Stmt0 = ml_stmt_do_commit(_Ref),
          Stmt = Stmt0
      ;
-        Stmt0 = try_commit(Ref, Statement0, Handler0),
+        Stmt0 = ml_stmt_try_commit(Ref, Statement0, Handler0),
          add_unchain_stack_to_statement(Statement0, Statement, !Info),
          add_unchain_stack_to_statement(Handler0, Handler, !Info),
-        Stmt = try_commit(Ref, Statement, Handler)
+        Stmt = ml_stmt_try_commit(Ref, Statement, Handler)
      ;
-        Stmt0 = atomic(_AtomicStmt0),
+        Stmt0 = ml_stmt_atomic(_AtomicStmt0),
          Stmt = Stmt0
      ).

@@ -2244,9 +2248,9 @@
          UnchainFrame = ml_gen_unchain_frame(Context, !.Info),
          Statement0 = statement(Stmt0, Context),
          RetRvals = list.map(func(Rval) = lval(Rval), RetLvals),
-        RetStmt = return(RetRvals),
+        RetStmt = ml_stmt_return(RetRvals),
          RetStatement = statement(RetStmt, Context),
-        Stmt = block([], [UnchainFrame, Statement0, RetStatement])
+        Stmt = ml_stmt_block([], [UnchainFrame, Statement0, RetStatement])
      ;
          CallKind = ordinary_call,
          Stmt = Stmt0
@@ -2275,7 +2279,7 @@
  prepend_unchain_frame(Stmt0, Context, ElimInfo) = Stmt :-
      UnchainFrame = ml_gen_unchain_frame(Context, ElimInfo),
      Statement0 = statement(Stmt0, Context),
-    Stmt = block([], [UnchainFrame, Statement0]).
+    Stmt = ml_stmt_block([], [UnchainFrame, Statement0]).

  :- func append_unchain_frame(mlds_stmt, mlds_context, elim_info) =
      mlds_stmt.
@@ -2283,7 +2287,7 @@
  append_unchain_frame(Stmt0, Context, ElimInfo) = Stmt :-
      UnchainFrame = ml_gen_unchain_frame(Context, ElimInfo),
      Statement0 = statement(Stmt0, Context),
-    Stmt = block([], [Statement0, UnchainFrame]).
+    Stmt = ml_stmt_block([], [Statement0, UnchainFrame]).

  :- func ml_gen_unchain_frame(mlds_context, elim_info) = statement.

@@ -2312,7 +2316,7 @@
      PrevFieldRval = lval(field(Tag, lval(StackChain), PrevFieldId,
          PrevFieldType, EnvPtrTypeName)),
      Assignment = assign(StackChain, PrevFieldRval),
-    UnchainFrame = statement(atomic(Assignment), Context).
+    UnchainFrame = statement(ml_stmt_atomic(Assignment), Context).

      % Generate a local variable declaration to hold the saved stack chain
      % pointer:
@@ -2343,7 +2347,7 @@
      SavedStackChain = var(qual(MLDS_Module, module_qual,
          ml_saved_stack_chain_name(Id)), ml_stack_chain_type),
      Assignment = assign(SavedStackChain, lval(ml_stack_chain_var)),
-    SaveStatement = statement(atomic(Assignment), Context).
+    SaveStatement = statement(ml_stmt_atomic(Assignment), Context).

      % Generate a statement to restore the stack chain pointer:
      %
@@ -2356,7 +2360,7 @@
      SavedStackChain = var(qual(MLDS_Module, module_qual,
          ml_saved_stack_chain_name(Id)), ml_stack_chain_type),
      Assignment = assign(ml_stack_chain_var, lval(SavedStackChain)),
-    RestoreStatement = statement(atomic(Assignment), Context).
+    RestoreStatement = statement(ml_stmt_atomic(Assignment), Context).

  :- func ml_saved_stack_chain_name(int) = mlds_var_name.

Index: compiler/ml_optimize.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.51
diff -u -r1.51 ml_optimize.m
--- compiler/ml_optimize.m	13 Aug 2007 01:27:44 -0000	1.51
+++ compiler/ml_optimize.m	21 Aug 2007 15:06:35 -0000
@@ -142,52 +142,53 @@

  optimize_in_stmt(OptInfo, Stmt0) = Stmt :-
      (
-        Stmt0 = mlcall(_, _, _, _, _, _),
+        Stmt0 = ml_stmt_call(_, _, _, _, _, _),
          Stmt = optimize_in_call_stmt(OptInfo, Stmt0)
      ;
-        Stmt0 = block(Defns0, Statements0),
+        Stmt0 = ml_stmt_block(Defns0, Statements0),
          maybe_convert_assignments_into_initializers(OptInfo,
              Defns0, Defns1, Statements0, Statements1),
          maybe_eliminate_locals(OptInfo, Defns1, Defns,
              Statements1, Statements2),
          maybe_flatten_block(Statements2, Statements3),
          Statements = optimize_in_statements(OptInfo, Statements3),
-        Stmt = block(Defns, Statements)
+        Stmt = ml_stmt_block(Defns, Statements)
      ;
-        Stmt0 = while(Rval, Statement0, Once),
-        Stmt = while(Rval, optimize_in_statement(OptInfo, Statement0), Once)
+        Stmt0 = ml_stmt_while(Rval, Statement0, Once),
+        Statement = optimize_in_statement(OptInfo, Statement0),
+        Stmt = ml_stmt_while(Rval, Statement, Once)
      ;
-        Stmt0 = if_then_else(Rval, Then, MaybeElse),
-        Stmt = if_then_else(Rval,
+        Stmt0 = ml_stmt_if_then_else(Rval, Then, MaybeElse),
+        Stmt = ml_stmt_if_then_else(Rval,
              optimize_in_statement(OptInfo, Then),
              map_maybe(optimize_in_statement(OptInfo), MaybeElse))
      ;
-        Stmt0 = switch(Type, Rval, Range, Cases0, Default0),
-        Stmt = switch(Type, Rval, Range,
+        Stmt0 = ml_stmt_switch(Type, Rval, Range, Cases0, Default0),
+        Stmt = ml_stmt_switch(Type, Rval, Range,
              list.map(optimize_in_case(OptInfo), Cases0),
              optimize_in_default(OptInfo, Default0))
      ;
-        Stmt0 = do_commit(_),
+        Stmt0 = ml_stmt_do_commit(_),
          Stmt = Stmt0
      ;
-        Stmt0 = return(_),
+        Stmt0 = ml_stmt_return(_),
          Stmt = Stmt0
      ;
-        Stmt0 = try_commit(Ref, TryGoal, HandlerGoal),
-        Stmt = try_commit(Ref,
-            optimize_in_statement(OptInfo, TryGoal),
-            optimize_in_statement(OptInfo, HandlerGoal))
+        Stmt0 = ml_stmt_try_commit(Ref, TryGoal0, HandlerGoal0),
+        TryGoal = optimize_in_statement(OptInfo, TryGoal0),
+        HandlerGoal = optimize_in_statement(OptInfo, HandlerGoal0),
+        Stmt = ml_stmt_try_commit(Ref, TryGoal, HandlerGoal)
      ;
-        Stmt0 = label(_Label),
+        Stmt0 = ml_stmt_label(_Label),
          Stmt = Stmt0
      ;
-        Stmt0 = goto(_Label),
+        Stmt0 = ml_stmt_goto(_Label),
          Stmt = Stmt0
      ;
-        Stmt0 = computed_goto(_Rval, _Label),
+        Stmt0 = ml_stmt_computed_goto(_Rval, _Label),
          Stmt = Stmt0
      ;
-        Stmt0 = atomic(_Atomic),
+        Stmt0 = ml_stmt_atomic(_Atomic),
          Stmt = Stmt0
      ).

@@ -207,14 +208,14 @@

  %-----------------------------------------------------------------------------%

-:- inst g == ground.
-:- inst mlcall ---> ml_backend.mlds.mlcall(g, g, g, g, g, g).
+:- inst mlcall
+    --->    ml_stmt_call(ground, ground, ground, ground, ground, ground).

  :- func optimize_in_call_stmt(opt_info::in, mlds_stmt::in(mlcall))
      = (mlds_stmt::out) is det.

  optimize_in_call_stmt(OptInfo, Stmt0) = Stmt :-
-    Stmt0 = mlcall(_Signature, FuncRval, _MaybeObject, CallArgs,
+    Stmt0 = ml_stmt_call(_Signature, FuncRval, _MaybeObject, CallArgs,
          _Results, _IsTailCall),
          % If we have a self-tailcall, assign to the arguments and
          % then goto the top of the tailcall loop.
@@ -225,15 +226,15 @@
              OptInfo ^ entity_name), Stmt0)
      ->
          CommentStatement = statement(
-            atomic(comment("direct tailcall eliminated")),
+            ml_stmt_atomic(comment("direct tailcall eliminated")),
              OptInfo ^ context),
          GotoStatement = statement(
-            goto(tailcall_loop_top(OptInfo ^ globals)),
+            ml_stmt_goto(tailcall_loop_top(OptInfo ^ globals)),
              OptInfo ^ context),
          OptInfo ^ func_params = mlds_func_params(FuncArgs, _RetTypes),
          generate_assign_args(OptInfo, FuncArgs, CallArgs,
              AssignStatements, AssignDefns),
-        AssignVarsStatement = statement(block(AssignDefns,
+        AssignVarsStatement = statement(ml_stmt_block(AssignDefns,
              AssignStatements), OptInfo ^ context),

          CallReplaceStatements = [
@@ -241,7 +242,7 @@
              AssignVarsStatement,
              GotoStatement
              ],
-        Stmt = block([], CallReplaceStatements)
+        Stmt = ml_stmt_block([], CallReplaceStatements)
      ;
          % Convert calls to `mark_hp' and `restore_hp' to the
          % corresponding MLDS instructions.  This ensures that
@@ -272,7 +273,7 @@
          PrivateBuiltin = mercury_private_builtin_module,
          ModName = mercury_module_name_to_mlds(PrivateBuiltin)
      ->
-        Stmt = atomic(AtomicStmt)
+        Stmt = ml_stmt_atomic(AtomicStmt)
      ;
          Stmt = Stmt0
      ).
@@ -360,10 +361,10 @@
              TempDefn = ml_gen_mlds_var_decl_init(var(TempName), Type,
                  Initializer, GCStatement, OptInfo ^ context),
              TempInitStatement = statement(
-                atomic(assign(var(QualTempName, Type), ArgRval)),
+                ml_stmt_atomic(assign(var(QualTempName, Type), ArgRval)),
                  OptInfo ^ context),
              AssignStatement = statement(
-                atomic(assign(
+                ml_stmt_atomic(assign(
                      var(QualVarName, Type),
                      lval(var(QualTempName, Type)))),
                  OptInfo ^ context),
@@ -401,7 +402,7 @@
              qual(OptInfo ^ module_name, module_qual, OptInfo ^ entity_name),
              CallStmt)
      ->
-        Comment = atomic(comment("tailcall optimized into a loop")),
+        Comment = ml_stmt_atomic(comment("tailcall optimized into a loop")),
          CommentStmt = statement(Comment, Context),
          % The loop can be defined either using while, break, and continue,
          % or using a label and goto.  We prefer to use the former, if possible,
@@ -416,11 +417,11 @@
              %   }
              % Any tail calls in the function body will have
              % been replaced with `continue' statements.
-            Stmt = while(const(mlconst_true),
-                statement(block([],
+            Stmt = ml_stmt_while(const(mlconst_true),
+                statement(ml_stmt_block([],
                      [CommentStmt,
                      statement(Stmt0, Context),
-                    statement(goto(break), Context)]),
+                    statement(ml_stmt_goto(break), Context)]),
                  Context), no)
          ;
              % Add a loop_top label at the start of the function
@@ -432,8 +433,8 @@
              %   }
              % Any tail calls in the function body will have
              % been replaced with `goto loop_top' statements.
-            Label = label(tailcall_loop_label_name),
-            Stmt = block([], [CommentStmt,
+            Label = ml_stmt_label(tailcall_loop_label_name),
+            Stmt = ml_stmt_block([], [CommentStmt,
                  statement(Label, Context),
                  statement(Stmt0, Context)])
          )
@@ -475,7 +476,7 @@
  :- func flatten_block(statement) = statements.

  flatten_block(Statement) =
-    ( Statement = statement(block([], BlockStatements), _) ->
+    ( Statement = statement(ml_stmt_block([], BlockStatements), _) ->
          BlockStatements
      ;
          [Statement]
@@ -590,7 +591,7 @@
          % Check if the first statement in the block is an assignment to one
          % of the variables declared in the block.
          !.Statements = [AssignStatement | !:Statements],
-        AssignStatement = statement(atomic(assign(LHS, RHS)), _),
+        AssignStatement = statement(ml_stmt_atomic(assign(LHS, RHS)), _),
          LHS = var(ThisVar, _ThisType),
          ThisVar = qual(Qualifier, QualKind, VarName),
          ThisData = qual(Qualifier, QualKind, var(VarName)),
@@ -823,7 +824,7 @@
          Statements) :-
      ( find_initial_val_in_statement(VarName, Rval1, Statement0, Statement1) ->
          Rval = Rval1,
-        ( Statement1 = statement(block([], []), _) ->
+        ( Statement1 = statement(ml_stmt_block([], []), _) ->
              Statements = Statements0
          ;
              Statements = [Statement1 | Statements0]
@@ -839,7 +840,7 @@
          \+ statement_contains_var(Statement0, DataName),
          \+ (
              statement_contains_statement(Statement0, Label),
-            Label = statement(label(_), _)
+            Label = statement(ml_stmt_label(_), _)
          ),
          find_initial_val_in_statements(VarName, Rval,
              Statements0, Statements1),
@@ -852,17 +853,17 @@
  find_initial_val_in_statement(Var, Rval, Statement0, Statement) :-
      Statement0 = statement(Stmt0, Context),
      Statement = statement(Stmt, Context),
-    ( Stmt0 = atomic(assign(var(Var, _Type), Rval0)) ->
+    ( Stmt0 = ml_stmt_atomic(assign(var(Var, _Type), Rval0)) ->
          Rval = Rval0,
          % Delete the assignment, by replacing it with an empty block.
-        Stmt = block([], [])
-    ; Stmt0 = block(Defns0, SubStatements0) ->
+        Stmt = ml_stmt_block([], [])
+    ; Stmt0 = ml_stmt_block(Defns0, SubStatements0) ->
          Var = qual(Mod, QualKind, UnqualVarName),
          Data = qual(Mod, QualKind, var(UnqualVarName)),
          \+ defns_contains_var(Defns0, Data),
          find_initial_val_in_statements(Var, Rval,
              SubStatements0, SubStatements),
-        Stmt = block(Defns0, SubStatements)
+        Stmt = ml_stmt_block(Defns0, SubStatements)
      ;
          fail
      ).
@@ -1074,63 +1075,62 @@

  eliminate_var_in_stmt(Stmt0, Stmt, !VarElimInfo) :-
      (
-        Stmt0 = block(Defns0, Statements0),
+        Stmt0 = ml_stmt_block(Defns0, Statements0),
          eliminate_var_in_block(Defns0, Defns, Statements0, Statements,
              !VarElimInfo),
-        Stmt = block(Defns, Statements)
+        Stmt = ml_stmt_block(Defns, Statements)
      ;
-        Stmt0 = while(Rval0, Statement0, Once),
+        Stmt0 = ml_stmt_while(Rval0, Statement0, Once),
          eliminate_var_in_rval(Rval0, Rval, !VarElimInfo),
          eliminate_var_in_statement(Statement0, Statement, !VarElimInfo),
-        Stmt = while(Rval, Statement, Once)
+        Stmt = ml_stmt_while(Rval, Statement, Once)
      ;
-        Stmt0 = if_then_else(Cond0, Then0, MaybeElse0),
+        Stmt0 = ml_stmt_if_then_else(Cond0, Then0, MaybeElse0),
          eliminate_var_in_rval(Cond0, Cond, !VarElimInfo),
          eliminate_var_in_statement(Then0, Then, !VarElimInfo),
          eliminate_var_in_maybe_statement(MaybeElse0, MaybeElse, !VarElimInfo),
-        Stmt = if_then_else(Cond, Then, MaybeElse)
+        Stmt = ml_stmt_if_then_else(Cond, Then, MaybeElse)
      ;
-        Stmt0 = switch(Type, Val0, Range, Cases0, Default0),
+        Stmt0 = ml_stmt_switch(Type, Val0, Range, Cases0, Default0),
          eliminate_var_in_rval(Val0, Val, !VarElimInfo),
          list.map_foldl(eliminate_var_in_case, Cases0, Cases, !VarElimInfo),
          eliminate_var_in_default(Default0, Default, !VarElimInfo),
-        Stmt = switch(Type, Val, Range, Cases, Default)
+        Stmt = ml_stmt_switch(Type, Val, Range, Cases, Default)
      ;
-        Stmt0 = label(_),
+        Stmt0 = ml_stmt_label(_),
          Stmt = Stmt0
      ;
-        Stmt0 = goto(_),
+        Stmt0 = ml_stmt_goto(_),
          Stmt = Stmt0
      ;
-        Stmt0 = computed_goto(Rval0, Labels),
+        Stmt0 = ml_stmt_computed_goto(Rval0, Labels),
          eliminate_var_in_rval(Rval0, Rval, !VarElimInfo),
-        Stmt = computed_goto(Rval, Labels)
+        Stmt = ml_stmt_computed_goto(Rval, Labels)
      ;
-        Stmt0 = mlcall(Sig, Func0, Obj0, Args0, RetLvals0, TailCall),
+        Stmt0 = ml_stmt_call(Sig, Func0, Obj0, Args0, RetLvals0, TailCall),
          eliminate_var_in_rval(Func0, Func, !VarElimInfo),
          eliminate_var_in_maybe_rval(Obj0, Obj, !VarElimInfo),
          eliminate_var_in_rvals(Args0, Args, !VarElimInfo),
          eliminate_var_in_lvals(RetLvals0, RetLvals, !VarElimInfo),
-        Stmt = mlcall(Sig, Func, Obj, Args, RetLvals, TailCall)
+        Stmt = ml_stmt_call(Sig, Func, Obj, Args, RetLvals, TailCall)
      ;
-        Stmt0 = return(Rvals0),
+        Stmt0 = ml_stmt_return(Rvals0),
          eliminate_var_in_rvals(Rvals0, Rvals, !VarElimInfo),
-        Stmt = return(Rvals)
+        Stmt = ml_stmt_return(Rvals)
      ;
-        Stmt0 = do_commit(Ref0),
+        Stmt0 = ml_stmt_do_commit(Ref0),
          eliminate_var_in_rval(Ref0, Ref, !VarElimInfo),
-        Stmt = do_commit(Ref)
+        Stmt = ml_stmt_do_commit(Ref)
      ;
-        Stmt0 = try_commit(Ref0, Statement0, Handler0),
+        Stmt0 = ml_stmt_try_commit(Ref0, Statement0, Handler0),
          eliminate_var_in_lval(Ref0, Ref, !VarElimInfo),
          eliminate_var_in_statement(Statement0, Statement, !VarElimInfo),
          eliminate_var_in_statement(Handler0, Handler, !VarElimInfo),
-        Stmt = try_commit(Ref, Statement, Handler)
+        Stmt = ml_stmt_try_commit(Ref, Statement, Handler)
      ;
-        Stmt0 = atomic(AtomicStmt0),
-        eliminate_var_in_atomic_stmt(AtomicStmt0, AtomicStmt,
-            !VarElimInfo),
-        Stmt = atomic(AtomicStmt)
+        Stmt0 = ml_stmt_atomic(AtomicStmt0),
+        eliminate_var_in_atomic_stmt(AtomicStmt0, AtomicStmt, !VarElimInfo),
+        Stmt = ml_stmt_atomic(AtomicStmt)
      ).

  :- pred eliminate_var_in_case(mlds_switch_case::in, mlds_switch_case::out,
Index: compiler/ml_simplify_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_simplify_switch.m,v
retrieving revision 1.21
diff -u -r1.21 ml_simplify_switch.m
--- compiler/ml_simplify_switch.m	15 Oct 2006 23:26:46 -0000	1.21
+++ compiler/ml_simplify_switch.m	21 Aug 2007 15:06:35 -0000
@@ -60,8 +60,8 @@
          % unless the target prefers switches.

          % Is this an int switch?
-        Stmt0 = switch(Type, Rval, Range, Cases, Default),
-        is_integral_type(Type),
+        Stmt0 = ml_stmt_switch(Type, Rval, Range, Cases, Default),
+        is_integral_type(Type) = yes,

          % Does the target want us to convert dense int switches
          % into computed gotos?
@@ -86,14 +86,14 @@
          generate_dense_switch(Cases, Default, FirstVal, LastVal,
              NeedRangeCheck, Type, Rval, MLDS_Context,
              Decls, Statements, !Info),
-        Stmt = block(Decls, Statements),
+        Stmt = ml_stmt_block(Decls, Statements),
          Statement = statement(Stmt, MLDS_Context)
      ;
          % Convert the remaining (sparse) int switches into if-then-else chains,
          % unless the target prefers switches.

-        Stmt0 = switch(Type, Rval, _Range, Cases, Default),
-        is_integral_type(Type),
+        Stmt0 = ml_stmt_switch(Type, Rval, _Range, Cases, Default),
+        is_integral_type(Type) = yes,
          \+ (
              target_supports_int_switch(Globals),
              globals.lookup_bool_option(Globals, prefer_switch, yes)
@@ -105,7 +105,7 @@
          % Optimize away trivial switches (these can occur e.g. with
          % --tags none, where the tag test always has only one reachable case)

-        Stmt0 = switch(_Type, _Rval, _Range, Cases, Default),
+        Stmt0 = ml_stmt_switch(_Type, _Rval, _Range, Cases, Default),
          Cases = [SingleCase],
          Default = default_is_unreachable
      ->
@@ -116,13 +116,45 @@
          Statement = statement(Stmt, MLDS_Context)
      ).

-:- pred is_integral_type(mlds_type::in) is semidet.
+:- func is_integral_type(mlds_type) = bool.

-is_integral_type(mlds_native_int_type).
-is_integral_type(mlds_native_char_type).
-is_integral_type(mercury_type(_, type_cat_int, _)).
-is_integral_type(mercury_type(_, type_cat_char, _)).
-is_integral_type(mercury_type(_, type_cat_enum, _)).
+is_integral_type(mlds_mercury_array_type(_)) = no.
+is_integral_type(mlds_cont_type(_)) = no.
+is_integral_type(mlds_commit_type) = no.
+is_integral_type(mlds_native_bool_type) = no.
+is_integral_type(mlds_native_int_type)  = yes.
+is_integral_type(mlds_native_char_type) = yes.
+is_integral_type(mlds_native_float_type) = no.
+is_integral_type(mercury_type(_, type_cat_int, _)) = yes.
+is_integral_type(mercury_type(_, type_cat_char, _)) = yes.
+is_integral_type(mercury_type(_, type_cat_string, _)) = no.
+is_integral_type(mercury_type(_, type_cat_float, _)) = no.
+is_integral_type(mercury_type(_, type_cat_higher_order, _)) = no.
+is_integral_type(mercury_type(_, type_cat_tuple, _)) = no.
+is_integral_type(mercury_type(_, type_cat_enum, _)) = yes.
+% XXX we are able to switch on foreign enumerations in C; this
+% may not be the case for the other target languages.
+is_integral_type(mercury_type(_, type_cat_foreign_enum, _)) = yes.
+is_integral_type(mercury_type(_, type_cat_dummy, _)) = no.
+is_integral_type(mercury_type(_, type_cat_variable, _)) = no.
+is_integral_type(mercury_type(_, type_cat_type_info, _)) = no.
+is_integral_type(mercury_type(_, type_cat_type_ctor_info, _)) = no.
+is_integral_type(mercury_type(_, type_cat_typeclass_info, _)) = no.
+is_integral_type(mercury_type(_, type_cat_base_typeclass_info, _)) = no.
+is_integral_type(mercury_type(_, type_cat_void, _)) = no.
+is_integral_type(mercury_type(_, type_cat_user_ctor, _)) = no.
+is_integral_type(mlds_foreign_type(_)) = no.
+is_integral_type(mlds_class_type(_, _, _)) = no.
+is_integral_type(mlds_ptr_type(_)) = no.
+is_integral_type(mlds_func_type(_)) = no.
+is_integral_type(mlds_type_info_type) = no.
+is_integral_type(mlds_generic_type) = no.
+is_integral_type(mlds_generic_env_ptr_type) = no.
+is_integral_type(mlds_array_type(_)) = no.
+is_integral_type(mlds_pseudo_type_info_type) = no.
+is_integral_type(mlds_rtti_type(_)) = no.
+is_integral_type(mlds_tabling_type(_)) = no.
+is_integral_type(mlds_unknown_type) = no.

  :- pred is_dense_switch(list(mlds_switch_case)::in, int::in) is semidet.

@@ -240,7 +272,8 @@
      ml_gen_new_label(DefaultLabel, !Info),
      CaseLabels = get_case_labels(FirstVal, LastVal,
          CaseLabelsMap, DefaultLabel),
-    DefaultLabelStatement = statement(label(DefaultLabel), MLDS_Context),
+    DefaultLabelStatement = statement(ml_stmt_label(DefaultLabel),
+        MLDS_Context),
      (
          Default = default_is_unreachable,
          % We still need the label, in case we inserted references to it
@@ -255,11 +288,11 @@
      ),

      StartComment = statement(
-        atomic(comment("switch (using dense jump table)")),
+        ml_stmt_atomic(comment("switch (using dense jump table)")),
          MLDS_Context),
-    DoJump = statement(computed_goto(Index, CaseLabels), MLDS_Context),
-    EndLabelStatement = statement(label(EndLabel), MLDS_Context),
-    EndComment = statement(atomic(comment("End of dense switch")),
+    DoJump = statement(ml_stmt_computed_goto(Index, CaseLabels), MLDS_Context),
+    EndLabelStatement = statement(ml_stmt_label(EndLabel), MLDS_Context),
+    EndComment = statement(ml_stmt_atomic(comment("End of dense switch")),
          MLDS_Context),

      % We may need to check that the value of the variable lies within the
@@ -268,11 +301,11 @@
          NeedRangeCheck = yes,
          Difference = LastVal - FirstVal,
          InRange = binop(unsigned_le, Index, const(mlconst_int(Difference))),
-        Else = yes(statement(block([], DefaultStatements),
+        Else = yes(statement(ml_stmt_block([], DefaultStatements),
              MLDS_Context)),
-        SwitchBody = statement(block([], [DoJump | CasesCode]),
+        SwitchBody = statement(ml_stmt_block([], [DoJump | CasesCode]),
              MLDS_Context),
-        DoSwitch = statement(if_then_else(InRange, SwitchBody, Else),
+        DoSwitch = statement(ml_stmt_if_then_else(InRange, SwitchBody, Else),
              MLDS_Context),
          Statements = [StartComment, DoSwitch] ++
              [EndLabelStatement, EndComment]
@@ -315,13 +348,13 @@
      insert_cases_into_map(MatchCondition, ThisLabel,
          CaseLabelsMap0, CaseLabelsMap),
      CaseStatement = statement(_, MLDS_Context),
-    LabelComment = statement(atomic(comment("case of dense switch")),
+    LabelComment = statement(ml_stmt_atomic(comment("case of dense switch")),
          MLDS_Context),
-    LabelCode = statement(label(ThisLabel), MLDS_Context),
+    LabelCode = statement(ml_stmt_label(ThisLabel), MLDS_Context),
      JumpComment = statement(
-        atomic(comment("branch to end of dense switch")),
+        ml_stmt_atomic(comment("branch to end of dense switch")),
          MLDS_Context),
-    JumpCode = statement(goto(label(EndLabel)), MLDS_Context),
+    JumpCode = statement(ml_stmt_goto(label(EndLabel)), MLDS_Context),
      Decls = [],
      Statements = [LabelComment, LabelCode, CaseStatement,
          JumpComment, JumpCode].
@@ -407,10 +440,10 @@
  ml_switch_to_if_else_chain([], Default, _Rval, MLDS_Context) = Statement :-
      (
          Default = default_do_nothing,
-        Statement = statement(block([],[]), MLDS_Context)
+        Statement = statement(ml_stmt_block([], []), MLDS_Context)
      ;
          Default = default_is_unreachable,
-        Statement = statement(block([],[]), MLDS_Context)
+        Statement = statement(ml_stmt_block([], []), MLDS_Context)
      ;
          Default = default_case(Statement)
      ).
@@ -426,7 +459,7 @@
          CaseMatchedRval = ml_gen_case_match_conds(MatchConditions, SwitchRval),
          RestStatement = ml_switch_to_if_else_chain(Cases, Default, SwitchRval,
              MLDS_Context),
-        IfStmt = if_then_else(CaseMatchedRval, CaseStatement,
+        IfStmt = ml_stmt_if_then_else(CaseMatchedRval, CaseStatement,
              yes(RestStatement)),
          Statement = statement(IfStmt, MLDS_Context)
      ).
Index: compiler/ml_string_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_string_switch.m,v
retrieving revision 1.30
diff -u -r1.30 ml_string_switch.m
--- compiler/ml_string_switch.m	23 Dec 2006 12:49:23 -0000	1.30
+++ compiler/ml_string_switch.m	21 Aug 2007 15:06:35 -0000
@@ -85,8 +85,7 @@

      % Generate new labels.
      ml_gen_new_label(EndLabel, !Info),
-    GotoEndStatement = statement(goto(label(EndLabel)),
-        MLDS_Context),
+    GotoEndStatement = statement(ml_stmt_goto(label(EndLabel)), MLDS_Context),

      % Determine how big to make the hash table. Currently we round the number
      % of cases up to the nearest power of two, and then double it. This should
@@ -132,7 +131,7 @@
          StringTableLval),

      % Generate code which does the hash table lookup.
-    SwitchStmt0 = switch(SlotVarType, lval(SlotVarLval),
+    SwitchStmt0 = ml_stmt_switch(SlotVarType, lval(SlotVarLval),
          range(0, TableSize - 1), SlotsCases, default_is_unreachable),
      ml_simplify_switch(SwitchStmt0, MLDS_Context, SwitchStatement, !Info),

@@ -146,30 +145,33 @@
                  VarRval)
          ),
      FoundMatchCode = statement(
-        block([], [
-            statement(atomic(comment("we found a match")), MLDS_Context),
-            statement(atomic(comment(
-                "dispatch to the corresponding code")), MLDS_Context),
+        ml_stmt_block([], [
+            statement(ml_stmt_atomic(comment("we found a match")),
+                MLDS_Context),
+            statement(ml_stmt_atomic(
+                    comment("dispatch to the corresponding code")),
+                MLDS_Context),
              SwitchStatement,
              GotoEndStatement
          ]),
          MLDS_Context),
      LoopBody = ml_gen_block([], [
-        statement(atomic(comment(
+        statement(ml_stmt_atomic(comment(
              "lookup the string for this hash slot")), MLDS_Context),
          statement(
-            atomic(assign(StringVarLval,
+            ml_stmt_atomic(assign(StringVarLval,
                  binop(array_index(elem_type_string),
                      lval(StringTableLval),
                      lval(SlotVarLval)))),
              MLDS_Context),
-        statement(atomic(comment("did we find a match?")), MLDS_Context),
-        statement(
-            if_then_else(FoundMatchCond, FoundMatchCode, no), MLDS_Context),
-        statement(atomic(comment(
+        statement(ml_stmt_atomic(comment("did we find a match?")),
+            MLDS_Context),
+        statement(ml_stmt_if_then_else(FoundMatchCond, FoundMatchCode, no),
+            MLDS_Context),
+        statement(ml_stmt_atomic(comment(
              "no match yet, so get next slot in hash chain")), MLDS_Context),
          statement(
-            atomic(assign(SlotVarLval,
+            ml_stmt_atomic(assign(SlotVarLval,
                  binop(array_index(elem_type_int),
                      lval(NextSlotsLval),
                      lval(SlotVarLval)))),
@@ -177,28 +179,29 @@
          ],
          Context),
      HashLookupStatements = [
-        statement(atomic(comment("hashed string switch")),
+        statement(ml_stmt_atomic(comment("hashed string switch")),
              MLDS_Context),
-        statement(atomic(comment(
+        statement(ml_stmt_atomic(comment(
              "compute the hash value of the input string")), MLDS_Context),
          statement(
-            atomic(assign(SlotVarLval, binop(bitwise_and,
+            ml_stmt_atomic(assign(SlotVarLval, binop(bitwise_and,
                  unop(std_unop(hash_string), VarRval),
                  const(mlconst_int(HashMask))))),
              MLDS_Context),
-        statement(atomic(comment("hash chain loop")), MLDS_Context),
+        statement(ml_stmt_atomic(comment("hash chain loop")), MLDS_Context),
          statement(
-            while(binop(int_ge, lval(SlotVarLval), const(mlconst_int(0))),
+            ml_stmt_while(
+                binop(int_ge, lval(SlotVarLval), const(mlconst_int(0))),
                  LoopBody,
-                yes), % this is a do...while loop
+                yes), % This is a do...while loop.
              MLDS_Context)
          ],
      FailComment =
-        statement(atomic(comment("no match, so fail")),
+        statement(ml_stmt_atomic(comment("no match, so fail")),
              MLDS_Context),
-    EndLabelStatement = statement(label(EndLabel), MLDS_Context),
+    EndLabelStatement = statement(ml_stmt_label(EndLabel), MLDS_Context),
      EndComment =
-        statement(atomic(comment("end of hashed string switch")),
+        statement(ml_stmt_atomic(comment("end of hashed string switch")),
              MLDS_Context),

      % Collect all the generated variable/constant declarations
@@ -251,9 +254,9 @@
          ml_gen_goal(CodeModel, Goal, GoalStatement, !Info),

          string.append_list(["case """, String, """"], CommentString),
-        Comment = statement(atomic(comment(CommentString)),
+        Comment = statement(ml_stmt_atomic(comment(CommentString)),
              MLDS_Context),
-        CaseStatement = statement(block([], [Comment, GoalStatement]),
+        CaseStatement = statement(ml_stmt_block([], [Comment, GoalStatement]),
              MLDS_Context),
          MLDS_Cases = [[match_value(const(mlconst_int(Slot)))] - CaseStatement]
      ;
Index: compiler/ml_switch_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_switch_gen.m,v
retrieving revision 1.30
diff -u -r1.30 ml_switch_gen.m
--- compiler/ml_switch_gen.m	7 May 2007 05:21:32 -0000	1.30
+++ compiler/ml_switch_gen.m	21 Aug 2007 15:06:35 -0000
@@ -373,7 +373,8 @@
          ml_switch_generate_if_else_chain(Cases, Var, CodeModel,
              CanFail, Context, RestDecls, RestStatements, !Info),
          Rest = ml_gen_block(RestDecls, RestStatements, Context),
-        IfStmt = if_then_else(TagTestExpression, GoalStatement, yes(Rest)),
+        IfStmt = ml_stmt_if_then_else(TagTestExpression, GoalStatement,
+            yes(Rest)),
          IfStatement = statement(IfStmt, mlds_make_context(Context)),
          Decls = TagTestDecls,
          Statements = TagTestStatements ++ [IfStatement]
@@ -398,7 +399,7 @@
      ml_switch_gen_range(!.Info, MLDS_Type, Range),
      ml_switch_generate_mlds_cases(Cases, CodeModel, MLDS_Cases, !Info),
      ml_switch_generate_default(CanFail, CodeModel, Context, Default, !Info),
-    SwitchStmt0 = switch(MLDS_Type, Rval, Range, MLDS_Cases, Default),
+    SwitchStmt0 = ml_stmt_switch(MLDS_Type, Rval, Range, MLDS_Cases, Default),
      MLDS_Context = mlds_make_context(Context),
      ml_simplify_switch(SwitchStmt0, MLDS_Context, SwitchStatement, !Info),
      Decls = [],
Index: compiler/ml_tag_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_tag_switch.m,v
retrieving revision 1.21
diff -u -r1.21 ml_tag_switch.m
--- compiler/ml_tag_switch.m	1 Dec 2006 15:04:08 -0000	1.21
+++ compiler/ml_tag_switch.m	21 Aug 2007 15:06:35 -0000
@@ -80,8 +80,8 @@

      % Package up the results into a switch statement.
      Range = range(0, MaxPrimary),
-    SwitchStmt0 = switch(mlds_native_int_type, PTagRval, Range, MLDS_Cases,
-        Default),
+    SwitchStmt0 = ml_stmt_switch(mlds_native_int_type, PTagRval, Range,
+        MLDS_Cases, Default),
      MLDS_Context = mlds_make_context(Context),
      ml_simplify_switch(SwitchStmt0, MLDS_Context, SwitchStatement, !Info),
      Decls = [],
@@ -187,8 +187,8 @@

      % Package up the results into a switch statement.
      Range = range_unknown, % XXX could do better
-    SwitchStmt = switch(mlds_native_int_type, STagRval, Range, MLDS_Cases,
-        Default),
+    SwitchStmt = ml_stmt_switch(mlds_native_int_type, STagRval, Range,
+        MLDS_Cases, Default),
      MLDS_Context = mlds_make_context(Context),
      ml_simplify_switch(SwitchStmt, MLDS_Context, Statement, !Info).

Index: compiler/ml_tailcall.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_tailcall.m,v
retrieving revision 1.45
diff -u -r1.45 ml_tailcall.m
--- compiler/ml_tailcall.m	25 Jul 2007 06:12:21 -0000	1.45
+++ compiler/ml_tailcall.m	21 Aug 2007 15:06:35 -0000
@@ -202,7 +202,7 @@
          FirstAtTail = AtTail
      ;
          Rest = [FirstRest | _],
-        ( FirstRest = statement(return(ReturnVals), _) ->
+        ( FirstRest = statement(ml_stmt_return(ReturnVals), _) ->
              FirstAtTail = yes(ReturnVals)
          ;
              FirstAtTail = no
@@ -228,44 +228,44 @@
          % of currently visible local declarations before processing the
          % statements in that block. The statement list will be in a tail
          % position iff the block is in a tail position.
-        Stmt0 = block(Defns0, Statements0),
+        Stmt0 = ml_stmt_block(Defns0, Statements0),
          Defns = mark_tailcalls_in_defns(Defns0),
          NewLocals = [defns(Defns) | Locals],
          Statements = mark_tailcalls_in_statements(Statements0,
              AtTail, NewLocals),
-        Stmt = block(Defns, Statements)
+        Stmt = ml_stmt_block(Defns, Statements)
      ;
          % The statement in the body of a while loop is never in a tail
          % position.
-        Stmt0 = while(Rval, Statement0, Once),
+        Stmt0 = ml_stmt_while(Rval, Statement0, Once),
          Statement = mark_tailcalls_in_statement(Statement0, no, Locals),
-        Stmt = while(Rval, Statement, Once)
+        Stmt = ml_stmt_while(Rval, Statement, Once)
      ;
          % Both the `then' and the `else' parts of an if-then-else are in a
          % tail position iff the if-then-else is in a tail position.
-        Stmt0 = if_then_else(Cond, Then0, MaybeElse0),
+        Stmt0 = ml_stmt_if_then_else(Cond, Then0, MaybeElse0),
          Then = mark_tailcalls_in_statement(Then0, AtTail, Locals),
          MaybeElse = mark_tailcalls_in_maybe_statement(MaybeElse0,
              AtTail, Locals),
-        Stmt = if_then_else(Cond, Then, MaybeElse)
+        Stmt = ml_stmt_if_then_else(Cond, Then, MaybeElse)
      ;
          % All of the cases of a switch (including the default) are in a
          % tail position iff the switch is in a tail position.
-        Stmt0 = switch(Type, Val, Range, Cases0, Default0),
+        Stmt0 = ml_stmt_switch(Type, Val, Range, Cases0, Default0),
          Cases = mark_tailcalls_in_cases(Cases0, AtTail, Locals),
          Default = mark_tailcalls_in_default(Default0, AtTail, Locals),
-        Stmt = switch(Type, Val, Range, Cases, Default)
+        Stmt = ml_stmt_switch(Type, Val, Range, Cases, Default)
      ;
-        Stmt0 = label(_),
+        Stmt0 = ml_stmt_label(_),
          Stmt = Stmt0
      ;
-        Stmt0 = goto(_),
+        Stmt0 = ml_stmt_goto(_),
          Stmt = Stmt0
      ;
-        Stmt0 = computed_goto(_, _),
+        Stmt0 = ml_stmt_computed_goto(_, _),
          Stmt = Stmt0
      ;
-        Stmt0 = mlcall(Sig, Func, Obj, Args, ReturnLvals, CallKind0),
+        Stmt0 = ml_stmt_call(Sig, Func, Obj, Args, ReturnLvals, CallKind0),

          % Check if we can mark this call as a tail call.
          (
@@ -288,27 +288,27 @@
          ->
              % Mark this call as a tail call.
              CallKind = tail_call,
-            Stmt = mlcall(Sig, Func, Obj, Args, ReturnLvals, CallKind)
+            Stmt = ml_stmt_call(Sig, Func, Obj, Args, ReturnLvals, CallKind)
          ;
              % Leave this call unchanged.
              Stmt = Stmt0
          )
      ;
-        Stmt0 = return(_Rvals),
+        Stmt0 = ml_stmt_return(_Rvals),
          Stmt = Stmt0
      ;
-        Stmt0 = do_commit(_Ref),
+        Stmt0 = ml_stmt_do_commit(_Ref),
          Stmt = Stmt0
      ;
-        Stmt0 = try_commit(Ref, Statement0, Handler0),
+        Stmt0 = ml_stmt_try_commit(Ref, Statement0, Handler0),
          % Both the statement inside a `try_commit' and the handler are in
          % tail call position iff the `try_commit' statement is in a tail call
          % position.
          Statement = mark_tailcalls_in_statement(Statement0, AtTail, Locals),
          Handler = mark_tailcalls_in_statement(Handler0, AtTail, Locals),
-        Stmt = try_commit(Ref, Statement, Handler)
+        Stmt = ml_stmt_try_commit(Ref, Statement, Handler)
      ;
-        Stmt0 = atomic(_),
+        Stmt0 = ml_stmt_atomic(_),
          Stmt = Stmt0
      ).

@@ -564,7 +564,7 @@
      % Nondeterministically find a non-tail call.
      statement_contains_statement(Statement, SubStatement),
      SubStatement = statement(SubStmt, Context),
-    SubStmt = mlcall(_CallSig, Func, _This, _Args, _RetVals, CallKind),
+    SubStmt = ml_stmt_call(_CallSig, Func, _This, _Args, _RetVals, CallKind),
      CallKind = ordinary_call,
      % Check if this call is a directly recursive call.
      Func = const(mlconst_code_addr(CodeAddr)),
Index: compiler/ml_type_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.67
diff -u -r1.67 ml_type_gen.m
--- compiler/ml_type_gen.m	20 Aug 2007 03:35:59 -0000	1.67
+++ compiler/ml_type_gen.m	21 Aug 2007 15:06:35 -0000
@@ -794,7 +794,7 @@
          InitMembers = InitMembers0
      ),

-    Stmt = statement(block([], InitMembers), Context),
+    Stmt = statement(ml_stmt_block([], InitMembers), Context),
      Attributes = [],
      EnvVarNames = set.init,
      Ctor = mlds_function(no, mlds_func_params(Args, ReturnValues),
@@ -861,7 +861,7 @@
              % But doing so breaks the IL back-end, because then the hack in
              % fixup_class_qualifiers doesn't work.
          Type, BaseClassId),
-    Statement = statement(atomic(assign(Field, Param)), Context).
+    Statement = statement(ml_stmt_atomic(assign(Field, Param)), Context).

      % Generate "this->data_tag = <TagVal>;".
      %
@@ -884,7 +884,7 @@
          named_field(qual(TagClassQualifier, type_qual, Name),
              mlds_ptr_type(SecondaryTagClassId)),
          Type, ClassType),
-    Statement = statement(atomic(assign(Field, Val)), Context).
+    Statement = statement(ml_stmt_atomic(assign(Field, Val)), Context).

  :- pred ml_gen_typeclass_info_member(module_info::in, prog_context::in,
      prog_constraint::in, mlds_defn::out, int::in, int::out) is det.
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.114
diff -u -r1.114 ml_unify_gen.m
--- compiler/ml_unify_gen.m	20 Aug 2007 03:35:59 -0000	1.114
+++ compiler/ml_unify_gen.m	21 Aug 2007 15:06:35 -0000
@@ -210,7 +210,7 @@
          % this is safe.
          CanCGC = can_cgc,
          ml_gen_var(!.Info, Var, VarLval),
-        Stmt = atomic(delete_object(VarLval)),
+        Stmt = ml_stmt_atomic(delete_object(VarLval)),
          CGC_Statements = [statement(Stmt, mlds_make_context(Context)) ]
      ;
          CanCGC = cannot_cgc,
@@ -659,7 +659,7 @@
          MakeNewObject = new_object(VarLval, MaybeTag, HasSecTag, MLDS_Type,
              yes(SizeInWordsRval), MaybeCtorName, ArgRvals, MLDS_ArgTypes,
              MayUseAtomic),
-        Stmt = atomic(MakeNewObject),
+        Stmt = ml_stmt_atomic(MakeNewObject),
          Statement = statement(Stmt, mlds_make_context(Context)),

          ml_gen_field_take_address_assigns(TakeAddrInfos, VarLval, MLDS_Type,
@@ -1629,7 +1629,7 @@
          Statements = TagTestStatements ++ [SetTagTestResult]
      ;
          GetArgs = ml_gen_block(GetArgsDecls, GetArgsStatements, Context),
-        IfStmt = if_then_else(SucceededExpression, GetArgs, no),
+        IfStmt = ml_stmt_if_then_else(SucceededExpression, GetArgs, no),
          IfStatement = statement(IfStmt, mlds_make_context(Context)),
          Decls = TagTestDecls,
          Statements = TagTestStatements ++ [SetTagTestResult, IfStatement]
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.57
diff -u -r1.57 ml_util.m
--- compiler/ml_util.m	20 Aug 2007 03:35:59 -0000	1.57
+++ compiler/ml_util.m	21 Aug 2007 15:06:35 -0000
@@ -215,7 +215,7 @@
      FuncName = mlds_user_pred_label(pf_predicate, _, "main", 2, _, _).

  can_optimize_tailcall(Name, Call) :-
-    Call = mlcall(_Signature, FuncRval, MaybeObject, _CallArgs,
+    Call = ml_stmt_call(_Signature, FuncRval, MaybeObject, _CallArgs,
          _Results, CallKind),
      % Check if this call can be optimized as a tail call.
      ( CallKind = tail_call ; CallKind = no_return_call ),
@@ -271,46 +271,46 @@

  stmt_contains_statement(Stmt, SubStatement) :-
      (
-        Stmt = block(_Defns, Statements),
+        Stmt = ml_stmt_block(_Defns, Statements),
          statements_contains_statement(Statements, SubStatement)
      ;
-        Stmt = while(_Rval, Statement, _Once),
+        Stmt = ml_stmt_while(_Rval, Statement, _Once),
          statement_contains_statement(Statement, SubStatement)
      ;
-        Stmt = if_then_else(_Cond, Then, MaybeElse),
+        Stmt = ml_stmt_if_then_else(_Cond, Then, MaybeElse),
          ( statement_contains_statement(Then, SubStatement)
          ; maybe_statement_contains_statement(MaybeElse, SubStatement)
          )
      ;
-        Stmt = switch(_Type, _Val, _Range, Cases, Default),
+        Stmt = ml_stmt_switch(_Type, _Val, _Range, Cases, Default),
          ( cases_contains_statement(Cases, SubStatement)
          ; default_contains_statement(Default, SubStatement)
          )
      ;
-        Stmt = label(_Label),
+        Stmt = ml_stmt_label(_Label),
          fail
      ;
-        Stmt = goto(_),
+        Stmt = ml_stmt_goto(_),
          fail
      ;
-        Stmt = computed_goto(_Rval, _Labels),
+        Stmt = ml_stmt_computed_goto(_Rval, _Labels),
          fail
      ;
-        Stmt = mlcall(_Sig, _Func, _Obj, _Args, _RetLvals, _TailCall),
+        Stmt = ml_stmt_call(_Sig, _Func, _Obj, _Args, _RetLvals, _TailCall),
          fail
      ;
-        Stmt = return(_Rvals),
+        Stmt = ml_stmt_return(_Rvals),
          fail
      ;
-        Stmt = do_commit(_Ref),
+        Stmt = ml_stmt_do_commit(_Ref),
          fail
      ;
-        Stmt = try_commit(_Ref, Statement, Handler),
+        Stmt = ml_stmt_try_commit(_Ref, Statement, Handler),
          ( statement_contains_statement(Statement, SubStatement)
          ; statement_contains_statement(Handler, SubStatement)
          )
      ;
-        Stmt = atomic(_AtomicStmt),
+        Stmt = ml_stmt_atomic(_AtomicStmt),
          fail
      ).

@@ -360,57 +360,57 @@

  stmt_contains_var(Stmt, Name) :-
      (
-        Stmt = block(Defns, Statements),
+        Stmt = ml_stmt_block(Defns, Statements),
          ( defns_contains_var(Defns, Name)
          ; statements_contains_var(Statements, Name)
          )
      ;
-        Stmt = while(Rval, Statement, _Once),
+        Stmt = ml_stmt_while(Rval, Statement, _Once),
          ( rval_contains_var(Rval, Name)
          ; statement_contains_var(Statement, Name)
          )
      ;
-        Stmt = if_then_else(Cond, Then, MaybeElse),
+        Stmt = ml_stmt_if_then_else(Cond, Then, MaybeElse),
          ( rval_contains_var(Cond, Name)
          ; statement_contains_var(Then, Name)
          ; maybe_statement_contains_var(MaybeElse, Name)
          )
      ;
-        Stmt = switch(_Type, Val, _Range, Cases, Default),
+        Stmt = ml_stmt_switch(_Type, Val, _Range, Cases, Default),
          ( rval_contains_var(Val, Name)
          ; cases_contains_var(Cases, Name)
          ; default_contains_var(Default, Name)
          )
      ;
-        Stmt = label(_Label),
+        Stmt = ml_stmt_label(_Label),
          fail
      ;
-        Stmt = goto(_),
+        Stmt = ml_stmt_goto(_),
          fail
      ;
-        Stmt = computed_goto(Rval, _Labels),
+        Stmt = ml_stmt_computed_goto(Rval, _Labels),
          rval_contains_var(Rval, Name)
      ;
-        Stmt = mlcall(_Sig, Func, Obj, Args, RetLvals, _TailCall),
+        Stmt = ml_stmt_call(_Sig, Func, Obj, Args, RetLvals, _TailCall),
          ( rval_contains_var(Func, Name)
          ; maybe_rval_contains_var(Obj, Name)
          ; rvals_contains_var(Args, Name)
          ; lvals_contains_var(RetLvals, Name)
          )
      ;
-        Stmt = return(Rvals),
+        Stmt = ml_stmt_return(Rvals),
          rvals_contains_var(Rvals, Name)
      ;
-        Stmt = do_commit(Ref),
+        Stmt = ml_stmt_do_commit(Ref),
          rval_contains_var(Ref, Name)
      ;
-        Stmt = try_commit(Ref, Statement, Handler),
+        Stmt = ml_stmt_try_commit(Ref, Statement, Handler),
          ( lval_contains_var(Ref, Name)
          ; statement_contains_var(Statement, Name)
          ; statement_contains_var(Handler, Name)
          )
      ;
-        Stmt = atomic(AtomicStmt),
+        Stmt = ml_stmt_atomic(AtomicStmt),
          atomic_stmt_contains_var(AtomicStmt, Name)
      ).

@@ -487,7 +487,7 @@
  has_foreign_languages(Statement, Langs) :-
      GetTargetCode = (pred(Lang::out) is nondet :-
          statement_contains_statement(Statement, SubStatement),
-        SubStatement = statement(atomic(
+        SubStatement = statement(ml_stmt_atomic(
              outline_foreign_proc(Lang, _, _, _)), _)
          ),
      solutions.solutions(GetTargetCode, Langs).
@@ -503,10 +503,10 @@
      statement_contains_statement(FunctionBody, Statement),
      Statement = statement(Stmt, _),
      (
-        Stmt = atomic(inline_target_code(TargetLang, _)),
+        Stmt = ml_stmt_atomic(inline_target_code(TargetLang, _)),
          TargetLang \= NativeTargetLang
      ;
-        Stmt = atomic(outline_foreign_proc(_, _, _, _))
+        Stmt = ml_stmt_atomic(outline_foreign_proc(_, _, _, _))
      ).

  defn_contains_outline_foreign_proc(ForeignLang, Defn) :-
@@ -514,7 +514,7 @@
      Body = mlds_function(_, _, body_defined_here(FunctionBody), _, _),
      statement_contains_statement(FunctionBody, Statement),
      Statement = statement(Stmt, _),
-    Stmt = atomic(outline_foreign_proc(ForeignLang, _, _, _)).
+    Stmt = ml_stmt_atomic(outline_foreign_proc(ForeignLang, _, _, _)).

  defn_is_type(Defn) :-
      Defn = mlds_defn(Name, _Context, _Flags, _Body),
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.152
diff -u -r1.152 mlds.m
--- compiler/mlds.m	20 Aug 2007 03:36:00 -0000	1.152
+++ compiler/mlds.m	21 Aug 2007 15:06:35 -0000
@@ -969,11 +969,11 @@
  :- type mlds_stmt
      % Sequence.

-    --->    block(mlds_defns, list(statement))
+    --->    ml_stmt_block(mlds_defns, list(statement))

      % Iteration.

-    ;       while(mlds_rval, statement, bool)
+    ;       ml_stmt_while(mlds_rval, statement, bool)
              % The `bool' is true iff the loop is guaranteed to iterate at
              % least once -- in that case, the compiler can generate a
              % `do...while' loop rather than a `while...' loop.
@@ -981,9 +981,9 @@

      % Selection (see also computed_goto).

-    ;       if_then_else(mlds_rval, statement, maybe(statement))
+    ;       ml_stmt_if_then_else(mlds_rval, statement, maybe(statement))

-    ;       switch(
+    ;       ml_stmt_switch(
                  % This representation for switches is very general:
                  % it allows switching on any type, and cases can match
                  % on ranges as well as on values.
@@ -1015,21 +1015,21 @@

      % Transfer of control.

-    ;       label(mlds_label)
+    ;       ml_stmt_label(mlds_label)
              % Defines a label that can be used as the target of calls,
              % gotos, etc.

-    ;       goto(mlds_goto_target)
+    ;       ml_stmt_goto(mlds_goto_target)
              % goto(Target): Branch to the specified address.

-    ;       computed_goto(mlds_rval, list(mlds_label))
+    ;       ml_stmt_computed_goto(mlds_rval, list(mlds_label))
              % Evaluate rval, which should be an integer, and jump to the
              % (rval+1)th label in the list. e.g. computed_goto(2, [A, B, C, D])
              % will branch to label C.

      % Function call/return.

-    ;       mlcall(
+    ;       ml_stmt_call(
                  mlds_func_signature,    % Signature of the function.
                  mlds_rval,              % The function to call.
                  maybe(mlds_rval),       % For method calls, this field
@@ -1041,13 +1041,13 @@
                                          % tail call.
              )

-    ;       return(list(mlds_rval))     % Some targets will not support
-                                        % returning more than one value.
+    ;       ml_stmt_return(list(mlds_rval))  % Some targets will not support
+                                             % returning more than one value.

      % Commits (a specialized form of exception handling).

-    ;       try_commit(mlds_lval, statement, statement)
-    ;       do_commit(mlds_rval)
+    ;       ml_stmt_try_commit(mlds_lval, statement, statement)
+    ;       ml_stmt_do_commit(mlds_rval)
              % try_commit(Ref, GoalToTry, CommitHandlerGoal):
              %   Execute GoalToTry.  If GoalToTry exits via a
              %   `commit(Ref)' instruction, then execute
@@ -1085,14 +1085,14 @@
      % It might not be a good choice for different target languages.
      % XXX Full exception handling support is not yet implemented.

-%   ;       throw(mlds_type, mlds_rval)
+%   ;       ml_stmt_throw(mlds_type, mlds_rval)
  %           % Throw the specified exception.

-%   ;       rethrow
+%   ;       ml_stmt_rethrow
  %           % Rethrow the current exception
  %           % (only valid inside an exception handler).

-%   ;       try_catch(
+%   ;       ml_stmt_try_catch(
  %               statement,
  %               list(mlds_exception_handler)
  %           )
@@ -1102,7 +1102,7 @@

      % Atomic statements.

-    ;       atomic(mlds_atomic_statement).
+    ;       ml_stmt_atomic(mlds_atomic_statement).

  %-----------------------------------------------------------------------------%
  %
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.221
diff -u -r1.221 mlds_to_c.m
--- compiler/mlds_to_c.m	20 Aug 2007 03:36:00 -0000	1.221
+++ compiler/mlds_to_c.m	21 Aug 2007 15:06:35 -0000
@@ -2584,7 +2584,8 @@
  :- pred mlds_output_stmt(indent::in, func_info::in, mlds_stmt::in,
      mlds_context::in, io::di, io::uo) is det.

-mlds_output_stmt(Indent, FuncInfo, block(Defns, Statements), Context, !IO) :-
+mlds_output_stmt(Indent, FuncInfo, ml_stmt_block(Defns, Statements), Context,
+        !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("{\n", !IO),
      (
@@ -2612,14 +2613,15 @@
      mlds_indent(Context, Indent, !IO),
      io.write_string("}\n", !IO).

-mlds_output_stmt(Indent, FuncInfo, while(Cond, Statement, no), _, !IO) :-
+mlds_output_stmt(Indent, FuncInfo, ml_stmt_while(Cond, Statement, no), _,
+        !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("while (", !IO),
      mlds_output_rval(Cond, !IO),
      io.write_string(")\n", !IO),
      mlds_output_statement(Indent + 1, FuncInfo, Statement, !IO).
-mlds_output_stmt(Indent, FuncInfo, while(Cond, Statement, yes), Context,
-        !IO) :-
+mlds_output_stmt(Indent, FuncInfo, ml_stmt_while(Cond, Statement, yes),
+        Context, !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("do\n", !IO),
      mlds_output_statement(Indent + 1, FuncInfo, Statement, !IO),
@@ -2628,8 +2630,8 @@
      mlds_output_rval(Cond, !IO),
      io.write_string(");\n", !IO).

-mlds_output_stmt(Indent, FuncInfo, if_then_else(Cond, Then0, MaybeElse),
-        Context, !IO) :-
+mlds_output_stmt(Indent, FuncInfo, IfThenElseStmt, Context, !IO) :-
+    IfThenElseStmt = ml_stmt_if_then_else(Cond, Then0, MaybeElse),
      % We need to take care to avoid problems caused by the dangling else
      % ambiguity.
      (
@@ -2646,9 +2648,9 @@
          % `if' rather than the outer `if'.

          MaybeElse = yes(_),
-        Then0 = statement(if_then_else(_, _, no), ThenContext)
+        Then0 = statement(ml_stmt_if_then_else(_, _, no), ThenContext)
      ->
-        Then = statement(block([], [Then0]), ThenContext)
+        Then = statement(ml_stmt_block([], [Then0]), ThenContext)
      ;
          % For examples of the form
          %
@@ -2663,9 +2665,9 @@
          % a warning from gcc.

          MaybeElse = no,
-        Then0 = statement(if_then_else(_, _, yes(_)), ThenContext)
+        Then0 = statement(ml_stmt_if_then_else(_, _, yes(_)), ThenContext)
      ->
-        Then = statement(block([], [Then0]), ThenContext)
+        Then = statement(ml_stmt_block([], [Then0]), ThenContext)
      ;
          Then = Then0
      ),
@@ -2683,8 +2685,8 @@
      ;
          MaybeElse = no
      ).
-mlds_output_stmt(Indent, FuncInfo, switch(_Type, Val, _Range, Cases, Default),
-        Context, !IO) :-
+mlds_output_stmt(Indent, FuncInfo,
+        ml_stmt_switch(_Type, Val, _Range, Cases, Default), Context, !IO) :-
      mlds_indent(Context, Indent, !IO),
      io.write_string("switch (", !IO),
      mlds_output_rval(Val, !IO),
@@ -2697,7 +2699,7 @@
      mlds_indent(Context, Indent, !IO),
      io.write_string("}\n", !IO).

-mlds_output_stmt(Indent, _FuncInfo, label(LabelName), _, !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_label(LabelName), _, !IO) :-
      % Note: MLDS allows labels at the end of blocks. C doesn't. Hence we need
      % to insert a semi-colon after the colon to ensure that there is a
      % statement to attach the label to.
@@ -2705,19 +2707,19 @@
      mlds_indent(Indent - 1, !IO),
      mlds_output_label_name(LabelName, !IO),
      io.write_string(":;\n", !IO).
-mlds_output_stmt(Indent, _FuncInfo, goto(label(LabelName)), _, !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_goto(label(LabelName)), _, !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("goto ", !IO),
      mlds_output_label_name(LabelName, !IO),
      io.write_string(";\n", !IO).
-mlds_output_stmt(Indent, _FuncInfo, goto(break), _, !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_goto(break), _, !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("break;\n", !IO).
-mlds_output_stmt(Indent, _FuncInfo, goto(continue), _, !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_goto(continue), _, !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("continue;\n", !IO).
-mlds_output_stmt(Indent, _FuncInfo, computed_goto(Expr, Labels), Context,
-        !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_computed_goto(Expr, Labels),
+        Context, !IO) :-
      % XXX For GNU C, we could output potentially more efficient code
      % by using an array of labels; this would tell the compiler that
      % it didn't need to do any range check.
@@ -2733,7 +2735,7 @@
      io.write_string("}\n", !IO).

  mlds_output_stmt(Indent, CallerFuncInfo, Call, Context, !IO) :-
-    Call = mlcall(Signature, FuncRval, MaybeObject, CallArgs,
+    Call = ml_stmt_call(Signature, FuncRval, MaybeObject, CallArgs,
          Results, IsTailCall),
      CallerFuncInfo = func_info(CallerName, CallerSignature),

@@ -2814,7 +2816,7 @@
      mlds_indent(Indent, !IO),
      io.write_string("}\n", !IO).

-mlds_output_stmt(Indent, _FuncInfo, return(Results), _, !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_return(Results), _, !IO) :-
      mlds_indent(Indent, !IO),
      io.write_string("return", !IO),
      (
@@ -2829,7 +2831,7 @@
      ),
      io.write_string(";\n", !IO).

-mlds_output_stmt(Indent, _FuncInfo, do_commit(Ref), _, !IO) :-
+mlds_output_stmt(Indent, _FuncInfo, ml_stmt_do_commit(Ref), _, !IO) :-
      mlds_indent(Indent, !IO),
      globals.io_lookup_bool_option(gcc_local_labels, GCC_LocalLabels, !IO),
      (
@@ -2848,8 +2850,8 @@
          io.write_string(", 1)", !IO)
      ),
      io.write_string(";\n", !IO).
-mlds_output_stmt(Indent, FuncInfo, try_commit(Ref, Stmt0, Handler), Context,
-        !IO) :-
+mlds_output_stmt(Indent, FuncInfo, TryCommitStmt, Context, !IO) :-
+    TryCommitStmt = ml_stmt_try_commit(Ref, Stmt0, Handler),
      globals.io_lookup_bool_option(gcc_local_labels, GCC_LocalLabels, !IO),
      (
          GCC_LocalLabels = yes,
@@ -2909,8 +2911,8 @@

          % We need to take care to avoid problems caused by the dangling else
          % ambiguity.
-        ( Stmt0 = statement(if_then_else(_, _, no), Context) ->
-            Stmt = statement(block([], [Stmt0]), Context)
+        ( Stmt0 = statement(ml_stmt_if_then_else(_, _, no), Context) ->
+            Stmt = statement(ml_stmt_block([], [Stmt0]), Context)
          ;
              Stmt = Stmt0
          ),
@@ -3072,7 +3074,8 @@

  %-----------------------------------------------------------------------------%

-mlds_output_stmt(Indent, FuncInfo, atomic(AtomicStatement), Context, !IO) :-
+mlds_output_stmt(Indent, FuncInfo, ml_stmt_atomic(AtomicStatement), Context,
+        !IO) :-
      mlds_output_atomic_stmt(Indent, FuncInfo, AtomicStatement, Context, !IO).

  :- pred mlds_output_label_name(mlds_label::in, io::di, io::uo) is det.
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.133
diff -u -r1.133 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	20 Aug 2007 03:36:00 -0000	1.133
+++ compiler/mlds_to_gcc.m	21 Aug 2007 15:06:35 -0000
@@ -397,7 +397,7 @@
  		qual(MLDS_ModuleName, module_qual, Name),
  		SymbolTable, LabelTable) },
  	{ term__context_init(Context) },
-	{ FuncBody = statement(block([], []),
+	{ FuncBody = statement(ml_stmt_block([], []),
  		mlds_make_context(Context)) },
  	gcc__start_function(GCC_FuncDecl),
  	gen_statement(DefnInfo, FuncBody),
@@ -1521,7 +1521,7 @@
  	is nondet.
  statement_contains_label(Statement, Label) :-
  	statement_contains_statement(Statement, SubStatement),
-	SubStatement = statement(label(Label), _).
+	SubStatement = statement(ml_stmt_label(Label), _).

  	% XXX we should lookup the existing definition, if there is one,
  	% rather than always making a new one
@@ -2741,7 +2741,7 @@
  	%
  	% sequence
  	%
-gen_stmt(DefnInfo0, block(Defns, Statements), _Context) -->
+gen_stmt(DefnInfo0, ml_stmt_block(Defns, Statements), _Context) -->
  	gcc__start_block,
  	{ FuncName = DefnInfo0 ^ func_name },
  	{ FuncName = qual(ModuleName, _, _) },
@@ -2752,7 +2752,8 @@
  	%
  	% iteration
  	%
-gen_stmt(DefnInfo, while(Cond, Statement, AtLeastOneIteration), _Context) -->
+gen_stmt(DefnInfo, ml_stmt_while(Cond, Statement, AtLeastOneIteration),
+		_Context) -->
  	gcc__gen_start_loop(Loop),
  	build_rval(Cond, DefnInfo, GCC_Cond),
  	(
@@ -2771,7 +2772,7 @@
  	%
  	% selection (see also computed_goto)
  	%
-gen_stmt(DefnInfo, if_then_else(Cond, Then, MaybeElse), _Context) -->
+gen_stmt(DefnInfo, ml_stmt_if_then_else(Cond, Then, MaybeElse), _Context) -->
  	build_rval(Cond, DefnInfo, GCC_Cond),
  	gcc__gen_start_cond(GCC_Cond),
  	gen_statement(DefnInfo, Then),
@@ -2783,7 +2784,7 @@
  		gen_statement(DefnInfo, Else)
  	),
  	gcc__gen_end_cond.
-gen_stmt(DefnInfo, switch(Type, Val, Range, Cases, Default), _) -->
+gen_stmt(DefnInfo, ml_stmt_switch(Type, Val, Range, Cases, Default), _) -->
  	build_type(Type, DefnInfo ^ global_info, GCC_Type),
  	( { Range = range(Min, Max) } ->
  		gcc__build_range_type(GCC_Type, Min, Max, GCC_RangeType)
@@ -2801,22 +2802,22 @@
  	%
  	% transfer of control
  	%
-gen_stmt(DefnInfo, label(LabelName), _) -->
+gen_stmt(DefnInfo, ml_stmt_label(LabelName), _) -->
  	{ LabelTable = DefnInfo ^ label_table },
  	{ GCC_Label = map__lookup(LabelTable, LabelName) },
  	gcc__gen_label(GCC_Label).
-gen_stmt(DefnInfo, goto(label(LabelName)), _) -->
+gen_stmt(DefnInfo, ml_stmt_goto(label(LabelName)), _) -->
  	{ LabelTable = DefnInfo ^ label_table },
  	{ GCC_Label = map__lookup(LabelTable, LabelName) },
  	gcc__gen_goto(GCC_Label).
-gen_stmt(_DefnInfo, goto(break), _) -->
+gen_stmt(_DefnInfo, ml_stmt_goto(break), _) -->
  	gcc__gen_break.
-gen_stmt(_DefnInfo, goto(continue), _) -->
+gen_stmt(_DefnInfo, ml_stmt_goto(continue), _) -->
  	% XXX not yet implemented
  	% but we set target_supports_break_and_continue to no
  	% for this target, so we shouldn't get any
  	{ unexpected(this_file, "continue") }.
-gen_stmt(_DefnInfo, computed_goto(_Expr, _Labels), _) -->
+gen_stmt(_DefnInfo, ml_stmt_computed_goto(_Expr, _Labels), _) -->
  	% XXX not yet implemented
  	% but we set target_supports_computed_goto to no
  	% for this target, so we shouldn't get any
@@ -2826,7 +2827,7 @@
  	% function call/return
  	%
  gen_stmt(DefnInfo, Call, _) -->
-	{ Call = mlcall(_Signature, FuncRval, MaybeObject, CallArgs,
+	{ Call = ml_stmt_call(_Signature, FuncRval, MaybeObject, CallArgs,
  		Results, CallKind) },
  	{ expect(unify(MaybeObject, no), this_file, "method call") },
  	build_args(CallArgs, DefnInfo, GCC_ArgList),
@@ -2866,7 +2867,7 @@
  	;
  		{ sorry(this_file, "call with multiple outputs") }
  	).
-gen_stmt(DefnInfo, return(Results), _) -->
+gen_stmt(DefnInfo, ml_stmt_return(Results), _) -->
  	( { Results = [] } ->
  		% XXX Not yet implemented
  		% These are not generated by the current MLDS code
@@ -2882,7 +2883,7 @@
  	%
  	% commits
  	%
-gen_stmt(DefnInfo, do_commit(Ref), _Context) -->
+gen_stmt(DefnInfo, ml_stmt_do_commit(Ref), _Context) -->
  	% generate `__builtin_longjmp(&<Ref>, 1);'
  	{ Ref = lval(RefLval0) ->
  		RefLval = RefLval0
@@ -2893,7 +2894,7 @@
  		[mem_addr(RefLval), const(mlconst_int(1))],
  		DefnInfo, GCC_CallLongjmp),
  	gcc__gen_expr_stmt(GCC_CallLongjmp).
-gen_stmt(DefnInfo, try_commit(Ref, Stmt, Handler), _) -->
+gen_stmt(DefnInfo, ml_stmt_try_commit(Ref, Stmt, Handler), _) -->
  	%
  	% Generate the following:
  	%
@@ -2921,7 +2922,7 @@
  	%
  	% atomic statements
  	%
-gen_stmt(DefnInfo, atomic(AtomicStatement), Context) -->
+gen_stmt(DefnInfo, ml_stmt_atomic(AtomicStatement), Context) -->
  	gen_atomic_stmt(DefnInfo, AtomicStatement, Context).

  %-----------------------------------------------------------------------------%
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.189
diff -u -r1.189 mlds_to_il.m
--- compiler/mlds_to_il.m	20 Aug 2007 03:36:01 -0000	1.189
+++ compiler/mlds_to_il.m	21 Aug 2007 15:06:35 -0000
@@ -457,19 +457,20 @@

  :- func rename_statement(statement) = statement.

-rename_statement(statement(block(Defns, Stmts), Context))
-    = statement(block(list.map(rename_defn, Defns),
+rename_statement(statement(ml_stmt_block(Defns, Stmts), Context))
+    = statement(ml_stmt_block(list.map(rename_defn, Defns),
          list.map(rename_statement, Stmts)), Context).
-rename_statement(statement(while(Rval, Loop, IterateOnce), Context))
-    = statement(while(rename_rval(Rval),
+rename_statement(statement(ml_stmt_while(Rval, Loop, IterateOnce), Context))
+    = statement(ml_stmt_while(rename_rval(Rval),
          rename_statement(Loop), IterateOnce), Context).
-rename_statement(statement(if_then_else(Rval, Then, MaybeElse), Context))
-    = statement(if_then_else(rename_rval(Rval),
+rename_statement(statement(ml_stmt_if_then_else(Rval, Then, MaybeElse),
+        Context)) =
+    statement(ml_stmt_if_then_else(rename_rval(Rval),
          rename_statement(Then),
          rename_maybe_statement(MaybeElse)), Context).
-rename_statement(statement(switch(Type, Rval, Range, Cases, Default0),
+rename_statement(statement(ml_stmt_switch(Type, Rval, Range, Cases, Default0),
          Context))
-    = statement(switch(Type, rename_rval(Rval), Range,
+    = statement(ml_stmt_switch(Type, rename_rval(Rval), Range,
          list.map(rename_switch_case, Cases), Default), Context) :-
      (
          Default0 = default_is_unreachable,
@@ -481,17 +482,17 @@
          Default0 = default_case(Stmt),
          Default = default_case(rename_statement(Stmt))
      ).
-rename_statement(statement(label(Label), Context))
-    = statement(label(Label), Context).
-rename_statement(statement(goto(Label), Context))
-    = statement(goto(Label), Context).
-rename_statement(statement(computed_goto(Rval, Labels), Context))
-    = statement(computed_goto(rename_rval(Rval), Labels), Context).
+rename_statement(statement(ml_stmt_label(Label), Context))
+    = statement(ml_stmt_label(Label), Context).
+rename_statement(statement(ml_stmt_goto(Label), Context))
+    = statement(ml_stmt_goto(Label), Context).
+rename_statement(statement(ml_stmt_computed_goto(Rval, Labels), Context))
+    = statement(ml_stmt_computed_goto(rename_rval(Rval), Labels), Context).

  rename_statement(statement(
-        mlcall(Signature, Rval, MaybeThis0, Args, Results, TailCall),
+        ml_stmt_call(Signature, Rval, MaybeThis0, Args, Results, TailCall),
          Context))
-    = statement(mlcall(Signature, rename_rval(Rval),
+    = statement(ml_stmt_call(Signature, rename_rval(Rval),
          MaybeThis, list.map(rename_rval, Args),
          list.map(rename_lval, Results), TailCall), Context) :-
      (
@@ -502,15 +503,15 @@
          MaybeThis = no
      ).

-rename_statement(statement(return(Vals), Context))
-    = statement(return(Vals), Context).
-rename_statement(statement(try_commit(Lval, Try, Handler), Context))
-    = statement(try_commit(rename_lval(Lval), rename_statement(Try),
+rename_statement(statement(ml_stmt_return(Vals), Context))
+    = statement(ml_stmt_return(Vals), Context).
+rename_statement(statement(ml_stmt_try_commit(Lval, Try, Handler), Context))
+    = statement(ml_stmt_try_commit(rename_lval(Lval), rename_statement(Try),
          rename_statement(Handler)), Context).
-rename_statement(statement(do_commit(Rval), Context))
-    = statement(do_commit(rename_rval(Rval)), Context).
-rename_statement(statement(atomic(Stmt), Context))
-    = statement(atomic(rename_atomic(Stmt)), Context).
+rename_statement(statement(ml_stmt_do_commit(Rval), Context))
+    = statement(ml_stmt_do_commit(rename_rval(Rval)), Context).
+rename_statement(statement(ml_stmt_atomic(Stmt), Context))
+    = statement(ml_stmt_atomic(rename_atomic(Stmt)), Context).

  :- func rename_switch_case(mlds_switch_case) = mlds_switch_case.

@@ -712,7 +713,7 @@
          Ctors0 = []
      ->
          % Generate an empty block for the body of the constructor.
-        Stmt = statement(block([], []), Context),
+        Stmt = statement(ml_stmt_block([], []), Context),

          Attributes = [],
          EnvVarNames = set.init,
@@ -1437,11 +1438,11 @@

      % XXX Should we look for tail calls?
      CallStatement = statement(
-        mlcall(Signature, CodeRval, no, ArgRvals, ReturnLvals,
+        ml_stmt_call(Signature, CodeRval, no, ArgRvals, ReturnLvals,
              ordinary_call), Context),
-    ReturnStatement = statement(return(ReturnRvals), Context),
+    ReturnStatement = statement(ml_stmt_return(ReturnRvals), Context),

-    Statement = statement(block(ReturnVarDecls,
+    Statement = statement(ml_stmt_block(ReturnVarDecls,
          ( ReturnRvals = [] ->
              [CallStatement]
          ;
@@ -1639,7 +1640,8 @@
  :- pred statement_to_il(statement::in, instr_tree::out,
      il_info::in, il_info::out) is det.

-statement_to_il(statement(block(Defns, Statements), Context), Instrs, !Info) :-
+statement_to_il(statement(BlockStmt, Context), Instrs, !Info) :-
+    BlockStmt = ml_stmt_block(Defns, Statements),
      il_info_get_module_name(!.Info, ModuleName),
      il_info_get_next_block_id(BlockId, !Info),
      list.map(defn_to_local(ModuleName), Defns, Locals),
@@ -1661,13 +1663,12 @@
      ]),
      il_info_remove_locals(Locals, !Info).

-statement_to_il(statement(atomic(Atomic), Context), Instrs, !Info) :-
+statement_to_il(statement(ml_stmt_atomic(Atomic), Context), Instrs, !Info) :-
      atomic_statement_to_il(Atomic, AtomicInstrs, !Info),
      Instrs = tree(context_node(Context), AtomicInstrs).

-statement_to_il(statement(
-        mlcall(Sig, Function, _This, Args, Returns, CallKind), Context),
-        Instrs, !Info) :-
+statement_to_il(statement(CallStmt, Context), Instrs, !Info) :-
+    CallStmt = ml_stmt_call(Sig, Function, _This, Args, Returns, CallKind),
      VerifiableCode = !.Info ^ verifiable_code,
      ByRefTailCalls = !.Info ^ il_byref_tailcalls,
      MsCLR = !.Info ^ support_ms_clr,
@@ -1757,8 +1758,8 @@
          ReturnsStoredInstrs
      ]).

-statement_to_il(statement(if_then_else(Condition, ThenCase, ElseCase),
-        Context), Instrs, !Info) :-
+statement_to_il(statement(IfThenElseStmt, Context), Instrs, !Info) :-
+    IfThenElseStmt = ml_stmt_if_then_else(Condition, ThenCase, ElseCase),
      generate_condition(Condition, ConditionInstrs, ElseLabel, !Info),
      il_info_make_next_label(DoneLabel, !Info),
      statement_to_il(ThenCase, ThenInstrs, !Info),
@@ -1777,15 +1778,15 @@
          instr_node(label(DoneLabel))
      ]).

-statement_to_il(statement(switch(_Type, _Val, _Range, _Cases, _Default),
-        _Context), _Instrs, !Info) :-
+statement_to_il(statement(SwitchStmt, _Context), _Instrs, !Info) :-
+    SwitchStmt = ml_stmt_switch(_Type, _Val, _Range, _Cases, _Default),
      % The IL back-end only supports computed_gotos and if-then-else chains;
      % the MLDS code generator should either avoid generating MLDS switches,
      % or should transform them into computed_gotos or if-then-else chains.
      unexpected(this_file, "`switch' not supported").

-statement_to_il(statement(while(Condition, Body, AtLeastOnce),
-        Context), Instrs, !Info) :-
+statement_to_il(statement(WhileStmt, Context), Instrs, !Info) :-
+    WhileStmt = ml_stmt_while(Condition, Body, AtLeastOnce),
      generate_condition(Condition, ConditionInstrs, EndLabel, !Info),
      il_info_make_next_label(StartLabel, !Info),
      statement_to_il(Body, BodyInstrs, !Info),
@@ -1814,7 +1815,7 @@
          ])
      ).

-statement_to_il(statement(return(Rvals), Context), Instrs, !Info) :-
+statement_to_il(statement(ml_stmt_return(Rvals), Context), Instrs, !Info) :-
      (
          Rvals = [],
          unexpected(this_file, "empty list of return values")
@@ -1832,7 +1833,7 @@
          sorry(this_file, "multiple return values")
      ).

-statement_to_il(statement(label(Label), Context), Instrs, !Info) :-
+statement_to_il(statement(ml_stmt_label(Label), Context), Instrs, !Info) :-
      string.format("label %s", [s(Label)], Comment),
      Instrs = node([
          comment(Comment),
@@ -1840,7 +1841,8 @@
          label(Label)
      ]).

-statement_to_il(statement(goto(label(Label)), Context), Instrs, !Info) :-
+statement_to_il(statement(GotoLabelStmt, Context), Instrs, !Info) :-
+    GotoLabelStmt = ml_stmt_goto(label(Label)),
      string.format("goto %s", [s(Label)], Comment),
      Instrs = node([
          comment(Comment),
@@ -1848,13 +1850,15 @@
          br(label_target(Label))
      ]).

-statement_to_il(statement(goto(break), _Context), _Instrs, !Info) :-
+statement_to_il(statement(ml_stmt_goto(break), _Context), _Instrs, !Info) :-
      sorry(this_file, "break").

-statement_to_il(statement(goto(continue), _Context), _Instrs, !Info) :-
+statement_to_il(statement(ml_stmt_goto(continue), _Context), _Instrs, !Info) :-
      sorry(this_file, "continue").

-statement_to_il(statement(do_commit(_Ref), Context), Instrs, !Info) :-
+statement_to_il(statement(DoCommitStmt, Context), Instrs, !Info) :-
+    DoCommitStmt = ml_stmt_do_commit(_Ref),
+
      % For commits, we use exception handling.
      %
      % For a do_commit instruction, we generate code equivalent
@@ -1867,7 +1871,7 @@
      %   newobj  instance void
      %       ['mercury']'mercury'.'runtime'.'Commit'::.ctor()
      %   throw
-
+    %
      NewObjInstr = newobj_constructor(il_commit_class_name, []),
      Instrs = tree_list([
          context_node(Context),
@@ -1876,8 +1880,9 @@
          instr_node(throw)
      ]).

-statement_to_il(statement(try_commit(_Ref, GoalToTry, CommitHandlerGoal),
-        Context), Instrs, !Info) :-
+statement_to_il(statement(TryCommitStmt, Context), Instrs, !Info) :-
+    TryCommitStmt = ml_stmt_try_commit(_Ref, GoalToTry, CommitHandlerGoal),
+
      % For commits, we use exception handling.
      %
      % For try_commit instructions, we generate IL code
@@ -1892,7 +1897,7 @@
      %       leave label1
      %   }
      %   label1:
-
+    %
      il_info_get_next_block_id(TryBlockId, !Info),
      statement_to_il(GoalToTry, GoalInstrsTree, !Info),
      il_info_get_next_block_id(CatchBlockId, !Info),
@@ -1918,8 +1923,8 @@
          instr_node(label(DoneLabel))
      ]).

-statement_to_il(statement(computed_goto(Rval, MLDSLabels), Context),
-        Instrs, !Info) :-
+statement_to_il(statement(ComputedGotoStmt, Context), Instrs, !Info) :-
+    ComputedGotoStmt = ml_stmt_computed_goto(Rval, MLDSLabels),
      load(Rval, RvalLoadInstrs, !Info),
      Targets = list.map(func(L) = label_target(L), MLDSLabels),
      Instrs = tree_list([
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.96
diff -u -r1.96 mlds_to_java.m
--- compiler/mlds_to_java.m	20 Aug 2007 03:36:01 -0000	1.96
+++ compiler/mlds_to_java.m	21 Aug 2007 15:06:35 -0000
@@ -624,13 +624,13 @@
  :- pred method_ptrs_in_stmt(mlds_stmt::in,
      list(mlds_code_addr)::in, list(mlds_code_addr)::out) is det.

-method_ptrs_in_stmt(block(Defns, Statements), !CodeAddrs) :-
+method_ptrs_in_stmt(ml_stmt_block(Defns, Statements), !CodeAddrs) :-
      method_ptrs_in_defns(Defns, !CodeAddrs),
      method_ptrs_in_statements(Statements, !CodeAddrs).
-method_ptrs_in_stmt(while(Rval, Statement, _Bool), !CodeAddrs) :-
+method_ptrs_in_stmt(ml_stmt_while(Rval, Statement, _Bool), !CodeAddrs) :-
      method_ptrs_in_rval(Rval, !CodeAddrs),
      method_ptrs_in_statement(Statement, !CodeAddrs).
-method_ptrs_in_stmt(if_then_else(Rval, StatementThen,
+method_ptrs_in_stmt(ml_stmt_if_then_else(Rval, StatementThen,
          MaybeStatementElse), !CodeAddrs) :-
      method_ptrs_in_rval(Rval, !CodeAddrs),
      method_ptrs_in_statement(StatementThen, !CodeAddrs),
@@ -640,39 +640,40 @@
      ;
          MaybeStatementElse = no
      ).
-method_ptrs_in_stmt(switch(_Type, Rval, _Range, Cases, Default),
+method_ptrs_in_stmt(ml_stmt_switch(_Type, Rval, _Range, Cases, Default),
          !CodeAddrs) :-
      method_ptrs_in_rval(Rval, !CodeAddrs),
      method_ptrs_in_switch_cases(Cases, !CodeAddrs),
      method_ptrs_in_switch_default(Default, !CodeAddrs).
-method_ptrs_in_stmt(label(_), _, _) :-
+method_ptrs_in_stmt(ml_stmt_label(_), _, _) :-
      unexpected(this_file,
          "method_ptrs_in_stmt: labels not supported in Java.").
-method_ptrs_in_stmt(goto(break), !CodeAddrs).
-method_ptrs_in_stmt(goto(continue), !CodeAddrs).
-method_ptrs_in_stmt(goto(label(_)), _, _) :-
+method_ptrs_in_stmt(ml_stmt_goto(break), !CodeAddrs).
+method_ptrs_in_stmt(ml_stmt_goto(continue), !CodeAddrs).
+method_ptrs_in_stmt(ml_stmt_goto(label(_)), _, _) :-
      unexpected(this_file,
          "method_ptrs_in_stmt: goto label not supported in Java.").
-method_ptrs_in_stmt(computed_goto(_, _), _, _) :-
+method_ptrs_in_stmt(ml_stmt_computed_goto(_, _), _, _) :-
      unexpected(this_file,
          "method_ptrs_in_stmt: computed gotos not supported in Java.").
-method_ptrs_in_stmt(try_commit(_Lval, StatementGoal,
+method_ptrs_in_stmt(ml_stmt_try_commit(_Lval, StatementGoal,
          StatementHandler), !CodeAddrs) :-
      % We don't check "_Lval" here as we expect it to be a local variable
      % of type mlds_commit_type.
      method_ptrs_in_statement(StatementGoal, !CodeAddrs),
      method_ptrs_in_statement(StatementHandler, !CodeAddrs).
-method_ptrs_in_stmt(do_commit(_Rval), !CodeAddrs).
+method_ptrs_in_stmt(ml_stmt_do_commit(_Rval), !CodeAddrs).
      % We don't check "_Rval" here as we expect it to be a local variable
      % of type mlds_commit_type.
-method_ptrs_in_stmt(return(Rvals), !CodeAddrs) :-
+method_ptrs_in_stmt(ml_stmt_return(Rvals), !CodeAddrs) :-
      method_ptrs_in_rvals(Rvals, !CodeAddrs).
-method_ptrs_in_stmt(mlcall(_FuncSig, _Rval, _MaybeThis, Rvals, _ReturnVars,
-        _IsTailCall), !CodeAddrs) :-
+method_ptrs_in_stmt(CallStmt, !CodeAddrs) :-
+    CallStmt = ml_stmt_call(_FuncSig, _Rval, _MaybeThis, Rvals, _ReturnVars, 
+        _IsTailCall),
      % We don't check "_Rval" - it may be a code address but is a
      % standard call rather than a function pointer use.
      method_ptrs_in_rvals(Rvals, !CodeAddrs).
-method_ptrs_in_stmt(atomic(AtomicStatement), !CodeAddrs) :-
+method_ptrs_in_stmt(ml_stmt_atomic(AtomicStatement), !CodeAddrs) :-
      (
          AtomicStatement = new_object(Lval, _MaybeTag, _Bool,
              _Type, _MemRval, _MaybeCtorName, Rvals, _Types, _MayUseAtomic)
@@ -936,17 +937,17 @@
          OrigRetTypes = [_ | _],
          CallRetLvals = [ReturnLval]
      ),
-    Call = mlcall(OrigFuncSignature, CallRval, no, CallArgs,
+    Call = ml_stmt_call(OrigFuncSignature, CallRval, no, CallArgs,
          CallRetLvals, ordinary_call),
      CallStatement = statement(Call, Context),

      % Create a return statement that returns the result of the call to the
      % original method, boxed as a java.lang.Object.
      ReturnRval = unop(box(ReturnVarType), lval(ReturnLval)),
-    Return = return([ReturnRval]),
+    Return = ml_stmt_return([ReturnRval]),
      ReturnStatement = statement(Return, Context),

-    Block = block(MethodDefns, [CallStatement, ReturnStatement]),
+    Block = ml_stmt_block(MethodDefns, [CallStatement, ReturnStatement]),
      Statements = statement(Block, Context),

      % Put it all together.
@@ -2176,8 +2177,8 @@

      % sequence
      %
-output_stmt(Indent, ModuleInfo, FuncInfo, block(Defns, Statements), Context,
-        ExitMethods, !IO) :-
+output_stmt(Indent, ModuleInfo, FuncInfo, ml_stmt_block(Defns, Statements),
+        Context, ExitMethods, !IO) :-
      indent_line(Indent, !IO),
      io.write_string("{\n", !IO),
      (
@@ -2196,7 +2197,7 @@

      % iteration
      %
-output_stmt(Indent, ModuleInfo, FuncInfo, while(Cond, Statement, no),
+output_stmt(Indent, ModuleInfo, FuncInfo, ml_stmt_while(Cond, Statement, no),
          _, ExitMethods, !IO) :-
      indent_line(Indent, !IO),
      io.write_string("while (", !IO),
@@ -2214,8 +2215,8 @@
              StmtExitMethods, !IO),
          ExitMethods = while_exit_methods(Cond, StmtExitMethods)
      ).
-output_stmt(Indent, ModuleInfo, FuncInfo, while(Cond, Statement, yes), Context,
-        ExitMethods, !IO) :-
+output_stmt(Indent, ModuleInfo, FuncInfo, ml_stmt_while(Cond, Statement, yes),
+        Context, ExitMethods, !IO) :-
      indent_line(Indent, !IO),
      io.write_string("do\n", !IO),
      output_statement(Indent + 1, ModuleInfo, FuncInfo, Statement,
@@ -2228,7 +2229,8 @@

      % selection (if-then-else)
      %
-output_stmt(Indent, ModuleInfo, FuncInfo, if_then_else(Cond, Then0, MaybeElse),
+output_stmt(Indent, ModuleInfo, FuncInfo,
+        ml_stmt_if_then_else(Cond, Then0, MaybeElse),
          Context, ExitMethods, !IO) :-
      % We need to take care to avoid problems caused by the dangling else
      % ambiguity.
@@ -2246,9 +2248,9 @@
          % inner `if' rather than the outer `if'.

          MaybeElse = yes(_),
-        Then0 = statement(if_then_else(_, _, no), ThenContext)
+        Then0 = statement(ml_stmt_if_then_else(_, _, no), ThenContext)
      ->
-        Then = statement(block([], [Then0]), ThenContext)
+        Then = statement(ml_stmt_block([], [Then0]), ThenContext)
      ;
          Then = Then0
      ),
@@ -2279,7 +2281,7 @@
      % selection (switch)
      %
  output_stmt(Indent, ModuleInfo, FuncInfo,
-        switch(_Type, Val, _Range, Cases, Default),
+        ml_stmt_switch(_Type, Val, _Range, Cases, Default),
          Context, ExitMethods, !IO) :-
      indent_line(Context, Indent, !IO),
      io.write_string("switch (", !IO),
@@ -2293,20 +2295,21 @@

      % transfer of control
      %
-output_stmt(_, _, _, label(_), _, _, _, _)  :-
+output_stmt(_, _, _, ml_stmt_label(_), _, _, _, _)  :-
      unexpected(this_file, "output_stmt: labels not supported in Java.").
-output_stmt(_, _, _, goto(label(_)), _, _, _, _) :-
+output_stmt(_, _, _, ml_stmt_goto(label(_)), _, _, _, _) :-
      unexpected(this_file, "output_stmt: gotos not supported in Java.").
-output_stmt(Indent, _, _FuncInfo, goto(break), _Context, ExitMethods, !IO) :-
+output_stmt(Indent, _, _FuncInfo, ml_stmt_goto(break), _Context,
+        ExitMethods, !IO) :-
      indent_line(Indent, !IO),
      io.write_string("break;\n", !IO),
      ExitMethods = set.make_singleton_set(can_break).
-output_stmt(Indent, _, _FuncInfo, goto(continue), _Context, ExitMethods,
-        !IO) :-
+output_stmt(Indent, _, _FuncInfo, ml_stmt_goto(continue), _Context,
+        ExitMethods, !IO) :-
      indent_line(Indent, !IO),
      io.write_string("continue;\n", !IO),
      ExitMethods = set.make_singleton_set(can_continue).
-output_stmt(_, _, _, computed_goto(_, _), _, _, _, _) :-
+output_stmt(_, _, _, ml_stmt_computed_goto(_, _), _, _, _, _) :-
      unexpected(this_file,
          "output_stmt: computed gotos not supported in Java.").

@@ -2314,7 +2317,7 @@
      %
  output_stmt(Indent, ModuleInfo, CallerFuncInfo, Call, Context, ExitMethods,
          !IO) :-
-    Call = mlcall(Signature, FuncRval, MaybeObject, CallArgs, Results,
+    Call = ml_stmt_call(Signature, FuncRval, MaybeObject, CallArgs, Results,
          _IsTailCall),
      Signature = mlds_func_signature(ArgTypes, RetTypes),
      ModuleName = CallerFuncInfo ^ func_info_name ^ mod_name,
@@ -2439,8 +2442,8 @@
      io.write_string("}\n", !IO),
      ExitMethods = set.make_singleton_set(can_fall_through).

-output_stmt(Indent, ModuleInfo, FuncInfo, return(Results0), _, ExitMethods,
-        !IO) :-
+output_stmt(Indent, ModuleInfo, FuncInfo, ml_stmt_return(Results0), _,
+        ExitMethods, !IO) :-
      %
      % XXX It's not right to just remove the dummy variables like this, but
      % currently they do not seem to be included in the ReturnTypes of
@@ -2484,8 +2487,9 @@
      ),
      ExitMethods = set.make_singleton_set(can_return).

-output_stmt(Indent, ModuleInfo, FuncInfo, do_commit(Ref), _, ExitMethods,
+output_stmt(Indent, ModuleInfo, FuncInfo, DoCommitStmt, _, ExitMethods,
          !IO) :-
+    DoCommitStmt = ml_stmt_do_commit(Ref),
      indent_line(Indent, !IO),
      output_rval(ModuleInfo, Ref, FuncInfo ^ func_info_name ^ mod_name, !IO),
      io.write_string(" = new mercury.runtime.Commit();\n", !IO),
@@ -2495,8 +2499,9 @@
      io.write_string(";\n", !IO),
      ExitMethods = set.make_singleton_set(can_throw).

-output_stmt(Indent, ModuleInfo, FuncInfo, try_commit(_Ref, Stmt, Handler), _,
-        ExitMethods, !IO) :-
+output_stmt(Indent, ModuleInfo, FuncInfo, TryCommitStmt, _, ExitMethods,
+        !IO) :-
+    TryCommitStmt = ml_stmt_try_commit(_Ref, Stmt, Handler),
      indent_line(Indent, !IO),
      io.write_string("try\n", !IO),
      indent_line(Indent, !IO),
@@ -2524,8 +2529,9 @@

      % atomic statements
      %
-output_stmt(Indent, ModuleInfo, FuncInfo, atomic(AtomicStatement), Context,
-        ExitMethods, !IO) :-
+output_stmt(Indent, ModuleInfo, FuncInfo, AtomicStmt, Context, ExitMethods,
+        !IO) :-
+    AtomicStmt = ml_stmt_atomic(AtomicStatement),
      output_atomic_stmt(Indent, ModuleInfo, FuncInfo, AtomicStatement, Context,
          !IO),
      ExitMethods = set.make_singleton_set(can_fall_through).
Index: compiler/mlds_to_managed.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_managed.m,v
retrieving revision 1.46
diff -u -r1.46 mlds_to_managed.m
--- compiler/mlds_to_managed.m	20 Aug 2007 03:36:02 -0000	1.46
+++ compiler/mlds_to_managed.m	21 Aug 2007 15:06:35 -0000
@@ -274,8 +274,8 @@
  write_statement(Args, statement(Statement, Context), !IO) :-
      (
          % XXX petdr
-        Statement = atomic(outline_foreign_proc(lang_csharp, OutlineArgs,
-            _Lvals, Code))
+        Statement = ml_stmt_atomic(ForeignProc),
+        ForeignProc = outline_foreign_proc(lang_csharp, OutlineArgs, _, Code)
      ->
          list.foldl(write_outline_arg_init, OutlineArgs, !IO),
          output_context(mlds_get_prog_context(Context), !IO),
@@ -284,14 +284,14 @@
          output_reset_context(!IO),
          list.foldl(write_outline_arg_final, OutlineArgs, !IO)
      ;
-        Statement = block(Defns, Statements)
+        Statement = ml_stmt_block(Defns, Statements)
      ->
          io.write_list(Defns, "", write_defn_decl, !IO),
          io.write_string("{\n", !IO),
          io.write_list(Statements, "", write_statement(Args), !IO),
          io.write_string("\n}\n", !IO)
      ;
-        Statement = return(Rvals)
+        Statement = ml_stmt_return(Rvals)
      ->
          ( Rvals = [Rval] ->
              io.write_string("return ", !IO),
@@ -301,7 +301,7 @@
              sorry(this_file, "multiple return values")
          )
      ;
-        Statement = atomic(assign(LVal, RVal))
+        Statement = ml_stmt_atomic(assign(LVal, RVal))
      ->
          write_lval(LVal, !IO),
          io.write_string(" = ", !IO),

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list