add [ ] and literal

master
Ondřej Hruška 3 years ago
parent acfab363d3
commit 44fd2f3dbc
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      include/fh_runtime.h
  2. 55
      src/fh_builtins.c
  3. 1
      src/fh_runtime.c

@ -90,6 +90,7 @@ enum fh_substate {
FH_SUBSTATE_EXIT,
FH_SUBSTATE_SEE_NAME,
FH_SUBSTATE_POSTPONE_NAME,
FH_SUBSTATE_CHAR,
FH_SUBSTATE_MAX,
};

@ -383,6 +383,37 @@ static enum fh_error w_postpone(struct fh_thread_s *fh, const struct fh_word_s *
return FH_OK;
}
static enum fh_error w_leftbracket(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
ENSURE_STATE(FH_STATE_COMPILE);
fh_setstate(fh, FH_STATE_INTERPRET, 0);
return FH_OK;
}
static enum fh_error w_rightbracket(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
ENSURE_STATE(FH_STATE_INTERPRET);
fh_setstate(fh, FH_STATE_COMPILE, 0);
return FH_OK;
}
static enum fh_error w_literal(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
ENSURE_STATE(FH_STATE_COMPILE);
struct fh_instruction_s instr;
uint32_t val;
TRY(ds_pop(fh, &val));
instr_init(&instr, FH_INSTR_NUMBER, val);
TRY(fh_compile_put(fh, &instr, INSTR_SIZE));
return FH_OK;
}
static enum fh_error w_semicolon(struct fh_thread_s *fh, const struct fh_word_s *w0)
{
(void) w0;
@ -768,6 +799,13 @@ static enum fh_error w_s_quote(struct fh_thread_s *fh, const struct fh_word_s *w
return FH_OK;
}
//static enum fh_error w_char(struct fh_thread_s *fh, const struct fh_word_s *w)
//{
// (void) w;
// fh_setsubstate(fh, FH_SUBSTATE_CHAR);
// return FH_OK;
//}
static enum fh_error w_error_word0(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
@ -1119,10 +1157,10 @@ enum fh_error register_builtin_words(struct fh_thread_s *fh)
const struct name_and_handler builtins[] = {
{"", w_error_word0, 1, 0},
/* Strings & Chars */
{"s\"", w_s_quote, 1, 0},
{".\"", w_dot_quote, 1, 0},
/* Compiler control words */
{"bye", w_bye, 0, 0},
// {"char", w_char, 1, 0},
/* Pointers */
{"@", w_fetch, 0, 0},
{"!", w_store, 0, 0},
@ -1131,8 +1169,6 @@ enum fh_error register_builtin_words(struct fh_thread_s *fh)
{"aligned", w_aligned, 0, 0},
{"allot", w_allot, 0, 0},
{"align", w_align, 0, 0},
{"depth", w_depth, 0, 0},
{"unused", w_unused, 0, 0},
{",", w_comma, 0, 0},
// TODO +!
// TODO pictured numbers (#)
@ -1227,10 +1263,19 @@ enum fh_error register_builtin_words(struct fh_thread_s *fh)
{";", w_semicolon, 1, 0},
{"\\", w_backslash, 1, 0}, // line comment
{"(", w_paren, 1, 0}, // enclosed comment
{"reset", w_reset, 1, 0},
/* Weird meta stuff */
{"immediate", w_immediate, 1, 0},
{"postpone", w_postpone, 1, 0},
{"[", w_leftbracket, 1, 0},
{"]", w_rightbracket, 1, 0},
{"literal", w_literal, 1, 0},
/* Runtime stats */
{"depth", w_depth, 0, 0},
{"unused", w_unused, 0, 0},
/* Debug tools & system */
{"reset", w_reset, 1, 0},
{"see", w_see, 0, 0},
{"bye", w_bye, 0, 0},
{ /* end marker */ }
};

@ -31,6 +31,7 @@ static const char *substatenames[FH_SUBSTATE_MAX] = {
[FH_SUBSTATE_EXIT] = "EXIT",
[FH_SUBSTATE_SEE_NAME] = "SEE_NAME",
[FH_SUBSTATE_POSTPONE_NAME] = "POSTPONE_NAME",
[FH_SUBSTATE_CHAR] = "CHAR",
};
/** Add a word to the dictionary. */

Loading…
Cancel
Save