Re: Out-of-bounds error when printing out a function value
[Thread Prev] | [Thread Next]
- Subject: Re: Out-of-bounds error when printing out a function value
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Mon, 4 Dec 2017 23:56:52 -0800
- To: myrddin-dev@xxxxxxxxxxxxxx
- Cc: nml <arumakanil@xxxxxxxxx>
On Tue, 5 Dec 2017 14:58:22 +0800, nml <arumakanil@xxxxxxxxx> wrote:
> FWIW
> I tried to add the & operator beside the _start:
> std.put("_start = {x}\n", &_start)
>
> It no longer shows out-of-bounds error but the printed value is still
> confusing.
>
> An equivalent C program prints exactly the value of the symbol shown by nm.
> Not sure if there is a difference between C and Myrddin regarding this
> example or I made some mistakes.
Myrddin is a different from C when it comes to passing functions. When
you have a function variable, the type is equivalent to the following C
type:
struct fptr {
void *env;
void (*fn)();
};
The environment is passed to the function in the case of %rax. Inside
the compiler, the global function symbols get promoted to a closure
when they get used:
const fp = (struct fptr){.env=NULL, .fn=_start};
So, as with slices, to get the 'base', you cast to a pointer:
std.put("p = {}\n", (_start : void#))
For an example of closure frobbing, take a look at lib/std/fndup.myr.
Also, you'll want to pull the most recent mc -- I just fixed a bug
that this code triggers, where it treats the local extern const as
a local variable instead of a global one.
> Hopefully, it's not too stupid.
>
> On 5 December 2017 at 14:36, nml <arumakanil@xxxxxxxxx> wrote:
>
> > The following program:
> >
> > use std
> > const main = {
> > extern const _start : (->void)
> > std.put("_start = {x}\n", _start)
> > }
> >
> > Output:
> > Building
> > 6m -I /lib/myr in.myr ld -o a.out /lib/myr/_myrrt.o in.o -lstd
> > -L/lib/myr -lsys 0x000000000041150d: out of bounds access Internal
> > error: /a.out: exited with signal 31
> >
> > Looks like a bug. I expected that the value shown by nm is printed.
> >
> > --
> > mura
> >
> >
> >
--
Ori Bernstein
| Out-of-bounds error when printing out a function value | nml <arumakanil@xxxxxxxxx> |
| Re: Out-of-bounds error when printing out a function value | nml <arumakanil@xxxxxxxxx> |
- Prev by Date: Re: Out-of-bounds error when printing out a function value
- Next by Date: Re: Out-of-bounds error when printing out a function value
- Previous by thread: Re: Out-of-bounds error when printing out a function value
- Next by thread: Re: Out-of-bounds error when printing out a function value
- Index(es):