-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtranspiler-refpersys.hh
152 lines (128 loc) · 3.91 KB
/
transpiler-refpersys.hh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// file misc-basile/transpiler-refpersys.hh
// SPDX-License-Identifier: GPL-3.0-or-later
/***
* © Copyright Basile Starynkevitch 2024
* program released under GNU General Public License
*
* this 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; either version 3, or (at your option) any later
* version.
*
* this 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.
***/
#ifndef TRANSPILER_REFPERSYS_INCLUDED
#define TRANSPILER_REFPERSYS_INCLUDED
#ifndef GIT_ID
#error GIT_ID should be defined by compilation command
#endif
#include <cstdint>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <set>
/// BSD like error functions
#include "err.h"
/// Boehm conservative garbage collector:
#include "gc_cpp.h"
/// GNU guile 3.0
#include "libguile.h"
// unistring library
#include "unistr.h"
// https://github.com/vimpunk/mio/tree/master/single_include/mio
#include "mio.hpp"
#define TRP_WARNING_AT_BIS(Fil,Lin,Fmt,...) do { \
warn("[from %s:%d]" Fmt "\n", \
(Fil),(Lin), __VA_ARGS__); } while (0)
#define TRP_WARNING_AT(Fil,Lin,Fmt,...) \
TRP_WARNING_AT_BIS(Fil,Lin,Fmt,__VA_ARGS__)
#define TRP_WARNING(Fmt,...) \
TRP_WARNING_AT(__FILE__,__LINE__,Fmt,##__VA_ARGS__)
#define TRP_EXIT_ERROR 100
#define TRP_ERROR_AT_BIS(Fil,Lin,Fmt,...) do { \
err(TRP_EXIT_ERROR,"[from %s:%d]" Fmt "\n", \
(Fil),(Lin), __VA_ARGS__); } while (0)
#define TRP_ERROR_AT(Fil,Lin,Fmt,...) \
TRP_ERROR_AT_BIS(Fil,Lin,Fmt,__VA_ARGS__)
#define TRP_ERROR(Fmt,...) \
TRP_ERROR_AT(__FILE__,__LINE__,Fmt,##__VA_ARGS__)
///naming convention: the trp_ prefix
extern "C" const char trp_git_id[];
extern "C" char*trp_progname;
extern "C" int64_t trp_prime_ranked (int rk);
extern "C" int64_t trp_prime_above (int64_t n);
extern "C" int64_t trp_prime_greaterequal_ranked (int64_t n, int*prank);
extern "C" int64_t trp_prime_below (int64_t n);
extern "C" int64_t trp_prime_lessequal_ranked (int64_t n, int*prank);
class Trp_InputFile;
class Trp_SymbolicName;
class Trp_Syntax;
class Trp_Token;
class Trp_StringToken;
class Trp_IntToken;
class Trp_NameToken;
class Trp_KeywordToken;
class Trp_DoubleToken;
class Trp_ChunkToken;
class Trp_InputFile : public mio::mmap_source
{
const std::string _inp_path;
const char* _inp_start;
const char* _inp_end;
const char* _inp_cur;
mutable const char* _inp_eol;
int _inp_line, _inp_col;
public:
Trp_InputFile(const std::string path);
Trp_Token*next_token(void);
void skip_spaces(void);
const char* eol(void) const;
ucs4_t peek_utf8(bool*goodp=nullptr) const;
ucs4_t peek_utf8(const char*&nextp) const;
int lineno() const
{
return _inp_line;
};
int colno() const
{
return _inp_col;
};
const std::string path() const
{
return _inp_path;
};
virtual ~Trp_InputFile();
}; // end Trp_InputFile
class Trp_SymbolicName : public gc_cleanup
{
const std::string _name_str;
static std::map<std::string,Trp_SymbolicName*> _name_dict_;
Trp_SymbolicName(const std::string);
public:
static Trp_SymbolicName* find(const std::string n);
}; // end Trp_SymbolicName
class Trp_Token : public gc_cleanup
{
private:
Trp_InputFile*tok_src;
int tok_lin, tok_col;
protected:
Trp_Token(Trp_InputFile*src, int lin, int col);
Trp_Token(Trp_InputFile*src, int col);
virtual ~Trp_Token();
}; // end class Trp_Token
class Trp_NameToken : public Trp_Token
{
}; // end class Trp_NameToken
#endif //TRANSPILER_REFPERSYS_INCLUDED
/****************
** for Emacs...
** Local Variables: ;;
** compile-command: "make transpiler-refpersys" ;;
** End: ;;
****************/
// end of file misc-basile/transpiler-refpersys.hh