[Cuis-dev] question about Compiler evaluate:
Weslleymberg Lisboa
weslleym.lisboa at gmail.com
Sat Jan 18 17:53:54 PST 2025
That's a very interesting project.
You can take a look at HitchHikersCompiler.md[1] in Cuis repository to
have a better idea of the inner workings of the compiler. It says the
compiler predates the exception frameworks so it has its ways to notify
about problems during compilation. I don't know how much Cuis community
changed that, but there are some exceptions/notifications in
Compiler-Exceptions and Compiler-Support categories.
Another good source of information are the unit tests of the compiler
(Feature require: 'BaseImageTests'). I think it will help you whith what
kind of erros the compiler generates and how.
1-
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Documentation/Technical/Compiler/HitchHikersCompiler.md
Em 18/01/2025 00:14, Mark Volkmann via Cuis-dev escreveu:
> I should have described more what I’m really after. My app (a GUI for my “method finder”) has a TextModelMorph where the user can enter any Smalltalk expression. I need to evaluate that string to arrive at a Smalltalk object. I was hoping that the Compiler class could give me an error message that describes what is wrong with anything the user enters. Having an expression like ‘1 + x’ where x is an unknown variable is a simple example, but I was hoping to get helpful error messages for any attempt at a Smalltalk expression.
>
> ---
> R. Mark Volkmann
> Object Computing, Inc.
>
>> On Jan 17, 2025, at 12:46 PM, Weslleymberg Lisboa via Cuis-dev <cuis-dev at lists.cuis.st> wrote:
>>
>> Hi, Mark
>>
>> I found 'is Undeclared' in UndeclaredVariableWarning>>defaultAction which seems to match what you see in the transcript.
>>
>> I was able to get rid of the transcript error message by doing:
>>
>> expression := '1 + x'.
>> [ Compiler evaluate: expression ] on: UndeclaredVariableWarning do: [:ex | ex resume: false] on: Error do: [:ex | ex inspect ]
>>
>> To give a little context, I searched for references to the class UndeclaredVariableWarning. One of the results was Encoder>>#undeclared: where the comments mention how to disable the warning.
>>
>> Em 17/01/2025 09:40, Mark Volkmann via Cuis-dev escreveu:
>>> In a Workspace, if I "Do It" the first expression below and "Print It" the second expression, it prints 3 as expected.
>>> expression := '1 + 2'.
>>> [ Compiler evaluate: expression ] on: Error do: [ :ex | ex inspect ].
>>> Now if I change the 2 in expression to x and repeat, it prints the following:
>>> MessageNotUnderstood: UndefinedObject>>adaptToNumber:andSend:
>>> It also writes the following to the Transcript:
>>> UndefinedObject>>DoIt (x is Undeclared)
>>> Looking in the Inspect window I see that none of the instance variables contain "x is Undeclared". I really want to get that string. I've searched the Compiler methods and haven't found a way to do this. Does anyone know how I could access that error message?
>>> I'd also like to prevent the error message from being written to the Transcript so I can completely handle it in my code.
>>> --
>>> R. Mark Volkmann
>>> Object Computing, Inc.
>>
>> --
>> Wéslleymberg Lisboa
>> Graduado em Sistemas de Informação
>> Docente no IFFluminense - Campus Itaboraí
>>
>> --
>> Cuis-dev mailing list
>> Cuis-dev at lists.cuis.st
>> https://lists.cuis.st/mailman/listinfo/cuis-dev
--
Wéslleymberg Lisboa
Graduado em Sistemas de Informação
Docente no IFFluminense - Campus Itaboraí
More information about the Cuis-dev
mailing list