Commit 39bd862d authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain
Browse files

getting c expressions writing their common thingy

parent 8c6eaae0
......@@ -674,6 +674,7 @@ compute_domain~w(const Table &table) {
\+ (
sub_formula(SubFormula, Index),
\+ (
format('// ~w~n', [SubFormula]),
generate_sub_formula(SubFormula, Index)
)
),
......@@ -855,14 +856,14 @@ generate_expression(A) :-
format('(*i)[~d]', [Index]).
generate_expression(if C then A else B) :-
gsl:write_condition(C),
write_condition_to_c(C, foltl:generate_expression),
write(' ? '),
generate_expression(A),
write(' : '),
generate_expression(B).
generate_expression(Expression) :-
gsl:write_arithmetic_expression(Expression).
write_expression_to_c(Expression, foltl:generate_expression).
binary_predicate(A = B, A, '==', B).
......
......@@ -185,118 +185,12 @@ write_arithmetic_expression(p(ParameterIndex)) :-
write_arithmetic_expression(f(ParameterIndex)) :-
format('f[~d]', [ParameterIndex]).
write_arithmetic_expression(- A) :-
write('- '),
write_arithmetic_expression_with_parentheses(A).
write_arithmetic_expression(A + B) :-
write_arithmetic_expression_with_parentheses(A),
write(' + '),
write_arithmetic_expression_with_parentheses(B).
write_arithmetic_expression(A - B) :-
write_arithmetic_expression_with_parentheses(A),
write(' - '),
write_arithmetic_expression_with_parentheses(B).
write_arithmetic_expression(A * B) :-
write_arithmetic_expression_with_parentheses(A),
write(' * '),
write_arithmetic_expression_with_parentheses(B).
write_arithmetic_expression(A / B) :-
write_arithmetic_expression_with_parentheses(A),
write(' / '),
write_arithmetic_expression_with_parentheses(B).
write_arithmetic_expression(A ^ B) :-
write('pow('),
write_arithmetic_expression(A),
write(', '),
write_arithmetic_expression(B),
write(')').
write_arithmetic_expression(sqrt(A)) :-
write('sqrt('),
write_arithmetic_expression(A),
write(')').
write_arithmetic_expression(cos(A)) :-
write('cos('),
write_arithmetic_expression(A),
write(')').
write_arithmetic_expression(sin(A)) :-
write('sin('),
write_arithmetic_expression(A),
write(')').
write_arithmetic_expression(exp(A)) :-
write('exp('),
write_arithmetic_expression(A),
write(')').
write_arithmetic_expression(log(A)) :-
write('log('),
write_arithmetic_expression(A),
write(')').
write_arithmetic_expression_with_parentheses(Expression) :-
write('('),
write_arithmetic_expression(Expression),
write(')').
write_condition(A = B) :-
write_arithmetic_expression_with_parentheses(A),
write(' == '),
write_arithmetic_expression_with_parentheses(B).
write_condition(A < B) :-
write_arithmetic_expression_with_parentheses(A),
write(' < '),
write_arithmetic_expression_with_parentheses(B).
write_condition(A > B) :-
write_arithmetic_expression_with_parentheses(A),
write(' > '),
write_arithmetic_expression_with_parentheses(B).
write_condition(A <= B) :-
write_arithmetic_expression_with_parentheses(A),
write(' <= '),
write_arithmetic_expression_with_parentheses(B).
write_condition(A >= B) :-
write_arithmetic_expression_with_parentheses(A),
write(' >= '),
write_arithmetic_expression_with_parentheses(B).
write_condition(true) :-
write('true').
write_condition(false) :-
write('false').
write_condition(A or B) :-
write_condition_with_parentheses(A),
write(' || '),
write_condition_with_parentheses(B).
write_condition(A and B) :-
write_condition_with_parentheses(A),
write(' && '),
write_condition_with_parentheses(B).
write_condition(not(A)) :-
write('!'),
write_condition_with_parentheses(A).
write_arithmetic_expression(E) :-
write_expression_to_c(E, gsl:write_arithmetic_expression).
write_condition_with_parentheses(Condition) :-
write('('),
write_condition(Condition),
write(')').
write_condition(C) :-
write_condition_to_c(C, gsl:write_arithmetic_expression).
write_initial_parameter_values(Options) :-
......
......@@ -47,7 +47,11 @@
open_file/1,
wait_timeout_option/1,
invert/2,
abscmp/3
abscmp/3,
write_expression_to_c/2,
write_expression_to_c_with_parentheses/2,
write_condition_to_c/2,
write_condition_to_c_with_parentheses/2
]).
:- use_module(library(process)).
......@@ -702,3 +706,117 @@ abscmp(Order, X, Y) :-
XX is abs(X),
YY is abs(Y),
compare(Order, XX, YY).
write_expression_to_c(- A, CallBack) :-
write('- '),
write_expression_to_c_with_parentheses(A, CallBack).
write_expression_to_c(A + B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' + '),
write_expression_to_c_with_parentheses(B, CallBack).
write_expression_to_c(A - B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' - '),
write_expression_to_c_with_parentheses(B, CallBack).
write_expression_to_c(A * B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' * '),
write_expression_to_c_with_parentheses(B, CallBack).
write_expression_to_c(A / B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' / '),
write_expression_to_c_with_parentheses(B, CallBack).
write_expression_to_c(A ^ B, CallBack) :-
write('pow('),
call(CallBack, A),
write(', '),
call(CallBack, B),
write(')').
write_expression_to_c(sqrt(A), CallBack) :-
write('sqrt('),
call(CallBack, A),
write(')').
write_expression_to_c(cos(A), CallBack) :-
write('cos('),
call(CallBack, A),
write(')').
write_expression_to_c(sin(A), CallBack) :-
write('sin('),
call(CallBack, A),
write(')').
write_expression_to_c(exp(A), CallBack) :-
write('exp('),
call(CallBack, A),
write(')').
write_expression_to_c(log(A), CallBack) :-
write('log('),
call(CallBack, A),
write(')').
write_expression_to_c_with_parentheses(Expression, CallBack) :-
write('('),
call(CallBack, Expression),
write(')').
write_condition_to_c(A = B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' == '),
write_expression_to_c_with_parentheses(B, CallBack).
write_condition_to_c(A < B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' < '),
write_expression_to_c_with_parentheses(B, CallBack).
write_condition_to_c(A > B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' > '),
write_expression_to_c_with_parentheses(B, CallBack).
write_condition_to_c('<='(A, B), CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' <= '),
write_expression_to_c_with_parentheses(B, CallBack).
write_condition_to_c(A >= B, CallBack) :-
write_expression_to_c_with_parentheses(A, CallBack),
write(' >= '),
write_expression_to_c_with_parentheses(B, CallBack).
write_condition_to_c(true, _CallBack) :-
write('true').
write_condition_to_c(false, _CallBack) :-
write('false').
write_condition_to_c(or(A, B), CallBack) :-
write_condition_to_c_with_parentheses(A, CallBack),
write(' || '),
write_condition_to_c_with_parentheses(B, CallBack).
write_condition_to_c(and(A, B), CallBack) :-
write_condition_to_c_with_parentheses(A, CallBack),
write(' && '),
write_condition_to_c_with_parentheses(B, CallBack).
write_condition_to_c(not(A), CallBack) :-
write('!'),
write_condition_to_c_with_parentheses(A, CallBack).
write_condition_to_c_with_parentheses(Condition, CallBack) :-
write('('),
write_condition_to_c(Condition, CallBack),
write(')').
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment