Skip to content

Commit 8ff7666

Browse files
pre stable 1.0
added types to variable typed operators type convertion
1 parent 993759c commit 8ff7666

7 files changed

Lines changed: 243 additions & 173 deletions

File tree

Error.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
#include "Error.h"
22

3-
const std::string Error::errorTypeWarn = "\x1B[35m";
4-
const std::string Error::errorTypeError = "\x1B[31m";
5-
const std::string Error::errorTypeInfo = "\x1B[33m";
6-
const std::string Error::errorTypeValid = "\x1b[32m";
7-
const std::string Error::errorTypeNormal = "\x1B[37m";
3+
const std::string Error::errorTypeWarn = "\x1B[35m";
4+
const std::string Error::errorTypeError = "\x1B[31m";
5+
const std::string Error::errorTypeInfo = "\x1B[33m";
6+
const std::string Error::errorTypeValid = "\x1b[32m";
7+
const std::string Error::errorTypeNormal = "\x1B[37m";
8+
const int Error::typeWarn = 0;
9+
std::map<int, bool> Error::enabledWarns = {
10+
{ typeWarn, true }
11+
};
12+
13+
void warn(int typewarn, int line, std::stringstream message) {
14+
if (Error::enabledWarns[typewarn]) {
15+
std::cout << Error::errorTypeWarn << "Warning at line " << Error::errorTypeNormal << line << " " << message.str() << std::endl;
16+
}
17+
}

Error.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22
#include <string>
3+
#include <iostream>
4+
#include <sstream>
5+
#include <map>
36

47
namespace Error
58
{
@@ -8,5 +11,9 @@ namespace Error
811
extern const std::string errorTypeInfo;
912
extern const std::string errorTypeValid;
1013
extern const std::string errorTypeNormal;
14+
extern const int typeWarn;
15+
16+
extern std::map<int, bool> enabledWarns;
1117
}
1218

19+
void warn(int warnType, int line, std::stringstream message);

LScc.cpp

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,29 @@
55
/*
66
todo:
77
8-
finish types
9-
signed unsigned (£ = unsigned)
10-
11-
preprocessors {
8+
fixed types
129
13-
def preprocessor():
14-
a b
15-
if a
16-
//
17-
else
18-
//
19-
endif
20-
}
10+
signed unsigned (£ = unsigned)
2111
2212
type child token(type...)
2313
2414
struct token
2515
2616
typedef token1 token2
2717
28-
fixed int a = 0
29-
float a = 0.5 // error invalid convertion of float to int
30-
int a = 0
31-
float a = 0.5 // ok
32-
33-
with "stdlang.pclslib"
34-
extern printf
35-
36-
def mainCRTStartup():
37-
start()
38-
return(0)
39-
end
40-
41-
def start():
42-
printf("%d", 0.5)
43-
return(0)
44-
end
18+
preprocessors
4519
4620
*/
4721

22+
std::map < string, Basetype > type_dict = {
23+
{ "float", Basetype::_float },
24+
{ "int", Basetype::_int },
25+
{ "str", Basetype::_string },
26+
{ "bool", Basetype::_bool },
27+
{ "ptr", Basetype::_ptr },
28+
{ "any", Basetype::_any }
29+
};
30+
4831
std::map < string, Tokentypes > tokens_dict = {
4932
{ "def", Tokentypes::definition },
5033
{ "end", Tokentypes::end },
@@ -55,14 +38,8 @@ std::map < string, Tokentypes > tokens_dict = {
5538
{ ")", Tokentypes::parameter_end },
5639
{ ",", Tokentypes::separator },
5740
{ ".", Tokentypes::float_separator },
58-
{ ";", Tokentypes::line_separator },
41+
{ ";", Tokentypes::lf },
5942
{ "\\", Tokentypes::line_concat },
60-
{ "float", Tokentypes::type },
61-
{ "int", Tokentypes::type },
62-
{ "str", Tokentypes::type },
63-
{ "bool", Tokentypes::type },
64-
{ "ptr", Tokentypes::type },
65-
{ "any", Tokentypes::type },
6643
{ "global", Tokentypes::global },
6744
{ "local", Tokentypes::local },
6845
{ "\n", Tokentypes::lf },
@@ -86,13 +63,9 @@ std::map < string, Tokentypes > tokens_dict = {
8663
{ "!<", Tokentypes::jnl },
8764
{ "<=", Tokentypes::jle },
8865
{ "!<=", Tokentypes::jnle },
89-
{ "!", Tokentypes::inv },
90-
{ "\\n", Tokentypes::strret },
91-
{ "\\0", Tokentypes::strterm },
92-
{ "\\", Tokentypes::strback }
66+
{ "!", Tokentypes::inv }
9367
};
9468

95-
9669
int ROspaces = 0;
9770
string section_data = "SECTION .data:\n";
9871
string section_text = "SECTION .text:\n";
@@ -150,7 +123,10 @@ int main(int argc, char** argv)
150123
-cc calling convention[SysVi386, SysV, M64] | default: SysV \n\
151124
-f format[elf32, elf64, elfx32, win32, win64] | default: elf64 \n\
152125
-n no start function \n\
153-
-s save asm file\n";
126+
-s save asm file \n\
127+
\n\
128+
----warnings options---- \n\
129+
--w-type disable type convertion warnings \n";
154130
}
155131
else {
156132
size_t in1 = in("-i", argv, argc);
@@ -194,11 +170,16 @@ int main(int argc, char** argv)
194170
Cconvention = "SysV";
195171
}
196172

173+
in1 = in("--w-type", argv, argc);
174+
if (in1 != -1) {
175+
Error::enabledWarns[Error::typeWarn] = false;
176+
}
177+
197178
if (Fformat == "elf64" || Fformat == "win64") {
198-
REG.insert(REG.end(), { "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "rsp", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "xmm0", "xmm1", "xmm2", "xmm3", "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp", "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" });
179+
REG.insert(REG.end(), { "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "rsp", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "xmm0", "xmm1", "xmm2", "xmm3", "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp", "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d", "cr0", "cr2", "cr3", "cr4", "cr8" });
199180
}
200181
elif(Fformat == "elf32" || Fformat == "win32" || Fformat == "elfx32") {
201-
REG.insert(REG.end(), { "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp", "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" });
182+
REG.insert(REG.end(), { "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp", "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d", "cr0", "cr2", "cr3", "cr4", "cr8"});
202183
}
203184
else {
204185
cout << "Error: invalid format \"" << Fformat << "\" !" << endl;
@@ -229,6 +210,7 @@ int main(int argc, char** argv)
229210
for (size_t i = 0; i < pcllibs.size(); i++) {
230211
tokenlibs.clear();
231212
tokenlibs = tokenize(pcllibs[i]);
213+
fuse_symbols(&tokenlibs);
232214
identify_tokens(&tokenlibs, true);
233215
clib.precompile_lib(tokenlibs);
234216
}

0 commit comments

Comments
 (0)