statemachine basic architecture
This commit is contained in:
parent
356a866e8d
commit
00e818e43b
98
engine/slc.h
98
engine/slc.h
@ -1,6 +1,10 @@
|
|||||||
#ifndef SLC_H
|
#ifndef SLC_H
|
||||||
#define SLC_H
|
#define SLC_H
|
||||||
|
|
||||||
|
#include<stdint.h> // uint8_t, uint32_t..
|
||||||
|
#include<string.h> // memcpy, strlen..
|
||||||
|
#include<stddef.h> // NULL
|
||||||
|
|
||||||
/** Possible word types */
|
/** Possible word types */
|
||||||
enum SLC_WORDTYP {
|
enum SLC_WORDTYP {
|
||||||
/** Still in plain text */
|
/** Still in plain text */
|
||||||
@ -211,27 +215,36 @@ enum slc_state : uint32_t {
|
|||||||
SLC_DEF_NAME,
|
SLC_DEF_NAME,
|
||||||
/** Variable-listing part of word-definition - endline, '(', '[' or '{' ends it */
|
/** Variable-listing part of word-definition - endline, '(', '[' or '{' ends it */
|
||||||
SLC_DEF_VAR,
|
SLC_DEF_VAR,
|
||||||
/** Raw body part of the word definition - these can contain local variable accesses + words (state-stack in code_stack) */
|
/** Raw body part of the word definition - these can contain local variable accesses + words, depth counted by vars */
|
||||||
SLC_DEF_BODY,
|
SLC_DEF_BODY,
|
||||||
/** ( .. ) part of the word definition - these can contain local variable accesses + words (state-stack in code_stack) */
|
/** Name part of a word "call" (non-definition). Ends by whitespace, '@' (in case of variable) or various parentheses */
|
||||||
SLC_DEF_PAR,
|
|
||||||
/** [ .. ] part of the word definition - these can contain local variable accesses + words (state-stack in code_stack) */
|
|
||||||
SLC_DEF_SQBR,
|
|
||||||
/** { .. } part of the word definition - these can contain local variable accesses + words (state-stack in code_stack) */
|
|
||||||
SLC_DEF_BR,
|
|
||||||
/** Name part of a word "call" (non-definition). */
|
|
||||||
SLC_WORD_NAME,
|
SLC_WORD_NAME,
|
||||||
/** Variable part of a word "call" */
|
/** Variable call (MYWORD@MYVAR) - we get to be here from SLC_WORD_NAME or from START */
|
||||||
SLC_WORD_VAR,
|
SLC_WORD_VAR,
|
||||||
/** ( .. ) part of a word "call" */
|
|
||||||
SLC_WORD_PAR,
|
|
||||||
/** [ .. ] part of a word "call" */
|
|
||||||
SLC_WORD_SQBR,
|
|
||||||
/** { .. } part of a word "call" */
|
|
||||||
SLC_WORD_BR,
|
|
||||||
};
|
};
|
||||||
typedef enum slc_state slc_state;
|
typedef enum slc_state slc_state;
|
||||||
|
|
||||||
|
static inline slc_state slc_comment_statechange_in(
|
||||||
|
slc_state current_state,
|
||||||
|
char c,
|
||||||
|
const char *singleline_comment,
|
||||||
|
const char *multiline_comment_opener,
|
||||||
|
int singleline_comment_len,
|
||||||
|
int multiline_comment_len,
|
||||||
|
int *comment_i,
|
||||||
|
int *multiline_i){
|
||||||
|
// FIXME: Implement
|
||||||
|
return current_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline slc_state slc_defname_statechange(
|
||||||
|
slc_state current_state,
|
||||||
|
char c,
|
||||||
|
const char *prefix) {
|
||||||
|
// FIXME: Implement
|
||||||
|
return current_state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function runs the main slc engine over a snippet of code.
|
* This function runs the main slc engine over a snippet of code.
|
||||||
*
|
*
|
||||||
@ -265,9 +278,9 @@ typedef enum slc_state slc_state;
|
|||||||
* @param data_stack The data stack (forth-like stack) to use.
|
* @param data_stack The data stack (forth-like stack) to use.
|
||||||
* @param insert_stack Used for temporarily expanding the input stream (one word level above current) with further words.
|
* @param insert_stack Used for temporarily expanding the input stream (one word level above current) with further words.
|
||||||
* @param io_connector The engine uses this to open/close pipes/files and write/read them.
|
* @param io_connector The engine uses this to open/close pipes/files and write/read them.
|
||||||
* @param singleline_comment OPTIONAL: Like "//" - the character string that makes the rest of the line being comment.
|
* @param singleline_comment Like "//" - the character string that makes the rest of the line being comment. Can be "" (no NULL).
|
||||||
* @param multiline_comment_opener OPTIONAL: The character string that starts a multiline comment. Like / and * for C.
|
* @param multiline_comment_opener The character string that starts a multiline comment. Like / and * for C. Can be "" (no NULL).
|
||||||
* @param multiline_comment_closer OPTIONAL: The character string that ends a multiline comment. Like * and / for C.
|
* @param multiline_comment_closer The character string that ends a multiline comment. Like * and / for C. Can be "" (no NULL).
|
||||||
* @param prefix The prefix added to the lookup of built-ins. Useful when you write a compiler with SLC. Defaults to "" (empty).
|
* @param prefix The prefix added to the lookup of built-ins. Useful when you write a compiler with SLC. Defaults to "" (empty).
|
||||||
* @param ender The character string that ends a word definition. Defaults to ";".
|
* @param ender The character string that ends a word definition. Defaults to ";".
|
||||||
* @param varprefix The character string that prefixes variable declarations. Defaults to "@".
|
* @param varprefix The character string that prefixes variable declarations. Defaults to "@".
|
||||||
@ -287,7 +300,54 @@ static inline void slc(
|
|||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *ender,
|
const char *ender,
|
||||||
const char *varprefix) {
|
const char *varprefix) {
|
||||||
slc_state main_state = SLC_START;
|
slc_state state = SLC_START;
|
||||||
|
int singleline_comment_len = strlen(singleline_comment);
|
||||||
|
int multiline_comment_opener_len = strlen(multiline_comment_opener);
|
||||||
|
|
||||||
|
uint8_t c = 0;
|
||||||
|
while(((c = code_src()) != 0)) {
|
||||||
|
switch(state) {
|
||||||
|
case SLC_START:
|
||||||
|
int comment_i = 0;
|
||||||
|
int multiline_i = 0;
|
||||||
|
int def_name_i = 0;
|
||||||
|
/* state -> comment | multiline_comment */
|
||||||
|
state = slc_comment_statechange_in(
|
||||||
|
state,
|
||||||
|
c,
|
||||||
|
singleline_comment,
|
||||||
|
multiline_comment_opener,
|
||||||
|
singleline_comment_len,
|
||||||
|
multiline_comment_opener_len,
|
||||||
|
&comment_i,
|
||||||
|
&multiline_i);
|
||||||
|
/* state -> def_name */
|
||||||
|
if(state == SLC_START) {
|
||||||
|
state = slc_defname_statechange(
|
||||||
|
state,
|
||||||
|
c,
|
||||||
|
prefix);
|
||||||
|
|
||||||
|
}
|
||||||
|
if(state == SLC_START) {
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SLC_COMMENT:
|
||||||
|
break;
|
||||||
|
case SLC_MULTILINE_COMMENT:
|
||||||
|
break;
|
||||||
|
case SLC_DEF_NAME:
|
||||||
|
break;
|
||||||
|
case SLC_DEF_VAR:
|
||||||
|
break;
|
||||||
|
case SLC_DEF_BODY:
|
||||||
|
break;
|
||||||
|
case SLC_WORD_NAME:
|
||||||
|
break;
|
||||||
|
case SLC_WORD_VAR:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SLC_H */
|
#endif /* SLC_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user