NewLang Project
Yet another programm language
Main Page
Namespaces
Classes
Files
File List
File Members
Loading...
Searching...
No Matches
lib
module.h
Go to the documentation of this file.
1
#pragma once
2
#ifndef INCLUDED_MODULE_CPP_
3
#define INCLUDED_MODULE_CPP_
4
5
//#include "pch.h"
6
#include "
nlc-rt.h
"
7
#include "
term.h
"
8
#include "
context.h
"
9
10
#include <
types.h
>
11
//#include <object.h>
12
//#include "runtime.h"
13
//#include "context.h"
14
15
namespace
newlang
{
16
17
18
class
Module
:
public
std::map<std::string, VariablePair> {
19
public
:
20
RunTime
*
m_rt
;
21
22
std::string
m_file
;
23
std::string
m_md5
;
24
std::string
m_timestamp
;
25
std::string
m_version
;
26
// std::vector<llvm::orc::ThreadModule> m_llvm_module;
27
// std::string m_source;
28
// bool m_is_main;
29
30
TermPtrConst
m_ast
;
31
public
:
32
33
Module
(
RunTime
*rt =
nullptr
,
TermPtr
ast =
nullptr
);
34
// static void RegisterStaticObject(Module &module, TermPtr term, Context *ctx);
35
36
// bool Load(Context & ctx, const char * path, bool is_main) {
37
// m_is_main = is_main;
38
// m_file = path;
39
// // m_var_name = ExtractModuleName(path);
40
// auto file = llvm::sys::fs::openNativeFileForRead(path);
41
// if (!file) {
42
// // LOG_ERROR("Error open module '%s' from file %s!", m_var_name.c_str(), path);
43
// return false;
44
// }
45
//
46
//
47
// char buffer[llvm::sys::fs::DefaultReadChunkSize];
48
// llvm::MutableArrayRef<char> Buf(buffer, llvm::sys::fs::DefaultReadChunkSize);
49
//
50
// llvm::Expected<size_t> readed(0);
51
// do {
52
// readed = llvm::sys::fs::readNativeFile(*file, Buf);
53
// if (!readed) {
54
// // LOG_ERROR("Error read module '%s' from file %s!", m_var_name.c_str(), path);
55
// return false;
56
// }
57
// m_source.append(Buf.data(), *readed);
58
// } while (*readed);
59
//
60
// llvm::sys::fs::file_status fs;
61
// std::error_code ec = llvm::sys::fs::status(*file, fs);
62
// if (ec) {
63
// m_timestamp = "??? ??? ?? ??:??:?? ????";
64
// } else {
65
// // auto tp = fs.getLastModificationTime();
66
// time_t temp = llvm::sys::toTimeT(fs.getLastModificationTime());
67
// struct tm * timeinfo;
68
// timeinfo = localtime(&temp);
69
// m_timestamp = asctime(timeinfo);
70
// m_timestamp = m_timestamp.substr(0, 24); // Remove \n on the end line
71
//
72
// }
73
//
74
// llvm::ErrorOr<llvm::MD5::MD5Result> md5 = llvm::sys::fs::md5_contents((int) *file);
75
// if (!md5) {
76
// m_md5 = "????????????????????????????????";
77
// } else {
78
// llvm::SmallString<32> hash;
79
// llvm::MD5::stringifyResult((*md5), hash);
80
// m_md5 = hash.c_str();
81
// }
82
// llvm::sys::fs::closeFile(*file);
83
//
84
// // m_var_is_init = true;
85
// return true;
86
// }
87
88
virtual
~Module
() {
89
90
}
91
92
std::string
Dump
() {
93
std::string
result
;
94
95
for
(
auto
&elem : *
this
) {
96
result
+=
'\n'
;
97
result
+= elem.first;
98
}
99
100
return
result
;
101
}
102
103
};
104
105
106
}
107
108
109
#endif
//INCLUDED_MODULE_CPP_
newlang::Module
Definition
module.h:18
newlang::Module::m_ast
TermPtrConst m_ast
Definition
module.h:30
newlang::Module::~Module
virtual ~Module()
Definition
module.h:88
newlang::Module::Dump
std::string Dump()
Definition
module.h:92
newlang::Module::m_rt
RunTime * m_rt
Definition
module.h:20
newlang::Module::m_file
std::string m_file
Definition
module.h:22
newlang::Module::m_md5
std::string m_md5
Definition
module.h:23
newlang::Module::m_timestamp
std::string m_timestamp
Definition
module.h:24
newlang::Module::m_version
std::string m_version
Definition
module.h:25
newlang::RunTime
Definition
runtime.h:189
context.h
result
int result
Definition
lexer.l:367
newlang
Definition
nlc.h:59
newlang::TermPtr
std::shared_ptr< Term > TermPtr
Definition
variable.h:33
newlang::TermPtrConst
std::shared_ptr< const Term > TermPtrConst
Definition
variable.h:34
newlang::ObjType::Module
@ Module
nlc-rt.h
term.h
types.h
Generated by
1.11.0