✨ change dir stl -> std
This commit is contained in:
parent
a7a2f47d1e
commit
ba6b7cd05c
|
@ -86,7 +86,7 @@ string linker::findf(const string& fname) {
|
|||
|
||||
// we will find lib.nas in nasal std directory
|
||||
if (fname=="lib.nas") {
|
||||
return is_windows()? findf("stl\\lib.nas"):findf("stl/lib.nas");
|
||||
return is_windows()? findf("std\\lib.nas"):findf("std/lib.nas");
|
||||
}
|
||||
if (!show_path) {
|
||||
err.err("link", "cannot find file <"+fname+">");
|
||||
|
@ -105,7 +105,7 @@ bool linker::imptchk(const ast& node) {
|
|||
/*
|
||||
call
|
||||
|_id:import
|
||||
|_callh:stl
|
||||
|_callh:std
|
||||
|_callh:file
|
||||
*/
|
||||
if (node.type()==ast_call && node[0].str()=="import" && node.size()>=2 && node[1].type()==ast_callh) {
|
||||
|
|
|
@ -237,6 +237,7 @@ void codegen::call_gen(call_expr* node) {
|
|||
case expr_type::ast_callh: call_hash_gen((call_hash*)i); break;
|
||||
case expr_type::ast_callv: call_vec((call_vector*)i); break;
|
||||
case expr_type::ast_callf: call_func((call_function*)i); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -341,6 +342,7 @@ void codegen::mcall(expr* node) {
|
|||
case expr_type::ast_callh: call_hash_gen((call_hash*)tmp); break;
|
||||
case expr_type::ast_callv: call_vec((call_vector*)tmp); break;
|
||||
case expr_type::ast_callf: call_func((call_function*)tmp); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
auto tmp = call_node->get_calls().back();
|
||||
|
@ -444,7 +446,7 @@ void codegen::def_gen(definition_expr* node) {
|
|||
node->get_variable_name()? single_def(node):multi_def(node);
|
||||
}
|
||||
|
||||
void codegen::assignment_gen(assignment_expr* node) {
|
||||
void codegen::assignment_expression(assignment_expr* node) {
|
||||
switch(node->get_assignment_type()) {
|
||||
case assignment_expr::assign_type::equal:
|
||||
calc_gen(node->get_right());
|
||||
|
@ -534,7 +536,7 @@ void codegen::assignment_gen(assignment_expr* node) {
|
|||
}
|
||||
}
|
||||
|
||||
void codegen::assign_statement(assignment_expr* node) {
|
||||
void codegen::assignment_statement(assignment_expr* node) {
|
||||
switch(node->get_assignment_type()) {
|
||||
case assignment_expr::assign_type::equal:
|
||||
if (node->get_left()->get_type()==expr_type::ast_id) {
|
||||
|
@ -672,6 +674,7 @@ void codegen::loop_gen(expr* node) {
|
|||
for_gen((for_expr*)node); break;
|
||||
case expr_type::ast_forei:
|
||||
forei_gen((forei_expr*)node); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,7 +702,7 @@ void codegen::while_gen(while_expr* node) {
|
|||
}
|
||||
|
||||
void codegen::for_gen(for_expr* node) {
|
||||
expr_gen(node->get_initial());
|
||||
statement_generation(node->get_initial());
|
||||
usize jmp_place = code.size();
|
||||
if (node->get_condition()->get_type()==expr_type::ast_null) {
|
||||
regist_num(1);
|
||||
|
@ -712,7 +715,7 @@ void codegen::for_gen(for_expr* node) {
|
|||
|
||||
block_gen(node->get_code_block());
|
||||
usize continue_place = code.size();
|
||||
expr_gen(node->get_step());
|
||||
statement_generation(node->get_step());
|
||||
gen(op_jmp, jmp_place, node->get_step()->get_line());
|
||||
code[label_exit].num = code.size();
|
||||
|
||||
|
@ -755,7 +758,7 @@ void codegen::forei_gen(forei_expr* node) {
|
|||
gen(op_pop, 0, node->get_line());// pop iterator
|
||||
}
|
||||
|
||||
void codegen::expr_gen(expr* node) {
|
||||
void codegen::statement_generation(expr* node) {
|
||||
switch(node->get_type()) {
|
||||
case expr_type::ast_null:break;
|
||||
case expr_type::ast_def:
|
||||
|
@ -763,17 +766,20 @@ void codegen::expr_gen(expr* node) {
|
|||
case expr_type::ast_multi_assign:
|
||||
multi_assign_gen((multi_assign*)node); break;
|
||||
case expr_type::ast_assign:
|
||||
assign_statement((assignment_expr*)node); break;
|
||||
assignment_statement((assignment_expr*)node); break;
|
||||
case expr_type::ast_nil:case expr_type::ast_num:
|
||||
case expr_type::ast_str:case expr_type::ast_bool: break;
|
||||
case expr_type::ast_vec:case expr_type::ast_hash:
|
||||
case expr_type::ast_func:case expr_type::ast_call:
|
||||
case expr_type::ast_vec:
|
||||
case expr_type::ast_hash:
|
||||
case expr_type::ast_func:
|
||||
case expr_type::ast_call:
|
||||
case expr_type::ast_unary:
|
||||
case expr_type::ast_binary:
|
||||
case expr_type::ast_ternary:
|
||||
calc_gen(node);
|
||||
gen(op_pop, 0, node->get_line());
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -956,6 +962,7 @@ void codegen::binary_gen(binary_operator* node) {
|
|||
gen(op_geqc, num_table.at(num), node->get_line());
|
||||
}
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -992,7 +999,7 @@ void codegen::calc_gen(expr* node) {
|
|||
case expr_type::ast_call:
|
||||
call_gen((call_expr*)node); break;
|
||||
case expr_type::ast_assign:
|
||||
assignment_gen((assignment_expr*)node); break;
|
||||
assignment_expression((assignment_expr*)node); break;
|
||||
case expr_type::ast_ternary:
|
||||
trino_gen((ternary_operator*)node); break;
|
||||
case expr_type::ast_unary:
|
||||
|
@ -1004,6 +1011,7 @@ void codegen::calc_gen(expr* node) {
|
|||
single_def((definition_expr*)node);
|
||||
call_id(((definition_expr*)node)->get_variable_name());
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1032,17 +1040,20 @@ void codegen::block_gen(code_block* node) {
|
|||
case expr_type::ast_for:
|
||||
case expr_type::ast_forei:
|
||||
loop_gen(tmp); break;
|
||||
case expr_type::ast_binary:
|
||||
case expr_type::ast_vec:case expr_type::ast_hash:
|
||||
case expr_type::ast_func:case expr_type::ast_call:
|
||||
case expr_type::ast_vec:
|
||||
case expr_type::ast_hash:
|
||||
case expr_type::ast_func:
|
||||
case expr_type::ast_call:
|
||||
case expr_type::ast_unary:
|
||||
case expr_type::ast_binary:
|
||||
case expr_type::ast_ternary:
|
||||
case expr_type::ast_def:
|
||||
case expr_type::ast_assign:
|
||||
case expr_type::ast_multi_assign:
|
||||
expr_gen(tmp); break;
|
||||
statement_generation(tmp); break;
|
||||
case expr_type::ast_ret:
|
||||
ret_gen((return_expr*)tmp); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,16 +74,16 @@ private:
|
|||
void multi_def(definition_expr*);
|
||||
void single_def(definition_expr*);
|
||||
void def_gen(definition_expr*);
|
||||
void assignment_gen(assignment_expr*);
|
||||
void assign_statement(assignment_expr*);
|
||||
void assignment_expression(assignment_expr*);
|
||||
void assignment_statement(assignment_expr*);
|
||||
void multi_assign_gen(multi_assign*);
|
||||
void cond_gen(condition_expr*);
|
||||
void loop_gen(expr*);
|
||||
void load_continue_break(i32, i32);
|
||||
void while_gen(while_expr*);
|
||||
void for_gen(for_expr*);
|
||||
void expr_gen(expr*);
|
||||
void forei_gen(forei_expr*);
|
||||
void statement_generation(expr*);
|
||||
void or_gen(binary_operator*);
|
||||
void and_gen(binary_operator*);
|
||||
void unary_gen(unary_operator*);
|
||||
|
|
|
@ -30,7 +30,8 @@ std::string linker::get_path(call_expr* node) {
|
|||
return fpath + ".nas";
|
||||
}
|
||||
|
||||
std::string linker::find_file(const std::string& filename) {
|
||||
std::string linker::find_file(
|
||||
const std::string& filename, const span& location) {
|
||||
// first add file name itself into the file path
|
||||
std::vector<std::string> fpath = {filename};
|
||||
|
||||
|
@ -48,9 +49,12 @@ std::string linker::find_file(const std::string& filename) {
|
|||
|
||||
// we will find lib.nas in nasal std directory
|
||||
if (filename=="lib.nas") {
|
||||
return is_windows()? find_file("stl\\lib.nas"):find_file("stl/lib.nas");
|
||||
return is_windows()?
|
||||
find_file("std\\lib.nas", location):
|
||||
find_file("std/lib.nas", location);
|
||||
}
|
||||
if (!show_path) {
|
||||
err.load(location.file);
|
||||
err.err("link", "cannot find file <" + filename + ">");
|
||||
return "";
|
||||
}
|
||||
|
@ -58,6 +62,7 @@ std::string linker::find_file(const std::string& filename) {
|
|||
for(const auto& i : fpath) {
|
||||
paths += " " + i + "\n";
|
||||
}
|
||||
err.load(location.file);
|
||||
err.err("link", "cannot find file <" + filename + "> in these paths:\n" + paths);
|
||||
return "";
|
||||
}
|
||||
|
@ -66,7 +71,7 @@ bool linker::import_check(expr* node) {
|
|||
/*
|
||||
call
|
||||
|_id:import
|
||||
|_callh:stl
|
||||
|_callh:std
|
||||
|_callh:file
|
||||
*/
|
||||
if (node->get_type()!=expr_type::ast_call) {
|
||||
|
@ -149,7 +154,7 @@ code_block* linker::import_regular_file(call_expr* node) {
|
|||
node->set_first(new nil_expr(location));
|
||||
|
||||
// avoid infinite loading loop
|
||||
filename = find_file(filename);
|
||||
filename = find_file(filename, node->get_location());
|
||||
if (!filename.length() || exist(filename)) {
|
||||
return new code_block({0, 0, 0, 0, filename});
|
||||
}
|
||||
|
@ -166,7 +171,7 @@ code_block* linker::import_regular_file(call_expr* node) {
|
|||
code_block* linker::import_nasal_lib() {
|
||||
lexer lex(err);
|
||||
parse par(err);
|
||||
auto filename = find_file("lib.nas");
|
||||
auto filename = find_file("lib.nas", {0, 0, 0, 0, files[0]});
|
||||
if (!filename.length()) {
|
||||
return new code_block({0, 0, 0, 0, filename});
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ private:
|
|||
bool exist(const std::string&);
|
||||
void link(code_block*, code_block*);
|
||||
std::string get_path(call_expr*);
|
||||
std::string find_file(const std::string&);
|
||||
std::string find_file(const std::string&, const span&);
|
||||
code_block* import_regular_file(call_expr*);
|
||||
code_block* import_nasal_lib();
|
||||
code_block* load(code_block*, u16);
|
||||
|
|
|
@ -80,6 +80,7 @@ std::ostream& version(std::ostream& out) {
|
|||
}
|
||||
out << "version " << __nasver;
|
||||
out << " (" << __DATE__ << " " << __TIME__ << ")\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import.stl.padding;
|
||||
import.stl.process_bar;
|
||||
import.std.padding;
|
||||
import.std.process_bar;
|
||||
|
||||
var char_ttf=[
|
||||
[" "," "," "," "," "," "],
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Road check and auto pilot by ValKmjolnir
|
||||
import.stl.fg_env;
|
||||
import.std.fg_env;
|
||||
|
||||
var dt=0.01;
|
||||
var intergral=0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.queue;
|
||||
import.std.queue;
|
||||
|
||||
rand(time(0));
|
||||
var pixel=[' ','#','.','*'];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.mat;
|
||||
import.std.mat;
|
||||
|
||||
rand(time(0));
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import.stl.padding;
|
||||
import.stl.file;
|
||||
import.stl.sort;
|
||||
import.std.padding;
|
||||
import.std.file;
|
||||
import.std.sort;
|
||||
|
||||
var source=find_all_files_with_extension(".","cpp","h");
|
||||
sort(source,func(a,b){return cmp(a,b)<0});
|
||||
|
||||
var lib=find_all_files_with_extension("./stl","nas");
|
||||
var lib=find_all_files_with_extension("./std","nas");
|
||||
sort(lib,func(a,b){return cmp(a,b)<0});
|
||||
|
||||
var testfile=find_all_files_with_extension("./test","nas");
|
||||
|
@ -79,7 +79,7 @@ var calc=func(codetype,files,path=""){
|
|||
}
|
||||
|
||||
var all=calc("source code:",source)
|
||||
+calc("lib:",lib,"stl/")
|
||||
+calc("lib:",lib,"std/")
|
||||
+calc("test file:",testfile,"test/")
|
||||
+calc("module:",module,"module/");
|
||||
println(rightpad("total:",padding_length),'|',leftpad(str(all),6),' kb |');
|
|
@ -1,7 +1,7 @@
|
|||
# coroutine.nas by ValKmjolnir
|
||||
# 2022/5/19
|
||||
import.stl.process_bar;
|
||||
import.stl.padding;
|
||||
import.std.process_bar;
|
||||
import.std.padding;
|
||||
|
||||
if(os.platform()=="windows"){
|
||||
system("chcp 65001");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import.stl.sort;
|
||||
import.stl.padding;
|
||||
import.stl.process_bar;
|
||||
import.std.sort;
|
||||
import.std.padding;
|
||||
import.std.process_bar;
|
||||
|
||||
var mess=func(vec) {
|
||||
srand();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import.stl.json;
|
||||
import.stl.process_bar;
|
||||
import.std.json;
|
||||
import.std.process_bar;
|
||||
|
||||
var ss=JSON.stringify({
|
||||
vec:[0,1,2],
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import.module.libsock;
|
||||
import.stl.json;
|
||||
import.std.json;
|
||||
|
||||
var gettime=func(){
|
||||
return split(" ",os.time())[1];
|
||||
|
|
|
@ -172,7 +172,7 @@ var lexer=func(file)
|
|||
};
|
||||
}
|
||||
|
||||
var lex=lexer("stl/fg_env.nas");
|
||||
var lex=lexer("std/fg_env.nas");
|
||||
lex.compile();
|
||||
foreach(var tok;lex.get_token())
|
||||
print('(',tok.line,' | ',tok.token,')\n');
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.process_bar;
|
||||
import.std.process_bar;
|
||||
|
||||
var new_map=func(width,height){
|
||||
var tmp=[];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import.test.md5;
|
||||
import.stl.process_bar;
|
||||
import.stl.file;
|
||||
import.std.process_bar;
|
||||
import.std.file;
|
||||
srand();
|
||||
|
||||
var compare=func() {
|
||||
|
@ -48,8 +48,8 @@ var filechecksum=func(){
|
|||
foreach(var p;find_all_files_with_extension("./test","nas")) {
|
||||
append(files,"./test/"~p);
|
||||
}
|
||||
foreach(var p;find_all_files_with_extension("./stl","nas")) {
|
||||
append(files,"./stl/"~p);
|
||||
foreach(var p;find_all_files_with_extension("./std","nas")) {
|
||||
append(files,"./std/"~p);
|
||||
}
|
||||
foreach(var p;find_all_files_with_extension("./module","nas","cpp")) {
|
||||
append(files,"./module/"~p);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.process_bar;
|
||||
import.std.process_bar;
|
||||
import.module.libkey;
|
||||
|
||||
var is_windows_platform=os.platform()=="windows";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.process_bar;
|
||||
import.std.process_bar;
|
||||
|
||||
var ppm=func(filename,width,height,RGB){
|
||||
# P3 use ASCII number
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.sort;
|
||||
import.std.sort;
|
||||
|
||||
var vec=[];
|
||||
rand(time(0));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import.stl.sort;
|
||||
import.std.sort;
|
||||
|
||||
var to_lower=func(s){
|
||||
var tmp="";
|
||||
|
|
Loading…
Reference in New Issue