亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? semantics.cpp

?? SSD6網(wǎng)上教程全部練習及答案 原版的正確答案
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
	mach->push(s);
	// is this a local? look in method symbol table
    if (method->get_localtable()->lookup(s, &index)) {
		must(emit(instr_compose(instr_store_local, (short) index)));
	} else if (fclass && 
               fclass->get_symboltable()->lookup(s, &mp, &index) &&
			   mp == NULL) {
		trace("assign_id got instance index of %d\n", index);
		must(emit(instr_compose(instr_store_instvar, (short) index)));
	} else { // load value from a global
		index = insert_symbol(id);
		must(emit(instr_compose(instr_store_global, (short) index)));
	}
	mach->pop();
	return true;
}


bool Semantics::field(char *id)
{
	trace("field not implemented\n");	// not implemented
	return true;
}


bool Semantics::aref()
{
	return emit(OP_AREF);
}

bool Semantics::if_true()
{
    // emit a test to branch over true part
    must(emit(OP_JUMPIFNOT));
    // save PC for the branch location
    if_stack->push(next_instr, mach);
    // emit zero as a placeholder for branch location
    return emit(0);
}


bool Semantics::if_else()
{
    // this is the target for the if:
	long target = if_stack->pop(mach);
    // emit a jump around else part
    must(emit(OP_JUMP));
    // save PC for the branch location
    if_stack->push(next_instr, mach);
    // emit zero as a placeholder for branch location
    emit(0);
    return emit_at(target, next_instr - target);
}


bool Semantics::if_end()
{
    // this is the target for whatever is on the stack
	long target = if_stack->pop(mach);
    return emit_at(target, next_instr - target);
}


bool Semantics::while_begin()
{
    // remember where to branch back to
    loop_stack->push(next_instr, mach);
    return true;
}

bool Semantics::while_true()
{
    // emit a test to branch over true part
    must(emit(OP_JUMPIFNOT));
    // save PC for the branch location
    loop_stack->push(next_instr, mach);
    // emit zero as a placeholder for branch location
    return emit(0);
}


bool Semantics::while_end()
{
    // top of stack is branch out of loop
    long end_of_loop_branch = loop_stack->pop(mach);
    // now emit loop branch
    must(emit(OP_JUMP));
    must(emit(loop_stack->pop(mach) - next_instr));
    // fix up previous branch to next instr (after loop)
    return emit_at(end_of_loop_branch, next_instr - end_of_loop_branch);
}


bool Semantics::return_end()
{
    return emit(OP_RETURN);
}


bool Semantics::load_end()
{
    return emit(OP_LOAD);
}


bool Semantics::print_expr()
{
	return emit(OP_PRINT);
}


bool Semantics::print_comma()
{
    return emit(OP_SPACE);
}


bool Semantics::print_end()
{
    return emit(OP_ENDL);
}


// assign_end -- called after rval is on stack
// 
// emit pushed instruction to finish the job:
// possibilities are:
//   assign to array: stack has array, index, value
//   assign to head: stack has node, value
//   assign to tail: stack has node, value
//   assign to variable: stack has value
//   assign to field of object: stack has object, index, value
//
bool Semantics::assign_end()
{
    short op = assign_stack->pop(mach);
    return emit(op);
}


// rval2lval -- prepare for an assignment statement
//
// when you encounter an '=', the expression on the left has
// just emitted an instruction to load the value to the stack
// The method "undoes" the emit, and converts the instruction
// from one that loads a value to one that stores a value.
// Error is returned if the instruction cannot be converted.
// E.g. if the instruction is an array reference, convert to 
// a store.  If the instruction is addition, return false.
//
bool Semantics::rval2lval()
{
    // first get previous instruction
    short op = unemit();
    short newop = OP_NOOP;
    
    // now compute the assignment version of op
    short typ = instr_type(op);
    short arg = instr_arg(op);
    if (typ == instr_op) {
        if (op == OP_AREF) newop = OP_SETAREF;
        else if (op == OP_FIELD) newop = OP_SETFIELD;
    } else if (typ == instr_load_global) {
        newop = instr_compose(instr_store_global, arg);
    } else if (typ == instr_load_instvar) {
        newop = instr_compose(instr_store_instvar, arg);
    } else if (typ == instr_load_local) {
        newop = instr_compose(instr_store_local, arg);
    }
    if (newop != OP_NOOP) {
        assign_stack->push(newop, mach);
        return true;
    }
    return false;
}
        

