a lot of ideas and a small bugfix for word definition start mixed with word occurence start
This commit is contained in:
parent
2f0c37fffe
commit
7b782df084
213
engine/slc.h
213
engine/slc.h
@ -83,7 +83,7 @@ static inline char endsline(char c) {
|
|||||||
* ^^The above always needs starting '#builtin' at the definition and inside. That is exchanged to real prefix...
|
* ^^The above always needs starting '#builtin' at the definition and inside. That is exchanged to real prefix...
|
||||||
* This is used for implementation implementing built-ins with FORTH-like code instead of native (saves native interpret. space)
|
* This is used for implementation implementing built-ins with FORTH-like code instead of native (saves native interpret. space)
|
||||||
*
|
*
|
||||||
* #: structural (
|
* #:: structural (
|
||||||
* #parse_num
|
* #parse_num
|
||||||
* #dup
|
* #dup
|
||||||
* #inc
|
* #inc
|
||||||
@ -344,7 +344,7 @@ static inline slc_state slc_def_name_statechange(
|
|||||||
const char *prefix,
|
const char *prefix,
|
||||||
int *prefix_i) {
|
int *prefix_i) {
|
||||||
|
|
||||||
/* If not a whitespace currently, check the prefix, otherwise check ending ':' */
|
/* If not a whitespace currently, check the prefix and check the ending ':' */
|
||||||
if(!isspace(c)) {
|
if(!isspace(c)) {
|
||||||
/* Early exit for not-a-definition sub-state */
|
/* Early exit for not-a-definition sub-state */
|
||||||
if(*prefix_i < 0) {
|
if(*prefix_i < 0) {
|
||||||
@ -360,8 +360,8 @@ static inline slc_state slc_def_name_statechange(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(c == ':') {
|
if(c == ':') {
|
||||||
*prefix_i = 0; /* XXX: restarts scan */
|
*prefix_i = 0; /* XXX: restarts scana for finnding it in the next cases */
|
||||||
return SLC_WORD_NAME;
|
return SLC_DEF_NAME;
|
||||||
} else {
|
} else {
|
||||||
*prefix_i = -1;
|
*prefix_i = -1;
|
||||||
}
|
}
|
||||||
@ -535,13 +535,184 @@ static inline void slc(
|
|||||||
if(state == SLC_START) { SET_SLC_START }
|
if(state == SLC_START) { SET_SLC_START }
|
||||||
break;
|
break;
|
||||||
case SLC_DEF_NAME:
|
case SLC_DEF_NAME:
|
||||||
// TODO
|
// TODO: Legyen nekem is fordítási idejű szó és sima!!! Optimalizációban sokat segít
|
||||||
|
// : iff
|
||||||
|
// ()
|
||||||
|
// asm{cmp eax, 0}
|
||||||
|
// asm{jnz else@}
|
||||||
|
// {}
|
||||||
|
// asm(goto endif@)
|
||||||
|
// asm{else@:}
|
||||||
|
// []
|
||||||
|
// asm{endif@:} // @ az asm asm-nél jelentse: valami hash...
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// De ezt vajon lehet? Szerintem ez ne lehessen / nem kell...
|
||||||
|
//
|
||||||
|
// : iff_not ()[]{}
|
||||||
|
// ()
|
||||||
|
// asm{cmp eax, 0}
|
||||||
|
// asm{jnz else@}
|
||||||
|
// []
|
||||||
|
// asm{else@:} // FIXME: nincs endif?
|
||||||
|
// {}
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
// Called like - v1:
|
||||||
|
//
|
||||||
|
// #include "iff.slc"
|
||||||
|
//
|
||||||
|
// iff(4 5 <) {
|
||||||
|
// 1 print
|
||||||
|
// } [
|
||||||
|
// 0 print
|
||||||
|
// ]
|
||||||
|
//
|
||||||
|
// Called like - v2:
|
||||||
|
//
|
||||||
|
// #include "iff2.slc"
|
||||||
|
//
|
||||||
|
// iff_not(4 5 <) {
|
||||||
|
// 1 print
|
||||||
|
// } [
|
||||||
|
// 0 print
|
||||||
|
// ]
|
||||||
|
//
|
||||||
|
// if(1) {
|
||||||
|
// A()
|
||||||
|
// } else {
|
||||||
|
// B()
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Kontext-függő stack kell legyen? case-t csak switch-en belül írhatok (vagy mást jelent stb.)
|
||||||
|
//
|
||||||
|
// Switch-case pl.:
|
||||||
|
//
|
||||||
|
// // case (5) // itt nem lenne jó!!!!
|
||||||
|
// switch(valami) {
|
||||||
|
// case(0) { // csak itt
|
||||||
|
//
|
||||||
|
// } [fallthrough]
|
||||||
|
// case(42) {
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Emiatt a zárójelezős stack-re nem csak zárójelek kerüljenek!!!
|
||||||
|
//
|
||||||
|
// NIL
|
||||||
|
// switch(
|
||||||
|
// switch{ // Ezen a ponton kellhet ":@ switch{case" szót keresni
|
||||||
|
// switch{case( // TODO: Ez biztos nem kell!
|
||||||
|
// switch{case{
|
||||||
|
//
|
||||||
|
// : switch
|
||||||
|
// ()
|
||||||
|
//
|
||||||
|
// : switch@case // TODO: jobb syntax? Vagy kell-e oda a zárójel? Vagy csak "gyereke"? (stack helyett csak uccsó tárolva...???? Esetleg utolsó megelőző testvér is?
|
||||||
|
// ()
|
||||||
|
// iff(=) {
|
||||||
|
// {}
|
||||||
|
// } // TODO: Ha van fallthrough GOTO-val
|
||||||
|
//
|
||||||
|
// Branch table-s fordítása is lehetséges két pass-ban pl...
|
||||||
|
//
|
||||||
|
// : switch
|
||||||
|
// ()
|
||||||
|
// generate_ifs_for_cases@inherits // "megörökli" az én kontextusom... tehát az én (..) [..] és {..}
|
||||||
|
// // esetleg lehet neki is mondjuk {..} és csak az íródik felül.. ESETLEG!
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Ehhez képest factor-ban:
|
||||||
|
//
|
||||||
|
// [printtrue] [printfalse] 4 5 < if
|
||||||
|
//
|
||||||
|
// FORTH-ban:
|
||||||
|
//
|
||||||
|
// 12 = IF FILL-CARTON THEN
|
||||||
|
//
|
||||||
|
// Magyar forth-ba:
|
||||||
|
//
|
||||||
|
// 12 = VOLT_AKKOR KARTON_UJRATOLTES TORTENT
|
||||||
|
//
|
||||||
|
// :: VOLT_AKKOR IF
|
||||||
|
//
|
||||||
|
// :: IF
|
||||||
|
// asm{cmp eax, 0}
|
||||||
|
// asm{jnz else@}
|
||||||
|
// DECODE_WORD
|
||||||
|
// CALL_WORD
|
||||||
|
// asm{else@:}
|
||||||
|
// ;
|
||||||
|
//
|
||||||
|
// While és do-while is megy így....
|
||||||
|
//
|
||||||
|
// XXX: De a for-ciklus??? Problémás...
|
||||||
|
//
|
||||||
|
// for(int i = 0; i < 50; ++i) {
|
||||||
|
// ....
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Szavak:
|
||||||
|
// - for(
|
||||||
|
// int
|
||||||
|
// i
|
||||||
|
// =
|
||||||
|
// 0;
|
||||||
|
// i
|
||||||
|
// <
|
||||||
|
// 50;
|
||||||
|
// ++i
|
||||||
|
// ) {
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// CSV(-szerű) cucc? Megoldás:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// :: for
|
||||||
|
// (
|
||||||
|
// ';'
|
||||||
|
// delim_parse // max 3 elemre parzol (vagy kevesebb)
|
||||||
|
// (
|
||||||
|
// parse_from_stack
|
||||||
|
// )
|
||||||
|
// [
|
||||||
|
// asm("ciklusfelt@:")
|
||||||
|
// parse_from_stack
|
||||||
|
// asm{cmp eax, 0}
|
||||||
|
// asm{jz ciklusend@}
|
||||||
|
// asm(jmp ciklusmag@)
|
||||||
|
// ]
|
||||||
|
// {
|
||||||
|
// asm("ciklusnovel@:")
|
||||||
|
// parse_from_stack
|
||||||
|
// asm("jmp ciklusfelt@")
|
||||||
|
// }
|
||||||
|
// // vissza is ad egy értéket a stackre, hogy "van-e még" adat? => tudok loop-olni (de max 1-2-3 féle kindra)
|
||||||
|
// )
|
||||||
|
// {
|
||||||
|
// asm("ciklusmag@:")
|
||||||
|
// parse_from_stack
|
||||||
|
// asm(goto ciklusnovel@)
|
||||||
|
// asm("ciklusend@:")
|
||||||
|
// }
|
||||||
|
//
|
||||||
break;
|
break;
|
||||||
case SLC_DEF_VAR:
|
case SLC_DEF_VAR:
|
||||||
break;
|
break;
|
||||||
case SLC_DEF_BODY:
|
case SLC_DEF_BODY:
|
||||||
break;
|
break;
|
||||||
case SLC_WORD_NAME:
|
case SLC_WORD_NAME:
|
||||||
|
// Words end with:
|
||||||
|
// - any parentheses
|
||||||
|
// - whitespaces:
|
||||||
|
// -- followed by parentheses
|
||||||
|
// -- followed by word
|
||||||
|
// - end of file
|
||||||
|
// return 42;
|
||||||
|
// if (..) [] {..};
|
||||||
|
// if(1 + a < 42)
|
||||||
break;
|
break;
|
||||||
case SLC_WORD_VAR:
|
case SLC_WORD_VAR:
|
||||||
break;
|
break;
|
||||||
@ -555,4 +726,36 @@ static inline void slc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FORTH mini példa - threaded kód példa...
|
||||||
|
*
|
||||||
|
* : addmul ( a b c -- d )
|
||||||
|
* +
|
||||||
|
* *
|
||||||
|
* ;
|
||||||
|
*
|
||||||
|
* 4 5 6 addmul
|
||||||
|
* 1 2 3 addmul
|
||||||
|
*
|
||||||
|
* ->
|
||||||
|
* goto main
|
||||||
|
* a:
|
||||||
|
* 'c' '+'
|
||||||
|
* 'c' '*'
|
||||||
|
* 'r'
|
||||||
|
*
|
||||||
|
* main:
|
||||||
|
*
|
||||||
|
* 'p' 4
|
||||||
|
* 'p' 5
|
||||||
|
* 'p' 6
|
||||||
|
* 'c' 'a'
|
||||||
|
*
|
||||||
|
* 'p' 1
|
||||||
|
* 'p' 2
|
||||||
|
* 'p' 3
|
||||||
|
* 'c' 'a'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#endif /* SLC_H */
|
#endif /* SLC_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user