Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions altlib/test_allocator.al
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
include altlib."posix.al"

def PROT_READ := 1
def PROT_WRITE := 2
def MAP_PRIVATE := 2
def MAP_ANONYMOUS := 32

typedef TestAllocator := #S {
data: #1I,
size: #I,
Expand All @@ -11,10 +16,6 @@ typedef TestAllocator := #S {
//* #1TestAllocator.init
//* Initializes an allocator with size `size` and allocates a buffer.
func ^#1TestAllocator.init(this #1TestAllocator, size #I) -> #V {
def PROT_READ := 1
def PROT_WRITE := 2
def MAP_PRIVATE := 2
def MAP_ANONYMOUS := 32
this->data& <- posix_mmap(0 as #1I, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
this->size& <- 0
this->reserved& <- size
Expand Down
16 changes: 16 additions & 0 deletions compiler/include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#include <stdbool.h>

enum NodeType {
NodeModule,
NodeBlock,
NodeInclude,
NodeTest,
NodeIf,
NodeWhile,
NodeFunctionDefinition,
NodePrototype,
NodeGlobalDefinition,
NodeDefinition,
NodeTypeDefinition,
NodeReturn,
Expand Down Expand Up @@ -57,13 +59,15 @@ enum NodeType {
};

struct Node;
struct Module;
struct Block;
struct Include;
struct Test;
struct If;
struct While;
struct FunctionDefinition;
struct Prototype;
struct GlobalDefinition;
struct Definition;
struct TypeDefinition;
struct Return;
Expand Down Expand Up @@ -94,6 +98,7 @@ struct FunctionSignature {
struct Vector identifiers;
struct Vector types;
struct TypeNode *return_type;
bool propagate_allocator;
};

struct Node {
Expand All @@ -103,6 +108,10 @@ struct Node {
enum NodeType node_type;
};

struct Module {
struct Vector statement_list;
};

struct Block {
struct Vector statement_list;
const char *label;
Expand Down Expand Up @@ -144,6 +153,12 @@ struct Prototype {
struct FunctionSignature *signature;
};

struct GlobalDefinition {
const char *identifier;
struct TypeNode *type;
struct Node *value;
};

struct Definition {
const char *identifier;
struct TypeNode *type;
Expand Down Expand Up @@ -220,6 +235,7 @@ struct Sizeof {
struct FunctionCall {
struct Node *function;
struct Vector arguments;
struct Node *propagate_allocator;
};

struct MethodCall {
Expand Down
20 changes: 14 additions & 6 deletions compiler/include/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include <typeast.h>
#include <stdbool.h>

struct GlobalVariableInfo {
const char *name;
struct TypeNode *type;
};

struct VariableInfo {
const char *name;
struct TypeNode *type;
Expand Down Expand Up @@ -32,6 +37,7 @@ struct LabelInfo {

struct CPContext {
struct Vector variables;
struct Vector global_variables;
struct Vector types;
struct Vector functions;
struct Vector block_labels;
Expand All @@ -55,11 +61,13 @@ struct CPContext {
struct TypeNode *node_void;
struct TypeNode *node_int;
struct TypeNode *node_char;
struct TypeNode *node_allocator;
};

struct VariableInfo *context_find_variable (struct CPContext*, const char*);
struct TypeInfo *context_find_type (struct CPContext*, const char*);
struct FunctionInfo *context_find_function (struct CPContext*, const char*);
struct FunctionInfo *context_find_method (struct CPContext*, const char*, struct TypeNode*);
struct LabelInfo *context_find_block_label (struct CPContext*, const char*);
struct LabelInfo *context_find_loop_label (struct CPContext*, const char*);
struct GlobalVariableInfo *context_find_global_variable(struct CPContext*, const char*);
struct VariableInfo *context_find_variable (struct CPContext*, const char*);
struct TypeInfo *context_find_type (struct CPContext*, const char*);
struct FunctionInfo *context_find_function (struct CPContext*, const char*);
struct FunctionInfo *context_find_method (struct CPContext*, const char*, struct TypeNode*);
struct LabelInfo *context_find_block_label (struct CPContext*, const char*);
struct LabelInfo *context_find_loop_label (struct CPContext*, const char*);
1 change: 1 addition & 0 deletions compiler/include/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum TokenType {
TokenDereference,
TokenGetField,
TokenSharp,
TokenAt,
TokenPlus,
TokenMinus,
TokenMult,
Expand Down
2 changes: 2 additions & 0 deletions compiler/include/typeast.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <stdbool.h>
#include <vector.h>

enum TypeNodeType {
Expand Down Expand Up @@ -46,6 +47,7 @@ struct TypeStruct {
struct TypeFunction {
struct Vector types;
struct TypeNode *return_type;
bool propagate_allocator;
};

struct TypeIdentifier {
Expand Down
Loading