bool Semantics::unary_minus()
{
    return emit(OP_MINUS);
}


bool Semantics::not()
{
    return emit(OP_NULL);
}


bool Semantics::lognot()
{
    return emit(OP_LOGNOT);
}


bool Semantics::push_long(int64 value)
{
	if (mach->arg_sign_extend(instr_arg((long) value)) == value) {
		return emit(instr_compose(instr_load_int, instr_arg((short) value)));
	} else {
		FVal lit = FLong::create(value, mach);
		mach->push(lit);
		assert(method);
		short arg = method->literal_add(lit, mach);
		mach->pop();
		return emit(instr_compose(instr_load_lit, arg));
	}
}

bool Semantics::push_double(double value)
{
	FVal lit = FDouble::create(value, mach);
	return push_fval(lit);
}


bool Semantics::push_string(char *s)
{
    FVal lit = FString::create(s, mach);
	return push_fval(lit);
}


bool Semantics::push_symbol(char *s)
{
    FVal lit = Symbol::create(s, mach);
    return push_fval(lit);
}


bool Semantics::push_fval(FVal v)
{
	mach->push(v);
	assert(method);
	short arg = method->literal_add(v, mach);
	mach->pop();
	return emit(instr_compose(instr_load_lit, arg));
}


bool Semantics::var_decl(char * id)
{
	if (method_started) { // local variable in method
		assert(method);
		Symbol_ptr s = Symbol::create(id, mach);
		assert(s);
		mach->push(s);
		trace("var_decl: before new method variable, locals are:\n");
		method->get_localtable()->trace_locals();
		if (!method->get_localtable()->
			insert_var(s, local_offset++, mach)) {
			comp->report_error("local variable already declared");
			mach->pop();
			return false;
		}
		method->set_stack_offset(1 + method->get_stack_offset());
		mach->pop();
	} else if (class_started) {
		assert(fclass);
		Symbol_ptr s = Symbol::create(id, mach);
		mach->push(s);
		trace("instance var at index %d\n", member_offset);
		if (!fclass->get_symboltable()->
			insert_var(s, member_offset++, mach)) {
			comp->report_error("instance variable already declared");
			mach->pop();
			return false;
		}
		mach->pop();
		fclass->set_inst_slots(member_offset);
	}
	// undeclared variables are globals, the value is stored on the
	// symbol itself, so we do not need to enter it into a table

	// show current state of things
	if (method_started) {
		trace("current locals are:\n");
		method->get_localtable()->trace_locals();
	} else if (class_started) {
		trace("current members are:\n");
		fclass->get_symboltable()->trace_members();
	} else trace("global variable declared\n");
	return true;		
}


// Here's how array code generation works:
//    the current array_index is pushed on array_stack
//     and array_index is set to 0
//     (in case we are dealing with nested arrays)
//    emit placeholder for the size of the array
//     (so there is an upper bound on the size of a 
//     literal array: the maximum literal integer,
//     which is 2047)
//    the location of the literal is pushed on array_stack
//    the create array instruction is emitted
//    for each expression, we duplicate the top of stack,
//     emit a literal index, and emit a store into array op
//    at array_end, we know the size of the array, so we
//     pop the stack and emit the size at that location
//    finally, pop the previous array_index value
bool Semantics::array_start()
{
	array_stack->push(array_index, mach);
	array_index = 0;
	array_stack->push(next_instr, mach);
	return emit(0) && emit(OP_NEWARRAY);
}

bool Semantics::dict_start()
{
	array_stack->push(array_index, mach);
	array_index = 0;
	array_stack->push(next_instr, mach);
	return emit(0) && emit(OP_NEWDICT);
}



bool Semantics::before_array_expr()
{
	short instr = instr_compose(instr_load_int, array_index);
	if (instr_arg(instr) != array_index) {
		comp->report_error("array expression too long");
		return false;
	}
	array_index++;
    return emit(OP_DUP) && emit(instr);
}


bool Semantics::before_dict_key()
{
	array_index++;
    return emit(OP_DUP);
}


bool Semantics::before_dict_val()
{
    return true;
}



