diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-03-22 13:20:56 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-03-22 13:20:56 -0400 |
commit | ac591cc542f039af8f66567439fbb0aee3d93963 (patch) | |
tree | 470c4277bf3b4bfafdd2b37aae064ee9ea53f77c /dimension/parse.c | |
parent | bb71a70253ae5bf91e99dcd2809471abebea1b69 (diff) | |
download | dimension-ac591cc542f039af8f66567439fbb0aee3d93963.tar.xz |
Add built-in float constants.
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: |