summaryrefslogtreecommitdiff
path: root/src/data/EpicInclude/stdagda.c
blob: 9ebec534059848c3fa3e8fa2db5da969a564d647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "stdagda.h"
#include <stdlib.h>
#include <unistd.h>
#include <gmp.h>
#include <string.h>
#include <sys/time.h>
#include <locale.h>
//#include "closure.h"


#define _UNICODE
#define UNICODE

void wputStr(char* s) { wprintf(L"%s",s); }

int eqString(char *x, char *y) {
    return strcmp(x, y) == 0;
}

VAL bigZeroRep;
VAL bigOneRep;

VAL bigZero() { return bigZeroRep;}
VAL bigOne() {return bigOneRep;}

void init(void) {
  setlocale(LC_CTYPE, "");

  bigZeroRep = NEWBIGINTVALI(0);
  bigOneRep  = NEWBIGINTVALI(1);
}

void printCharRep(int c) {

  wprintf(L"%lc", c);
}

int bigToInt(VAL n) {
  return (int) mpz_get_si(*(GETBIGINT(n)));
}

VAL intToBig(int n) {
  return NEWBIGINTVALI(n);
} 

VAL getArgBig(VAL num) {
  return evm_getArg(bigToInt(num));
}

VAL numArgsBig(void) { 
  return NEWBIGINTVALI(epic_numArgs());
}

char* charToStr(int x)
{
    char* buf = EMALLOC(2*sizeof(char));
    buf[0] = (char)x; buf[1] = '\0';
    return buf;
}

int eof() { return EOF; }

int charAtBig(char* str, VAL n)
{
    return (int)str[bigToInt(n)];
}

int charAt(char* str, int n) { return (int)str[n]; }

#define STRING_BUFFER_SIZE 1024

int eofstdin() { return feof(stdin);}

char* readStrChunk() { return freadStrChunk(stdin); }

char* freadStrChunk(FILE* f) {
  char* in = EMALLOC(sizeof(char)*STRING_BUFFER_SIZE);
  fgets(in,STRING_BUFFER_SIZE,f);
  return in;
}

void** newArray(VAL size)
{
  return EMALLOC(sizeof(void*)*bigToInt(size));
}

void* arrayIndex(void** array, VAL i)
{
  return array[bigToInt(i)];
}

void setArrayIndex(void** array, VAL i, void* val)
{
  array[bigToInt(i)] = val;
}