Skip to content

Commit 248e163

Browse files
committed
remove deadname
1 parent 7200d68 commit 248e163

39 files changed

+210
-216
lines changed

CMakeLists.txt

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
cmake_minimum_required(VERSION 3.17)
2-
project(dlang)
2+
project(scl
3+
LANGUAGES C CXX)
4+
enable_language(CXX)
5+
enable_language(C)
6+
37

48
set(CMAKE_CXX_STANDARD 20)
59

610
find_package(Threads REQUIRED)
711
link_libraries(dl)
812

9-
# set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lefence -g")
13+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lefence -g -Wall -Wextra")
1014
#set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
1115

12-
add_executable(dlang main.cpp parse/lex.cpp parse/parse.cpp vm/value.cpp vm/value.hpp vm/gc/gc.cpp vm/gc/gc.hpp compile/bytecode.hpp compile/bytecode.cpp compile/compile.cpp compile/compile.hpp compile/semantics/process_tree.hpp compile/semantics/syntax.hpp compile/semantics/syntax.cpp compile/semantics/process_tree.cpp util.cpp util.hpp vm/closure.cpp vm/closure.hpp vm/vm.cpp vm/vm.hpp vm/literal.cpp vm/literal.hpp vm/bc/read_bc.cpp vm/bc/read_bc.hpp vm/bc/exec_bc_instr.cpp vm/bc/exec_bc_instr.hpp vm/operators/operators.cpp vm/operators/operators.hpp vm/operators/math.cpp vm/operators/math.hpp vm/lambda_return.hpp vm/global_ids.cpp vm/global_ids.hpp vm/bc/bc.cpp vm/bc/bc.hpp vm/operators/refs.cpp vm/operators/refs.hpp debug.hpp vm/operators/internal_tools.cpp vm/operators/internal_tools.hpp vm/operators/cmp.cpp vm/operators/cmp.hpp vm/operators/logic.cpp vm/operators/logic.hpp vm/async.hpp lib/tsl/ordered_hash.h lib/tsl/ordered_map.hpp lib/tsl/ordered_set.hpp vm/value_types.hpp)
16+
add_executable(dlang main.cpp parse/lex.cpp parse/parse.cpp vm/value.cpp vm/value.hpp vm/gc/gc.cpp vm/gc/gc.hpp compile/bytecode.hpp compile/bytecode.cpp compile/compile.cpp compile/compile.hpp compile/semantics/process_tree.hpp compile/semantics/syntax.hpp compile/semantics/syntax.cpp compile/semantics/process_tree.cpp util.cpp util.hpp vm/closure.cpp vm/closure.hpp vm/vm.cpp vm/vm.hpp vm/literal.cpp vm/literal.hpp vm/bc/read_bc.cpp vm/bc/read_bc.hpp vm/bc/exec_bc_instr.cpp vm/bc/exec_bc_instr.hpp vm/operators/operators.cpp vm/operators/operators.hpp vm/operators/math.cpp vm/operators/math.hpp vm/lambda_return.hpp vm/global_ids.cpp vm/global_ids.hpp vm/bc/bc.cpp vm/bc/bc.hpp vm/operators/refs.cpp vm/operators/refs.hpp debug.hpp vm/operators/internal_tools.cpp vm/operators/internal_tools.hpp vm/operators/cmp.cpp vm/operators/cmp.hpp vm/operators/logic.cpp vm/operators/logic.hpp vm/async.hpp lib/tsl/ordered_hash.h lib/tsl/ordered_map.hpp lib/tsl/ordered_set.hpp vm/value_types.hpp compile/command.hpp compile/command.cpp)
1317

1418
target_link_libraries(dlang PRIVATE Threads::Threads)

compile/bytecode.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ std::string compile_text(std::vector<Command> cmds)
1919
}
2020

