serene/serene/src/types.h

100 lines
2.2 KiB
C

/* -*- C -*-
* Serene Programming Language
*
* Copyright (c) 2019-2024 Sameer Rahmani <lxsameer@gnu.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TYPES_H
#define TYPES_H
#include "serene/config.h"
#include <cstdint>
// Steps for defining a new type:
// 1. Define the type former
// 2. Type constructors
// 3. Type eliminators
// 4. Computation rule (eval rules)
// 5. (optional) A uniqueness principle
// Types to create:
// Universe
// Unit Type
// Dependent Function Type
// Pair (or even better, records)
typedef struct {
const TypeID id;
const char *name;
} Type;
typedef struct {
const Type type;
const void *data;
} Object;
static const Type type = {.id = TYPE, .name = "type"};
static const Type nil_type = {.id = NIL, .name = "nil"};
static const Type function_type = {.id = FN, .name = "function"};
static const Type protocol_type = {.id = PROTOCOL, .name = "protocol"};
static const Type int_type = {.id = INT, .name = "int"};
static const Type list_type = {.id = LIST, .name = "list"};
typedef struct {
const Type type;
const Type **args;
const Type *returnType;
} FunctionType;
typedef struct {
const Type type;
const char *name;
const FunctionType **functions;
} ProtocolType;
typedef struct {
const Type type;
const Type first;
const Type second;
} PairType;
typedef struct {
const PairType type;
void *first;
void *second;
} Pair;
typedef struct {
const Pair *head;
const unsigned int len;
} List;
typedef struct {
const char *name;
} Symbol;
typedef struct {
const char *data;
const unsigned int len;
} String;
typedef struct {
const long data;
} Number;
#endif