Skip to content

Commit

Permalink
Move code to reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Apr 22, 2024
1 parent 58485a7 commit 4869804
Showing 1 changed file with 63 additions and 46 deletions.
109 changes: 63 additions & 46 deletions std/reflection.pr
Original file line number Diff line number Diff line change
@@ -1,86 +1,102 @@
export type Type = &interface {
let name: string
let module: string
let id: uint64
let size: size_t
let align: size_t
}

export type OpaqueT = struct {
name: string
module: string
const size: size_t = 1
const algin: size_t = 1
export def implements(a: Type, b: StructuralT) -> bool {
return false
}

export type BaseType = struct {
export def assignable(a: Type, b: Type) -> bool {
return false
}

export def == (a: Type, b: Type) -> bool {
return a.id == b.id
}
export def != (a: Type, b: Type) -> bool {
return not (a == b)
}

type BaseType = struct {
name: string
module: string
id: uint64
}

export type BoolT = struct {
&BaseType
export type OpaqueT = &struct {
BaseType
const size: size_t = 1
const algin: size_t = 1
}

export type BoolT = &struct {
BaseType
const size: size_t = size_of bool
const align: size_t = align_of bool
}
export type FloatT = struct {
&BaseType
export type FloatT = &struct {
BaseType
size: size_t
align: size_t
}
export type WordT = struct {
&BaseType
export type WordT = &struct {
BaseType
signed: bool
size: size_t
align: size_t
}
export type CharT = struct {
&BaseType
export type CharT = &struct {
BaseType
const size: size_t = size_of char
const align: size_t = align_of char
}

export type BoxType = struct {
&BaseType
BaseType
ref: Type
}

export type PointerT = struct {
export type PointerT = &struct {
BoxType
const size: size_t = size_of *
const align: size_t = align_of *
}
export type ReferenceT = struct {
export type ReferenceT = &struct {
BoxType
const size: size_t = size_of &
const align: size_t = align_of &
}
export type WeakReferenceT = struct {
export type WeakReferenceT = &struct {
BoxType
const size: size_t = size_of weak_ref
const align: size_t = align_of weak_ref
}
export type ArrayT = struct {
export type ArrayT = &struct {
BoxType
const size: size_t = size_of [*]
const align: size_t = align_of [*]
}
export type StaticArrayT = struct {
export type StaticArrayT = &struct {
BoxType
size: size_t
align: size_t
length: size_t
}

export type FunctionT = struct {
&BaseType
export type FunctionT = &struct {
BaseType
arguments: [Type]
returns: [Type]
const size: size_t = size_of ->
const align: size_t = align_of ->
}

export type RecordType = struct {
&BaseType
type RecordType = struct {
BaseType
size: size_t
align: size_t
members: [Field]
Expand All @@ -90,18 +106,18 @@ export type Field = struct {
offset: size_t
tpe: *Type
}
export type Struct = struct {
export type Struct = &struct {
RecordType
}
export type Union = struct {
export type Union = &struct {
RecordType
}

export type EnumValue = struct {
name: string
value: int64
}
export type EnumT = struct {
export type EnumT = &struct {
BaseType
signed: bool
size: size_t
Expand All @@ -116,41 +132,29 @@ export type Function = struct {
tpe: &FunctionT
}

export type InterfaceT = struct {
&BaseType
export type InterfaceT = &struct {
BaseType
const size: size_t = 0
const align: size_t = 0
members: [Function]
}

export type VariantT = struct {
&BaseType
export type VariantT = &struct {
BaseType
size: size_t
align: size_t
variants: [Type]
}

export type TupleT = struct {
&BaseType
export type TupleT = &struct {
BaseType
size: size_t
align: size_t
elements: [Type]
}

var types: [Type]

// Type registry functions
def load_types(size: size_t, data: *uint8, strings: *char) {
var index = 0
var offset = 0
while index < size {
index += 1
}
}

def type_id(index: size_t) -> Type {
return types ++ index
}
var upper_id: int64

type TypeKind = enum {
BOOL
Expand All @@ -171,4 +175,17 @@ type TypeKind = enum {
TYPE
VARIANT
TUPLE
}

// Type registry functions
def load_types(size: size_t, data: *uint8, strings: *char) {
var index = 0
var offset = 0
while index < size {
index += 1
}
}

def type_id(index: size_t) -> Type {
return types ++ index
}

0 comments on commit 4869804

Please sign in to comment.