ugl
This commit is contained in:
parent
bcb2714028
commit
a5b1333ab7
|
@ -1,2 +1,2 @@
|
|||
# without 'v' prefix
|
||||
echo -n "2.16.4"
|
||||
echo -n "2.16.5"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
/* ugl_error.c */
|
||||
void ugl_err(const char *fmt, ...) __attribute__ ((noreturn));
|
||||
void ugl_plog(const char *fmt, ...);
|
||||
void ugl_glog(const char *fmt, ...);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -57,13 +57,13 @@ void ugl_ResolveSymbols(void)
|
|||
|
||||
ugl_CheckForAllLabelsDefined();
|
||||
|
||||
ugl_plog("Resolve start=%p, end=%p", code, dest);
|
||||
ugl_plog("Resolve bytecode len=%d", ugl_bytecode_len);
|
||||
ugl_glog("Resolve start=%p, end=%p", code, dest);
|
||||
ugl_glog("Resolve bytecode len=%d", ugl_bytecode_len);
|
||||
|
||||
while( code < dest )
|
||||
{
|
||||
cmd = *code;
|
||||
ugl_plog("Resolve pos=%p, cmd=%02x", code, cmd);
|
||||
ugl_glog("Resolve pos=%p, cmd=%02x", code, cmd);
|
||||
code++;
|
||||
val = cmd;
|
||||
val &=0x0f0; /* put upper four bit as upper 4bit of the 12bit value into val */
|
||||
|
@ -82,10 +82,10 @@ void ugl_ResolveSymbols(void)
|
|||
case BC_CMD_BRANCH:
|
||||
val |= *code;
|
||||
code++;
|
||||
ugl_plog("Resolve BRANCH '%s' (idx=%d)", ugl_label_name[val], val);
|
||||
ugl_glog("Resolve BRANCH '%s' (idx=%d)", ugl_label_name[val], val);
|
||||
val = ugl_GetLabelBytecodePos(val);
|
||||
val = (val - (uint16_t)(code - ugl_bytecode_array));
|
||||
ugl_plog("Resolve BRANCH delta=0x%03x", val);
|
||||
ugl_glog("Resolve BRANCH delta=0x%03x", val);
|
||||
*(code-2) &= 0x0f;
|
||||
*(code-2) |= (val >> 4) & 0x0f0;
|
||||
*(code-1) = val & 255;
|
||||
|
@ -110,7 +110,7 @@ void ugl_ResolveSymbols(void)
|
|||
val |= code[1];
|
||||
|
||||
|
||||
ugl_plog("Resolve JUMP '%s'", ugl_label_name[val]);
|
||||
ugl_glog("Resolve JUMP '%s'", ugl_label_name[val]);
|
||||
|
||||
val = ugl_GetLabelBytecodePos(val);
|
||||
|
||||
|
@ -121,11 +121,12 @@ void ugl_ResolveSymbols(void)
|
|||
|
||||
break;
|
||||
case BC_CMD_CALL_PROCEDURE:
|
||||
case BC_CMD_CALL_PROCEDURE_POP_STACK:
|
||||
val = code[0];
|
||||
val <<= 8;
|
||||
val |= code[1];
|
||||
|
||||
ugl_plog("Resolve CALL Procedre '%s'", ugl_label_name[val]);
|
||||
ugl_glog("Resolve CALL Procedre '%s'", ugl_label_name[val]);
|
||||
|
||||
val = ugl_GetLabelBytecodePos(val);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "ugl_bc.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
void bc_push_on_stack(bc_t *bc, uint16_t val)
|
||||
{
|
||||
|
@ -15,6 +16,7 @@ void bc_push_on_stack(bc_t *bc, uint16_t val)
|
|||
|
||||
uint16_t bc_pop_from_stack(bc_t *bc)
|
||||
{
|
||||
assert( bc->stack_pointer > 0 );
|
||||
bc->stack_pointer--;
|
||||
return bc->stack[bc->stack_pointer] ;
|
||||
}
|
||||
|
@ -25,6 +27,17 @@ void bc_duplicate_stack_top_value(bc_t *bc)
|
|||
bc->stack_pointer++;
|
||||
}
|
||||
|
||||
uint16_t bc_get_value(uint8_t *code)
|
||||
{
|
||||
uint16_t val;
|
||||
val = *code;
|
||||
code++;
|
||||
val <<= 8;
|
||||
val |= *code;
|
||||
code++;
|
||||
return val;
|
||||
}
|
||||
|
||||
void bc_exec(bc_t *bc, uint8_t *code)
|
||||
{
|
||||
uint16_t val;
|
||||
|
@ -114,7 +127,11 @@ void bc_exec(bc_t *bc, uint8_t *code)
|
|||
if ( bc_pop_from_stack(bc) == 0 )
|
||||
code = bc->code+val;
|
||||
break;
|
||||
|
||||
case BC_CMD_CALL_PROCEDURE:
|
||||
val = bc_get_value(code);
|
||||
break;
|
||||
case BC_CMD_CALL_PROCEDURE_POP_STACK:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ extern bc_buildin_fn bc_buildin_list[];
|
|||
#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)
|
||||
/* lower 4 bit: 15, upper 4 bit: 7 --> adr are next 16 bit */
|
||||
#define BC_CMD_CALL_PROCEDURE_POP_STACK (0x07f)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,4 +22,14 @@ void ugl_plog(const char *fmt, ...)
|
|||
vprintf(fmt, va);
|
||||
printf("\n");
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
/* generic log */
|
||||
void ugl_glog(const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vprintf(fmt, va);
|
||||
printf("\n");
|
||||
va_end(va);
|
||||
}
|
|
@ -211,8 +211,15 @@ void ugl_bytecode_call_procedure(const char *name, int is_toplevel)
|
|||
|
||||
ugl_plog("BC call %sbytecode '%s'", is_toplevel?"toplevel ":"", name);
|
||||
idx = ugl_GetLabel(name);
|
||||
|
||||
ugl_AddBytecode(BC_CMD_CALL_PROCEDURE );
|
||||
|
||||
if ( is_toplevel == 0 )
|
||||
{
|
||||
ugl_AddBytecode(BC_CMD_CALL_PROCEDURE );
|
||||
}
|
||||
else
|
||||
{
|
||||
ugl_AddBytecode(BC_CMD_CALL_PROCEDURE_POP_STACK );
|
||||
}
|
||||
ugl_AddBytecode(idx>>8);
|
||||
ugl_AddBytecode(idx&0x0ff);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue