tests & map utils
This commit is contained in:
parent
1b4af50038
commit
1219edb49f
|
@ -143,6 +143,21 @@ namespace builtin {
|
|||
s->functions.insert({l->args[0].ident,f});
|
||||
return 0;
|
||||
}
|
||||
std::any _udef(lexi *l,state *s){
|
||||
s->names.erase(l->args[0].ident);
|
||||
return 0;
|
||||
}
|
||||
std::any _seta(lexi *l, state* s){
|
||||
//std::cout<<l->args[0].ident<<std::endl;
|
||||
//exit(0);
|
||||
auto bb = std::get<std::map<std::string,object>>(s->names[l->args[0].ident].value);
|
||||
bb[std::get<std::string>(l->args[1].value)] = l->args[2];
|
||||
s->names[l->args[0].ident].value = bb;//[std::get<int>(l->args[1].value)];
|
||||
return 0;
|
||||
//auto ob = std::get<std::vector<object>>(l->args[0].value);
|
||||
//if(std::get<int>(l->args[1].value)>ob.size()) p_ferr("out of range",1);
|
||||
//return ob[std::get<int>(l->args[1].value)];
|
||||
}
|
||||
}
|
||||
|
||||
void ttest(lexi l){
|
||||
|
|
|
@ -67,7 +67,8 @@ namespace builtin {
|
|||
std::any _xor(lexi*, state*);
|
||||
|
||||
std::any _defn(lexi*, state*);
|
||||
|
||||
std::any _udef(lexi*, state*);
|
||||
std::any _seta(lexi*, state*);
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,13 +98,15 @@ static builtin::builtin _or("||",{INT,INT},INT,builtin::_or);
|
|||
static builtin::builtin _xor("^",{INT,INT},INT,builtin::_xor);
|
||||
|
||||
static builtin::builtin _defn("defn",{NONE,INT,ANON},ANY,builtin::_defn);
|
||||
static builtin::builtin _udef("udef",{NONE},NONE,builtin::_udef);
|
||||
static builtin::builtin _seta("seta",{NONE,STRING,ANY},NONE,builtin::_seta);
|
||||
|
||||
|
||||
static std::map<std::string, builtin::builtin*> builtins = {
|
||||
{"write",&_write},{"exit",&_exit},{"if",&_if},{"__anon",&__anon},{"def",&_def},{"+",&_add}
|
||||
,{"-",&_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}
|
||||
{"!",&_not},{"||",&_or},{"^",&_xor},{"defn",&_defn},{"udef",&_udef},{"seta",&_seta}
|
||||
};
|
||||
|
||||
void ttest(lexi);
|
||||
|
|
|
@ -46,7 +46,7 @@ tests = {
|
|||
ex_out = "6\n5\n2222\n5",
|
||||
},{
|
||||
file = "./test/assoc.ll",
|
||||
ex_return = "5",
|
||||
ex_return = "2",
|
||||
ex_out = "wowa wowa",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(def hello {"a":"ww", "b":"wowa wowa", "exit":5})
|
||||
(write (geta hello "b"))
|
||||
(seta hello "exit" 2)
|
||||
(exit (geta hello "exit"))
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
(def start 10)
|
||||
(def numone 0)
|
||||
(def numtwo 1)
|
||||
(def next_num numtwo)
|
||||
(def count 1)
|
||||
(defn fibon 1
|
||||
((write next_num)
|
||||
(def count (+ count 1))
|
||||
(def numone numtwo)
|
||||
(def numtwo next_num)
|
||||
(def next_num (+ numone numtwo))
|
||||
(if (>= start count) (fibon) (write "end"))))
|
||||
|
||||
(fibon)
|
|
@ -0,0 +1,3 @@
|
|||
(def meow 5)
|
||||
(udef meow)
|
||||
(write meow)
|
Loading…
Reference in New Issue