Support returning vector expressions.

Currently fails due to a scheduling problem when the vector expression
contains functions.
This commit is contained in:
Bill Currie 2018-10-13 23:32:53 +09:00
parent 0f5f2a125a
commit 6c53be928b
5 changed files with 39 additions and 4 deletions

View file

@ -625,7 +625,7 @@ expr_t *build_for_statement (expr_t *init, expr_t *test, expr_t *next,
expr_t *break_label, expr_t *continue_label);
expr_t *build_state_expr (expr_t *e);
expr_t *think_expr (struct symbol_s *think_sym);
expr_t *assign_expr (expr_t *e1, expr_t *e2);
expr_t *assign_expr (expr_t *dst, expr_t *src);
expr_t *cast_expr (struct type_s *t, expr_t *e);
const char *get_op_string (int op) __attribute__((const));

View file

@ -1999,8 +1999,13 @@ return_expr (function_t *f, expr_t *e)
warning (e, "type mismatch for return value of %s",
f->sym->name);
} else {
if (f->sym->type->t.func.type != t)
if (f->sym->type->t.func.type != t) {
e = cast_expr (f->sym->type->t.func.type, e);
t = f->sym->type->t.func.type;
}
}
if (e->type == ex_vector) {
e = assign_expr (new_ret_expr (t), e);
}
return new_unary_expr ('r', e);
}

View file

@ -258,8 +258,6 @@ is_indirect (expr_t *e)
return is_const_ptr (e->e.expr.e1);
}
expr_t *
aassign_expr (expr_t *dst, expr_t *src);
expr_t *
assign_expr (expr_t *dst, expr_t *src)
{

View file

@ -45,6 +45,7 @@ test_progs_dat=\
structptr.dat \
swap.dat \
triangle.dat \
vecexpr.dat \
vecinit.dat \
while.dat \
voidfor.dat
@ -195,6 +196,14 @@ triangle.run: Makefile build-run
$(srcdir)/build-run $@ 100000 100000 1.00005 50002.4961
include ./$(DEPDIR)/triangle.Qo
vecexpr_dat_SOURCES=vecexpr.r
vecexpr_obj=$(vecexpr_dat_SOURCES:.r=.qfo)
vecexpr.dat$(EXEEXT): $(vecexpr_obj) $(QFCC_DEP)
$(QFCC) $(QCFLAGS) -o $@ $(vecexpr_obj)
vecexpr.run: Makefile build-run
$(srcdir)/build-run $@
include ./$(DEPDIR)/vecexpr.Qo
vecinit_dat_SOURCES=vecinit.r
vecinit_obj=$(vecinit_dat_SOURCES:.r=.qfo)
vecinit.dat$(EXEEXT): $(vecinit_obj) $(QFCC_DEP)

23
tools/qfcc/test/vecexpr.r Normal file
View file

@ -0,0 +1,23 @@
vector
t1()
{
return [1, 2, 3];
}
vector
t2(float x)
{
return [x, x, x];
}
vector
t3(float x)
{
return [x, t2(9).z, x];
}
int
main ()
{
return t3(5) == '5 9 5' ? 0 : 1;
}