ugl
This commit is contained in:
parent
caf0daa718
commit
262c09e871
|
@ -36,6 +36,17 @@ void ugl_ExecBytecode(void)
|
|||
}
|
||||
|
||||
|
||||
void ugl_CheckForAllLabelsDefined(void)
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < ugl_label_cnt; i++ )
|
||||
{
|
||||
if ( ugl_label_bytecode_pos[ugl_label_cnt] == 0x0ffff )
|
||||
{
|
||||
ugl_err("undefined label '%s'", ugl_label_name[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ugl_ResolveSymbols(void)
|
||||
{
|
||||
|
@ -44,6 +55,8 @@ void ugl_ResolveSymbols(void)
|
|||
uint16_t val;
|
||||
uint8_t cmd;
|
||||
|
||||
ugl_CheckForAllLabelsDefined();
|
||||
|
||||
ugl_plog("Resolve start=%p, end=%p", code, dest);
|
||||
ugl_plog("Resolve bytecode len=%d", ugl_bytecode_len);
|
||||
|
||||
|
@ -106,6 +119,21 @@ void ugl_ResolveSymbols(void)
|
|||
*code = val&255;
|
||||
code++;
|
||||
|
||||
break;
|
||||
case BC_CMD_CALL_PROCEDURE:
|
||||
val = code[0];
|
||||
val <<= 8;
|
||||
val |= code[1];
|
||||
|
||||
ugl_plog("Resolve CALL Procedre '%s'", ugl_label_name[val]);
|
||||
|
||||
val = ugl_GetLabelBytecodePos(val);
|
||||
|
||||
*code = val>>8;
|
||||
code++;
|
||||
*code = val&255;
|
||||
code++;
|
||||
|
||||
break;
|
||||
default:
|
||||
ugl_err("Resolve: Unexpected command");
|
||||
|
@ -120,18 +148,6 @@ void ugl_ResolveSymbols(void)
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int ugl_FindLabel(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -13,12 +13,16 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#define BC_STACK_SIZE 64
|
||||
#define BC_RETURN_STACK_SIZE 6
|
||||
|
||||
struct bc_struct
|
||||
{
|
||||
uint8_t *code;
|
||||
uint8_t stack_pointer; /* starts at 0 and grows */
|
||||
uint16_t stack[BC_STACK_SIZE];
|
||||
uint8_t return_stack_pointer; /* starts at 0 and grows */
|
||||
uint16_t stack[BC_STACK_SIZE]; /* parameter and return value stack */
|
||||
|
||||
uint16_t return_stack[BC_RETURN_STACK_SIZE]; /* return from procedure stack */
|
||||
};
|
||||
typedef struct bc_struct bc_t;
|
||||
|
||||
|
@ -31,7 +35,7 @@ extern bc_buildin_fn bc_buildin_list[];
|
|||
/* lower 4 bit: 1, upper 4 bit + next byte --> 12 bit value */
|
||||
#define BC_CMD_CALL_BUILDIN (0x01)
|
||||
|
||||
/* lower 4 bit: 2, upper 4 bit + next byte --> 12 bit value */
|
||||
/* lower 4 bit: 2, upper 4 bit + next byte --> 12 bit value (toplevel call, return value will be removed) */
|
||||
#define BC_CMD_CALL_BUILDIN_POP_STACK (0x02)
|
||||
|
||||
/* lower 4 bit: 2, upper 4 bit + next byte --> 12 bit relative adr */
|
||||
|
@ -49,6 +53,10 @@ extern bc_buildin_fn bc_buildin_list[];
|
|||
#define BC_CMD_JUMP_NOT_ZERO (0x4f)
|
||||
/* lower 4 bit: 15, upper 4 bit: 5 --> adr are next 16 bit*/
|
||||
#define BC_CMD_JUMP_ZERO (0x05f)
|
||||
/* lower 4 bit: 15, upper 4 bit: 6 --> adr are next 16 bit */
|
||||
#define BC_CMD_CALL_PROCEDURE (0x06f)
|
||||
|
||||
|
||||
|
||||
void bc_exec(bc_t *bc, uint8_t *code);
|
||||
|
||||
|
|
|
@ -207,7 +207,14 @@ void ugl_bytecode_buildin_procedure(const char *name, int idx, int is_toplevel)
|
|||
|
||||
void ugl_bytecode_call_procedure(const char *name, int is_toplevel)
|
||||
{
|
||||
uint16_t idx;
|
||||
|
||||
ugl_plog("BC call %sbytecode '%s'", is_toplevel?"toplevel ":"", name);
|
||||
idx = ugl_GetLabel(name);
|
||||
|
||||
ugl_AddBytecode(BC_CMD_CALL_PROCEDURE );
|
||||
ugl_AddBytecode(idx>>8);
|
||||
ugl_AddBytecode(idx&0x0ff);
|
||||
}
|
||||
|
||||
void ugl_bytecode_constant_value(long num)
|
||||
|
@ -320,6 +327,9 @@ void ugl_parse_proc(const char **s, const char *id, int is_toplevel)
|
|||
(*s)++;
|
||||
skip_space(s);
|
||||
|
||||
if ( **s == ')' )
|
||||
break;
|
||||
|
||||
if ( (**s >= '0' && **s <= '9') || **s == '$' || **s == '\'' )
|
||||
{
|
||||
ugl_bytecode_constant_value(get_num(s));
|
||||
|
@ -362,7 +372,8 @@ int ugl_read_line(const char **s)
|
|||
ugl_plog("start procedure '%s'", name);
|
||||
if ( ugl_indent_level != 0 )
|
||||
ugl_err("nested procedures not allowed");
|
||||
ugl_GetLabel(name); /* just create a label for the procedure name */
|
||||
ugl_GetLabel(name); /* create a label for the procedure name */
|
||||
ugl_SetLabelBytecodePos(name, ugl_bytecode_len); /* and set the label for it */
|
||||
ugl_IncIndent(UGL_INDENT_TYPE_PROC);
|
||||
}
|
||||
else if ( strcmp(id, "endproc") == 0 )
|
||||
|
|
Loading…
Reference in New Issue