type function + tests

This commit is contained in:
ame 2023-09-19 11:50:10 -05:00
parent 20bae619b5
commit e9270a7ff8
8 changed files with 36 additions and 5 deletions

View File

@ -2,4 +2,9 @@ todo:
* clean header files (please)
* generics D:
* custom functions can take arguments
* return
* loops

View File

@ -202,6 +202,9 @@ namespace builtin {
s->names[l->args[0].ident].value = std::get<int>(s->names[l->args[0].ident].value) - 1;
return 0;
}
std::any _type(lexi*l,state*s){
return (int)l->args[0].type;
}
}
void ttest(lexi l){

View File

@ -69,7 +69,7 @@ namespace builtin {
std::any _defn(lexi*, state*);
std::any _udef(lexi*, state*);
std::any _seta(lexi*, state*);
std::any _type(lexi*, state*);
//shorthands
std::any _pp(lexi*, state*);
std::any _mm(lexi*, state*);
@ -105,6 +105,7 @@ static builtin::builtin _xor("^",{{INT,INT}},INT,builtin::_xor);
static builtin::builtin _defn("defn",{{NONE,ANON},{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 builtin::builtin _type("type",{{ANY}},INT,builtin::_type);
static builtin::builtin _pp("++",{{NONE}},NONE,builtin::_pp);
static builtin::builtin _mm("--",{{NONE}},INT,builtin::_add);
@ -114,6 +115,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}
};
void ttest(lexi);

View File

@ -31,7 +31,12 @@ class object {
val value = NULL;
std::vector<lexi> n_value;
type type = NONE;
object(){};
object(std::string ident,val value, enum type type){
this->ident = ident;
this->value = value;
this->type = type;
}
std::vector<lexi> to_larray();
void gen_value();
void clear();

View File

@ -7,6 +7,7 @@ int main(int argc, char* argv[]){
//std::cout<<batch_format(test("(exit 5 22)(meow \"wharrrr\" (a 5 (aaa 5.5) ) 445)"),0);
//std::cout<<batch_format(test(f_read("./test/if.ll")),0);
state state;
state.names = {{"true",object("true",1,INT)},{"true",object("false",0,INT)}};
interp(test(f_read(argv[1])),&state);
//std::cout<<batch_format(test(f_read(argv[1])),0);
//interp(test(f_read("./test/exit.ll")));

View File

@ -62,6 +62,10 @@ tests = {
file = "./test/defn.ll",
ex_return = "0",
ex_out = "5\n4\n3\n2\n1\nmeow",
},{
file = "./test/types.ll",
ex_return = "5",
ex_out = "4\n1\n8\n13\n0",
},
}
@ -132,7 +136,7 @@ for ind,t in pairs(tests) do
end
if(test_count>rtest_count) then
print(red.."missing "..test_count - rtest_count.." tests (from ./test/), missing:")
print(red.."missing "..test_count - rtest_count.." test(s) (from ./test/), missing:")
for _,t in pairs(filest) do
print(" --"..t)
end

View File

@ -1,3 +1,3 @@
(def a 20)
(def a "20")
(def a (+ (+ a 20) 20))
(exit a)

11
test/types.ll Normal file
View File

@ -0,0 +1,11 @@
(def meow "nya")
(def whar (+ 5 5))
(def huhr {5,4,3})
(def nahr {"h":meow})
(defn uwu (exit 5))
(write (type meow))
(write (type whar))
(write (type huhr))
(write (type nahr))
(write (type uwu))
(uwu)