-
Notifications
You must be signed in to change notification settings - Fork 1
/
compiler_idl_object.kalos
99 lines (95 loc) · 3.13 KB
/
compiler_idl_object.kalos
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
# Dynamic dispatch system for IDL objects. We don't support dynamic classes _yet_, but this is
# a start.
# Maps a list of simple properties to a list of values, returning the value at the matching index
fn map_object_property(props, property, list): any {
var prop;
var index = 0;
for prop in props {
if prop == property {
return list[index];
}
index = index + 1;
}
return "out of index {index} {props} {property}";
}
# Maps a list of lists to a list of objects, where the type of object is defined by the first
# value of the list. This is useful in the case where you have a list of objects of various types.
fn map_to_objects(list): object {
var out = [];
var obj;
for obj in list {
var object = kidl.create_list_object(obj[0], obj);
append(out, object);
}
return out;
}
# Maps a list of lists to a list of objects, where the type of the object is defined up-front.
fn map_to_objects_type(type, list): object {
var out = [];
var obj;
for obj in list {
var object = kidl.create_list_object(type, obj);
append(out, object);
}
return out;
}
on kidl.resolve_list_object_prop(type, property, list): any {
if type == "idl" {
if property == @@(.modules) {
return map_to_objects(list[3]);
}
return map_object_property([@@(.class), @@(.prefix), @@(.dispatch)], property, list);
}
if type == "module" {
if property == @@(.items) {
return map_to_objects(list[3]);
}
return map_object_property([@@(.class), @@(.invoke_id), @@(.name)], property, list);
}
if type == "fn" {
if property == @@(.overloads) {
return map_to_objects_type("overload", list[2]);
}
return map_object_property([@@(.class), @@(.name)], property, list);
}
if type == "overload" {
if property == @@(.args) {
return map_to_objects_type("arg", list[0]);
}
if property == @@(.binding) {
return kidl.create_list_object("binding", list[2]);
}
return map_object_property([@@(.args), @@(.return_type), @@(.binding)], property, list);
}
if type == "binding" {
return map_object_property([@@(.type), @@(.string), @@(.invoke_id)], property, list);
}
if type == "handler" {
if property == @@(.args) {
return map_to_objects_type("arg", list[4]);
}
return map_object_property([@@(.class), @@(.invoke_id), @@(.name), @@(.return_type)], property, list);
}
if type == "arg" {
return map_object_property([@@(.name), @@(.type), @@(.is_vararg)], property, list);
}
if type == "const" {
return map_object_property([@@(.class), @@(.name), @@(.type), @@(.value)], property, list);
}
if type == "object" {
if property == @@(.items) {
return map_to_objects(list[2]);
}
return map_object_property([@@(.class), @@(.name)], property, list);
}
if type == "prop" {
if property == @@(.read_binding) {
return kidl.create_list_object("binding", list[3]);
}
if property == @@(.write_binding) {
return kidl.create_list_object("binding", list[4]);
}
return map_object_property([@@(.class), @@(.name), @@(.type), @@(.read_binding), @@(.write_binding)], property, list);
}
return "unknown ({type})";
}