Skip to content

Commit

Permalink
#588 determine inverse expression for unit conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Mar 5, 2017
1 parent 3eb1bfc commit 329c45e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/corto/src/_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ typedef struct ext_corto_expr_opt {
corto_object scope;
corto_type returnType;
corto_bool returnsReference;
corto_bool inverse;
} ext_corto_expr_opt;

ext_corto_expr* ext_corto_expr_alloc(void);
Expand Down
19 changes: 14 additions & 5 deletions packages/corto/src/lang/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@ corto_int16 _corto_unit_construct(
corto_unit this)
{
/* $begin(corto/lang/unit/construct) */
ext_corto_expr *expr = NULL;
ext_corto_expr *exprToQuantity = NULL, *exprFromQuantity = NULL;

if (this->conversion) {
corto_id typeId;
expr = ext_corto_expr_alloc();
exprToQuantity = ext_corto_expr_alloc();
exprFromQuantity = ext_corto_expr_alloc();

corto_fullpath(typeId, this->type);
char *types[] = {typeId};

if (ext_corto_expr_compb(expr, NULL, this->conversion, types)) {
corto_dealloc(expr);
if (ext_corto_expr_compb(exprToQuantity, NULL, this->conversion, types)) {
corto_dealloc(exprToQuantity);
goto error;
}

this->toQuantity = (corto_word)expr;
ext_corto_expr_opt opt = {.inverse = TRUE};

if (ext_corto_expr_compb(exprFromQuantity, &opt, this->conversion, types)) {
corto_dealloc(exprFromQuantity);
goto error;
}

this->toQuantity = (corto_word)exprToQuantity;
this->fromQuantity = (corto_word)exprFromQuantity;
}

return 0;
Expand Down

0 comments on commit 329c45e

Please sign in to comment.