Commit 2cdec6f9 authored by Vladislav Perepelkin's avatar Vladislav Perepelkin
Browse files

merged

parent 03628f3a
......@@ -246,7 +246,7 @@ def expr_type(x, scope):
return res['type']
else:
return 'value'
elif x['type'] in ['<', '<=', '==', '!=', '>=', '>', '&&', '||']:
elif x['type'] in ['<', '<=', '==', '!=', '>=', '>', '&&', '||', '?:']:
return 'int'
else:
R(x, x['type'])
......@@ -285,7 +285,11 @@ def gen_formula(x, scope, dest_value_type):
else:
R(op, xt, oxt)
if x['type']=='?:':
return '((%s)?(%s):(%s))' % (ops[0], ops[1], ops[2])
formula=x['type'].join(['(%s)' % op for op in ops])
if oxt=='value':
if dest_value_type in ['int', 'real']:
return '(%s).get_%s()' % (formula, dest_value_type)
......@@ -322,7 +326,7 @@ def value_int(x, scope):
return 'static_cast<int>(%s)' % gen_formula(x, scope,
'int')
elif x['type'] in ['<', '<=', '==', '!=', '>=', '>',
'&&', '||']:
'&&', '||', '?:']:
return 'static_cast<int>(%s)' % gen_formula(x, scope, 'int')
elif x['type']=='?:':
raise NotImplementedError(x['type'])
......@@ -422,7 +426,7 @@ def value_value(x, scope):
else:
return 'self.wait(%s)' % ref1(x['ref'], scope)
elif x['type'] in ['+', '-', '*', '/', '%', '<', '<=', '==',
'!=', '>=', '>']:
'!=', '>=', '>', '?:']:
return '(%s)' % gen_formula(x, scope, 'value')
else:
R(x)
......
......@@ -45,13 +45,13 @@ void add_header(const string &key, const string &value);
%nonassoc IFX
%nonassoc KW_ELSE
%left QMARK
%left COLON
%left DBLPIPE
%left DBLAMP
%left LEQ GEQ DBLEQ NEQ GT LT
%left PLUS MINUS
%left MUL DIV MOD
%left QMARK
%left COLON
%%
......
RUN=luna -q ternary.fa
RETCODE=0
STDERR_EMPTY
STDOUT=output.txt
c_init: 4, size: 4
c_init: 7, size: 4
c_print: 7
#!/usr/bin/luna
import c_init(int, name) as init;
import c_iprint(int) as iprint;
import c_print(value) as print;
sub main()
{
df x, y;
cf a: init(7, x) @ {
request y;
req_count x = (x > y ? 3 : 2);
};
init(4, y);
print(x>y? x: y);
}
#include <cstdio>
#include "ucenv.h"
extern "C" {
void c_init(int val, OutputDF &df) {
df.setValue(val);
printf("c_init: %d, size: %d\n", val, (int)df.getSize());
}
void c_iprint(int val) {
printf("c_iprint %d\n", val);
}
void c_print(const InputDF &df) {
printf("c_print: %d\n", df.getValue<int>());
}
}
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