Skip to content

Commit

Permalink
Fixed multiple integration issues with matte and debugging features.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorks committed May 29, 2023
1 parent 2533b51 commit c05b8b7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 33 deletions.
2 changes: 0 additions & 2 deletions src/binary/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ int main(int argc, char ** argv) {
topazScriptManager_Permission_All
);

// enable debugging!
topaz_script_enable_debugging(script);


// first, load all and any bundles into memory. This
Expand Down
3 changes: 2 additions & 1 deletion src/components_text2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ static void text2d_update(Text2D * t, const topazString_t * str, const topazAsse

// current string is the base, new content being added.
} else if (lenNew > len && i == len) {
text2d_update__add(t, str, font, pixelSize);
//text2d_update__add(t, str, font, pixelSize); //< bugged
text2d_update__full(t, str, font, pixelSize);

// default full update.
} else {
Expand Down
2 changes: 1 addition & 1 deletion system/inputManager/glfw/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static int get_key(int kglfw) {
SMAP(GLFW_KEY_KP_ENTER , topazKey_enter);
SMAP(GLFW_KEY_KP_EQUAL , topazKey_equal);
SMAP(GLFW_KEY_LEFT_SHIFT , topazKey_lshift);
SMAP(GLFW_KEY_LEFT_CONTROL , topazKey_rshift);
SMAP(GLFW_KEY_LEFT_CONTROL , topazKey_lctrl);
SMAP(GLFW_KEY_LEFT_ALT , topazKey_lalt);
SMAP(GLFW_KEY_LEFT_SUPER , topazKey_lsuper);
SMAP(GLFW_KEY_RIGHT_SHIFT , topazKey_rshift);
Expand Down
2 changes: 1 addition & 1 deletion system/script/matte/src/bootstrap.mt
Original file line number Diff line number Diff line change
Expand Up @@ -3875,7 +3875,7 @@ Topaz = class(
attachPostManagerUnpausable : ::(manager){topaz__attach_post_manager_unpausable(a:manager.native);},
quit : getExternalFunction(name:'topaz__quit'),
frameStart ::(FPS) {topaz__frame_start(a:FPS);},
frameEnd ::(FPS) {topaz__frame_end();},
frameEnd ::() {topaz__frame_end();},
toBase64 ::(bytes) {topaz__to_base64(a:bytes);},
fromBase64 : ::(string) {
return __Topaz__.Data.new(native:topaz__from_base64(a:string));
Expand Down
88 changes: 60 additions & 28 deletions system/script/matte/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ static topazString_t * topaz_matte_stack_where(TOPAZMATTE * ctx) {
const matteString_t * fileName = matte_vm_get_script_name_by_id(ctx->vm, fileid);

if (i == ctx->debugLevel) {
topaz_string_concat_printf(str, " -> @%d:%s <%s>, line %d\n", i, matte_string_get_c_str(frame.prettyName), fileName ? matte_string_get_c_str(fileName) : "???", inst[frame.pc].lineNumber);
topaz_string_concat_printf(str, " -> @%d: <%s>, line %d\n", i, fileName ? matte_string_get_c_str(fileName) : "???", (int)inst[frame.pc].lineNumber);
} else {
topaz_string_concat_printf(str, " @%d:%s <%s>, line %d\n", i, matte_string_get_c_str(frame.prettyName), fileName ? matte_string_get_c_str(fileName) : "???", inst[frame.pc].lineNumber);
topaz_string_concat_printf(str, " @%d: <%s>, line %d\n", i, fileName ? matte_string_get_c_str(fileName) : "???", (int)inst[frame.pc].lineNumber);
}
}
return str;
Expand Down Expand Up @@ -333,9 +333,6 @@ static void topaz_matte_object_finalizer(void * objectUserdata, void * functionU
}
#endif

if (tag->selfID.value.id == 2051)
printf("bruh");

// if this is even happening, the global stash entry was already removed.

// call c finalizer, which is why this is here mostly
Expand Down Expand Up @@ -423,16 +420,24 @@ static topazScript_Object_t * topaz_matte_value_to_tso(TOPAZMATTE * ctx, matteVa
return o;
}

static matteString_t * topaz_matte_run__error__file = NULL;
static int topaz_matte_run__error__last_success = 0;
static void topaz_matte_run__error(const matteString_t * s, uint32_t line, uint32_t ch, void * userdata) {
TOPAZMATTE * ctx = userdata;
topazString_t * str = topaz_string_create();
topaz_string_concat_printf(str, "ERROR @ line %d, %d:\n%s\n", line, ch, matte_string_get_c_str(s));
topaz_string_concat(str, topaz_matte_stack_where(ctx));
matteString_t * errm = matte_string_create_from_c_str("%s", topaz_string_get_c_str(str));
matte_vm_raise_error_string(ctx->vm, errm);
matte_string_destroy(errm);
PERROR(ctx->ctx, ctx->script, str);

topaz_string_concat_printf(
str,
"ERROR in %s, line %d, %d:\n%s\n",

topaz_matte_run__error__file ? matte_string_get_c_str(topaz_matte_run__error__file) : "<unknown file>" ,
line, ch,
matte_string_get_c_str(s)
);

matteString_t * errm = matte_string_create_from_c_str("%s", topaz_string_get_c_str(str));
matte_vm_raise_error_string(ctx->vm, errm);
matte_string_destroy(errm);
topaz_matte_run__error__last_success = 0;
}

static void topaz_matte_expression__error(matteVM_t * vm, matteVMDebugEvent_t event, uint32_t file, int lineNumber, matteValue_t value, void * userdata) {
Expand Down Expand Up @@ -519,19 +524,33 @@ static matteValue_t topaz_matte_native_function_internal(matteVM_t * vm, matteVa
static void topaz_matte_fatal(matteVM_t * vm, uint32_t file, int lineNumber, matteValue_t value, void * udata) {
TOPAZMATTE * ctx = udata;
matteStore_t * store = matte_vm_get_store(vm);
int hadSummary = 0;
{
const matteString_t * rep = matte_value_string_get_string_unsafe(store, matte_value_object_access_string(store, value, MATTE_VM_STR_CAST(vm, "summary")));

PERROR(ctx->ctx, ctx->script, topaz_string_create_from_c_str("Topaz Scripting error: (%s, line %d):\n%s\n%s",
matte_string_get_c_str(matte_vm_get_script_name_by_id(vm, file)),
const matteString_t * rep = NULL;

if (value.binID == MATTE_VALUE_TYPE_OBJECT) {
rep = matte_value_string_get_string_unsafe(store, matte_value_object_access_string(store, value, MATTE_VM_STR_CAST(vm, "summary")));
hadSummary = 1;
} else if (value.binID == MATTE_VALUE_TYPE_STRING) {
rep = matte_value_string_get_string_unsafe(store, value);
}
const matteString_t * filename = (matte_vm_get_script_name_by_id(vm, file));


PERROR(ctx->ctx, ctx->script, topaz_string_create_from_c_str("Topaz Scripting error: (%s, line %d):\n%s\n",
filename ? matte_string_get_c_str(filename) : "<unknown file>",
lineNumber,
matte_string_get_c_str(rep)));
rep ? matte_string_get_c_str(rep) : "Unknown error. No summary available."));
}
topazString_t * str = topaz_matte_stack_where(ctx);
if (topaz_string_get_length(str)) {
PERROR(ctx->ctx, ctx->script, str);
} else {
topaz_string_destroy(str);
// try to include a callstack if summary isnt included
if (!hadSummary) {
topazString_t * str = topaz_matte_stack_where(ctx);
if (topaz_string_get_length(str)) {
PERROR(ctx->ctx, ctx->script, str);
} else {
topaz_string_destroy(str);
}
}

}
Expand Down Expand Up @@ -570,16 +589,24 @@ static uint32_t topaz_matte_import(

// process and load source into
uint32_t bytecodeLen = 0;
const char * cstr = topaz_string_get_c_str(srcstr);
topaz_matte_run__error__file = matte_string_create_from_c_str("%s", importName);
topaz_matte_run__error__last_success = 1;
uint8_t * bytecode = matte_compiler_run(
ctx->syngraph,
(const uint8_t*)topaz_string_get_c_str(srcstr),
topaz_string_get_length(srcstr),
(const uint8_t*)cstr,
strlen(cstr),
&bytecodeLen,
topaz_matte_run__error,
ctx
);


matte_string_destroy(topaz_matte_run__error__file);
topaz_matte_run__error__file = NULL;
if (!topaz_matte_run__error__last_success) {
matte_deallocate(bytecode);
return 0;
}

matteArray_t * stubs = matte_bytecode_stubs_from_bytecode(
matte_vm_get_store(matte_get_vm(m)),
fileid,
Expand Down Expand Up @@ -784,6 +811,9 @@ static void topaz_matte_run(


uint32_t bytelen = 0;

topaz_matte_run__error__file = matte_string_create_from_c_str("%s", topaz_string_get_c_str(sourceName));
topaz_matte_run__error__last_success = 1;
uint8_t * bytecode = matte_compiler_run(
ctx->syngraph,
(const uint8_t*)topaz_string_get_c_str(sourceDataD),
Expand All @@ -792,11 +822,11 @@ static void topaz_matte_run(
topaz_matte_run__error,
ctx
);
matte_string_destroy(topaz_matte_run__error__file);
topaz_matte_run__error__file = NULL;


if (!bytecode || !bytelen) {
topazString_t * str = topaz_string_create_from_c_str("Could not compile source \"%s\"", topaz_string_get_c_str(sourceName));
PERROR(ctx->ctx, ctx->script, str);
if (!bytecode || !bytelen || !topaz_matte_run__error__last_success) {
return;
}

Expand Down Expand Up @@ -1093,6 +1123,7 @@ static void topaz_matte_debug_callback(
int pendingError = 0;
TopazMatteBreakpoint * pendingBreakpoint = NULL;
TOPAZMATTE * ctx = data;
/*
if (event == MATTE_VM_DEBUG_EVENT__ERROR_RAISED) {
// forward a formal pause command and continue
topaz_script_debug_send_command(
Expand All @@ -1102,6 +1133,7 @@ static void topaz_matte_debug_callback(
);
pendingError = 1;
}
*/

if (topaz_array_get_size(ctx->debugBreakpoints)) {
uint32_t i;
Expand Down

0 comments on commit c05b8b7

Please sign in to comment.