[m-dev.] for review: refactor generation of builtins

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Mar 15 19:23:53 AEDT 2000


On 15-Mar-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> On 15-Mar-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > +:- pred translate_builtin_2(string, string, int, list(T), simple_code(T)).
> > +:- mode translate_builtin_2(in, in, in, in, out) is semidet.
> 
> I think you can find a better name than this for this predicate.

I went with Zoltan's suggestion of `builtin_translation'.

(The change here was completely trivial, just
s/translate_builtin_2/builtin_translation/g,
so I didn't bother with a relative diff.)

> The code for converting a test into LLDS should be in its own predicate or
> function, just as the code for converting an assignment into LLDS is, and
> as both kinds of conversions to MLDS are.

Done.  I've mode that code into a new predicate named
call_gen__generate_simple_test.  Here's the (fairly trivial)
relative diff.  I'll go ahead and commit this now.

Cheers,
	Fergus.

--- call_gen.m.old	Wed Mar 15 18:59:34 2000
+++ call_gen.m	Wed Mar 15 19:23:03 2000
@@ -521,20 +521,8 @@
 		(
 			{ SimpleCode = test(TestExpr) }
 		->
-			(
-				{ TestExpr = binary(BinOp, X0, Y0) },
-				{ X1 = convert_simple_expr(X0) },
-				{ Y1 = convert_simple_expr(Y0) },
-				call_gen__generate_builtin_arg(X1, X, CodeX),
-				call_gen__generate_builtin_arg(Y1, Y, CodeY),
-				{ Rval = binop(BinOp, X, Y) },
-				{ ArgCode = tree(CodeX, CodeY) }
-			;
-				{ TestExpr = unary(UnOp, X0) },
-				{ X1 = convert_simple_expr(X0) },
-				call_gen__generate_builtin_arg(X1, X, ArgCode),
-				{ Rval = unop(UnOp, X) }
-			),
+			call_gen__generate_simple_test(TestExpr, Rval,
+				ArgCode),
 			code_info__fail_if_rval_is_false(Rval, TestCode),
 			{ Code = tree(ArgCode, TestCode) }
 		;
@@ -554,7 +542,25 @@
 convert_simple_expr(binary(BinOp, Expr1, Expr2)) =
 	binop(BinOp, convert_simple_expr(Expr1), convert_simple_expr(Expr2)).
 
-%---------------------------------------------------------------------------%
+:- pred call_gen__generate_simple_test(simple_expr(prog_var), rval,
+		code_tree, code_info, code_info).
+:- mode call_gen__generate_simple_test(in(simple_test_expr), out, out, in, out)
+		is det.
+call_gen__generate_simple_test(TestExpr, Rval, ArgCode) -->
+	(
+		{ TestExpr = binary(BinOp, X0, Y0) },
+		{ X1 = convert_simple_expr(X0) },
+		{ Y1 = convert_simple_expr(Y0) },
+		call_gen__generate_builtin_arg(X1, X, CodeX),
+		call_gen__generate_builtin_arg(Y1, Y, CodeY),
+		{ Rval = binop(BinOp, X, Y) },
+		{ ArgCode = tree(CodeX, CodeY) }
+	;
+		{ TestExpr = unary(UnOp, X0) },
+		{ X1 = convert_simple_expr(X0) },
+		call_gen__generate_builtin_arg(X1, X, ArgCode),
+		{ Rval = unop(UnOp, X) }
+	).
 
 :- pred call_gen__generate_builtin_arg(rval, rval, code_tree,
 	code_info, code_info).
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list