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...
|
||||
* This is used for implementation implementing built-ins with FORTH-like code instead of native (saves native interpret. space)
|
||||
*
|
||||
* #: structural (
|
||||
* #:: structural (
|
||||
* #parse_num
|
||||
* #dup
|
||||
* #inc
|
||||
@ -344,7 +344,7 @@ static inline slc_state slc_def_name_statechange(
|
||||
const char *prefix,
|
||||
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)) {
|
||||
/* Early exit for not-a-definition sub-state */
|
||||
if(*prefix_i < 0) {
|
||||
@ -360,8 +360,8 @@ static inline slc_state slc_def_name_statechange(
|
||||
}
|
||||
} else {
|
||||
if(c == ':') {
|
||||
*prefix_i = 0; /* XXX: restarts scan */
|
||||
return SLC_WORD_NAME;
|
||||
*prefix_i = 0; /* XXX: restarts scana for finnding it in the next cases */
|
||||
return SLC_DEF_NAME;
|
||||
} else {
|
||||
*prefix_i = -1;
|
||||
}
|
||||
@ -535,13 +535,184 @@ static inline void slc(
|
||||
if(state == SLC_START) { SET_SLC_START }
|
||||
break;
|
||||
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;
|
||||
case SLC_DEF_VAR:
|
||||
break;
|
||||
case SLC_DEF_BODY:
|
||||
break;
|
||||
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;
|
||||
case SLC_WORD_VAR:
|
||||
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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user