Compare commits
No commits in common. "9ec2dffd1b8c8b10e7786dbe78f360e3606330aa" and "b4df642d7209a5009f532e684f3c75907a01e7bf" have entirely different histories.
9ec2dffd1b
...
b4df642d72
@ -142,7 +142,7 @@ static word_body word_processed_body(word *w) {
|
|||||||
|
|
||||||
enum SLC_SYM_OP { SLC_SYM_SET = 0, SLC_SYM_GET = 1, SLC_SYM_ERASE = 2 };
|
enum SLC_SYM_OP { SLC_SYM_SET = 0, SLC_SYM_GET = 1, SLC_SYM_ERASE = 2 };
|
||||||
typedef enum SLC_SYM_OP SLC_SYM_OP;
|
typedef enum SLC_SYM_OP SLC_SYM_OP;
|
||||||
enum SLC_STACK_OP { SLC_STACK_PUSH, SLC_STACK_POP, SLC_STACK_AT, SLC_STACK_POPAT, SLC_STACK_COUNT, SLC_STACK_ERASE };
|
enum SLC_STACK_OP { SLC_STACK_PUSH, SLC_STACK_POP, SLC_STACK_AT, SLC_STACK_COUNT, SLC_STACK_ERASE };
|
||||||
typedef enum SLC_STACK_OP SLC_STACK_OP;
|
typedef enum SLC_STACK_OP SLC_STACK_OP;
|
||||||
enum SLC_SESSION_OP {
|
enum SLC_SESSION_OP {
|
||||||
SLC_SESSION_ALLOC,
|
SLC_SESSION_ALLOC,
|
||||||
@ -152,8 +152,7 @@ enum SLC_SESSION_OP {
|
|||||||
SLC_SESSION_SET,
|
SLC_SESSION_SET,
|
||||||
SLC_SESSION_GET32,
|
SLC_SESSION_GET32,
|
||||||
SLC_SESSION_SET32,
|
SLC_SESSION_SET32,
|
||||||
SLC_SESSION_PROCESS,
|
SLC_SESSION_PROCESS
|
||||||
SLC_SESSION_MARK
|
|
||||||
};
|
};
|
||||||
typedef enum SLC_SESSION_OP SLC_SESSION_OP;
|
typedef enum SLC_SESSION_OP SLC_SESSION_OP;
|
||||||
enum SLC_IO_OP {
|
enum SLC_IO_OP {
|
||||||
@ -198,7 +197,6 @@ typedef void* (*sym)(SLC_SYM_OP op, do_not_save_charptr key, void *ptr);
|
|||||||
* SLC_STACK_PUSH pushes the "elem" to the stack. Returns 1 if succeeded, otherwise 0.
|
* SLC_STACK_PUSH pushes the "elem" to the stack. Returns 1 if succeeded, otherwise 0.
|
||||||
* SLC_STACK_POP pops the stack - does not return meaningful value, beware of underflowing!
|
* SLC_STACK_POP pops the stack - does not return meaningful value, beware of underflowing!
|
||||||
* SLC_STACK_AT returns the "param"th element down from the top of the stack
|
* SLC_STACK_AT returns the "param"th element down from the top of the stack
|
||||||
* SLC_STACK_POPAT pops at the paramth element down from the top of the stack
|
|
||||||
* SLC_STACK_COUNT returns the number of elements in the stack
|
* SLC_STACK_COUNT returns the number of elements in the stack
|
||||||
* SLC_STACK_ERASE Makes the stack empty. Basically as if you would POP the COUNT times.
|
* SLC_STACK_ERASE Makes the stack empty. Basically as if you would POP the COUNT times.
|
||||||
*
|
*
|
||||||
@ -213,14 +211,13 @@ typedef uint32_t (*stack)(SLC_STACK_OP op, uint32_t param);
|
|||||||
*
|
*
|
||||||
* Operations:
|
* Operations:
|
||||||
* SLC_SESSION_ALLOC allocates parameter amount of memory and returns an accessor index.
|
* SLC_SESSION_ALLOC allocates parameter amount of memory and returns an accessor index.
|
||||||
* SLC_SESSION_ERASE erase the session storage (until last marker!) - all parameters are unused
|
* SLC_SESSION_ERASE erase the session storage (all of it) - all parameters are unused
|
||||||
* SLC_SESSION_PUSH adds the given byte (value in i) to the end of the session storage (by growing it) - j unused
|
* SLC_SESSION_PUSH adds the given byte (value in i) to the end of the session storage (by growing it) - j unused
|
||||||
* SLC_SESSION_GET gets byte at the ith accessor index - j unused
|
* SLC_SESSION_GET gets byte at the ith accessor index - j unused
|
||||||
* SLC_SESSION_SET gets byte at the ith accessor index to be of (byte)j
|
* SLC_SESSION_SET gets byte at the ith accessor index to be of (byte)j
|
||||||
* SLC_SESSION_GET32 gets uint32_t at the ith accessor index - j unused. XXX: Beware, architectures unaligned access crash!
|
* SLC_SESSION_GET32 gets uint32_t at the ith accessor index - j unused. XXX: Beware, architectures unaligned access crash!
|
||||||
* SLC_SESSION_SET32 gets uint32_t at the ith accessor index to be of j. XXX: Beware, architectures unaligned access crash!
|
* SLC_SESSION_SET32 gets uint32_t at the ith accessor index to be of j. XXX: Beware, architectures unaligned access crash!
|
||||||
* SLC_SESSION_PROCESS gets the last j bytes and moves them overriding bytes at index i, then "shrinks" the storage by j.
|
* SLC_SESSION_PROCESS gets the last j bytes and moves them overriding bytes at index i, then "shrinks" the storage by j.
|
||||||
* SLC_SESSION_MARK sets marker
|
|
||||||
*
|
*
|
||||||
* @param op Defines which operation the caller wants.
|
* @param op Defines which operation the caller wants.
|
||||||
* @param i Used on SESSION_GET and is the accessor index, in case of SESSIN_ALLOC it is the amount to allocate.
|
* @param i Used on SESSION_GET and is the accessor index, in case of SESSIN_ALLOC it is the amount to allocate.
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
Parses this:
|
|
||||||
|
|
||||||
do {
|
|
||||||
...code...
|
|
||||||
} (...cond...)
|
|
||||||
|
|
||||||
Into this:
|
|
||||||
|
|
||||||
...code...
|
|
||||||
while(...cond...) {
|
|
||||||
...code...
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// -> [bytecodes]
|
|
||||||
::builtin do @body
|
|
||||||
"" parseblock {} // "" means no entry into the symbol table (unnamed function) - equals to 0
|
|
||||||
do@body(.) // (.) does not removes - only (_) no need for gencode because
|
|
||||||
gen(while) // address top bit 1 when builtin from C
|
|
||||||
genopen() // equal to gencode(1)
|
|
||||||
"" parseblock ()
|
|
||||||
genclose()
|
|
||||||
genopen{}
|
|
||||||
do@body
|
|
||||||
genclose{}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
:builtin dup @t
|
|
||||||
dup@t(_)
|
|
||||||
dup@t
|
|
||||||
dup@t
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
::builtin for
|
|
||||||
parseword drop // TODO: error handling
|
|
||||||
"" ";" parse
|
|
||||||
gen(while)
|
|
||||||
genopen()
|
|
||||||
"" ";" parse
|
|
||||||
genclose()
|
|
||||||
genopen{}
|
|
||||||
"" ")" parse()
|
|
||||||
"" parseblock {}
|
|
||||||
swap
|
|
||||||
genclose{}
|
|
||||||
;
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
: gen
|
|
||||||
if(1 !=) {
|
|
||||||
dup 1 -
|
|
||||||
gen
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
5 gen
|
|
||||||
@ -1 +0,0 @@
|
|||||||
"word_name" gen_str // -> session storage-be
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
// prefixed builtins with '#'
|
|
||||||
// when writing a compiler - like a c-like language
|
|
||||||
|
|
||||||
:if
|
|
||||||
()
|
|
||||||
#asm(jz else$)
|
|
||||||
{}
|
|
||||||
#asm(jmp ifend$)
|
|
||||||
#asm(else$:)
|
|
||||||
[]
|
|
||||||
#asm(ifend$:)
|
|
||||||
;
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
"word_name" gen_str // -> session storage-be - amúgy ez utf8
|
|
||||||
|
|
||||||
"abc" "df" strcon
|
|
||||||
/*
|
|
||||||
abc0
|
|
||||||
0004
|
|
||||||
df00
|
|
||||||
0002
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: implement as C builtin instead.. but doable this way
|
|
||||||
:builtin strcon @off1 @mod1 @
|
|
||||||
dup
|
|
||||||
7 + 4 /
|
|
||||||
strcon@off1(_) // (_) azt jelenti, hogy pop és változóba tesz, (.) means peek and put in var
|
|
||||||
dup
|
|
||||||
4 %
|
|
||||||
strcon@mod1(_)
|
|
||||||
strcon@off1
|
|
||||||
popat
|
|
||||||
|
|
||||||
+
|
|
||||||
;
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
// a b -> b a
|
|
||||||
:builtin swap @tmp1 @tmp2
|
|
||||||
swap@tmp1(_)
|
|
||||||
swap@tmp2(_)
|
|
||||||
swap@tmp1
|
|
||||||
swap@tmp2
|
|
||||||
;
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
: player_data @xpos @ypos @health
|
|
||||||
;
|
|
||||||
22
main.c
22
main.c
@ -46,18 +46,18 @@ char testcoderead() {
|
|||||||
static int i = 0;
|
static int i = 0;
|
||||||
static const char *code =
|
static const char *code =
|
||||||
"// This is a small test program to push(42); print\n"
|
"// This is a small test program to push(42); print\n"
|
||||||
"/*#21\n"
|
"/*#push(21)\n"
|
||||||
"#21\n"
|
"#push(21)\n"
|
||||||
"#+*/\n"
|
"#add*/\n"
|
||||||
" #42\n"
|
" #push(42)\n"
|
||||||
" #printnum\n"
|
" #print\n"
|
||||||
"\n"
|
"\n"
|
||||||
"#: word_test\n"
|
"#: word_test\n"
|
||||||
" #21\n"
|
" #push(21)\n"
|
||||||
" #21\n"
|
" #push(21)\n"
|
||||||
" #+\n"
|
" #add\n"
|
||||||
" #printnum\n"
|
" #print\n"
|
||||||
";\n"
|
"\n"
|
||||||
"word_test\n";
|
"word_test\n";
|
||||||
return code[i++];
|
return code[i++];
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ int main(int argc, const char **argv) {
|
|||||||
"/*", // multiline_comment_opener
|
"/*", // multiline_comment_opener
|
||||||
"*/", // multiline_comment_closer,
|
"*/", // multiline_comment_closer,
|
||||||
"#", // prefix
|
"#", // prefix
|
||||||
";", // ender
|
"#", // ender
|
||||||
"@" // varprefix
|
"@" // varprefix
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user