adding @Any directive

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-17 21:11:02 +01:00
parent 6085177982
commit 1584ec7563
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 21 additions and 5 deletions

View file

@ -447,7 +447,7 @@ main := fn(): uint {
return @inline(foo.foo) return @inline(foo.foo)
} }
$sum := fn(a: @any(), b: @TypeOf(a)): @TypeOf(a) return a + b $sum := fn(a: @Any(), b: @TypeOf(a)): @TypeOf(a) return a + b
// in module: foo.hb // in module: foo.hb
@ -473,6 +473,7 @@ arbitrary text
- `@inline(<func>, ...<args>)`: equivalent to `<func>(...<args>)` but function is guaranteed to inline, compiler will otherwise never inline - `@inline(<func>, ...<args>)`: equivalent to `<func>(...<args>)` but function is guaranteed to inline, compiler will otherwise never inline
- `@len(<ty>)`: reports a length of the type of indexing purposes or length ot a string constant - `@len(<ty>)`: reports a length of the type of indexing purposes or length ot a string constant
- `@kindof(<ty>)`: gives an u8 integer describing the kind of type as an index to array `[Builtin, Struct, Enum, Union, Ptr, Slice, Opt, Func, Template, Global, Const, Module]` - `@kindof(<ty>)`: gives an u8 integer describing the kind of type as an index to array `[Builtin, Struct, Enum, Union, Ptr, Slice, Opt, Func, Template, Global, Const, Module]`
- `@Any()`: generic parameter based on inference, TBD: this will ake arguments in the future that restrict what is accepted
#### c_strings #### c_strings
```hb ```hb

View file

@ -2862,7 +2862,16 @@ impl<'a> Codegen<'a> {
self.tys.tmp.args.push(ty); self.tys.tmp.args.push(ty);
let sym = parser::find_symbol(&fast.symbols, carg.id); let sym = parser::find_symbol(&fast.symbols, carg.id);
let ty = if ty == ty::Id::ANY_TYPE { let ty = if ty == ty::Id::ANY_TYPE {
todo!() let ty = self.infer_type(arg);
*self.tys.tmp.args.last_mut().unwrap() = ty;
self.ci.scope.vars.push(Variable::new(
carg.id,
ty,
false,
NEVER,
&mut self.ci.nodes,
));
continue;
} else if sym.flags & idfl::COMPTIME == 0 { } else if sym.flags & idfl::COMPTIME == 0 {
// FIXME: could fuck us // FIXME: could fuck us
continue; continue;
@ -2872,7 +2881,7 @@ impl<'a> Codegen<'a> {
arg.pos(), arg.pos(),
fa!( fa!(
"arbitrary comptime types are not supported yet \ "arbitrary comptime types are not supported yet \
(expected '{}' got '{}')", (expected '{}' got '{}')",
self.ty_display(ty::Id::TYPE), self.ty_display(ty::Id::TYPE),
self.ty_display(ty) self.ty_display(ty)
), ),

View file

@ -1,5 +1,11 @@
main: fun:
UN UN
code size: 9 main:
ADDI64 r254, r254, -8d
ST r31, r254, 0a, 8h
JAL r31, r0, :fun
LD r31, r254, 0a, 8h
ADDI64 r254, r254, 8d
code size: 64
ret: 0 ret: 0
status: Err(Unreachable) status: Err(Unreachable)