bool Semantics::array_expr()
{
    return emit(OP_SETAREF);
}

bool Semantics::dict_key()
{
    return true;
}


bool Semantics::dict_val()
{
    return emit(OP_SETAREF);
}



bool Semantics::array_end()
{
	must(emit_at(array_stack->pop(mach), 
			     instr_compose(instr_load_int, array_index)));
	array_index = array_stack->pop(mach);
	return true;
}


bool Semantics::dict_end()
{
	must(emit_at(array_stack->pop(mach), 
			     instr_compose(instr_load_int, array_index)));
	array_index = array_stack->pop(mach);
	return true;
}


// here's how calls work: 
// there are many built-in functions that compile to instructions
// which must be handled here rather than at run-time. When call()
// or method_call() is called, we look up the function to see if it
// is built-in. If so, we push the corresponding opcode and then
// the required number of parameters onto the call_stack (a 
// compile-time structure). If the function is not built-in, we
// push zero and -1. Whenever we get an actual, we look at the top
// of stack. If opcode = 0 (not built-in), we generate a param opcode, 
// otherwise we decrement
// the top of stack. (At runtime the parameter will be left on the
// expression stack, not copied to a frame.) If the top of stack 
// would go to -1, we return an error (too many parameters).
// When we get an actual_end() we look at the opcode:
// If non-zero, emit it. If zero, emit the
// call opcode. If actuals is greater than zero, return an error
// (too few actuals).
// FOR CONVENIENCE, we will keep the top of the stack in member vars,
// opcode and actuals.

bool Semantics::actual()
{
    if (opcode == 0) return emit(OP_PARAM);
	if (actuals == 0) {
		comp->report_error("too many parameters");
		return false;
	}
	actuals--;
	return true;
}


bool Semantics::keyword(long index)
{
    assert(index < 0x10000);
    if (opcode == 0) {
        return emit(OP_KEYPARAM) && emit((short) index);
    } else {
        comp->report_error("unexpected keyword parameter");
        return false;
    }
}


bool Semantics::actual_end()
{
    // if optional start, stop parameters are missing, fill
    // them in now
    if (opcode == instr_compose(instr_op, OP_FIND)) {
        if (actuals == 2) {
            push_long(0);
            actuals--;
        }
        if (actuals == 1) {
            push_long(-1);
            actuals--;
        }
    // this is another style for variable argument lists
    // if get(key) use OP_GET, if get(key, default) use OP_GET2:
    } else if (opcode == instr_compose(instr_op, OP_GET)) {
        if (actuals == 1) {
            actuals--; // OP_GET really takes one parameter
        } else if (actuals == 0) {
            // 2 parameters, so use OP_GET2:
            opcode = instr_compose(instr_op, OP_GET2);
        }
    }
	if (actuals > 0) {
		comp->report_error("too few parameters");
		return false;
	}
	if (opcode != 0) emit(opcode);
	else emit(instr_compose(instr_op, OP_CALL));
    actuals = call_stack->pop(mach);  // restore actuals
	opcode = call_stack->pop(mach);   // restore opcode
	return true;
}


bool Semantics::end_id_expr()
{
	emit(instr_compose(instr_op, OP_POP));
	return true;
}

int Semantics::insert_symbol(char *str)
{
	Symbol_ptr s = Symbol::create(str, mach);
	mach->push(s);
	long len = symbols->get_array_len();
	for (int i = 0; i < len; i++) {
		if (symbols->fastref(i).symbol == s) {
			mach->pop();
			return i;
		}
	}
	symbols->append(s, mach);
	mach->pop();
	return i;
}


bool Semantics::relop(char *op)
{
    if (streql(op, "<")) return emit(OP_LESS);
    if (streql(op, ">")) return emit(OP_GTR);
    if (streql(op, "<=")) return emit(OP_LESSEQL);
    if (streql(op, ">=")) return emit(OP_GTREQL);
    if (streql(op, "==")) return emit(OP_ISEQUAL);
    if (streql(op, "!=")) return emit(OP_NOTEQUAL);
    if (streql(op, "is")) return emit(OP_IS);
    if (streql(op, "isnot")) return emit(OP_ISNOT);
    if (streql(op, "in")) return emit(OP_MEMBER);
    if (streql(op, "notin")) return emit(OP_NOTMEMBER);
    return false;
}


