添加struct里使用lambda测试
This commit is contained in:
@@ -66,7 +66,7 @@ def calc_lambda_text(text:str):
|
|||||||
def create_lambda(text:str):
|
def create_lambda(text:str):
|
||||||
global LAMBDA_INDEX
|
global LAMBDA_INDEX
|
||||||
text=text.replace("lambda(","")[:-1] # 去掉lambda和首末括号
|
text=text.replace("lambda(","")[:-1] # 去掉lambda和首末括号
|
||||||
fun_name=f"lambda_{LAMBDA_INDEX}"
|
fun_name=f"__lambda_{LAMBDA_INDEX}"
|
||||||
LAMBDA_INDEX+=1
|
LAMBDA_INDEX+=1
|
||||||
return_type=text[:text.find("(")]
|
return_type=text[:text.find("(")]
|
||||||
# 有","则至少有两个参数否则可能有一个参数,可能没有
|
# 有","则至少有两个参数否则可能有一个参数,可能没有
|
||||||
|
22
make.py
22
make.py
@@ -132,7 +132,8 @@ def build_depend(src:list):
|
|||||||
if(ret):
|
if(ret):
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
print(f"{i} 没有更新源文件")
|
# print(f"{i} 没有更新源文件")
|
||||||
|
pass
|
||||||
|
|
||||||
# 生成中间文件
|
# 生成中间文件
|
||||||
def build_object(src:list):
|
def build_object(src:list):
|
||||||
@@ -150,13 +151,15 @@ def build_object(src:list):
|
|||||||
if(check_rebuild(dst,read_depend_files(cd))):
|
if(check_rebuild(dst,read_depend_files(cd))):
|
||||||
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
||||||
else:
|
else:
|
||||||
print(f"{i} 没有更新依赖关系")
|
# print(f"{i} 没有更新依赖关系")
|
||||||
|
pass
|
||||||
elif(file_type in ['s','S','asm','ASM']):
|
elif(file_type in ['s','S','asm','ASM']):
|
||||||
if(check_rebuild(dst,[i])):
|
if(check_rebuild(dst,[i])):
|
||||||
# cmd=f"{AS} -c {i} -o {dst} {flags}"
|
# cmd=f"{AS} -c {i} -o {dst} {flags}"
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print(f"{i} 没有更新依赖关系")
|
# print(f"{i} 没有更新依赖关系")
|
||||||
|
pass
|
||||||
if(len(cmd)>0):
|
if(len(cmd)>0):
|
||||||
print(cmd)
|
print(cmd)
|
||||||
ret=os.system(cmd)
|
ret=os.system(cmd)
|
||||||
@@ -179,29 +182,26 @@ def build_target(src:list):
|
|||||||
if(ret):
|
if(ret):
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
print(f"{dst} 没有更新的链接文件")
|
# print(f"{dst} 没有更新的链接文件")
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global CSRC
|
global CSRC
|
||||||
global ASRC
|
global ASRC
|
||||||
|
if(not os.path.exists(BUILD_DIR)):
|
||||||
|
os.makedirs(BUILD_DIR)
|
||||||
|
|
||||||
CSRC+=find_type('soft',['c','C'])
|
CSRC+=find_type('soft',['c','C'])
|
||||||
CSRC+=find_type('cpu',['c','C'])
|
CSRC+=find_type('cpu',['c','C'])
|
||||||
CSRC=search_lambda(CSRC)
|
CSRC=search_lambda(CSRC)
|
||||||
# ASRC+=find_type('./',['s','S','asm','ASM'])
|
# ASRC+=find_type('./',['s','S','asm','ASM'])
|
||||||
|
|
||||||
if(not os.path.exists(BUILD_DIR)):
|
|
||||||
os.makedirs(BUILD_DIR)
|
|
||||||
|
|
||||||
print("生成依赖关系")
|
|
||||||
build_depend(CSRC)
|
build_depend(CSRC)
|
||||||
print("生成对象文件")
|
|
||||||
build_object(CSRC)
|
build_object(CSRC)
|
||||||
# build_object(ASRC)
|
# build_object(ASRC)
|
||||||
print("生成目标文件")
|
|
||||||
build_target(CSRC+ASRC)
|
build_target(CSRC+ASRC)
|
||||||
# os.system(f"{HEX} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.hex")
|
|
||||||
# os.system(f"{BIN} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.bin")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@@ -7,9 +7,17 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "lambda.h"
|
#include "lambda.h"
|
||||||
|
|
||||||
lambda_use
|
typedef struct test_struct{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
int (*sub)(int a, int b);
|
||||||
|
int (*add)(int a, int b);
|
||||||
|
int (*sum)(struct test_struct* self);
|
||||||
|
} test_struct;
|
||||||
|
|
||||||
|
|
||||||
|
lambda_use
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -21,7 +29,19 @@ void run_callback(int (*fun)(int a, int b)) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static test_struct test_struct_var = {
|
||||||
|
.a = 1,
|
||||||
|
.b = 2,
|
||||||
|
.sub = lambda(int(int a, int b) {
|
||||||
|
return a - b;
|
||||||
|
}),
|
||||||
|
.add = lambda(int(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}),
|
||||||
|
.sum = lambda(int(struct test_struct* self) {
|
||||||
|
return self->a + self->b;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -65,6 +85,10 @@ int thread_fun(void* t)
|
|||||||
return a * b * 10;
|
return a * b * 10;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
printf("test_struct_var.sub(1,2) = %d\n", test_struct_var.sub(1, 2));
|
||||||
|
printf("test_struct_var.add(1,2) = %d\n", test_struct_var.add(1, 2));
|
||||||
|
printf("test_struct_var.sum(&test_struct_var) = %d\n", test_struct_var.sum(&test_struct_var));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user