2121
// convert to compressed binary format
22-
// return number of bytes stored in ret
2322
std::vector<char> compile_bin(std::vector<Command> cmds)
2423
{
2524
std::vector<char> ret;
@@ -30,6 +29,5 @@ std::vector<char> compile_bin(std::vector<Command> cmds)
3029
for (int i = 0; i < n; i++)
3130
ret.push_back(buff[i]);
3231
}
33-
3432
return ret;
3533
}

compile/bytecode.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Created by tate on 01-05-20.
33
//
44

5-
#ifndef DLANG_BYTECODE_HPP
6-
#define DLANG_BYTECODE_HPP
5+
#ifndef SCL_BYTECODE_HPP
6+
#define SCL_BYTECODE_HPP
77

88
#include <string>
99
#include <vector>
@@ -15,8 +15,7 @@ std::string compile_text(std::vector<Command>);
1515

1616

1717
// convert to compressed binary format
18-
// return number of bytes stored in ret
1918
std::vector<char> compile_bin(std::vector<Command>);
2019

2120

22-
#endif //DLANG_BYTECODE_HPP
21+
#endif //SCL_BYTECODE_HPP

compile/command.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Created by tate on 29-04-20.
33
//
44

5-
#ifndef DLANG_COMMAND_HPP
6-
#define DLANG_COMMAND_HPP
5+
#ifndef SCL_COMMAND_HPP
6+
#define SCL_COMMAND_HPP
77

88
#include <cinttypes>
99
#include <cstdlib>
@@ -337,4 +337,4 @@ class Command {
337337
};
338338

339339

340-
#endif //DLANG_COMMAND_HPP
340+
#endif //SCL_COMMAND_HPP

compile/compile.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int64_t MutilatedSymbol::_uid = 20;
2626
// ParsedMacro::read_* : recursively convert the AST of the macro into a list of commands and populate structures
2727

