diff: clpr bug fixes
Fergus Henderson
fjh at kryten.cs.mu.OZ.AU
Wed Sep 3 05:28:51 AEST 1997
Various bug fixes and improvements to the clpr stuff.
The dc_analysis test in tranny.m now works.
clpr/cfloat.m:
- Fix a bug in equality for cfloats: it was assuming the old
non-COMPACT_ARGS argument passing convention.
- Fix a bug in cfloat__div(ca, co, ca): it was doing multiplication
rather than division.
- Use `pragma c_code(...)' rather than the old `pragma(c_code, ...)'
syntax.
- Various minor layout changes.
clpr/tranny.m:
- Fix a bug in `go1': for some reason, it had the transistor
state hard-coded to `cutoff', rather than backtracking over
all the possible transistor states. This caused go1 to
report an error, because there is no solution with State = cutoff.
- Add code to print out some nice output.
clpr/dump.m:
- Rename the non-logical debugging pred `dump' as `unsafe_dump'.
- Add a new predicate dump_cfloat/3 for dumping a cfloat to stdout.
(Also added an unsafe version unsafe_dump_cfloat.)
clpr/fib.exp:
clpr/laplace.exp:
- Minor changes (add trailing zeros, s/75/74.99/) to ensure
that the expected output matches the actual output [on kryten].
clpr/Mmake:
- Add back `tranny', since it now works.
- Make *_init.c depend on cfloat.c, to avoid trying to
access cfloat.c before it has been created.
cvs diff: Diffing .
Index: Mmake
===================================================================
RCS file: /home/staff/zs/imp/clpr/Mmake,v
retrieving revision 1.4
diff -u -u -r1.4 Mmake
--- 1.4 1997/08/27 17:11:02
+++ Mmake 1997/09/02 19:19:57
@@ -1,7 +1,14 @@
#-----------------------------------------------------------------------------#
+# Call me paranoid...
+MCFLAGS = --no-optimize-duplicate-calls
+MGNUCFLAGS = -g
+MLFLAGS = -g
+
+#-----------------------------------------------------------------------------#
+
# PROGS=simple sum test test2 fib
-PROGS= fib laplace mortgage sum_list # tranny
+PROGS= fib laplace mortgage sum_list tranny
DEPENDS=$(PROGS:%=%.depend)
CS=$(PROGS:%=%.c)
@@ -17,6 +24,7 @@
GRADE=asm_fast.gc.tr
C2INITFLAGS = cfloat.c
+%_init.c: cfloat.c
MLLIBS= clpr/*.o $(EXTRA_MLLIBS)
Index: cfloat.m
===================================================================
RCS file: /home/staff/zs/imp/clpr/cfloat.m,v
retrieving revision 1.2
diff -u -u -r1.2 cfloat.m
--- 1.2 1997/09/02 13:54:00
+++ cfloat.m 1997/09/02 19:22:51
@@ -334,8 +334,6 @@
ML_cfloat_choicepoint ML_cfloat_first_choicepoint;
ML_cfloat_choicepoint * ML_cfloat_current_cp = &ML_cfloat_first_choicepoint;
-/* XXX efficiency could be improved -- we should use a free list here */
-
#define ML_cfloat_next_choicepoint() \
( ML_cfloat_current_cp->next == NULL ? \
(ML_cfloat_current_cp->next = make(ML_cfloat_choicepoint), \
@@ -362,9 +360,11 @@
").
-:- pragma(c_code, "
+:- pragma c_code("
-void ML_cfloat_trail_solver(void) {
+void
+ML_cfloat_trail_solver(void)
+{
ML_cfloat_choicepoint *choicepoint = ML_cfloat_next_choicepoint();
choicepoint->stamp = stamp;
choicepoint->slack_id = slack_id;
@@ -374,7 +374,9 @@
stamp = MR_current_choicepoint_id();
}
-void ML_cfloat_untrail_func(Word datum, MR_untrail_reason reason) {
+void
+ML_cfloat_untrail_func(Word datum, MR_untrail_reason reason)
+{
ML_cfloat_choicepoint *choicepoint = (ML_cfloat_choicepoint *) datum;
switch (reason) {
case MR_undo:
@@ -427,14 +429,14 @@
ML_cfloat_maybe_trail_solver(); \
init_eqn(); \
s_evar(1.0, Svar1); \
- eqn_scratch->constant += (double)Val; \
+ eqn_scratch->constant += (double) Val; \
s_evar(-1.0, Svar2); \
s_econ(0.0); \
}
").
-:- pragma(c_code, "
+:- pragma c_code("
/* base_type_functors for `cfloat' */
@@ -469,9 +471,9 @@
Define_entry(mercury____Unify___cfloat__cfloat_0_0);
ML_cfloat_maybe_trail_solver();
init_eqn();
- s_evar(1.0, r2);
- s_evar(-1.0, r3);
- SUCCESS_INDICATOR = s_econ(0.0);
+ s_evar(1.0, unify_input1);
+ s_evar(-1.0, unify_input2);
+ unify_output = s_econ(0.0);
proceed();
Define_entry(mercury____Compare___cfloat__cfloat_0_0);
@@ -495,49 +497,49 @@
").
-:- pragma(c_code, cfloat__init(Svar::co), "ML_cfloat_init_solver_var(Svar);").
+:- pragma c_code(cfloat__init(Svar::co), "ML_cfloat_init_solver_var(Svar);").
-:- pragma(c_code, cfloat__plus(Svar1::ca, Svar2::ca, Svar3::co),
+:- pragma c_code(cfloat__plus(Svar1::ca, Svar2::ca, Svar3::co),
"
ML_cfloat_init_solver_var(Svar3);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::ca, Svar2::co, Svar3::ca),
+:- pragma c_code(cfloat__plus(Svar1::ca, Svar2::co, Svar3::ca),
"
ML_cfloat_init_solver_var(Svar2);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::ca, Svar2::co, Svar3::co),
+:- pragma c_code(cfloat__plus(Svar1::ca, Svar2::co, Svar3::co),
"
ML_cfloat_init_solver_var(Svar2);
ML_cfloat_init_solver_var(Svar3);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::co, Svar2::ca, Svar3::ca),
+:- pragma c_code(cfloat__plus(Svar1::co, Svar2::ca, Svar3::ca),
"
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::co, Svar2::ca, Svar3::co),
+:- pragma c_code(cfloat__plus(Svar1::co, Svar2::ca, Svar3::co),
"
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_init_solver_var(Svar3);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::co, Svar2::co, Svar3::ca),
+:- pragma c_code(cfloat__plus(Svar1::co, Svar2::co, Svar3::ca),
"
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_init_solver_var(Svar2);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::co, Svar2::co, Svar3::co),
+:- pragma c_code(cfloat__plus(Svar1::co, Svar2::co, Svar3::co),
"
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_init_solver_var(Svar2);
ML_cfloat_init_solver_var(Svar3);
ML_cfloat_add_solver_vars(Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__plus(Svar1::ca, Svar2::ca, Svar3::ca),
+:- pragma c_code(cfloat__plus(Svar1::ca, Svar2::ca, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -547,61 +549,61 @@
SUCCESS_INDICATOR = s_econ(0.0);
").
-:- pragma(c_code, cfloat__plus_float(Svar1::co, Val::in, Svar2::ca),
+:- pragma c_code(cfloat__plus_float(Svar1::co, Val::in, Svar2::ca),
"
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_add_float_and_cfloats(Svar1, Val, Svar2);
").
-:- pragma(c_code, cfloat__plus_float(Svar1::ca, Val::in, Svar2::co),
+:- pragma c_code(cfloat__plus_float(Svar1::ca, Val::in, Svar2::co),
"
ML_cfloat_init_solver_var(Svar2);
ML_cfloat_add_float_and_cfloats(Svar1, Val, Svar2);
").
-:- pragma(c_code, cfloat__plus_float(Svar1::co, Val::in, Svar2::co),
+:- pragma c_code(cfloat__plus_float(Svar1::co, Val::in, Svar2::co),
"
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_init_solver_var(Svar2);
ML_cfloat_add_float_and_cfloats(Svar1, Val, Svar2);
").
-:- pragma(c_code, cfloat__plus_float(Svar1::ca, Val::in, Svar2::ca),
+:- pragma c_code(cfloat__plus_float(Svar1::ca, Val::in, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
- eqn_scratch->constant += (double)Val;
+ eqn_scratch->constant += (double) Val;
s_evar(1.0, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
-:- pragma(c_code, cfloat__mult(Svar1::ca, Svar2::ca, Svar3::ca),
+:- pragma c_code(cfloat__mult(Svar1::ca, Svar2::ca, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
SUCCESS_INDICATOR = s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::ca, Svar2::co, Svar3::ca),
+:- pragma c_code(cfloat__mult(Svar1::ca, Svar2::co, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar2);
SUCCESS_INDICATOR = s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::co, Svar2::ca, Svar3::ca),
+:- pragma c_code(cfloat__mult(Svar1::co, Svar2::ca, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar1);
SUCCESS_INDICATOR = s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::ca, Svar2::ca, Svar3::co),
+:- pragma c_code(cfloat__mult(Svar1::ca, Svar2::ca, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar3);
s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::co, Svar2::co, Svar3::ca),
+:- pragma c_code(cfloat__mult(Svar1::co, Svar2::co, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -609,7 +611,7 @@
ML_cfloat_init_solver_var(Svar2);
s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::ca, Svar2::co, Svar3::co),
+:- pragma c_code(cfloat__mult(Svar1::ca, Svar2::co, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -617,7 +619,7 @@
ML_cfloat_init_solver_var(Svar3);
s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::co, Svar2::ca, Svar3::co),
+:- pragma c_code(cfloat__mult(Svar1::co, Svar2::ca, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -625,7 +627,7 @@
ML_cfloat_init_solver_var(Svar3);
s_mult(1.0, Svar3, Svar2, Svar1);
").
-:- pragma(c_code, cfloat__mult(Svar1::co, Svar2::co, Svar3::co),
+:- pragma c_code(cfloat__mult(Svar1::co, Svar2::co, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -640,7 +642,7 @@
"
ML_cfloat_maybe_trail_solver();
init_eqn();
- s_evar((double)Val, Svar1);
+ s_evar((double) Val, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
@@ -649,7 +651,7 @@
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar1);
- s_evar((double)Val, Svar1);
+ s_evar((double) Val, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
@@ -658,7 +660,7 @@
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar2);
- s_evar((double)Val, Svar1);
+ s_evar((double) Val, Svar1);
s_evar(-1.0, Svar2);
s_econ(0.0);
").
@@ -668,40 +670,40 @@
init_eqn();
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_init_solver_var(Svar2);
- s_evar((double)Val, Svar1);
+ s_evar((double) Val, Svar1);
s_evar(-1.0, Svar2);
s_econ(0.0);
").
-:- pragma(c_code, cfloat__div(Svar1::ca, Svar2::ca, Svar3::ca),
+:- pragma c_code(cfloat__div(Svar1::ca, Svar2::ca, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
SUCCESS_INDICATOR = s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::ca, Svar2::co, Svar3::ca),
+:- pragma c_code(cfloat__div(Svar1::ca, Svar2::co, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar2);
- SUCCESS_INDICATOR = s_mult(1.0, Svar3, Svar2, Svar1);
+ SUCCESS_INDICATOR = s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::co, Svar2::ca, Svar3::ca),
+:- pragma c_code(cfloat__div(Svar1::co, Svar2::ca, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar1);
SUCCESS_INDICATOR = s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::ca, Svar2::ca, Svar3::co),
+:- pragma c_code(cfloat__div(Svar1::ca, Svar2::ca, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar3);
SUCCESS_INDICATOR = s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::co, Svar2::co, Svar3::ca),
+:- pragma c_code(cfloat__div(Svar1::co, Svar2::co, Svar3::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -709,7 +711,7 @@
ML_cfloat_init_solver_var(Svar2);
s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::ca, Svar2::co, Svar3::co),
+:- pragma c_code(cfloat__div(Svar1::ca, Svar2::co, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -717,7 +719,7 @@
ML_cfloat_init_solver_var(Svar3);
s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::co, Svar2::ca, Svar3::co),
+:- pragma c_code(cfloat__div(Svar1::co, Svar2::ca, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -725,7 +727,7 @@
ML_cfloat_init_solver_var(Svar3);
SUCCESS_INDICATOR = s_mult(1.0, Svar1, Svar2, Svar3);
").
-:- pragma(c_code, cfloat__div(Svar1::co, Svar2::co, Svar3::co),
+:- pragma c_code(cfloat__div(Svar1::co, Svar2::co, Svar3::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -740,7 +742,7 @@
"
ML_cfloat_maybe_trail_solver();
init_eqn();
- s_evar(1/(double)Val, Svar1);
+ s_evar(1 / (double) Val, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
@@ -749,7 +751,7 @@
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar1);
- s_evar(1/(double)Val, Svar1);
+ s_evar(1 / (double) Val, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
@@ -758,7 +760,7 @@
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar2);
- s_evar(1/(double)Val, Svar1);
+ s_evar(1 / (double) Val, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
@@ -768,14 +770,14 @@
init_eqn();
ML_cfloat_init_solver_var(Svar1);
ML_cfloat_init_solver_var(Svar2);
- s_evar(1/(double)Val, Svar1);
+ s_evar(1 / (double) Val, Svar1);
s_evar(-1.0, Svar2);
SUCCESS_INDICATOR = s_econ(0.0);
").
-:- pragma(c_code, cfloat__eq(Svar1::ca, Svar2::ca),
+:- pragma c_code(cfloat__eq(Svar1::ca, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -784,7 +786,9 @@
SUCCESS_INDICATOR = s_econ(0.0);
"
).
-:- pragma(c_code, cfloat__eq(Svar1::co, Svar2::ca),
+:- pragma c_code(cfloat__eq(Svar1::co, Svar2::ca),
+ % XXX simplify:
+ % Svar1 = Svar2
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -794,7 +798,9 @@
s_econ(0.0);
"
).
-:- pragma(c_code, cfloat__eq(Svar1::ca, Svar2::co),
+:- pragma c_code(cfloat__eq(Svar1::ca, Svar2::co),
+ % XXX simplify:
+ % Svar2 = Svar1
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -804,7 +810,10 @@
s_econ(0.0);
"
).
-:- pragma(c_code, cfloat__eq(Svar1::co, Svar2::co),
+:- pragma c_code(cfloat__eq(Svar1::co, Svar2::co),
+ % XXX simplify:
+ % ML_cfloat_init_solver_var(Svar1);
+ % Svar2 = Svar1
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -816,7 +825,7 @@
"
).
-:- pragma(c_code, cfloat__eq_float(Svar::ca, Val::in),
+:- pragma c_code(cfloat__eq_float(Svar::ca, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -824,7 +833,7 @@
SUCCESS_INDICATOR = s_econ(Val);
"
).
-:- pragma(c_code, cfloat__eq_float(Svar::co, Val::in),
+:- pragma c_code(cfloat__eq_float(Svar::co, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -834,7 +843,7 @@
"
).
-:- pragma(c_code, '>'(Svar1::ca, Svar2::ca),
+:- pragma c_code('>'(Svar1::ca, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -843,7 +852,7 @@
SUCCESS_INDICATOR = s_gt0(0.0);
"
).
-:- pragma(c_code, '>'(Svar1::co, Svar2::ca),
+:- pragma c_code('>'(Svar1::co, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -853,7 +862,7 @@
s_gt0(0.0);
"
).
-:- pragma(c_code, '>'(Svar1::ca, Svar2::co),
+:- pragma c_code('>'(Svar1::ca, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -863,7 +872,7 @@
s_gt0(0.0);
"
).
-:- pragma(c_code, '>'(Svar1::co, Svar2::co),
+:- pragma c_code('>'(Svar1::co, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -875,7 +884,7 @@
"
).
-:- pragma(c_code, '>='(Svar1::ca, Svar2::ca),
+:- pragma c_code('>='(Svar1::ca, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -884,7 +893,7 @@
SUCCESS_INDICATOR = s_ge0(0.0);
"
).
-:- pragma(c_code, '>='(Svar1::co, Svar2::ca),
+:- pragma c_code('>='(Svar1::co, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -894,7 +903,7 @@
s_ge0(0.0);
"
).
-:- pragma(c_code, '>='(Svar1::ca, Svar2::co),
+:- pragma c_code('>='(Svar1::ca, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -904,7 +913,7 @@
s_ge0(0.0);
"
).
-:- pragma(c_code, '>='(Svar1::co, Svar2::co),
+:- pragma c_code('>='(Svar1::co, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -916,39 +925,39 @@
"
).
-:- pragma(c_code, cfloat__gt_float(Svar::ca, Val::in),
+:- pragma c_code(cfloat__gt_float(Svar::ca, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
s_evar(1.0, Svar);
- SUCCESS_INDICATOR = s_gt0((double)Val);
+ SUCCESS_INDICATOR = s_gt0((double) Val);
").
-:- pragma(c_code, cfloat__gt_float(Svar::co, Val::in),
+:- pragma c_code(cfloat__gt_float(Svar::co, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar);
s_evar(1.0, Svar);
- s_gt0((double)Val);
+ s_gt0((double) Val);
").
-:- pragma(c_code, cfloat__ge_float(Svar::ca, Val::in),
+:- pragma c_code(cfloat__ge_float(Svar::ca, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
s_evar(1.0, Svar);
- SUCCESS_INDICATOR = s_ge0((double)Val);
+ SUCCESS_INDICATOR = s_ge0((double) Val);
").
-:- pragma(c_code, cfloat__ge_float(Svar::co, Val::in),
+:- pragma c_code(cfloat__ge_float(Svar::co, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar);
s_evar(1.0, Svar);
- s_ge0((double)Val);
+ s_ge0((double) Val);
").
-:- pragma(c_code, '<'(Svar1::ca, Svar2::ca),
+:- pragma c_code('<'(Svar1::ca, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -957,7 +966,7 @@
SUCCESS_INDICATOR = s_gt0(0.0);
"
).
-:- pragma(c_code, '<'(Svar1::ca, Svar2::co),
+:- pragma c_code('<'(Svar1::ca, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -967,7 +976,7 @@
s_gt0(0.0);
"
).
-:- pragma(c_code, '<'(Svar1::co, Svar2::ca),
+:- pragma c_code('<'(Svar1::co, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -977,7 +986,7 @@
s_gt0(0.0);
"
).
-:- pragma(c_code, '<'(Svar1::co, Svar2::co),
+:- pragma c_code('<'(Svar1::co, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -989,7 +998,7 @@
"
).
-:- pragma(c_code, '=<'(Svar1::ca, Svar2::ca),
+:- pragma c_code('=<'(Svar1::ca, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -999,7 +1008,7 @@
"
).
-:- pragma(c_code, '=<'(Svar1::ca, Svar2::co),
+:- pragma c_code('=<'(Svar1::ca, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -1010,7 +1019,7 @@
"
).
-:- pragma(c_code, '=<'(Svar1::co, Svar2::ca),
+:- pragma c_code('=<'(Svar1::co, Svar2::ca),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -1021,7 +1030,7 @@
"
).
-:- pragma(c_code, '=<'(Svar1::co, Svar2::co),
+:- pragma c_code('=<'(Svar1::co, Svar2::co),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
@@ -1033,46 +1042,47 @@
"
).
-:- pragma(c_code, cfloat__lt_float(Svar::ca, Val::in),
+:- pragma c_code(cfloat__lt_float(Svar::ca, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
s_evar(-1.0, Svar);
- SUCCESS_INDICATOR = s_gt0((double)(-(Val)));
+ SUCCESS_INDICATOR = s_gt0((double) -Val);
").
-:- pragma(c_code, cfloat__lt_float(Svar::co, Val::in),
+:- pragma c_code(cfloat__lt_float(Svar::co, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar);
s_evar(-1.0, Svar);
- s_gt0((double)(-(Val)));
+ s_gt0((double) -Val);
").
-:- pragma(c_code, cfloat__le_float(Svar::ca, Val::in),
+:- pragma c_code(cfloat__le_float(Svar::ca, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
s_evar(-1.0, Svar);
- SUCCESS_INDICATOR = s_ge0((double)(-(Val)));
+ SUCCESS_INDICATOR = s_ge0((double) -Val);
").
-:- pragma(c_code, cfloat__le_float(Svar::co, Val::in),
+:- pragma c_code(cfloat__le_float(Svar::co, Val::in),
"
ML_cfloat_maybe_trail_solver();
init_eqn();
ML_cfloat_init_solver_var(Svar);
s_evar(-1.0, Svar);
- s_ge0((double)(-(Val)));
+ s_ge0((double) -Val);
").
-:- pragma(c_code, cfloat__get_val(Svar::ca, Val::out),
+:- pragma c_code(cfloat__get_val(Svar::ca, Val::out),
"
if (!is_ground(Svar, &Val)) {
- fprintf(stderr, ""ERROR: Var %d not ground."", Svar);
- fatal_error(""Solver variable not ground in cfloat__get_val"");
+ fprintf(stderr, ""ERROR: Var %d not ground.\\n"", Svar);
+ fatal_error(""Solver variable not ground ""
+ ""in cfloat__get_val"");
}
"
).
:- pragma(c_header_code, "extern void print_tableaus(void);").
-:- pragma(c_code, cfloat__dump_tableaus, "print_tableaus(); getchar();").
+:- pragma c_code(cfloat__dump_tableaus, "print_tableaus(); getchar();").
Index: dump.m
===================================================================
RCS file: /home/staff/zs/imp/clpr/dump.m,v
retrieving revision 1.6
diff -u -u -r1.6 dump.m
--- 1.6 1997/08/27 17:11:13
+++ dump.m 1997/09/02 19:19:04
@@ -18,7 +18,7 @@
:- import_module cfloat, list, string, io.
- % dump_one_solution(Pred, IO, IO0) is true iff
+ % dump_one_solution(Pred, IO0, IO) is true iff
% there is some constraint C between variables in CfloatList
% such that Pred(CfloatsList, NameList) is satisfied if C holds,
% and IO is obtained from IO0 by writing a representation of C
@@ -30,18 +30,53 @@
pred(list_co, out) is cc_nondet,
io__state::di, io__state::uo) is cc_multi.
+:- pred dump_cfloat(cfloat::ca, io__state::di, io__state::uo) is cc_multi.
+ % dump_cfloat(X, IO0, IO) is true iff
+ % IO is obtained from IO0 by writing either
+ % a floating point value F such that X has value F,
+ % or
+ % "_v<N>", where <N> is an integer.
+
+ % XXX this one is a non-logical hack, use only for debugging
+:- pred unsafe_dump(list(cfloat)::list_ca, list(string)::in) is det.
+
% XXX this one is a non-logical hack, use only for debugging
-:- pred dump(list(cfloat)::list_ca, list(string)::in) is det.
+:- pred unsafe_dump_cfloat(cfloat::ca) is det.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module int, require.
+:- pragma(c_header_code, "#include ""clpr/solver.h""").
+:- pragma(c_header_code, "#include ""clpr/clpr_misc.h""").
+
+:- pragma c_code(dump_cfloat(Svar::ca, IO0::di, IO::uo),
+"{
+ double val;
+ if (is_ground(Svar, &val)) {
+ printf(""%f"", val);
+ } else {
+ printf(""_v%d"", Svar);
+ }
+ IO = IO0;
+}").
+
+
+:- pragma c_code(unsafe_dump_cfloat(Svar::ca),
+"{
+ double val;
+ if (is_ground(Svar, &val)) {
+ printf(""%f"", val);
+ } else {
+ printf(""_v%d"", Svar);
+ }
+}").
+
% WARNING: The implementation of this predicate is non-logical.
dump_one_solution(Pred) -->
( { call(Pred, Vars, VarNames) } ->
- { dump(Vars, VarNames) }
+ { unsafe_dump(Vars, VarNames) }
;
io__write_string("No solution.\n")
).
@@ -54,12 +89,12 @@
same_len([], []).
same_len([_|Xs], [_|Ys]) :- same_len(Xs, Ys).
- % dump(CfloatList, NameList) writes the constraint
+ % unsafe_dump(CfloatList, NameList) writes the constraint
% relationships between the cfloats in the list CfloatList to
% stdout, using the names given in the list NamesList.
% Perhaps these should be one assoc_list(?).
-dump(Cfloats, Names) :-
+unsafe_dump(Cfloats, Names) :-
% Ensure Cfloats and names have the same length
(
same_len(Cfloats, Names)
Index: fib.exp
===================================================================
RCS file: /home/staff/zs/imp/clpr/fib.exp,v
retrieving revision 1.2
diff -u -u -r1.2 fib.exp
--- 1.2 1996/06/18 12:10:40
+++ fib.exp 1997/09/02 19:15:45
@@ -1,2 +1,2 @@
-Fib(14) = 610
-Fib-1(610) = 14
+Fib(14) = 610.000000000000
+Fib-1(610) = 14.0000000000000
Index: laplace.exp
===================================================================
RCS file: /home/staff/zs/imp/clpr/laplace.exp,v
retrieving revision 1.1
diff -u -u -r1.1 laplace.exp
--- 1.1 1996/06/14 06:31:19
+++ laplace.exp 1997/09/02 19:16:01
@@ -4,7 +4,7 @@
100.00 71.90 54.41 44.62 39.74 38.26 39.74 44.62 54.41 71.90 100.00
100.00 82.11 68.59 59.79 54.97 53.44 54.97 59.79 68.59 82.11 100.00
100.00 87.96 78.03 71.00 66.90 65.56 66.90 71.00 78.03 87.96 100.00
- 100.00 91.71 84.57 79.28 76.07 75.00 76.07 79.28 84.57 91.71 100.00
+ 100.00 91.71 84.57 79.28 76.07 74.99 76.07 79.28 84.57 91.71 100.00
100.00 94.30 89.29 85.46 83.09 82.29 83.09 85.46 89.29 94.30 100.00
100.00 96.19 92.81 90.20 88.55 87.99 88.55 90.20 92.81 96.19 100.00
100.00 97.66 95.58 93.96 92.93 92.58 92.93 93.96 95.58 97.66 100.00
cvs diff: tranny.exp is a new entry, no comparison available
Index: tranny.m
===================================================================
RCS file: /home/staff/zs/imp/clpr/tranny.m,v
retrieving revision 1.5
diff -u -u -r1.5 tranny.m
--- 1.5 1997/08/27 17:11:45
+++ tranny.m 1997/09/02 19:19:05
@@ -18,7 +18,7 @@
:- implementation.
:- import_module cfloat, float_cfloat, cfloat_float, float.
-:- import_module require, std_util, int, list.
+:- import_module require, std_util, int, list, dump.
:- inst pair(I1, I2) = bound('-'(I1, I2)).
:- inst list(I) = list_skel(I).
@@ -85,18 +85,37 @@
/****************************************************************************/
/* Major goals */
/****************************************************************************/
-:- pred dc_analysis(cfloat::ca, cfloat::ca, circuit::in(circuit)) is cc_nondet.
-dc_analysis(Vcc1,Vcc2,Circuit) :-
+:- pred dc_analysis(cfloat::ca, cfloat::ca, circuit::in(circuit),
+ list(circuit_node)::out(list_skel(circuit_node))) is cc_nondet.
+dc_analysis(Vcc1,Vcc2,Circuit, Nodelist) :-
choose_circuit(Circuit),
cfloat__init(A),
cfloat__init(B),
cfloat__init(C),
X == 0.0,
- solve_dc(mean,Circuit ,
- [n(cc1,Vcc1,[A]),n(cc2,Vcc2,[B]),n(gnd,X,[C])],
- Nodelist, _Collector_Currents),
+% unsafe_dump([A,B,C,X],["A","B","C","x"]),
+ Nodelist0 = [n(cc1,Vcc1,[A]),n(cc2,Vcc2,[B]),n(gnd,X,[C])],
+% unsafe_print_value(Nodelist0),
+ solve_dc(mean, Circuit, Nodelist0, Nodelist, _Collector_Currents),
+% unsafe_print_value(Nodelist),
+% unsafe_dump([A,B,C,X],["A","B","C","X"]),
current_solve(Nodelist).
+:- pred unsafe_print_value(list(circuit_node)).
+:- mode unsafe_print_value(in(list_skel(circuit_node))) is cc_multi.
+unsafe_print_value(N) :-
+ unsafe_get_io(IO0),
+ print_value(N, IO0, IO),
+ unsafe_set_io(IO).
+
+:- pred unsafe_get_io(io__state::uo) is det.
+:- pred unsafe_set_io(io__state::di) is det.
+
+:- pragma c_header_code("extern Word save_iostate;").
+:- pragma c_code("Word save_iostate;").
+:- pragma c_code(unsafe_get_io(IO::uo), "IO = save_iostate;").
+:- pragma c_code(unsafe_set_io(IO::di), "save_iostate = IO;").
+
/*
:- pred full_analysis(cfloat, cfloat, circuit, node, node, configuration,
@@ -197,7 +216,7 @@
solve_dc(_, [], List, List, []).
solve_dc(Kind,[(Component - Points) | Rest], Inlist, Outlist, CC):-
connecting(Points, Volts, Amps, Inlist,Tmplist),
- solve_dc(Kind, Rest, Tmplist, Outlist, CC0),
+ solve_dc(Kind, Rest, Tmplist, Outlist, CC0),
component_dc(Component, Volts, Amps, CC0, CC, Kind).
% component_type(Component, Volts, Amps, CCin, CCout, ComputationType).
@@ -224,7 +243,7 @@
Max = data(Beta, Vbe, Vcesat, _)
),
transistor_state(Type,State,Beta,Vbe,Vcesat, V1, V2, V3, Ib, Ic, Ie),
- CC = [Ic|CC0].
+ CC = [Ic | CC0].
component_dc(diode(_Code, Data), [V1, V2], [I1, I2], Cc, Cc, _):-
Data = diode_data(_, State, Vf, Vbreak),
diode_state(State, Vf, Vbreak, V1, V2, I1, I2).
@@ -437,39 +456,39 @@
X == 0.0.
:- pred print_value(list(circuit_node)::in(list_skel(circuit_node)),
- io__state::di, io__state::uo) is det.
-print_value(_) --> [].
-/*
+ io__state::di, io__state::uo) is cc_multi.
print_value([]) --> [].
print_value([n(P,V,I) | Rest]) -->
{ get_node_string(P, PString) },
io__write_string(PString),
io__write_string(" at "),
- { cfloat__get_val(V, VVal) },
- io__write_float(VVal),
- write_cfloat_list(I),
+ dump_cfloat(V),
+ io__write_string(" "),
+ dump_cfloat_list(I),
io__write_string("\n"),
print_value(Rest).
-*/
-:- pred write_cfloat_list(list(cfloat)::list_ca,
- io__state::di, io__state::uo) is det.
-write_cfloat_list(X) -->
- io__write_string("[ "),
- write_cfloat_list_2(X),
+:- pred dump_cfloat_list(list(cfloat)::list_ca,
+ io__state::di, io__state::uo) is cc_multi.
+dump_cfloat_list(X) -->
+ io__write_string("["),
+ dump_cfloat_list_2(X),
io__write_string("]").
-:- pred write_cfloat_list_2(list(cfloat)::list_ca,
- io__state::di, io__state::uo) is det.
-write_cfloat_list_2([]) --> [].
-write_cfloat_list_2([X|Xs]) -->
- { cfloat__get_val(X, Xval) },
- io__write_float(Xval),
- io__write_string(" "),
- write_cfloat_list_2(Xs).
-
+:- pred dump_cfloat_list_2(list(cfloat)::list_ca,
+ io__state::di, io__state::uo) is cc_multi.
+dump_cfloat_list_2([]) --> [].
+dump_cfloat_list_2([X|Xs]) -->
+ dump_cfloat(X),
+ ( { Xs \= [] } ->
+ io__write_string(", ")
+ ;
+ []
+ ),
+ dump_cfloat_list_2(Xs).
+
:- pred print_circuit(circuit::in(circuit), io__state::di, io__state::uo)
- is det.
+ is cc_multi.
print_circuit([]) --> [].
print_circuit([(Component - _Points) | Rest]) -->
print_component(Component),
@@ -488,28 +507,73 @@
get_node_string(out, "out").
:- pred print_component(component::in(component),
- io__state::di, io__state::uo) is det.
+ io__state::di, io__state::uo) is cc_multi.
print_component(resistor(Name, Value)) -->
io__write_string("resistor at "),
write_resistor_name(Name),
- { cfloat__get_val(Value, V) },
- io__write_float(V),
+ dump_cfloat(Value),
io__write_string("\n").
print_component(capacitor(Name)) -->
io__write_string("capacitor at "),
write_capacitor_name(Name),
io__write_string("\n").
-print_component(diode(Name, _Data)) -->
+print_component(diode(Name, Data)) -->
io__write_string("diode at "),
write_diode_name(Name),
- %write_diode_data(Data),
+ write_diode_data(Data),
io__write_string("\n").
-print_component(transistor(Name, _Info)) -->
+print_component(transistor(Name, Info)) -->
io__write_string("transistor at "),
write_transistor_name(Name),
- %write_transistor_info(Info),
+ write_transistor_info(Info),
io__write_string("\n").
+:- pred write_diode_data(diode_data, io__state, io__state).
+:- mode write_diode_data(in(diode_data), di, uo) is cc_multi.
+
+write_diode_data(diode_data(Code, State, Vf, Vbreak)) -->
+ print("["),
+ print(Code),
+ print(", "),
+ print(State),
+ print(", "),
+ dump_cfloat(Vf),
+ print(", "),
+ dump_cfloat(Vbreak),
+ print("]").
+
+:- pred write_transistor_info(transistor_info, io__state, io__state).
+:- mode write_transistor_info(in(transistor_info), di, uo) is cc_multi.
+
+write_transistor_info(info(Type, Code, State, DataMean, DataMin, DataMax)) -->
+ print("["),
+ print(Type),
+ print(", "),
+ print(Code),
+ print(", "),
+ print(State),
+ print(", "),
+ write_transistor_data(DataMean),
+ print(", "),
+ write_transistor_data(DataMin),
+ print(", "),
+ write_transistor_data(DataMax),
+ print("]").
+
+:- pred write_transistor_data(transistor_data, io__state, io__state).
+:- mode write_transistor_data(in(transistor_data), di, uo) is cc_multi.
+
+write_transistor_data(data(Beta, Vbe, Vcestat, Vt)) -->
+ print("info("),
+ dump_cfloat(Beta),
+ print(", "),
+ dump_cfloat(Vbe),
+ print(", "),
+ dump_cfloat(Vcestat),
+ print(", "),
+ dump_cfloat(Vt),
+ print(")").
+
:- pred print_amplifier_type(configuration::in, io__state::di, io__state::uo)
is det.
print_amplifier_type(common_emitter) -->
@@ -583,7 +647,11 @@
:- mode resistor_val(ca) is nondet.
resistor_val(X) :-
- ( X == 100.0 ; X == 50.0 ; X == 5.0 ; X == 1.0 ).
+ ( X == 100.0
+ ; X == 50.0
+ ; X == 5.0
+ ; X == 1.0
+ ).
:- pred diode_type(diode_code, cfloat, cfloat).
:- mode diode_type(in, ca, ca) is semidet.
@@ -696,32 +764,43 @@
:- pred go1(io__state::di, io__state::uo) is cc_multi.
go1 -->
- {cfloat__init(A)},
- {B == 100.0},
- {C == 100.0},
- {D == 5.0},
- {V == 15.0},
- {cfloat__init(X1), cfloat__init(X2), cfloat__init(X3), cfloat__init(X4)},
- {cfloat__init(Y1), cfloat__init(Y2), cfloat__init(Y3), cfloat__init(Y4)},
- {cfloat__init(Z1), cfloat__init(Z2), cfloat__init(Z3), cfloat__init(Z4)},
- {Data1 = data(X1, X2, X3, X4)},
- {Data2 = data(Y1, Y2, Y3, Y4)},
- {Data3 = data(Z1, Z2, Z3, Z4)},
- {Circuit = [
- (capacitor(c1) - [in,b]),
- (resistor(r1,B) - [b,cc1]),
- (resistor(r2,C) - [b,gnd]),
- (transistor(t1,info(npn,tr0,cutoff,Data1,Data2,Data3))
- - [b,cc1,e]),
- (resistor(r3,D) - [e,gnd]),
- (capacitor(c3) - [e,out])
- ]},
+ {
+ cfloat__init(A),
+ B == 100.0,
+ C == 100.0,
+ D == 5.0,
+ V == 15.0,
+ cfloat__init(X1), cfloat__init(X2), cfloat__init(X3), cfloat__init(X4),
+ cfloat__init(Y1), cfloat__init(Y2), cfloat__init(Y3), cfloat__init(Y4),
+ cfloat__init(Z1), cfloat__init(Z2), cfloat__init(Z3), cfloat__init(Z4),
+ Data1 = data(X1, X2, X3, X4),
+ Data2 = data(Y1, Y2, Y3, Y4),
+ Data3 = data(Z1, Z2, Z3, Z4)
+ },
(
- { dc_analysis(V, A, Circuit) }
+ {
+ ( State = active ; State = saturated ; State = cutoff ),
+ Circuit = [
+ (capacitor(c1) - [in,b]),
+ (resistor(r1,B) - [b,cc1]),
+ (resistor(r2,C) - [b,gnd]),
+ (transistor(t1,info(npn,tr0,State,
+ Data1,Data2,Data3)) - [b,cc1,e]),
+ (resistor(r3,D) - [e,gnd]),
+ (capacitor(c3) - [e,out])
+ ],
+ % unsafe_dump([B,C,D,V,X1,X2,X3,X4],
+ % ["B","C","D","V","x1","x2","x3","x4"]),
+ % unsafe_set_io(IO0),
+ dc_analysis(V, A, Circuit, Nodelist)
+ % unsafe_get_io(IO1)
+ }
->
- print_circuit(Circuit)
+ print_circuit(Circuit),
+ print_value(Nodelist),
+ print("Transistor state = "), print(State), nl
;
- { error("dc_analysis failed") }
+ print("No solution\n")
).
/*
@@ -734,7 +813,7 @@
[diode,d4,[di1,St4,_,_],[p1,b]],
[resistor,r2,100,[b,cc2]],
[transistor,tr,[npn,tr0,State,_,_,_],[b,c,gnd]],
- [resistor,rc,100,[c,cc1]]]).
+ [resistor,rc,100,[c,cc1]]], _).
*/
/*
@@ -745,10 +824,10 @@
(
{ full_analysis(Vcc1, Vcc2, Circuit, _, _, Amp_Type, Stability,
Gain, Inresistance, Outresistance) },
- { cfloat__lt_float(Stability, 0.5) },
- { cfloat__gt_float(Gain, 0.5) },
- { cfloat__ge_float(Inresistance, 25.0) },
- { cfloat__le_float(Outresistance, 0.5) }
+ { Stability < 0.5 },
+ { Gain > 0.5 },
+ { Inresistance >= 25.0 },
+ { Outresistance =< 0.5 }
->
print_amplifier_type(Amp_Type),
print_circuit(Circuit)
--
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.
More information about the developers
mailing list