Comments (9)
null
is a value, not a type. There is no name for the base type of the null
constant.
from umka-lang.
@vtereshkov thanks :D
edit: the commit notice is there already lol
from umka-lang.
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 Value
s.
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.
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.
off-topic but I got issue number 404 XD
from umka-lang.
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.
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.
As for
Nil
, I don't know what is better: to use your ownNil
as you defined it, or just setany
tonull
.
wait, I could make Nil
a ^null
instead, can't I?
from umka-lang.
Great! By the way, you can join our community chat if you wish: https://discord.gg/PcT7cn59h9
from umka-lang.
Related Issues (20)
- `a == b` is not equivalent to `b == a`
- Proposal: Anonymous struct embedding with method inheritance
- Umka API requires `main()` function in the main module.
- Optimize zeroing HOT 1
- No `libumka_static.a` in the Linux release folder
- Confusing error messages in type declarations HOT 1
- `append` stops after the first two appends on an empty dynarr HOT 3
- Allow implicit type casts for expression list items HOT 2
- Optimize `switch`
- Umka API doesn't work well under Windows with MSVC HOT 1
- Implement `sort()`
- Dynamic array literals in constant expressions
- Functions with variadic parameters inconsistently handle newlines.
- `return` doesn't check for overflow
- Structured constants are not constants
- Bad bit negation handling HOT 2
- Reassigning a field in a struct initializer should be an error.
- Convenience functions/macros for accessing function parameters from C HOT 1
- Can create arrays and maps of `void`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umka-lang.