On Sat, Mar 30, 2024 at 10:31:46PM +0100, Ralf Hemmecke wrote:
> On 3/30/24 00:43, Waldek Hebisch wrote:
> > Compiler knows function name and constructor name. Note however
> > that FriCAS types are parametrized, and type parameter are known
> > only at runtime.
>
> Waldek, that sounds as if printing function and constructor name would be
> quite easy to achieve.
>
> Yes, the parameters of the constructor would be nice, but for me it would
> already be pretty helpful to know function and constructor name.
In a sense yes. There are limitations:
1) 'error' needs special treatment in the compiler because
'error' means abnormal exit from a function, so no need
for return value. Without that knowledge you would have
to write silly code like
my_error("error")
return some_dummy
to satisfy type checker. Theoretically 'Exit' as return type
could be used for this purpose, but I am affraid that it only
works in the interpeter.
2) Currently 'error' calls 'error' in 'g-error.boot'. So there
is one argument and to call _must_ go to 'errorSupervisor'
before it prints anything. Namely, 'errorSupervisor' may
trap errors, in which case nothing should be printed.
3) 'error' messages are most important in unexpected situations.
Which means that we want to keep error handlers as simple as
possible. Otherwise there is real risk that when "interesting"
error hapen we will get crash in error handler instead of
error message.
Currently actual code for 'error' is generated in 'compForm1'
in 'compiler.boot'. Handling is dead simple:
op="error" =>
#argl = 1 =>
arg := first(argl)
u := comp(arg, $String, e) =>
[[op, u.expr], m, e]
SAY ['"compiling call to error ", argl]
u := outputComp(arg, e) =>
[[op, ['LIST, ['QUOTE, 'mathprint], u.expr]], m, e]
nil
SAY ['"compiling call to error ", argl]
nil
So, if function name is 'error' and there is one argument it
tries to compile this aregument, and if succesful generates call
to 'error' at Boot level passing to computed value of the argument.
Otherwise, in case of one argument it tries to compile agument as
an output form, if that warks it callse Boot hadler giving it
wrapped OutputForm.
Of none of the above works call is treated as error is source
code. There is backtracking in Spad compiler, so theoretically
soemthing else could compile the call, but AFAICS all things
go trough 'compForm1', so probably different treatment is
not possible.
Now, what could we change easily? We could add two or three
argument error at Boot level and call it with extra data.
For example, passing '%' to handler would give it complete
information about current constructor ('%' contains domain
vector which contains all runtime information about type,
including constructor name and parameters). We could pass
'$op' which IIRC contains current function name.
Attached is a little patch which changes error function to
'error3' and adds two extra paramters, that is constructor name
and function name.
You need to add definition of 'error3', for example:
error3(con, fun, mess) ==
errorSupervisor($AlgebraError, [STRCONC(con, '"$", fun, '": "), mess])
Note: to test patch 'compiler.boot' and read it. Then read
boot file with definition of 'error3'.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/ZgjAhyBta7PXq8Q3%40fricas.org.
--- ../trunk.pp6/src/interp/compiler.boot 2024-03-28 21:46:24.406140407 +0000
+++ compiler.boot 2024-03-31 01:41:48.306221983 +0000
@@ -484,10 +484,16 @@
compForm1(form is [op,:argl],m,e) ==
op="error" =>
+ constr :=
+ NULL($functorForm) => nil
+ first($functorForm)
+ fun :=
+ $op = constr => nil
+ $op
#argl = 1 =>
arg := first(argl)
u := comp(arg, $String, e) =>
- [[op, u.expr], m, e]
+ [["error3", MKQ(constr), MKQ(fun), u.expr], m, e]
SAY ['"compiling call to error ", argl]
u := outputComp(arg, e) =>
[[op, ['LIST, ['QUOTE, 'mathprint], u.expr]], m, e]