summaryrefslogtreecommitdiffstats
path: root/dimension/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-22 13:20:56 -0400
committerTavian Barnes <tavianator@gmail.com>2010-03-22 13:20:56 -0400
commitac591cc542f039af8f66567439fbb0aee3d93963 (patch)
tree470c4277bf3b4bfafdd2b37aae064ee9ea53f77c /dimension/parse.c
parentbb71a70253ae5bf91e99dcd2809471abebea1b69 (diff)
downloaddimension-ac591cc542f039af8f66567439fbb0aee3d93963.tar.xz
Add built-in float constants.
Diffstat (limited to 'dimension/parse.c')
-rw-r--r--dimension/parse.c32
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: