read & better functions stuff

This commit is contained in:
ame 2023-09-20 11:27:54 -05:00
parent 59c230d5e0
commit 735dc2f8ac
6 changed files with 24 additions and 5 deletions

View File

@ -87,10 +87,8 @@ namespace builtin {
std::any _if(lexi *l, state* s){
if(std::get<int>(l->args[0].value)==1)
interp(l->args[1].to_larray(),s);
else
else if(l->args.size()>2) //only do the second if there is one
interp(l->args[2].to_larray(),s);
//std::cout<<batch_format(l.args[1].to_larray(),0);
return 0;
}
std::any __anon(lexi *l,state* s){
@ -218,6 +216,14 @@ namespace builtin {
std::any _type(lexi*l,state*s){
return (int)l->args[0].type;
}
std::any _read(lexi *l,state *s){
object o;
std::cin>>o.ident;
o.value = o.ident;
o.type = STRING;
s->names[l->args[0].ident] = o;
return 0;
}
}
void ttest(lexi l){

View File

@ -70,6 +70,8 @@ namespace builtin {
std::any _udef(lexi*, state*);
std::any _seta(lexi*, state*);
std::any _type(lexi*, state*);
std::any _read(lexi*, state*);
//shorthands
std::any _pp(lexi*, state*);
std::any _mm(lexi*, state*);
@ -106,6 +108,7 @@ static builtin::builtin _defn("defn",{{NONE,ANON},{NONE,ARRAY,ANON}},ANY,builtin
static builtin::builtin _udef("udef",{{NONE}},NONE,builtin::_udef);
static builtin::builtin _seta("seta",{{NONE,STRING,ANY}},NONE,builtin::_seta);
static builtin::builtin _type("type",{{ANY}},INT,builtin::_type);
static builtin::builtin _read("read",{{NONE}},NONE,builtin::_read);
static builtin::builtin _pp("++",{{NONE}},NONE,builtin::_pp);
static builtin::builtin _mm("--",{{NONE}},INT,builtin::_add);
@ -115,7 +118,7 @@ static std::map<std::string, builtin::builtin*> builtins = {
,{"-",&_sub},{"*",&_mul},{"/",&_div},{"%",&_mod},{"get",&_get},{"geta",&_geta},{"set",&_set},{"==",&_equ},
{">",&_great},{"<",&_less},{">=",&_great_o_equ},{"<=",&_less_o_equ},{"!=",&_nequ},{"&&",&_and},
{"!",&_not},{"||",&_or},{"^",&_xor},{"defn",&_defn},{"udef",&_udef},{"seta",&_seta},{"++",&_pp},{"--",&_mm}
,{"type",&_type}
,{"type",&_type},{"read",&_read}
};
void ttest(lexi);

View File

@ -300,7 +300,7 @@ std::vector<lexi> test(std::string input){
con_level = 0;
last_con = input[i];
}
else
else if(input[i]!=' '&&input[i]!='\n')
tob.oper+=input[i];
} else if(read==READING_A){
if(input[i]==' '&&carg.ident!=""&&carg.ident!="\n"){

View File

@ -66,6 +66,10 @@ tests = {
file = "./test/types.ll",
ex_return = "5",
ex_out = "4\n1\n8\n13\n0",
},{
file = "./test/rec.ll",
ex_return = "0",
ex_out = "5\n4\n3\n2\n1",
},
}

View File

@ -1,4 +1,5 @@
(if 1 (write "test"))
(if 0 (write "test"))
(if 1
((if 1 ((write "no")) ((exit 5))))
((write "nya")))

5
test/rec.ll Normal file
View File

@ -0,0 +1,5 @@
(defn uwu {num}
((write num)
(def num (- num 1))
(if (!= num 0) (uwu num))))
(uwu 5)