Giter Site home page Giter Site logo

Comments (12)

munificent avatar munificent commented on July 28, 2024

Interesting. I wonder if we need another cast in the middle there to explicitly truncate it down to 32 bits. I can't repro this locally, but I can explain what's happening if that will help you look into this. Wren stores all values as a union of a Nan-tagged double and a 64-bit uint. The .bits gets the value as a 64-bit uint. The & ~(SIGN_BIT | QNAN) masks off all of the Nan stuff, leaving a 32-bit pointer stored in the rightmost bits of the 32-bit uint. Then we cast that to a pointer.

Can you try changing that line to:

#define AS_OBJ(value) ((Obj*)(uint32_t)((value).bits & ~(SIGN_BIT | QNAN)))

And see if that helps?

from wren.

minirop avatar minirop commented on July 28, 2024

it worked, but I also had to modify wren_value.h:L667, change 64 to 32.:

return (Value)(SIGN_BIT | QNAN | (uint32_t)(obj));

on another (not serious) point, I also hade to remove -fPIC since ยซ all code is position independent ยป.

from wren.

lluchs avatar lluchs commented on July 28, 2024

FWIW removing -Werror also makes it compile just fine (passes all tests).

from wren.

munificent avatar munificent commented on July 28, 2024

I may still need to do a fix here, but I just landed a bunch of patches to make Wren compile as C++. That involves changing the value representation, so this might be fixed. Or, who knows, made worse.

Any chance you could retest?

Thanks!

from wren.

minirop avatar minirop commented on July 28, 2024

it does not compile with g++, I get src/main.c:183:3: sorry, unimplemented: non-trivial designated initializers not supported.

If had to make a few changes to to make it compile:
change the C++ standard to C++11 and change the initialization of "config" to:

WrenConfiguration config { // no equals sign
    reallocateFn: NULL, // field in the same order as the struct
    // Since we're running in a standalone process, be generous with memory.
    initialHeapSize: 1024 * 1024 * 100,
    minHeapSize: 0,
    heapGrowthPercent: 0
  };

Also I know how to fix what causes the segfault of my first post, but I have no idea why. Just print the value of pinned in wrapPinObj:

void wrenPinObj(WrenVM* vm, Obj* obj, WrenPinnedObj* pinned)
{
  printf("%p\n", pinned); // <-- remove this line and it will segfault
  pinned->obj = obj;
  pinned->previous = vm->pinned;
  vm->pinned = pinned;
}

from wren.

munificent avatar munificent commented on July 28, 2024

I'd like to not require C++11 (although, of course, it should allow that). I just went ahead and removed that initializer and initialized the struct manually. Does that help?

from wren.

minirop avatar minirop commented on July 28, 2024

it does to compile in C++98 now.
About the casting in AS_OBJ and wrenObjectToValue, maybe using uintptr_t could help.

from wren.

munificent avatar munificent commented on July 28, 2024

it does to compile in C++98 now.

\o/

About the casting in AS_OBJ and wrenObjectToValue, maybe using uintptr_t could help.

Maybe, I think just truncating works too. I'll try to get a fix in soon for that.

from wren.

minirop avatar minirop commented on July 28, 2024

uintptr_t would help because it should equivalent to uint32_t on x86 and to uint64_t on x86_64. No need to another #if/#else to avoid the cast [...] of different size.

ps: I read the standard and it says that uintptr_t is optional, but so is uintN_t.

from wren.

munificent avatar munificent commented on July 28, 2024

OK, I think I got it. If not, let me know.

from wren.

minirop avatar minirop commented on July 28, 2024

compiled perfectly (C & C++) \o/

from wren.

munificent avatar munificent commented on July 28, 2024

๐ŸŽ‰

from wren.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.