summaryrefslogtreecommitdiff
path: root/libtnsl/reflect/virtual.tnsl
blob: 6c0fd6d68c85a6a397081005e7db3618501f1236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/##
	Copyright 2021-2022 Kyle Gunger

	Dual licensed under the CDDL 1.0 and BSD 3-Clause licenses.

	This file may only be used in accordance with one of the two
	licenses.  You should have received a copy of each license with
	the source code.  In the event that you did not recieve a copy
	of the licenses, they may be found at the following URLs:

	CDDL 1.0:
	https://opensource.org/licenses/CDDL-1.0

	BSD 3-Clause:
	https://opensource.org/licenses/BSD-3-Clause

	THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
	WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
	EXPRESS OR IMPLIED
#/

/## _LIB_TABLE
	The array of library export trees.

	Convention:
		- index 0 is always reserved for language-specific types + libtnsl
		- index 0 module 0 represents the fundimental in-built types like int
#/
: extern const {}~library _LIB_TABLE

; raw struct library {
	# Version
	uint16
		major,
		minor,
		patch

	~sym_node
		root_node
}

/## tnsl.reflect._method
	Metadata for methods (can be decoded from library
	symbol tables).  Limits for methods defined here:
	- Max 2^8 inputs
	- Max 2^8 outputs
#/
; raw struct _method {
	{uint8}charp
		name,
	
	{uint8}~_type
		inputs,
		outputs,

	~void
		address
}

/## tnsl.reflect._member
	Metadata about struct members
#/
; raw struct _member {
	{uint8}charp
		name,
	
	_type
		member_type,

	uint
		byte_offset
}

/## tnsl.reflect.sym_node
	Represents a module in a symbol tree
#/
; raw struct sym_node {
	{uint8}charp
		name,
	
	uint16
		id,
	
	{}~sym_node
		sub_modules,

	{}~sym_type
		sub_types
}

/## tnsl.reflect.sym_type
	Represents a type in a symbol tree
#/
; raw struct sym_type {
	{uint8}charp
		name,
	
	{uint8}~sym_type
		super_types,

}

###############################
#  Traverse the Library Tree  #
###############################

/; get_sym_node (~sym_node root, uint16 mod_id) [~sym_node]
	/;loop (root != null)
		/; loop (uint16 sub = 0; sub < len `root.sub_modules) [sub++]
			/; if (mod_id < `root.sub_modules{sub}.id)
				/; if (sub == 0)
					; return null
				;/
				;root = `root.sub_modules{sub - 1}
				; continue 1
			;; else if (mod_id == `root.sub_modules{sub}.id)
				; return `root.sub_modules{sub}
			;/
		;/

		; break
	;/

	; return null
;/

/; get_sym_node (uint16 lib_id, mod_id) [~sym_node]

	;~library lib = _LIB_TABLE{lib_id}

	;return get_sym_node(`lib.root_node, mod_id)
;/

/; get_sym_type(uint16 lib_id, mod_id, typ_id) [~sym_type]

	;~library lib = _LIB_TABLE{lib_id}
	;~sym_node mod = get_sym_node(`lib.root_node, mod_id)

	;return `mod.sub_types{typ_id}
;/

/; get_sym_type(`const {}charp path) [~sym_type]

;/