Giter Site home page Giter Site logo

Comments (6)

felipensp avatar felipensp commented on June 3, 2024

@spytheman feel free to edit the FR with your suggestions.

from v.

enghitalo avatar enghitalo commented on June 3, 2024

What is the chance of have something like

struct TypeData {
...
nr_muls int
}

This can help to avoid need use

#ifdef __GNUC__
#define IS_POINTER(x) __builtin_types_compatible_p(__typeof__(x), void *)
#else
#define IS_POINTER(x) (((void*)(x) == (void*)0) != ((void*)&(x) == (void*)0))
#endif

To verify if it is pointer

from v.

felipensp avatar felipensp commented on June 3, 2024

What is the chance of have something like

struct TypeData {
...
indirections int
}

This can help to avoid need use

#ifdef __GNUC__
#define IS_POINTER(x) __builtin_types_compatible_p(__typeof__(x), void *)
#else
#define IS_POINTER(x) (((void*)(x) == (void*)0) != ((void*)&(x) == (void*)0))
#endif

To verify if it is pointer

Yes, the indirectionsone from FieldData must be in the new TypeData and an is_ptr field too.

from v.

enghitalo avatar enghitalo commented on June 3, 2024

@felipensp Just for FieldData? I was thing in something like

fn main() {
	a := 'a'
	pa := &a
	ppa := &pa
	pppa := &ppa

	assert count_nr_muls(a) == 0
	assert count_nr_muls(pa) == 1
	assert count_nr_muls(ppa) == 2
	assert count_nr_muls(pppa) == 3
}

fn count_nr_muls[T](val T) int {
	return typeof[T]().nr_muls
}

from v.

spytheman avatar spytheman commented on June 3, 2024

Use typeof[T](), not typeof(T) .

from v.

enghitalo avatar enghitalo commented on June 3, 2024

Use typeof[T](), not typeof(T) .

Please try again.](code.v:14:21: error: invalid field .nr_muls for type typeof[T]())

from v.

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.