defn arguments!

This commit is contained in:
ame 2023-09-20 10:23:53 -05:00
parent f248989ac1
commit 59c230d5e0
10 changed files with 37 additions and 15 deletions

View File

@ -171,9 +171,22 @@ namespace builtin {
return (int)(std::get<int>(l->args[0].value)^std::get<int>(l->args[1].value));
}
std::any _defn(lexi*l, state*s){
std::vector<std::string> t;
std::vector<type> tt;
if(l->args.size()==3){
//for(int i = 1; i!=l->args.size()-1; i++){
std::vector<object> aa = std::get<std::vector<object>>(l->args[1].value);
for(object o : aa){
t.push_back(o.ident);
tt.push_back(STRING);
}
//}
}
func f;
f.call = l->args[0].ident;
f.args = {};
f.args = t;
f.argst = tt;
f._return = NONE;
f.calls = l->args[l->args.size()==3?2:1].n_value;
s->functions.insert({l->args[0].ident,f});

View File

@ -102,7 +102,7 @@ static builtin::builtin _not("!",{{INT}},INT,builtin::_not);
static builtin::builtin _or("||",{{INT,INT}},INT,builtin::_or);
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 _defn("defn",{{NONE,ANON},{NONE,ARRAY,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);

View File

@ -5,7 +5,7 @@ std::any single_ex(lexi l, state*s){
if(!builtins.count(l.oper)&&l.oper!="__anon"){
if(!s->functions.count(l.oper))
p_ferr("undefined refrence to "+l.oper+" on line:"+std::to_string(l.line)+":"+std::to_string(l._char),1);
lexi gen = s->gen_args(s->functions[l.oper].args,l);
lexi gen = s->gen_args(s->functions[l.oper].argst,l);
return s->functions[l.oper].exec(gen,s);
}
int sel_args = builtins[l.oper]->check_args(l,s);

View File

@ -37,6 +37,7 @@ class object {
this->value = value;
this->type = type;
}
void print(){};
std::vector<lexi> to_larray();
void gen_value();
void clear();

View File

@ -33,7 +33,16 @@ object dtype(object l, std::any a, type t, type wants){
}
std::any func::exec(lexi l, state*s) {
//return 0l
//return 0
//if(args.size()>=2&&l.args.size()!=args[1].size()) abort();//exit(0);
//std::cout<<l.args.size()<<" "<<args[1].size()<<std::endl;
//for(int i = 0; i!=l.args.size();i++)
// std::cout<<l.args[i]<<std::endl;
//std::cout<<args.size();
if(1||args.size()==3){
for(int i = 0; i!=l.args.size(); i++)
s->names[args[i]] = l.args[i];
}
for(lexi ss : calls){
single_ex(ss,s);
}

View File

@ -17,7 +17,9 @@ object dtype(object l, std::any a, type t, type wants);
class func {
public:
std::string call = "";
std::vector<type> args = {};
std::vector<std::string> args = {};
std::vector<type> argst = {};
type _return = NONE;
std::vector<lexi> calls;
std::any exec(lexi l, state*s);

View File

@ -61,7 +61,7 @@ tests = {
},{
file = "./test/defn.ll",
ex_return = "0",
ex_out = "5\n4\n3\n2\n1\nmeow",
ex_out = "wowa",
},{
file = "./test/types.ll",
ex_return = "5",

View File

@ -1,5 +1,3 @@
(def hi 5)
(defn name ((write hi)
(def hi (- hi 1))
(if (> hi 0) (name) (write "meow"))))
(name)
(defn test {a,num,e}
((write a)))
(test "wowa" 5 5)

View File

@ -3,8 +3,7 @@
(def numtwo 1)
(def next_num numtwo)
(def count 1)
(defn fibon 1
((write next_num)
(defn fibon ((write next_num)
(++ count)
(def numone numtwo)
(def numtwo next_num)

View File

@ -2,10 +2,10 @@
(def whar (+ 5 5))
(def huhr {5,4,3})
(def nahr {"h":meow})
(defn uwu (exit 5))
(defn uwu {a} (exit 5))
(write (type meow))
(write (type whar))
(write (type huhr))
(write (type nahr))
(write (type uwu))
(uwu)
(uwu 5)