2828
void ParsedMacro::read_num_lit(AST& tree) {
29-
DLANG_DEBUG_MSG("read_num_lit\n");
29+
SCL_DEBUG_MSG("read_num_lit\n");
3030
try { // try to parse int first
3131
// sigh...
3232
int64_t v;
@@ -64,7 +64,7 @@ void ParsedMacro::read_num_lit(AST& tree) {
6464
}
6565

6666
void ParsedMacro::read_string_lit(AST& tree) {
67-
DLANG_DEBUG_MSG("read_string_lit\n");
67+
SCL_DEBUG_MSG("read_string_lit\n");
6868

6969
// get string text
7070
std::string v = tree.token.token;
@@ -82,7 +82,7 @@ void ParsedMacro::read_string_lit(AST& tree) {
8282
}
8383

8484
void ParsedMacro::read_dot_op(AST& tree) {
85-
DLANG_DEBUG_MSG("read_dot_op");
85+
SCL_DEBUG_MSG("read_dot_op");
8686

8787
auto& obj = tree.members[0];
8888
auto& mem = tree.members[1];
@@ -122,7 +122,7 @@ void ParsedMacro::read_index_op(AST& tree){
122122
}
123123

124124
void ParsedMacro::read_decl(AST& tree) {
125-
DLANG_DEBUG_MSG("read_decl\n");
125+
SCL_DEBUG_MSG("read_decl\n");
126126
if (tree.members.empty()) {
127127
this->errors.emplace_back(SemanticError(
128128
"empty declaration", tree.token.pos, this->file_name));
@@ -134,7 +134,7 @@ void ParsedMacro::read_decl(AST& tree) {
134134
tree.members = tree.members[0].members;
135135

136136
for (auto& d : tree.members) {
137-
DLANG_DEBUG_MSG("read_decl:" <<debug_AST(d) <<std::endl);
137+
SCL_DEBUG_MSG("read_decl:" << debug_AST(d) << std::endl);
138138
if (d.type == AST::NodeType::IDENTIFIER) {
139139
if (keyword_values.find(d.token.token) != keyword_values.end()) {
140140
this->errors.emplace_back(SemanticError(
@@ -155,7 +155,7 @@ void ParsedMacro::read_decl(AST& tree) {
155155
const auto idid = this->declare_id(d.members[0].token.token);
156156
this->body.emplace_back(Command(Command::OPCode::DECL_ID, idid));
157157
this->read_tree(d);
158-
DLANG_DEBUG_MSG("read_decl: "<<d.members[0].token.token <<" = " <<idid <<std::endl);
158+
SCL_DEBUG_MSG("read_decl: " << d.members[0].token.token << " = " << idid << std::endl);
159159
} else {
160160
this->errors.emplace_back(SemanticError(
161161
"invalid assignment, expected identifier, got: " + (
@@ -171,7 +171,7 @@ void ParsedMacro::read_decl(AST& tree) {
171171
}
172172

173173
void ParsedMacro::read_id(AST& tree) {
174-
DLANG_DEBUG_MSG("read_id\n");
174+
SCL_DEBUG_MSG("read_id\n");
175175

176176
if (tree.token.token == "true") {
177177
this->body.emplace_back(Command::OPCode::VAL_TRUE);
@@ -202,7 +202,7 @@ void ParsedMacro::read_id(AST& tree) {
202202

203203
//
204204
void ParsedMacro::read_assignment(AST& t) {
205-
DLANG_DEBUG_MSG("read_assignment\n");
205+
SCL_DEBUG_MSG("read_assignment\n");
206206

207207
// a = 123
208208
if (t.members[0].type == AST::NodeType::IDENTIFIER) {
@@ -279,7 +279,7 @@ void ParsedMacro::read_assignment(AST& t) {
279279

280280
// operators defined only for convenience
281281
void ParsedMacro::read_operation(AST& t){
282-
DLANG_DEBUG_MSG("read_operation\n");
282+
SCL_DEBUG_MSG("read_operation\n");
283283
// TODO: replace with actual operator ID's from VM
284284
std::unordered_map<std::string, uint16_t> op_ids {
285285
{ "+", 0 },
@@ -320,7 +320,7 @@ void ParsedMacro::read_operation(AST& t){
320320
}
321321

322322
void ParsedMacro::read_macro_invoke(AST& t) {
323-
DLANG_DEBUG_MSG("read_macro_invoke\n");
323+
SCL_DEBUG_MSG("read_macro_invoke\n");
324324

325325
if (t.members.size() < 1) {
326326
this->errors.emplace_back(SemanticError(
@@ -345,7 +345,7 @@ void ParsedMacro::read_macro_invoke(AST& t) {
345345
}
346346

347347
void ParsedMacro::read_macro_lit(AST& tree) {
348-
DLANG_DEBUG_MSG("read_macro_lit\n");
348+
SCL_DEBUG_MSG("read_macro_lit\n");
349349

350350
// compile macro
351351
std::vector<ParsedMacro*> pps = this->parents;
@@ -365,7 +365,7 @@ void ParsedMacro::read_macro_lit(AST& tree) {
365365
}
366366

367367
void ParsedMacro::read_list_lit(AST& tree) {
368-
DLANG_DEBUG_MSG("read_list_lit\n");
368+
SCL_DEBUG_MSG("read_list_lit\n");
369369
// put elements onto stack
370370
for (auto& m : tree.members)
371371
read_tree(m);
@@ -374,7 +374,7 @@ void ParsedMacro::read_list_lit(AST& tree) {
374374
}
375375

376376
void ParsedMacro::read_statements(AST& tree) {
377-
DLANG_DEBUG_MSG("read_statements\n");
377+
SCL_DEBUG_MSG("read_statements\n");
378378
for (AST& statement : tree.members) {
379379
read_tree(statement);
380380
this->body.emplace_back(Command(Command::OPCode::CLEAR_STACK));
@@ -387,7 +387,7 @@ void ParsedMacro::read_statements(AST& tree) {
387387
}
388388

389389
void ParsedMacro::read_obj_lit(AST& tree) {
390-
DLANG_DEBUG_MSG("read_obj_lit");
390+
SCL_DEBUG_MSG("read_obj_lit");
391391

392392
// Handle {}
393393
if (tree.members.empty()) {
@@ -412,7 +412,7 @@ void ParsedMacro::read_obj_lit(AST& tree) {
412412
}
413413

414414
void ParsedMacro::read_tree(AST& tree) {
415-
DLANG_DEBUG_MSG("read_tree: " <<tree.type_name() <<std::endl);
415+
SCL_DEBUG_MSG("read_tree: " << tree.type_name() << std::endl);
416416
switch (tree.type) {
417417
case AST::NodeType::STATEMENTS:
418418
read_statements(tree);
@@ -570,20 +570,20 @@ void Program::load_file(const std::string& fname) {
570570

571571
// std::cout <<"tokenizing...";
572572

573-
DLANG_DEBUG_MSG("tokenizing...");
573+
SCL_DEBUG_MSG("tokenizing...");
574574
const auto toks = tokenize_stream(file);
575-
DLANG_DEBUG_MSG("done\n");
575+
SCL_DEBUG_MSG("done\n");
576576

577577

578-
DLANG_DEBUG_MSG("parsing...");
578+
SCL_DEBUG_MSG("parsing...");
579579
// std::cout <<"parsing...";
580580
AST main = parse(toks);
581581
// std::cout <<"done\n";
582-
DLANG_DEBUG_MSG("done\n");
582+
SCL_DEBUG_MSG("done\n");
583583

584584
// semantic analysis
585585
std::vector<SemanticError> errs = process_tree(main, fname);
586-
DLANG_DEBUG_MSG("After Semantics: " <<debug_AST(main) <<std::endl);
586+
SCL_DEBUG_MSG("After Semantics: " << debug_AST(main) << std::endl);
587587

588588
// implicit main macro
589589
ParsedMacro entry(main, fname,

compile/compile.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Created by tate on 02-05-20.
33
//
44

5-
#ifndef DLANG_COMPILE_HPP
6-
#define DLANG_COMPILE_HPP
5+
#ifndef SCL_COMPILE_HPP
6+
#define SCL_COMPILE_HPP
77

88
#include <cinttypes>
99
#include <string>
@@ -178,4 +178,4 @@ class Program {
178178
};
179179

180180

181-
#endif //DLANG_COMPILE_HPP
181+
#endif //SCL_COMPILE_HPP

compile/semantics/process_tree.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
#include "syntax.hpp"
88

9-
10-
119
std::vector<SemanticError> process_tree(AST& t, const std::string f) {
12-
1310
std::vector<SemanticError> ret;
1411
sem_convert_syntax(t, f, ret);
1512
return ret;

compile/semantics/process_tree.hpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// Created by tate on 02-05-20.
33
//
44

5-
#ifndef DLANG_PROCESS_TREE_HPP
6-
#define DLANG_PROCESS_TREE_HPP
7-
5+
#ifndef SCL_PROCESS_TREE_HPP
6+
#define SCL_PROCESS_TREE_HPP
87

98
#include <cinttypes>
109
#include <string>
1110
#include <unordered_map>
1211
#include <vector>
1312

14-
1513
#include "../../parse/parse.hpp"
1614

1715
/* Semantic Analysis
@@ -38,7 +36,6 @@
3836
* - replace object member requests with index operation (compile-time IC)
3937
*/
4038

41-
4239
class SemanticError {
4340
public:
4441
std::string msg;
@@ -49,7 +46,6 @@ class SemanticError {
4946
msg(message), pos(position), file(fname), is_warn(is_warning) {}
5047
};
5148

52-
5349
std::vector<SemanticError> process_tree(AST&, std::string);
5450

55-
#endif //DLANG_PROCESS_TREE_HPP
51+
#endif //SCL_PROCESS_TREE_HPP

compile/semantics/syntax.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Created by tate on 02-05-20.
33
//
44

5-
#ifndef DLANG_SYNTAX_HPP
6-
#define DLANG_SYNTAX_HPP
5+
#ifndef SCL_SEMANTICS_SYNTAX_HPP
6+
#define SCL_SEMANTICS_SYNTAX_HPP
77

88
#include "process_tree.hpp"
99

1010
// Basically finish parser's job
1111
void sem_convert_syntax(AST& t, const std::string& f, std::vector<SemanticError>& errs);
1212

13-
#endif //DLANG_SYNTAX_HPP
13+
#endif //SCL_SEMANTICS_SYNTAX_HPP

debug.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// Created by tate on 29-05-20.
33
//
44

5-
#ifndef DLANG_DEBUG_HPP
6-
#define DLANG_DEBUG_HPP
5+
#ifndef SCL_DEBUG_HPP
6+
#define SCL_DEBUG_HPP
77

8-
//#define DLANG_DEBUG_DEBUG_LOG 1
8+
#define SCL_DEBUG_DEBUG_LOG 1
99

10-
#ifdef DLANG_DEBUG_DEBUG_LOG
11-
#define DLANG_DEBUG_MSG(m) std::cout <<m;
12-
#define DLANG_DEBUG DLANG_DEBUG_MSG
10+
#ifdef SCL_DEBUG_DEBUG_LOG
11+
#define SCL_DEBUG_MSG(m) std::cout <<m;
12+
#define SCL_DEBUG DLANG_DEBUG_MSG
1313
#else
14-
#define DLANG_DEBUG_MSG(m)
14+
#define SCL_DEBUG_MSG(m)
1515
#endif
1616

17-
#endif //DLANG_DEBUG_HPP
17+
#endif //SCL_DEBUG_HPP

main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "vm/vm.hpp"
1111
#include "vm/bc/read_bc.hpp"
1212

13-
// dlang <cmd> <in> options
13+
// scl <cmd> <in> options
1414

1515
void print_help_msg(){
1616
std::cout <<"For now these are options:\n"
@@ -68,12 +68,12 @@ int main(int argc, char** argv) {
6868

6969
if (run) {
7070
std::ifstream bc_src = std::ifstream(fname);
71-
#ifdef DLANG_DEBUG
71+
#ifdef SCL_DEBUG
7272
std::cout <<"reading lit header... ";
7373
#endif
7474
std::vector<Literal>&& lits = read_lit_header(bc_src);
7575

76-
#ifdef DLANG_DEBUG
76+
#ifdef SCL_DEBUG
7777
std::cout <<"done\n";
7878
#endif
7979
std::vector<std::string> args(argc);

parse/lex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ std::vector<Token> tokenize_stream(std::istream& in) {
298298
return std::vector<Token>({ t });
299299
} else {
300300
// Next token
301-
#ifdef DLANG_DEBUG
301+
#ifdef SCL_DEBUG
302302
std::cout <<"new tok: " <<t.type <<':' <<t.token <<':' <<t.pos << '/' <<i <<std::endl;
303303
#endif
304304
ret.emplace_back(t);

parse/lex.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Created by tate on 27-04-20.
33
//
44

5-
#ifndef DLANG_LEX_HPP
6-
#define DLANG_LEX_HPP
5+
#ifndef SCL_LEX_HPP
6+
#define SCL_LEX_HPP
77

88
#include <string>
99
#include <vector>
@@ -39,4 +39,4 @@ class Token {
3939
// Lexer
4040
std::vector<Token> tokenize_stream(std::istream& in);
4141

42-
#endif //DLANG_LEX_HPP
42+
#endif //SCL_LEX_HPP

0 commit comments

Comments
 (0)