Skip to content

Commit

Permalink
Use strchr() to implement \ and (
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereira committed Jan 30, 2025
1 parent 0317ad9 commit efaa3fd
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/samples/forthsalon/forth.c
Original file line number Diff line number Diff line change
@@ -404,7 +404,6 @@ bool forth_parse_string(struct forth_ctx *ctx, const char *code)
code++;
}


code = found_word(ctx, code, word_ptr, (size_t)(code - word_ptr));
if (!code)
return false;
@@ -451,13 +450,19 @@ struct forth_builtin {
static const char *id_(struct forth_ctx *ctx, const char *code)

#define BUILTIN(name_) BUILTIN_DETAIL(name_, LWAN_TMP_ID, LWAN_TMP_ID)
#define BUILTIN_COMPILER(name_) BUILTIN_COMPILER_DETAIL(name_, LWAN_TMP_ID, LWAN_TMP_ID)
#define BUILTIN_COMPILER(name_) \
BUILTIN_COMPILER_DETAIL(name_, LWAN_TMP_ID, LWAN_TMP_ID)

BUILTIN_COMPILER("\\")
{
while (*code && *code != '\n')
code++;
return code;
code = strchr(code, '\n');
return code ? code + 1 : NULL;
}

BUILTIN_COMPILER("(")
{
code = strchr(code, ')');
return code ? code + 1 : NULL;
}

BUILTIN_COMPILER(":")
@@ -495,13 +500,6 @@ BUILTIN_COMPILER(";")
return code;
}

BUILTIN_COMPILER("(")
{
while (*code && *code != ')')
code++;
return code;
}

BUILTIN_COMPILER("if")
{
PUSH_R((int32_t)forth_code_len(&ctx->defining_word->code));

0 comments on commit efaa3fd

Please sign in to comment.