Commit e66b7d23 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

add descriptor for primitive types

parent 58d57552
......@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "khash.h"
#include "mem.h"
// shorthand way to get the key from hashtable or null (0) if not found
#define kh_get_val(kname, hash, key) ({k=kh_get(kname, hash, key);(k!=kh_end(hash)?kh_val(hash,k):0);})
......@@ -32,3 +33,29 @@ FunFlags* find_desc(char* fn)
return kh_get_val(khStrPtr, funHash, fn);
}
FunEntry* alloc_prim(char* name)
{
int len = strlen(name);
FunEntry* entry = (FunEntry*) alloc_desc(sizeof(FunEntry) + len + 1);
entry->flags.type = FT_FUN;
entry->flags.arity = 0;
memcpy(entry->name, name, len + 1);
return entry;
}
void init_desc()
{
__INT__ = alloc_prim("INT");
__BOOL__ = alloc_prim("BOOL");
__CHAR__ = alloc_prim("CHAR");
__REAL__ = alloc_prim("REAL");
__STRING__ = alloc_prim("STRING");
__ARRAY__ = alloc_prim("ARRAY");
}
struct FunEntry* __INT__;
struct FunEntry* __BOOL__;
struct FunEntry* __CHAR__;
struct FunEntry* __REAL__;
struct FunEntry* __STRING__;
struct FunEntry* __ARRAY__;
\ No newline at end of file
......@@ -6,7 +6,7 @@
#define FT_CAF 3
#define FT_CAF_REDUCED 4
#define FT_FUN 5
#define FT_FUN_SLICE 6
#define FT_SLICE 6
struct FunFlags
{
......@@ -22,10 +22,10 @@ struct FunEntry
char name[];
};
struct FunSliceEntry
struct SliceEntry
{
struct FunFlags flags;
struct FunEntry* fun;
void* forward_ptr; // FunEntry or ADTEntry
};
struct ADTEntry
......@@ -57,7 +57,16 @@ struct RecordEntry
char name[];
};
void init_desc();
void add_desc(char* fn, FunFlags* desc);
FunFlags* find_desc(char* fn);
extern struct FunEntry* __INT__;
extern struct FunEntry* __BOOL__;
extern struct FunEntry* __CHAR__;
extern struct FunEntry* __REAL__;
extern struct FunEntry* __STRING__;
extern struct FunEntry* __ARRAY__;
#endif // __DESC_H
\ No newline at end of file
......@@ -9,7 +9,8 @@
int main()
{
init_mem();
init_desc();
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));
......
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