bool Semantics::addop(char *op)
{
    if (streql(op, "+")) return emit(OP_ADD);
    if (streql(op, "-")) return emit(OP_SUB);
    return false;
}


bool Semantics::mulop(char *op)
{
    if (streql(op, "*")) return emit(OP_MUL);
    if (streql(op, "/")) return emit(OP_DIV);
    if (streql(op, "%")) return emit(OP_REM);
    return false;
}


bool Semantics::power()
{
    return emit(OP_POWER);
}


bool Semantics::begin_and(char *op)
{
    if (op[0] == '&') return true; // logical and
    must(emit(OP_CNDAND));
    if_stack->push(next_instr, mach);
    // emit zero as a placeholder for branch location
    return emit(0);
}


bool Semantics::end_and(char *op)
{
    if (op[0] == '&') return emit(OP_LOGAND);
	long target = if_stack->pop(mach);
    return emit_at(target, next_instr - target);
    // emit a jump around 2nd operand to here
}

bool Semantics::begin_or(char *op)
{
    if (op[0] == '|' ||
        op[0] == '^') return true; // logical or
    must(emit(OP_CNDOR));
    if_stack->push(next_instr, mach);
    // emit zero as a placeholder for branch location
    return emit(0);
}


bool Semantics::end_or(char *op)
{
    if (op[0] == '|') return emit(OP_LOGIOR);
    if (op[0] == '^') return emit(OP_LOGXOR);
    if (op[0] == '<') return emit(OP_LSHIFT);
    if (op[0] == '>') return emit(OP_RSHIFT);
	long target = if_stack->pop(mach);
    return emit_at(target, next_instr - target);
    // emit a jump around 2nd operand to here
}



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久精品天堂| 午夜精品一区二区三区免费视频 | 亚洲欧美日韩人成在线播放| 亚洲国产精品久久一线不卡| 国产成人在线视频免费播放| 欧美日韩精品三区| 国产精品白丝在线| 国产一区二区三区精品欧美日韩一区二区三区 | 久久精品国产一区二区三区免费看| 成人晚上爱看视频| 日韩一二三四区| 亚洲最大成人网4388xx| 国产99久久久精品| 久久久亚洲精品石原莉奈| 亚洲18色成人| 在线一区二区三区四区五区| 中文字幕精品三区| 国产精品自拍在线| 久久久蜜臀国产一区二区| 免费成人av在线| 91精品婷婷国产综合久久性色| 亚洲一区二区三区激情| 91年精品国产| 亚洲乱码国产乱码精品精的特点 | 欧美性xxxxx极品少妇| 国产精品毛片久久久久久| 国产一区二区在线观看视频| 日韩欧美国产一区在线观看| 日韩电影在线观看一区| 欧美日韩激情一区| 日韩av一区二| 欧美成人午夜电影| 国产一区不卡在线| 国产欧美一区二区精品性色超碰| 国产一区二区不卡老阿姨| 久久欧美一区二区| 成人一区二区三区视频 | 国产成人亚洲综合色影视| 久久亚洲二区三区| 国产激情一区二区三区| 国产精品久久二区二区| 99视频精品免费视频| 亚洲女与黑人做爰| 欧美日本在线观看| 麻豆精品视频在线观看| 欧美v日韩v国产v| 国产98色在线|日韩| 日韩美女视频一区| 91.麻豆视频| 国产麻豆91精品| 亚洲人精品一区| 欧美日韩mp4| 国产精品香蕉一区二区三区| 国产精品美女视频| 欧美人狂配大交3d怪物一区| 精品一区二区三区不卡| 国产精品理伦片| 欧美日韩国产高清一区二区三区 | 欧美精品一区二区三区一线天视频 | 56国语精品自产拍在线观看| 蜜桃视频一区二区| 国产精品每日更新在线播放网址| 色吊一区二区三区| 久久国产尿小便嘘嘘| 中文字幕一区在线观看| 欧美精选午夜久久久乱码6080| 国产一区二区三区久久久| 亚洲情趣在线观看| 久久欧美一区二区| 欧美性生活久久| 国产高清精品在线| 丝袜美腿亚洲一区二区图片| 国产人伦精品一区二区| 欧美挠脚心视频网站| 成人中文字幕合集| 伦理电影国产精品| 亚洲一区二区三区四区不卡| 久久久久国产精品厨房| 欧美久久久久久蜜桃| 99国产精品视频免费观看| 美国精品在线观看| 亚洲成人av电影| 中文字幕在线观看一区| 精品福利av导航| 9191久久久久久久久久久| 99re6这里只有精品视频在线观看| 免费欧美日韩国产三级电影| 亚洲一区二区在线播放相泽 | 亚洲美女视频在线| 久久九九久精品国产免费直播| 欧美丝袜丝交足nylons图片| 成人精品免费网站| 国产精品18久久久久久vr| 天天综合色天天综合色h| 亚洲欧美日韩成人高清在线一区| 欧美va在线播放| 91麻豆精品91久久久久同性| 日本高清成人免费播放| av不卡在线播放| 成人一区二区三区在线观看| 国产精品中文字幕欧美| 免费一区二区视频| 青青青爽久久午夜综合久久午夜| 亚洲国产一区二区三区| 亚洲免费大片在线观看| 亚洲乱码精品一二三四区日韩在线| 久久久久久久久伊人| 久久综合999| 久久综合九色综合欧美就去吻| 欧美日韩精品高清| 欧美在线免费观看亚洲| 欧美视频一区二区三区在线观看 | 亚洲一二三专区| 亚洲三级电影网站| 亚洲丝袜制服诱惑| 欧美激情在线一区二区| 国产三级久久久| 日本一区二区免费在线观看视频 | 亚洲va在线va天堂| 亚洲小说春色综合另类电影| 亚洲一二三四区| 亚洲一区二区三区在线看| 亚洲成人三级小说| 日韩福利电影在线| 精品影视av免费| 国产高清成人在线| 91热门视频在线观看| 欧美亚洲愉拍一区二区| 在线视频国产一区| 5月丁香婷婷综合| 久久综合中文字幕| 亚洲欧美视频在线观看视频| 一区二区三区加勒比av| 丝袜美腿亚洲一区二区图片| 秋霞午夜鲁丝一区二区老狼| 韩国v欧美v日本v亚洲v| 成人精品免费看| 欧美体内she精高潮| 精品少妇一区二区三区免费观看| 欧美国产激情二区三区| 亚洲免费电影在线| 经典三级一区二区| 99久久婷婷国产综合精品| 欧美日韩高清一区二区三区| 亚洲精品在线观看网站| 亚洲三级在线看| 亚洲国产精品久久人人爱 | 亚洲精品高清在线| 免费看精品久久片| 99久久精品国产毛片| 91精品国产综合久久小美女| 久久久电影一区二区三区| 亚洲亚洲人成综合网络| 国产精品亚洲一区二区三区妖精 | 91看片淫黄大片一级| 欧美顶级少妇做爰| 国产精品高潮呻吟久久| 蜜臀av一级做a爰片久久| 97国产一区二区| 欧美成人国产一区二区| 亚洲激情六月丁香| 国产在线一区观看| 欧美精选午夜久久久乱码6080| 亚洲国产精品传媒在线观看| 婷婷开心激情综合| aaa欧美大片| 久久综合九色综合97婷婷女人| 亚洲综合色丁香婷婷六月图片| 国产在线国偷精品免费看| 欧美视频日韩视频在线观看| 国产精品久久毛片| 精品一区二区在线看| 精品视频999| 亚洲日本在线a| 东方欧美亚洲色图在线| 精品国产制服丝袜高跟| 日韩制服丝袜av| 欧美午夜片在线观看| 最新热久久免费视频| 在线精品视频免费播放| 国产午夜精品一区二区三区视频| 日韩精品1区2区3区| 欧美三级视频在线| 一区二区三区日韩精品| 91一区二区在线观看| 久久久久久电影| 国产一区91精品张津瑜| 欧美不卡一区二区三区四区| 日韩影视精彩在线| 欧美日韩aaaaaa| 视频一区免费在线观看| 欧美日韩国产三级| 首页亚洲欧美制服丝腿| 欧美日韩不卡视频| 日本欧美一区二区在线观看| 欧美精品色一区二区三区| 五月综合激情日本mⅴ| 欧美色网站导航| 午夜精品久久久久久久久久久 | 欧美在线|欧美|