|
|
@ -957,22 +957,20 @@ void printBacktrace(oop top) |
|
|
|
fflush(stdout); |
|
|
|
printLocation(top); |
|
|
|
while (CallArray_position(&backtrace) > 0) { |
|
|
|
struct Call call= CallArray_pop(&backtrace); |
|
|
|
if (is(Map, call.ast) && Call_proto == map_get(call.ast, __proto___symbol)) { |
|
|
|
oop name= get(call.function, Function, name); |
|
|
|
if (null != name) { |
|
|
|
printf(" in "); |
|
|
|
if (get(call.function, Function, primitive)) |
|
|
|
printf("primitive "); |
|
|
|
else |
|
|
|
printf("function "); |
|
|
|
println(get(call.function, Function, name)); |
|
|
|
struct Call call= CallArray_pop(&backtrace); |
|
|
|
if (is(Map, call.ast) && Call_proto == map_get(call.ast, __proto___symbol)) { |
|
|
|
oop name= get(call.function, Function, name); |
|
|
|
if (null != name) { |
|
|
|
printf(" in "); |
|
|
|
if (get(call.function, Function, primitive)) printf("primitive "); |
|
|
|
else printf("function "); |
|
|
|
println(get(call.function, Function, name)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
printLocation(call.ast); |
|
|
|
else { |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
printLocation(call.ast); |
|
|
|
} |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
@ -1353,10 +1351,8 @@ oop eval(oop scope, oop ast) |
|
|
|
case t_Call: { |
|
|
|
oop func = eval(scope, map_get(ast, func_symbol)); |
|
|
|
if (!is(Function, func)) { |
|
|
|
// TODO better error printing |
|
|
|
// Please search for ISSUE1 in parse.leg |
|
|
|
printf("cannot call "); |
|
|
|
println(func); |
|
|
|
printf("\ncannot call %s\n", printString(func)); |
|
|
|
printBacktrace(ast); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
@ -1413,8 +1409,8 @@ oop eval(oop scope, oop ast) |
|
|
|
oop this = eval(scope, map_get(ast, this_symbol)); |
|
|
|
oop func = getVariable(this, map_get(ast, name_symbol)); |
|
|
|
if (!is(Function, func)) { |
|
|
|
printf("cannot invoke "); |
|
|
|
println(func); |
|
|
|
printf("\ncannot invoke %s\n", printString(func)); |
|
|
|
printBacktrace(ast); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
@ -1797,22 +1793,14 @@ oop prim_length(oop scope, oop params) |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO |
|
|
|
// ISSUE1: how can I handle the "cannot invoke " with nice printing the func name and its args |
|
|
|
// it would be really nice to have a toString() function (that would be directly used in print()) |
|
|
|
// but it seems that it's really complicated to write a toString() for integer, function and maps... |
|
|
|
// please see the draft line 490 in object.c |
|
|
|
|
|
|
|
// ISSUE2: how can I tackle the 2 fprintf(stderr, "\nbreak/continue oustide of a loop\n") in prim_invoke and prim_apply |
|
|
|
// in this situation it seems that I don't have access to any AST |
|
|
|
oop prim_invoke(oop scope, oop params) |
|
|
|
{ |
|
|
|
oop this= null; if (map_hasIntegerKey(params, 0)) this= get(params, Map, elements)[0].value; |
|
|
|
oop func= null; if (map_hasIntegerKey(params, 1)) func= get(params, Map, elements)[1].value; |
|
|
|
oop args= null; if (map_hasIntegerKey(params, 2)) args= get(params, Map, elements)[2].value; |
|
|
|
if (!is(Function, func)) { |
|
|
|
printf("cannot invoke "); |
|
|
|
println(func); |
|
|
|
printf("\ncannot invoke %s\n", printString(func)); |
|
|
|
printBacktrace(mrAST); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
if (NULL != get(func, Function, primitive)) { |
|
|
@ -1852,8 +1840,8 @@ oop prim_invoke(oop scope, oop params) |
|
|
|
oop apply(oop scope, oop func, oop args) |
|
|
|
{ |
|
|
|
if (!is(Function, func)) { |
|
|
|
printf("cannot apply "); |
|
|
|
println(func); |
|
|
|
printf("\ncannot apply %s\n", printString(func)); |
|
|
|
printBacktrace(mrAST); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
if (NULL != get(func, Function, primitive)) { |
|
|
@ -1964,8 +1952,7 @@ void readEvalPrint(oop scope, char *fileName) |
|
|
|
case j_continue: |
|
|
|
runtimeError("continue outside of a loop"); |
|
|
|
case j_throw: |
|
|
|
printf("\nunhandled exception: "); |
|
|
|
println(res); |
|
|
|
printf("\nunhandled exception: %s\n", printString(res)); |
|
|
|
printBacktrace(mrAST); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|