Commit 58d57552 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

support CAFs

parent 258b1d18
......@@ -10,8 +10,8 @@ int main()
{
init_mem();
char* stream = "40 R10 example._R2 1 9 example.a9 example.b46 F13 example.Start0 0 AF10 example._R2 LI1 LI2 29 F4 main0 0 VF13 example.Start";
char* stream = "40 R10 example._R2 1 9 example.a9 example.b37 F12 example.g_482 3 AF3 add2 VA0 VA1 39 C9 example.fAF12 example.g_482 LI1 LI2 55 F13 example.Start0 0 AF10 example._R2 LI1 VF9 example.f29 F4 main0 0 VF13 example.Start";
int res = parse(&stream, strlen(stream));
printf("%d", res);
......
......@@ -65,6 +65,27 @@ int parseDef1(char** ptr)
add_desc(entry->name, (FunFlags*) entry);
break;
}
case 'C': // CAF
{
// example.f =: example.g_48 1 2
// 39 C9 example.fAF12 example.g_482 LI1 LI2
int nameLength;
if(!parseInt(ptr, &nameLength)) return 0;
CAFEntry* entry = (CAFEntry*) alloc_desc(sizeof(CAFEntry) + nameLength + 1);
entry->flags.type = FT_CAF;
entry->flags.arity = 0;
copyName(entry->name, ptr, nameLength);
// set the continuation for stage 2
entry->body = *ptr;
add_desc(entry->name, (FunFlags*) entry);
break;
}
case 'A': // ADT
{
......
......@@ -30,6 +30,9 @@ sFunc ctx (FTFunc name body params) a
# ctx = {ctx & vars = addVars ctx.vars 0 params}
= a <++ "F" <++ sText (unpackVar name) <++ sNum (length params) <++ sNum (calcStrictness params) <++ sTerm ctx body
sFunc ctx (FTCAF name body) a
= a <++ "C" <++ sText (unpackVar name) <++ sTerm ctx body
sFunc ctx (FTRecord name fields) a
= a <++ "R" <++ sText (unpackVar name) <++ sNum (length fields) <++ sNum (calcStrictness fields) <++ sList0 sText (map unpackVar fields)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment