Ejemplo n.º 1
0
/// compile_opcode - Dispatch to a more specific compiler function based
/// on the opcode of the current node.
void BrainFTraceRecorder::compile_opcode(BrainFTraceNode *node,
                                         IRBuilder<>& builder) {
  switch (node->opcode) {
    case '+':
      compile_plus(node, builder);
      break;
    case '-':
      compile_minus(node, builder);
      break;
    case '<':
      compile_left(node, builder);
      break;
    case '>':
      compile_right(node, builder);
      break;
    case '.':
      compile_put(node, builder);
      break;
    case ',':
      compile_get(node, builder);
      break;
    case '[':
      compile_if(node, builder);
      break;
    case ']':
      compile_back(node, builder);
      break;
    case '0':
      compile_set_zero(node, builder);
      break;
    default:
      assert(0 && "Unknown opcode?");
  }
}
Ejemplo n.º 2
0
expr_val * compile_statement(base_node * stmt, scope * scope, str_list * lines) {
	int op;
	switch (stmt->type) {
		case BINARY_OP_NODE:
			op = ((binary_op_node*) stmt)->op;
			switch(op) {
				case OP_EQUAL:
					return compile_assignment(((binary_op_node*) stmt), scope, lines);
				case OP_PLUS:
					return compile_addition(((binary_op_node*) stmt), scope, lines);
				case OP_TYPE_ASS:
					return compile_type_assignment(((binary_op_node*) stmt), scope, lines);
				case EQUAL: case LESS: case LESS_EQUAL: case GREATER: case GREATER_EQUAL:
					return compile_comparison_assignment(((binary_op_node*) stmt), scope, lines);
			}
		case IF_NODE:
			return compile_if((if_node*) stmt, scope, lines);
		case BLOCK_NODE:
			return compile_block((block_node *) stmt, scope, lines, 1);
		case ID_NODE:	
			return compile_id(((id_node*) stmt), scope, lines);
		case INT_NODE:
			return compile_int((int_node*) stmt, scope, lines);	
		case CHAR_NODE:
			return compile_char((char_node*) stmt, scope, lines);	
		case INT_TYPE_NODE:
			return compile_int_type((type_node *) stmt, scope, lines);
		case CHAR_TYPE_NODE:
			return compile_char_type((type_node *) stmt, scope, lines);
		case FUNC_NODE:
			return compile_function((function_node*) stmt, scope, lines);
		case FUNC_ARGS_NODE:
			return compile_args((argument_node *) stmt, scope, lines);
		case RETURN_NODE:
			return compile_return((return_node *) stmt, scope, lines);
		case CALL_NODE:
			return compile_call((call_node *) stmt, scope, lines);
		case CALL_ARGS_NODE:
			return compile_call_args((argument_node *) stmt, scope, lines);
		case END_NODE:
			break;
	}
	return NULL;
}
Ejemplo n.º 3
0
value_t compile_form(value_t expr, value_t next) {

	if (SYM_QUOTE == UNSPECIFIED) {
		SYM_QUOTE = make_symbol("quote");
		SYM_IF = make_symbol("if");
		SYM_DEFINE = make_symbol("$DEFINE");
		SYM_LAMBDA = make_symbol("lambda");
		SYM_SET1 = make_symbol("set!");
		SYM_DEFMACRO = make_symbol("define-rewriter");
		SYM_CALLCC = make_symbol("$CALL-CC");
	}
	
	value_t head = pair_left(expr);
	value_t result;
	if (head == SYM_IF) {
		result = compile_if(pair_right(expr), next);
	}
	else if (head == SYM_LAMBDA) {
		result = compile_lambda(pair_right(expr), next);
	}
	else if (head == SYM_QUOTE) {
		result = compile_quote(pair_right(expr), next);
	}
	else if (head == SYM_DEFINE) {
		result = compile_define(pair_right(expr), next);
	}
	else if (head == SYM_SET1) {
		result = compile_assignment(pair_right(expr), next);
	}
	else if (head == SYM_DEFMACRO) {
		result = compile_defmacro(pair_right(expr), next);
	}
	else if (head == SYM_CALLCC) {
		result = compile_call_cc(pair_right(expr), next);
	}
	else {
		result = compile_application(expr, next);
	}
	return result;
}
Ejemplo n.º 4
0
// Main compiler dispatch system
void compile(compiler_wrapper *cw, ast_node *root)
{
    switch(root->type)
    {
        case ABINARY_EXPRESSION:
            compile_binary(cw, root);
        break;
        case AUNARY_EXPRESSION:
            compile_unary(cw, root);
        break;
        case AVALUE:
            compile_value(cw, root);
        break;
        case AUNIT:
            compile_unit_value(cw, root);
        break;
        case ACOND_CHAIN:
            compile_cond(cw, root);
        break;
        case AIF:
            compile_if(cw, root);
        break;
        case ALOOP:
            compile_loop(cw, root);
        break;
        case AITERLOOP:
            compile_iter_loop(cw, root);
        break;
        case AFUNC_DECL:
            compile_function(cw, root);
        break;
        case AFUNC_CALL:
            compile_function_call(cw, root);
        break;
        case ACLASS_DECL:
            compile_class_decl(cw, root);
        break;
        case ATERNARY:
            compile_ternary(cw, root);
        break;
        case AMEMBER_ACCESS:
            compile_member_access(cw, root);
        break;
        case AARRAY:
            compile_array(cw, root);
        break;
        case ATABLE:
            compile_table(cw, root);
        break;
        case AOBJDECL:
            compile_object(cw, root);
        break;
        case AINDEX:
            compile_indx(cw, root);
        break;
        case ATRIPLESET:
            compile_triple_set(cw, root);
        break;
        case ATRYCATCH:
            compile_try_catch(cw, root);
        break;
        case AONEOFF:
            compile_one_off(cw, root);
        break;
        case ALOAD:
            compile_load(cw, root);
        break;
        case AREGEX:
            compile_regex(cw, root);
        break;
        default:
        break;
    }
}