コード例 #1
0
ファイル: string.c プロジェクト: senarukana/ABCLang
static void vstr_append_character(VString *v, ABC_Char ch) {
    int current_len;
    
    current_len = vstr_len(v->string);
    v->string = MEM_realloc(v->string, sizeof(ABC_Char) *current_len + 2);
    v->string[current_len] = ch;
    v->string[current_len+1] = L'\0';
}
コード例 #2
0
ファイル: error.c プロジェクト: lfkdsk/CodeParse
static void add_character(VString *v, int ch){
        int current_len;

        current_len = my_strlen(v->string);
        v->string = MEM_realloc(v->string, current_len + 2);
        v->string[current_len] = ch;
        v->string[current_len + 1] = '\0'
}
コード例 #3
0
ファイル: execute.c プロジェクト: aaronguo1996/MiniC
static void
expand_stack(MVM_VirtualMachine *mvm, int need_stack_size)
{
    int revalue_up;
    int rest;

    rest = mvm->stack.alloc_size - mvm->stack.stack_pointer;
    if (rest <= need_stack_size) {
        revalue_up = ((rest / STACK_ALLOC_SIZE) + 1) * STACK_ALLOC_SIZE;

        mvm->stack.alloc_size += revalue_up;
        mvm->stack.stack = MEM_realloc(mvm->stack.stack,
                                       mvm->stack.alloc_size * sizeof(MVM_Value));
        mvm->stack.pointer_flags = MEM_realloc(mvm->stack.pointer_flags,
                                               mvm->stack.alloc_size * sizeof(MVM_Boolean));
    }
}
コード例 #4
0
ファイル: string.c プロジェクト: Wonicon/crowbar-learn
void
crb_add_string_literal(char ch)
{
    if (st_string_literal_buffer_size == st_string_literal_buffer_alloc_size) {
        st_string_literal_buffer_alloc_size += STRING_ALLOC_SIZE;
        st_string_literal_buffer = MEM_realloc(st_string_literal_buffer, st_string_literal_buffer_alloc_size);
    }
    st_string_literal_buffer[st_string_literal_buffer_size++] = ch;
}
コード例 #5
0
ファイル: error.c プロジェクト: lfkdsk/CodeParse
static void add_string(VString *v, char *str){
        int new_size;
        int old_len;

        old_len = my_strlen(v->string);
        new_size = old_len + strlen(str) + 1;
        v->string = MEM_realloc(v->string, new_size);
        strcpy(&v->string[old_len], str);
}
コード例 #6
0
ファイル: string.c プロジェクト: senarukana/ABCLang
static void vstr_append_string(VString *v, ABC_Char *str){
    int new_size;
    int old_len;

    old_len = vstr_len(v->string);
    new_size = old_len + abc_wcs_len(str)  + 1;
    v->string = MEM_realloc(v->string, sizeof(ABC_Char) * new_size);
    abc_wcs_cpy(&v->string[old_len], str);
}
コード例 #7
0
ファイル: util.c プロジェクト: 3man/devlang
void
dkc_vwstr_append_character(VWString *v, int ch)
{
    int current_len;
    
    current_len = my_wcslen(v->string);
    v->string = MEM_realloc(v->string,sizeof(DVM_Char) * (current_len + 2));
    v->string[current_len] = ch;
    v->string[current_len+1] = L'\0';
}
コード例 #8
0
ファイル: util.c プロジェクト: BluePanM/code
void
crb_vstr_append_character(VString *v, CRB_Char ch)
{
    int current_len;
    
    current_len = my_strlen(v->string);
    v->string = MEM_realloc(v->string,sizeof(CRB_Char) * (current_len + 2));
    v->string[current_len] = ch;
    v->string[current_len+1] = L'\0';
}
コード例 #9
0
ファイル: util.c プロジェクト: 3man/devlang
void
dkc_vstr_append_character(VString *v, int ch)
{
    int current_len;
    
    current_len = my_strlen(v->string);
    v->string = MEM_realloc(v->string, current_len + 2);
    v->string[current_len] = ch;
    v->string[current_len+1] = '\0';
}
コード例 #10
0
ファイル: native.c プロジェクト: BluePanM/code
static CRB_Value
nv_fgets_proc(CRB_Interpreter *interpreter,
              CRB_LocalEnvironment *env,
              int arg_count, CRB_Value *args)
{
    CRB_Value value;
    FILE *fp;
    char buf[LINE_BUF_SIZE];
    char *mb_buf = NULL;
    int ret_len = 0;
    CRB_Char *wc_str;

    CRB_check_argument_count(interpreter, env, arg_count, 1);

    if (args[0].type != CRB_NATIVE_POINTER_VALUE
        || (!CRB_check_native_pointer_type(args[0].u.object,
                                           &st_file_type_info))) {
        CRB_error(interpreter, env, &st_lib_info, __LINE__,
                  (int)FGETS_ARGUMENT_TYPE_ERR,
                  CRB_MESSAGE_ARGUMENT_END);
    }
    check_file_pointer(interpreter,env, args[0].u.object);
    fp = CRB_object_get_native_pointer(args[0].u.object);

    while (fgets(buf, LINE_BUF_SIZE, fp)) {
        int new_len;
        new_len = ret_len + strlen(buf);
        mb_buf = MEM_realloc(mb_buf, new_len + 1);
        if (ret_len == 0) {
            strcpy(mb_buf, buf);
        } else {
            strcat(mb_buf, buf);
        }
        ret_len = new_len;
        if (mb_buf[ret_len-1] == '\n')
            break;
    }
    if (ret_len > 0) {
        wc_str = CRB_mbstowcs_alloc(interpreter, env, __LINE__, mb_buf);
        if (wc_str == NULL) {
            MEM_free(mb_buf);
            CRB_error(interpreter, env, &st_lib_info, __LINE__,
                      (int)FGETS_BAD_MULTIBYTE_CHARACTER_ERR,
                      CRB_MESSAGE_ARGUMENT_END);
        }
        value.type = CRB_STRING_VALUE;
        value.u.object = CRB_create_crowbar_string(interpreter, env, wc_str);
    } else {
        value.type = CRB_NULL_VALUE;
    }
    MEM_free(mb_buf);

    return value;
}
コード例 #11
0
ファイル: util.c プロジェクト: 3man/devlang
void
dkc_vwstr_append_string(VWString *v, DVM_Char *str)
{
    int new_size;
    int old_len;

    old_len = my_wcslen(v->string);
    new_size = sizeof(DVM_Char) * (old_len + dvm_wcslen(str)  + 1);
    v->string = MEM_realloc(v->string, new_size);
    dvm_wcscpy(&v->string[old_len], str);
}
コード例 #12
0
ファイル: util.c プロジェクト: BluePanM/code
void
crb_vstr_append_string(VString *v, CRB_Char *str)
{
    int new_size;
    int old_len;

    old_len = my_strlen(v->string);
    new_size = sizeof(CRB_Char) * (old_len + CRB_wcslen(str)  + 1);
    v->string = MEM_realloc(v->string, new_size);
    CRB_wcscpy(&v->string[old_len], str);
}
コード例 #13
0
ファイル: string.c プロジェクト: 3man/devlang
void
dkc_add_string_literal(int letter)
{
    if (st_string_literal_buffer_size == st_string_literal_buffer_alloc_size) {
        st_string_literal_buffer_alloc_size += STRING_ALLOC_SIZE;
        st_string_literal_buffer
            = MEM_realloc(st_string_literal_buffer,
                          st_string_literal_buffer_alloc_size);
    }
    st_string_literal_buffer[st_string_literal_buffer_size] = letter;
    st_string_literal_buffer_size++;
}
コード例 #14
0
ファイル: execute.c プロジェクト: aaronguo1996/MiniC
void
MVM_add_native_function(MVM_VirtualMachine *mvm, char *func_name,
                        MVM_NativeFunctionProc *proc, int arg_count)
{
    mvm->function = MEM_realloc(mvm->function,
                                sizeof(Function) * (mvm->function_count + 1));

    mvm->function[mvm->function_count].name = MEM_strdup(func_name);
    mvm->function[mvm->function_count].kind = NATIVE_FUNCTION;
    mvm->function[mvm->function_count].u.native_f.proc = proc;
    mvm->function[mvm->function_count].u.native_f.arg_count = arg_count;
    mvm->function_count++;
}
コード例 #15
0
ファイル: generate.c プロジェクト: BluePanM/code
static int
add_constant_pool(DVM_Executable *exe, DVM_ConstantPool *cp)
{
    int ret;

    exe->constant_pool
        = MEM_realloc(exe->constant_pool,
                      sizeof(DVM_ConstantPool)
                      * (exe->constant_pool_count + 1));
    exe->constant_pool[exe->constant_pool_count] = *cp;

    ret = exe->constant_pool_count;
    exe->constant_pool_count++;

    return ret;
}
コード例 #16
0
ファイル: eval.c プロジェクト: lyyyuna/sim_car
static void
push_value(SIMCAR_Interpreter *inter, SIMCAR_Value *value)
{
    DBG_assert(inter->stack.stack_pointer <= inter->stack.stack_alloc_size,
               ("stack_pointer..%d, stack_alloc_size..%d\n",
                inter->stack.stack_pointer, inter->stack.stack_alloc_size));

    if (inter->stack.stack_pointer == inter->stack.stack_alloc_size) {
        inter->stack.stack_alloc_size += STACK_ALLOC_SIZE;
        inter->stack.stack
            = MEM_realloc(inter->stack.stack,
                          sizeof(SIMCAR_Value) * inter->stack.stack_alloc_size);
    }
    inter->stack.stack[inter->stack.stack_pointer] = *value;
    inter->stack.stack_pointer++;
}
コード例 #17
0
ファイル: generate.c プロジェクト: BluePanM/code
static int
get_label(OpcodeBuf *ob)
{
    int ret;

    if (ob->label_table_alloc_size < ob->label_table_size + 1) {
        ob->label_table = MEM_realloc(ob->label_table,
                                      (ob->label_table_alloc_size
                                       + LABEL_TABLE_ALLOC_SIZE)
                                      * sizeof(LabelTable));
        ob->label_table_alloc_size += LABEL_TABLE_ALLOC_SIZE;
    }
    ret = ob->label_table_size;
    ob->label_table_size++;

    return ret;
}
コード例 #18
0
ファイル: create.c プロジェクト: ftomassetti/Loopr
void
Asm_begin_namespace(char *name)
{
	Asm_Compiler *compiler;

	compiler = Asm_get_current_compiler();
	compiler->name_space = MEM_realloc(compiler->name_space,
									   sizeof(NameSpace) * (compiler->name_space_count + 1));
	compiler->name_space[compiler->name_space_count].name = name;
	compiler->name_space[compiler->name_space_count].top_level = NULL;
	compiler->name_space[compiler->name_space_count].function_count = 0;
	compiler->name_space[compiler->name_space_count].function_definition = NULL;
	compiler->current_name_space_index = compiler->name_space_count;
	compiler->name_space_count++;

	return;
}
コード例 #19
0
ファイル: generate.c プロジェクト: BluePanM/code
static void
generate_code(OpcodeBuf *ob, int line_number, DVM_Opcode code, ...)
{
    va_list     ap;
    int         i;
    char        *param;
    int         param_count;
    int         start_pc;

    va_start(ap, code);

    param = dvm_opcode_info[(int)code].parameter;
    param_count = strlen(param);
    if (ob->alloc_size < ob->size + 1 + (param_count * 2)) {
        ob->code = MEM_realloc(ob->code, ob->alloc_size + OPCODE_ALLOC_SIZE);
        ob->alloc_size += OPCODE_ALLOC_SIZE;
    }

    start_pc = ob->size;
    ob->code[ob->size] = code;
    ob->size++;
    for (i = 0; param[i] != '\0'; i++) {
        unsigned int value = va_arg(ap, int);
        switch (param[i]) {
        case 'b': /* byte */
            ob->code[ob->size] = (DVM_Byte)value;
            ob->size++;
            break;
        case 's': /* short(2byte int) */
            ob->code[ob->size] = (DVM_Byte)(value >> 8);
            ob->code[ob->size+1] = (DVM_Byte)(value & 0xff);
            ob->size += 2;
            break;
        case 'p': /* constant pool index */
            ob->code[ob->size] = (DVM_Byte)(value >> 8);
            ob->code[ob->size+1] = (DVM_Byte)(value & 0xff);
            ob->size += 2;
            break;
        default:
            DBG_assert(0, ("param..%s, i..%d", param, i));
        }
    }
    add_line_number(ob, line_number, start_pc);

    va_end(ap);
}
コード例 #20
0
ファイル: native.c プロジェクト: night-lin/origin
ORG_Value org_nv_fgets_proc(ORG_Interpreter *interpreter, int arg_count, ORG_Value *args) {
    ORG_Value value;
    FILE *fp;
    char buf[LINE_BUF_SIZE];
    char *ret_buf = NULL;
    int ret_len = 0;

    if (arg_count < 1) {
        //org_runtime_error(0, ARGUMENT_TOO_FEW_ERR, MESSAGE_ARGUMENT_END);
        exit(1);
    } else if (arg_count > 1) {
        //org_runtime_error(0, ARGUMENT_TOO_MANY_ERR, MESSAGE_ARGUMENT_END);
        exit(1);
    }
    if (args[0].type != ORG_NATIVE_POINTER_VALUE || !check_native_pointer(&args[0])) {
        //org_runtime_error(0, FGETS_ARGUMENT_TYPE_ERR, MESSAGE_ARGUMENT_END);
        exit(1);
    }
    fp = args[0].u.native_pointer.pointer;

    while (fgets(buf, LINE_BUF_SIZE, fp)) {
        int new_len;
        new_len = ret_len + strlen(buf);
        ret_buf = MEM_realloc(ret_buf, new_len + 1);
        if (ret_len == 0) {
            strcpy(ret_buf, buf);
        } else {
            strcat(ret_buf, buf);
        }
        ret_len = new_len;
        if (ret_buf[ret_len-1] == '\n')
            break;
    }
    if (ret_len > 0) {
        value.type = ORG_STRING_VALUE;
        value.u.string_value = org_create_origin_string(interpreter, ret_buf);
    } else {
        value.type = ORG_NULL_VALUE;
    }

    return value;
}
コード例 #21
0
ファイル: generate.c プロジェクト: BluePanM/code
static void
add_line_number(OpcodeBuf *ob, int line_number, int start_pc)
{
    if (ob->line_number == NULL
        || (ob->line_number[ob->line_number_size-1].line_number
            != line_number)) {
        ob->line_number = MEM_realloc(ob->line_number,
                                      sizeof(DVM_LineNumber)
                                      * (ob->line_number_size + 1));

        ob->line_number[ob->line_number_size].line_number = line_number;
        ob->line_number[ob->line_number_size].start_pc = start_pc;
        ob->line_number[ob->line_number_size].pc_count
            = ob->size - start_pc;
        ob->line_number_size++;

    } else {
        ob->line_number[ob->line_number_size-1].pc_count
            += ob->size - start_pc;
    }
}
コード例 #22
0
ファイル: create.c プロジェクト: ftomassetti/Loopr
Statement *
Asm_create_statement(char *label, Bytecode *code, Constant *const_opt)
{
	NameSpace *name_space;
	Statement *ret;

	name_space = &Asm_get_current_compiler()->name_space[Asm_get_current_compiler()->current_name_space_index];
	ret = ASM_malloc(sizeof(Statement));
	ret->label = label;
	ret->bytecode = code;
	ret->constant = const_opt;
	ret->line_number = get_current_line_number();

	if (code && code->name == NULL && code->next
		&& !strcmp(code->next->name, Loopr_CR_Info[LCR_FUNCTION].assembly_name)) {
		if (name_space->function_definition) {
			name_space->function_definition = MEM_realloc(name_space->function_definition,
														sizeof(FunctionDefinition) * (name_space->function_count + 1));
		} else {
			name_space->function_definition = MEM_malloc(sizeof(FunctionDefinition) * (name_space->function_count + 1));
		}

		name_space->function_definition[name_space->function_count].is_void = LPR_False;
		while (const_opt && const_opt->type == CONST_KEYWORD) {
			switch (const_opt->u.keyword_value) {
				case ASM_VOID:
					name_space->function_definition[name_space->function_count].is_void = LPR_True;
					const_opt = const_opt->next;
					break;
				default:
					DBG_panic(("line %d: Unknown keyword %d\n", const_opt->line_number, const_opt->u.keyword_value));
					break;
			}
		}
		name_space->function_definition[name_space->function_count].name = MEM_strdup(const_opt->u.string_value);
		name_space->function_count++;
	}

	return ret;
}
コード例 #23
0
ファイル: execute.c プロジェクト: aaronguo1996/MiniC
static void
add_functions(MVM_VirtualMachine *mvm, MVM_Executable *executable)
{
    int src_idx;
    int dest_idx;
    int func_count = 0;

    for (src_idx = 0; src_idx < executable->function_count; src_idx++) {
        if (executable->function[src_idx].is_implemented) {
            func_count++;
            for (dest_idx = 0; dest_idx < mvm->function_count; dest_idx++) {
                if (!strcmp(mvm->function[dest_idx].name,
                            executable->function[src_idx].name)) {
                    /*
                    mvm_error(NULL, NULL, NO_LINE_NUMBER_PC,
                          FUNCTION_MULTIPLE_DEFINE_ERR,
                          STRING_MESSAGE_ARGUMENT, "name",
                          mvm->function[dest_idx].name,
                          MESSAGE_ARGUMENT_END); */
                }
            }
        }
    }
    mvm->function = MEM_realloc(mvm->function,
                                sizeof(Function) * (mvm->function_count + func_count));

    for (src_idx = 0, dest_idx = mvm->function_count;
            src_idx < executable->function_count; src_idx++) {
        if (!executable->function[src_idx].is_implemented)
            continue;
        mvm->function[dest_idx].name
            = MEM_strdup(executable->function[src_idx].name);
        mvm->function[dest_idx].u.minic_f.executable
            = executable;
        mvm->function[dest_idx].u.minic_f.index = src_idx;
        dest_idx++;
    }
    mvm->function_count += func_count;
}
コード例 #24
0
ファイル: heap.c プロジェクト: yili3366/toy_compiler
void
crb_array_add(CRB_Interpreter *inter, CRB_Object *obj, CRB_Value v)
{
    int new_size;

    DBG_assert(obj->type == ARRAY_OBJECT, ("bad type..%d\n", obj->type));

    check_gc(inter);
    if (obj->u.array.size + 1 > obj->u.array.alloc_size) {
        new_size = obj->u.array.alloc_size * 2;
        if (new_size == 0
            || new_size - obj->u.array.alloc_size > ARRAY_ALLOC_SIZE) {
            new_size = obj->u.array.alloc_size + ARRAY_ALLOC_SIZE;
        }
        obj->u.array.array = MEM_realloc(obj->u.array.array,
                                         new_size * sizeof(CRB_Value));
        inter->heap.current_heap_size
            += (new_size - obj->u.array.alloc_size) * sizeof(CRB_Value);
        obj->u.array.alloc_size = new_size;
    }
    obj->u.array.array[obj->u.array.size] = v;
    obj->u.array.size++;
}
コード例 #25
0
ファイル: heap.c プロジェクト: yili3366/toy_compiler
void
crb_array_resize(CRB_Interpreter *inter, CRB_Object *obj, int new_size)
{
    int new_alloc_size;
    CRB_Boolean need_realloc;
    int i;

    check_gc(inter);

    if (new_size > obj->u.array.alloc_size) {
        new_alloc_size = obj->u.array.alloc_size * 2;
        if (new_alloc_size < new_size) {
            new_alloc_size = new_size + ARRAY_ALLOC_SIZE;
        } else if (new_alloc_size - obj->u.array.alloc_size
                   > ARRAY_ALLOC_SIZE) {
            new_alloc_size = obj->u.array.alloc_size + ARRAY_ALLOC_SIZE;
        }
        need_realloc = CRB_TRUE;
    } else if (obj->u.array.alloc_size - new_size > ARRAY_ALLOC_SIZE) {
        new_alloc_size = new_size;
        need_realloc = CRB_TRUE;
    } else {
        need_realloc = CRB_FALSE;
    }
    if (need_realloc) {
        check_gc(inter);
        obj->u.array.array = MEM_realloc(obj->u.array.array,
                                         new_alloc_size * sizeof(CRB_Value));
        inter->heap.current_heap_size
            += (new_alloc_size - obj->u.array.alloc_size) * sizeof(CRB_Value);
        obj->u.array.alloc_size = new_alloc_size;
    }
    for (i = obj->u.array.size; i < new_size; i++) {
        obj->u.array.array[i].type = CRB_NULL_VALUE;
    }
    obj->u.array.size = new_size;
}