summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-05-25 19:17:57 +0200
committerJo-Philipp Wich <jo@mein.io>2021-05-25 21:02:40 +0200
commit5879bdf94fa8f899a1961f6eb5fbc4aacfa84b2a (patch)
treefe91228a2b8e9636a8f7b58ca09d3b3d1332460d
parentd4edadc839bd0b5a1345c9f5a42dd8a8d0cdf4f1 (diff)
syntax: drop Infinity and NaN keywords
Turn the Infinity and NaN keywords into global properties. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lexer.c6
-rw-r--r--lib.c4
2 files changed, 4 insertions, 6 deletions
diff --git a/lexer.c b/lexer.c
index 95acfe6..0d0b9b0 100644
--- a/lexer.c
+++ b/lexer.c
@@ -136,7 +136,6 @@ static const struct token tokens[] = {
static const struct keyword reserved_words[] = {
{ TK_ENDFUNC, "endfunction", 11, { 0 } },
- { TK_DOUBLE, "Infinity", 8, { .d = INFINITY } },
{ TK_CONTINUE, "continue", 8, { 0 } },
{ TK_ENDWHILE, "endwhile", 8, { 0 } },
{ TK_FUNC, "function", 8, { 0 } },
@@ -160,7 +159,6 @@ static const struct keyword reserved_words[] = {
{ TK_THIS, "this", 4, { 0 } },
{ TK_NULL, "null", 4, { 0 } },
{ TK_CASE, "case", 4, { 0 } },
- { TK_DOUBLE, "NaN", 3, { .d = NAN } },
{ TK_TRY, "try", 3, { 0 } },
{ TK_FOR, "for", 3, { 0 } },
{ TK_LOCAL, "let", 3, { 0 } },
@@ -742,10 +740,6 @@ parse_label(uc_lexer *lex)
lookbehind_reset(lex);
switch (word->type) {
- case TK_DOUBLE:
- rv = emit_op(lex, lex->source->off - word->plen, word->type, ucv_double_new(word->u.d));
- break;
-
case TK_BOOL:
rv = emit_op(lex, lex->source->off - word->plen, word->type, ucv_boolean_new(word->u.b));
break;
diff --git a/lib.c b/lib.c
index 1a70d37..98307f6 100644
--- a/lib.c
+++ b/lib.c
@@ -2601,6 +2601,10 @@ uc_alloc_global(uc_vm *vm)
ucv_object_add(global, "REQUIRE_SEARCH_PATH", arr);
+ /* register global math constants */
+ ucv_object_add(global, "NaN", ucv_double_new(NAN));
+ ucv_object_add(global, "Infinity", ucv_double_new(INFINITY));
+
/* register global property */
ucv_object_add(global, "global", ucv_get(global));