Giter Site home page Giter Site logo

Comments (9)

vtereshkov avatar vtereshkov commented on July 22, 2024 1

null is a value, not a type. There is no name for the base type of the null constant.

from umka-lang.

thacuber2a03 avatar thacuber2a03 commented on July 22, 2024 1

@vtereshkov thanks :D
edit: the commit notice is there already lol

from umka-lang.

vtereshkov avatar vtereshkov commented on July 22, 2024

No, this is not possible. The feature would have a high runtime cost. It has been considered in #179 and rejected.

However, I cannot see why you need this hierarchy of interfaces at all. Your Value is just a VM stack slot, not even an AST node. It's quite "passive", i.e., it shouldn't know how to evaluate() itself, as this is done by the appropriate VM instructions. Everything on the stack, including functions and objects, can be Values.

My radical suggestion is:

type Value* = any

Thus you also get the type information out of the box. Why write

if a.valueType() == .String && b.valueType() == .String {
	push(value::String(a) + value::String(b))
}

if you can write

    if lhs, rhs := ^str(a), ^str(b); lhs != null && rhs != null {
        push(lhs^ + rhs^)
    }

?

from umka-lang.

thacuber2a03 avatar thacuber2a03 commented on July 22, 2024

Thus you also get the type information out of the box. Why write

if a.valueType() == .String && b.valueType() == .String {
    push(value::String(a) + value::String(b))
}

if you can write

if lhs, rhs := ^str(a), ^str(b); lhs != null && rhs != null {
    push(lhs^ + rhs^)
}

?

what about the values that aren't base types, like value::Nil:

type Nil* = struct {}

or, say, this Function type:

type Function* = struct {
	arity: uint
	chunk: chunk::Chunk
	name: value::String
}

from umka-lang.

thacuber2a03 avatar thacuber2a03 commented on July 22, 2024

off-topic but I got issue number 404 XD

from umka-lang.

thacuber2a03 avatar thacuber2a03 commented on July 22, 2024

Thus you also get the type information out of the box. Why write

if a.valueType() == .String && b.valueType() == .String {
    push(value::String(a) + value::String(b))
}

if you can write

if lhs, rhs := ^str(a), ^str(b); lhs != null && rhs != null {
    push(lhs^ + rhs^)
}

?

what about the values that aren't base types, like value::Nil:

type Nil* = struct {}

or, say, this Function type:

type Function* = struct {
	arity: uint
	chunk: chunk::Chunk
	name: value::String
}

nevermind, did not read this:

Everything on the stack, including functions and objects, can be Values.

let me try that and see if it works out
I, however, want to keep the print and isFalsey methods

from umka-lang.

vtereshkov avatar vtereshkov commented on July 22, 2024

what about the values that aren't base types, like value::Nil ... or, say, this Function type:

You can convert any type (not necessarily a basic type) to any. So you can put your Function into any and then check if it's indeed your Function:

val := any(Function{/*...*/})
//...
if f := ^Function(val); f != null {
    call(f^)
}

As for Nil, I don't know what is better: to use your own Nil as you defined it, or just set any to null.

Anyway, I think you needn't reinvent RTTI.

off-topic but I got issue number 404 XD

Also noticed this :)

from umka-lang.

thacuber2a03 avatar thacuber2a03 commented on July 22, 2024

As for Nil, I don't know what is better: to use your own Nil as you defined it, or just set any to null.

wait, I could make Nil a ^null instead, can't I?

from umka-lang.

vtereshkov avatar vtereshkov commented on July 22, 2024

Great! By the way, you can join our community chat if you wish: https://discord.gg/PcT7cn59h9

from umka-lang.

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.