diff options
Diffstat (limited to 'dimension/parse.c')
-rw-r--r-- | dimension/parse.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/dimension/parse.c b/dimension/parse.c index 6de30c9..cfef162 100644 --- a/dimension/parse.c +++ b/dimension/parse.c @@ -572,6 +572,33 @@ dmnsn_make_ast_maybe_integer(dmnsn_astnode *ret, double n) } static dmnsn_astnode +dmnsn_eval_zeroary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable) +{ + dmnsn_astnode ret = dmnsn_copy_astnode(astnode); + + switch(astnode.type) { + case DMNSN_AST_PI: + dmnsn_make_ast_float(&ret, 4*atan(1.0)); + break; + case DMNSN_AST_TRUE: + dmnsn_make_ast_integer(&ret, 1); + break; + case DMNSN_AST_FALSE: + dmnsn_make_ast_integer(&ret, 0); + break; + + default: + dmnsn_diagnostic(astnode.filename, astnode.line, astnode.col, + "invalid constant '%s'", + dmnsn_astnode_string(astnode.type)); + ret.type = DMNSN_AST_NONE; + break; + } + + return ret; +} + +static dmnsn_astnode dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable) { unsigned int i; @@ -1391,6 +1418,11 @@ dmnsn_eval(dmnsn_astnode astnode, dmnsn_symbol_table *symtable) } } + case DMNSN_AST_PI: + case DMNSN_AST_TRUE: + case DMNSN_AST_FALSE: + return dmnsn_eval_zeroary(astnode, symtable); + case DMNSN_AST_DOT_X: case DMNSN_AST_DOT_Y: case DMNSN_AST_DOT_Z: |