poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] pkl: Use `format` function in `assert` implementation


From: Jose E. Marchesi
Subject: Re: [PATCH] pkl: Use `format` function in `assert` implementation
Date: Tue, 09 Nov 2021 18:18:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Hi, Jose.
>
> On Sat, Jul 31, 2021 at 06:54:24PM +0430, Mohammad-Reza Nabipoor wrote:
>> Hi, Jose.
>> 
>> On Sat, Jul 31, 2021 at 03:47:01PM +0200, Jose E. Marchesi wrote:
>> > 
>> > Hi Mohammad.
>> > 
>> > Sorry it took so long for me to look at this.
>> > 
>> 
>> 
>> I'm happy that you're hacking poke again :)
>> 
>> 
>> > > This commit changes the implementation of `assert` statement to
>> > > pass source location info (FILENAME, LINE and COLUMN) separately,
>> > > instead of passing a pre-formated string
>> > > ("<FILENAME>:<LINE>:<COLUMN>"). And makes `msg` string using `format`
>> > > function.
>> > >
>> > > The reason that this commit, separates the runtime library (`pkl-rt.pk`)
>> > > into two separate files (`pkl-rt-1.pk` and `pkl-rt-2.pk`) is that
>> > > codegen of `format` generates a function call to
>> > > `_pkl_reduce_string_array`, and it's inaccessible to codegen at this
>> > > stage. Because `_pkl_reduce_string_array` is also defined in the runtime
>> > > library. Moving `_pkl_assert` function to `pkl-rt-2.pk` makes codegen
>> > > happy!
>> > 
>> > I would like to understand why this is happening.  Moving the definition
>> > of _pkl_assert down in pkl-rt.pk after _pkl_reduce_string_array doesn't
>> > fix the problem?
>> > 
>> 
>> This is what I get when the `_pkl_assert` is defined in the same compilation
>> unit as `_pkl_reduce_string_array`:
>> 
>> ```
>> lt-poke: ../../libpoke/pkl-asm.c:2117: pkl_asm_call: Assertion `tmp != NULL' 
>> failed.
>> Aborted (core dumped)
>> ```
>> Even moving it down after the `_pkl_reduce_string_array` doesn't fix the
>> problem.
>> 
>> The following assertion is the problem in `pkl_asm_call` function:
>> 
>> ```c
>>   tmp = pkl_env_lookup (compiler_env, PKL_ENV_NS_MAIN,
>>                         funcname, &back, &over);
>>   assert (tmp != NULL);
>> ```
>> 
>> I've checked the `compiler_env`; it's empty.
>> And the `funcname` is `"_pkl_reduce_string_array"`.
>> 
>
>
> Is this related to the lexical environment problems?

Nope.

But I think I now know why this is happening: the CALL PVM instruction
works by looking up the global environment.  However, until the file
(PROGRAM) is completely compiled its definitions are not added to the
global environment.  That explains it.


So please go ahead with the introduction of pkl-rt-2.pk.

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]