Skip to content

Commit a1dc0c8

Browse files
committed
lc-compile: Generate/parse record type info in interface files
1 parent f98760e commit a1dc0c8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

libscript/src/script-module.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,24 @@ bool MCScriptWriteInterfaceOfModule(MCScriptModuleRef self, MCStreamRef stream)
13881388
}
13891389
break;
13901390
case kMCScriptTypeKindRecord:
1391-
// TODO - Records not yet supported
1392-
break;
1391+
{
1392+
auto t_record_type =
1393+
static_cast<MCScriptRecordType *>(t_type);
1394+
__enterln(stream, "record type %@", t_def_name);
1395+
for (uindex_t t_field = 0;
1396+
t_field < t_record_type->field_count;
1397+
++t_field)
1398+
{
1399+
MCAutoStringRef t_ftype_name;
1400+
type_to_string(self, t_record_type->fields[t_field].type,
1401+
&t_ftype_name);
1402+
__writeln(stream, "%@ as %@",
1403+
t_record_type->fields[t_field].name,
1404+
*t_ftype_name);
1405+
}
1406+
__leaveln(stream, "end type");
1407+
}
1408+
break;
13931409
default:
13941410
{
13951411
MCAutoStringRef t_sig;

toolchain/lc-compile/src/grammar.g

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@
227227
228228
'rule' ImportDefinition(-> type(Position, public, Id, handler(Position, foreign, Signature))):
229229
"foreign" @(-> Position) "handler" "type" Identifier(-> Id) Signature(-> Signature)
230-
230+
231+
'rule' ImportDefinition(-> type(Position, public, Id, record(Position, Fields))):
232+
"record" @(-> Position) "type" Identifier(-> Id) Separator
233+
RecordFields(-> Fields)
234+
"end" "type"
235+
231236
'rule' ImportDefinition(-> type(Position, public, Id, Type)):
232237
"type" @(-> Position) Identifier(-> Id) "is" Type(-> Type)
233238

0 commit comments

Comments
 (0)