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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? semantics.cpp

?? 卡耐基SSD6全部選擇題和練習題解決方法。
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/* semantics -- */

#include "flincl.h"
#include "shortstack.h"
#include "semantics.h"
#include "stdio.h" // for compiler.h
#include "compiler.h"
#include "assert.h"

#define must(emit) if (!(emit)) return false;

typedef struct {
	char *name;
	short params;
	short op;
} Builtin_desc;

// built_ins are "global functions" that cannot be
// overridden or overloaded
Builtin_desc built_ins[] = {
	{ "array", 1, OP_NEWARRAY },
    { "dict", 1, OP_NEWDICT },
    { "flatten", 1, OP_FLATTEN },
    { "repr", 1, OP_REPR },
    { "str", 1, OP_STR },
    { "type", 1, OP_TYPE },
    { "len", 1, OP_LENGTH },
    { "cos", 1, OP_COS },
    { "sin", 1, OP_SIN },
    { "tan", 1, OP_TAN },
    { "exp", 1, OP_EXP },
    { "sqrt", 1, OP_SQRT },
    { "rem", 1, OP_REM },
    { "min", 2, OP_MIN },
    { "max", 2, OP_MAX },
    { "random", 0, OP_RANDOM },
    { "abs", 1, OP_ABS },
    { "int", 1, OP_TRUNCATE },
    { "round", 1, OP_ROUND },
    { "float", 1, OP_FLOAT },
    { "chr", 1, OP_CHR },
    { "ord", 1, OP_ORD },
    { "hex", 1, OP_HEX },
    { "id", 1, OP_ID },
    { "intern", 1, OP_INTERN },
    { "isinstance", 2, OP_INST },
    { "issubclass", 2, OP_SUBCL },
    { "oct", 1, OP_OCT },
    { "strcat", 2, OP_STRCAT },
    { "subseq", 3, OP_SUBSEQ },
    { "isupper", 1, OP_ISUPPER },
    { "islower", 1, OP_ISLOWER },
    { "isalpha", 1, OP_ISALPHA },
    { "isdigit", 1, OP_ISDIGIT },
    { "isalnum", 1, OP_ISALNUM },
    { "toupper", 1, OP_TOUPPER },
    { "tolower", 1, OP_TOLOWER },
    { "find", 4, OP_FIND },
	{ "exit", 0, OP_EXIT },
	{ "frame_previous", 1, OP_FRMPREV },
	{ "frame_variables", 1, OP_FRMVARS },
	{ "frame_pc", 1, OP_FRMPC },
	{ "frame_method", 1, OP_FRMMETH },
	{ "frame_class", 1, OP_FRMCLASS },
	{ "runtime_exception_nesting", 0, OP_NEST },
	{ "frame_get", 0, OP_FRMGET },
	{ NULL, 0, 0 }
};

// builtin_methods are implemented by op_codes,
// but if the first operand's type is object,
// a method lookup is performed. Builtin_methods
// allow us to implement builtin methods on builtin
// types, and run more efficiently than a full
// method call which allocates a frame.
Builtin_desc builtin_methods[] = {
    { "readline", 0, OP_READLINE },
    { "write", 1, OP_WRITE },
    { "read", 1, OP_READ },
	{ "unread", 1, OP_UNREAD },
    { "readvalue", 0, OP_READVAL },
    { "close", 0, OP_CLOSE },
    { "token", 0, OP_TOKEN },
	{ "append", 1, OP_APPEND },
	{ "unappend", 0, OP_UNAPPEND },
    { "last", 0, OP_LAST },
    { "keys", 0, OP_KEYS },
    { "values", 0, OP_VALUES },
    { "clear", 0, OP_CLEAR },
    { "index", 1, OP_INDEX },
    { "reverse", 0, OP_REVERSE },
    { "sort", 0, OP_SORT },
    { "remove", 1, OP_REMOVE },
    { "copy", 0, OP_COPY },
    { "has_key", 1, OP_HASKEY },
    { "get", 2, OP_GET },
	{ "value", 0, OP_VALUE },
    // { "get2", 2, OP_GET2 },
    { NULL, 0, 0 }
};



// builtin -- searches for id in built-in list
//
// if found, return op-code required to execute the built-in
// and set actuals to the number of parameters required by
// the built-in function
// otherwise, return 0 and set actuals to -1
//
short Semantics::builtin(char *id, short *actuals)
{
    int i = 0;
	while (built_ins[i].name) {
		if (streql(built_ins[i].name, id)) {
			*actuals = built_ins[i].params;
			return instr_compose(instr_op, built_ins[i].op);
		}
		i++;
	}
	*actuals = -1;
	return 0;
}


short Semantics::builtin_method(char *id, short *actuals)
{
    int i = 0;
    while (builtin_methods[i].name) {
        if (streql(builtin_methods[i].name, id)) {
            *actuals = builtin_methods[i].params;
            return instr_compose(instr_op, builtin_methods[i].op);
        }
        i++;
    }
    *actuals = -1;
    return 0;
}


bool Semantics::init(Machine_ptr m, Compiler_ptr c)
{
	mach = m;
	comp = c;
	instructions = NULL;
	if_stack = Short_stack::create(3, mach);
	loop_stack = Short_stack::create(2, mach);
	assign_stack = Short_stack::create(2, mach);
	indent_stack = Short_stack::create(8, mach);
	array_stack = Short_stack::create(2, mach);
	call_stack = Short_stack::create(2, mach);
    return if_stack && loop_stack && assign_stack && 
        indent_stack && array_stack && call_stack;
    // BUG: need error report here if returning false
}


Semantics::Semantics()
{
}


bool Semantics::reset()
{
    if (instructions) {
        //FLSys::free(instructions, max_instr);
    }
	class_started = false;
	method_started = false;
	local_offset = 0;
	member_offset = 0;
    next_instr = 0;
    max_instr = 0;
	method = NULL;
	fclass = NULL;
	method_name = NULL;
    class_name = NULL;
    var_name = NULL;
	array_index = 0;
	opcode = 0;
    actuals = 0;
	// initially has room for 16 symbols
	symbols = Array::create(0, 16, mach);
    return symbols != NULL;
}


bool Semantics::emit(short instruction)
{
    if (next_instr >= max_instr) {
        if (!grow()) return false;
    }
    if (next_instr < max_instr) {
        instructions->set_instr(next_instr++, instruction, 
                                mach->trace_flag);
    }
    return true;
}


bool Semantics::emit_at(long location, long instruction)
{
    assert(location < next_instr);
	if (instruction > 0x7FFF || instruction < -0x10000) {
		comp->report_error("virtual machine limitation: branch out of bounds");
		return false;
	}
    instructions->set_instr(location, (short) instruction, 
                            mach->trace_flag);
	return true;
}


bool Semantics::for_var(char *id)
{
	long index;  // variable index in frame
	// is this a local? look in method symbol table
	Symbol_ptr s = Symbol::create(id, mach);
    if (!method->get_localtable()->lookup(s, &index)) {
		comp->report_error("undeclared loop variable");
		return false;
	}
	// now index is the loop variable offset
	loop_stack->push((short) index, mach);
	return true;
}


bool Semantics::for_init()
{
	short index = loop_stack->pop(mach);
	// store the initial value
	must(emit(instr_compose(instr_store_local, (short) index)));
	loop_stack->push(index, mach);  // save for later
	return true;
}


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


bool Semantics::for_by(bool by_flag)
{
	if (!by_flag) { // no BY expression
		emit(instr_compose(instr_load_int, 1));
	}
	// generate instruction to push the loopcounter
	short index = loop_stack->pop(mach);
	loop_stack->push(index, mach);
	emit(instr_compose(instr_load_local, (short) index));
	emit(OP_JUMP);
	loop_stack->push(next_instr, mach);
	emit(0);
	// machine stack is to_value, by_value, loopcount (top)
	return true;
}


// for_end_range -- called after for-=-to-by-:
//
bool Semantics::for_end_range()
{
	long looptop = loop_stack->pop(mach);
	long loopvar = loop_stack->pop(mach);
	return emit(OP_LOOPINC) &&
	       emit((short) loopvar) &&
		   // jump instruction is pc += *pc,
		   //    next_instr = looptop + *looptop,
		   //    *looptop = next_instr - looptop
		   emit_at(looptop, next_instr - looptop) &&
		   emit(OP_LOOPTST) &&
		   // jump instruction is pc += *pc
		   //    looptop + 1 = next_instr + *next_instr
		   //    *next_instr = looptop + 1 - next_instr
		   emit(looptop + 1 - next_instr) &&
	       // break instructions should branch to here
		   emit(OP_POP2);
}


bool Semantics::for_array()
{
	short index = loop_stack->pop(mach);
	must(emit(instr_compose(instr_load_int, 0)));
	must(emit(OP_JUMP));
	loop_stack->push(next_instr, mach);
	return emit(0) &&
		   // store the initial value
		   emit(instr_compose(instr_store_local, index));
}


bool Semantics::for_end_elements()
{
	// stack has looptop-1
	// machine stack has array index, then array
	long looptop = loop_stack->pop(mach);
	return emit_at(looptop, next_instr - looptop) &&
		   emit(OP_LOOPNXT) &&
		   emit(looptop - next_instr);
}


bool Semantics::return_null()
{
    emit(OP_RETNULL);
    return true;
}


// unemit -- undo the previous emit, and return opcode
//
short Semantics::unemit()
{
    if (next_instr <= 0) return OP_NOOP;
    next_instr--;
    return instructions->get_instr(next_instr);
}

    
bool Semantics::grow()
{
    short newlen = 128;
    if (newlen <= max_instr) newlen = max_instr * 2;
    assert(max_instr < newlen);
    Code_ptr newinstr = Code::create(newlen, mach);
    if (!newinstr) return false;
	if (next_instr > 0) {
        for (long i = 0; i < next_instr; i++) {
            newinstr->set_instr(i, instructions->get_instr(i), false);
		}
	}
    instructions = newinstr;
    max_instr = newlen;
    return true;
}


// call prepares to invoke a function.
// The current opcode,actuals pair is pushed
// The new opcode is looked up and saved until
// after parameters are ready
//
bool Semantics::call(char *id)
{
	call_stack->push(opcode, mach);
	call_stack->push(actuals, mach);
	opcode = builtin(id, &actuals);
	if (opcode == 0) {
	    long index = insert_symbol(id);
	    assert(index >= 0 && index < 2048);
	    emit(instr_compose(instr_local_frame, (short) index));
	}
	return true;
}


bool Semantics::method_call(char *id)
{
	call_stack->push(opcode, mach);
	call_stack->push(actuals, mach);
    opcode = builtin_method(id, &actuals);
    if (opcode == 0) {
	    long index = insert_symbol(id);
	    assert(index >= 0 && index < 2048);
	    opcode = instr_compose(instr_frame, (short) index);
    }
    return true;
}


bool Semantics::class_start(char *class_name, char *super_name)
{
	fclass = FClass::create(mach);
	if (!fclass) return false;
	Symbol_ptr s = Symbol::create(class_name, mach);
	mach->push(s);
	FClass_ptr probe = mach->class_lookup(s);
	if (probe) {
		comp->report_error("class is already defined");
		mach->pop();
		fclass = NULL;
		return false;
	}
	mach->class_add(s, fclass);
	mach->pop();
	if (super_name[0]) {
		s = Symbol::create(super_name, mach);
		FClass_ptr super = mach->class_lookup(s);
		if (!super) {
			comp->report_error("super class is undefined");
			fclass = NULL;
			return false;
		}
		fclass->init_super(super);
		member_offset = super->get_inst_slots();
	} else {
		member_offset = 1; // all objects have class pointer
	}
	class_started = true;
	return true;
}


bool Semantics::method_start()
{
    method_started = true;
    local_offset = 0;
    return true;
}


bool Semantics::method_end()
{
	emit(instr_compose(instr_op, OP_RETNULL));
	// copy the code vector to the method
    Code_ptr newinstr = Code::create(next_instr, mach);
    if (!newinstr) return false;
    for (long i = 0; i < next_instr; i++) {
        newinstr->set_instr(i, instructions->get_instr(i), false);
	}
    int len = 1;
    if (mach->trace_flag) {
        for (i = 0; i < next_instr; i += len) {
            char text[64];
            trace(newinstr->disassemble(i, newinstr->get_instr(i), 
                                        newinstr->get_instr(i + 1), text, 
                                        &len, method));
        }
    }
	method->set_code(newinstr, mach);
	method = NULL;
	method_started = false;
	next_instr = 0;
	return true;
}


bool Semantics::method_name_is(char *name)
{
	method_name = Symbol::create(name, mach);
    method = Method::create(method_name, mach);
    if (class_started) { // insert method in the class
		fclass->enter_method(method_name, method, mach);
		method->set_fclass(fclass, mach);
	} else { // attach method to symbol
        method_name->set_function(method, mach);
        method->set_fclass(NULL, mach);
    }
    // add symbols to method:
   	method->init_symbols(symbols, mach);
	if (mach->trace_flag)
        trace("method_name_is: symbol name is %s\n", 
		      method_name->get_name()->get_string());
    return true;
}


bool Semantics::begin_formals()
{
    formal_type = FORMAL_REQUIRED;
    return true;
}


bool Semantics::set_formal_type(short ft)
{
    if (ft < formal_type) {
    	comp->report_error("formal type out of order");
        return false;
    }
    formal_type = ft;
    return true;
}


bool Semantics::formal_is(char *name)
{
	// convert the name to a symbol in this class
	var_name = Symbol::create(name, mach);
    // position the stack above the parameter:
	method->set_stack_offset(1 + method->get_stack_offset());
    switch (formal_type) {
      case FORMAL_OPTIONAL:
        method->set_optionals(1 + method->get_optionals());
        // no break, fall through to increment parameters too!
      case FORMAL_REQUIRED:
        method->set_parameters(1 + method->get_parameters());
        break;
      case FORMAL_KEYWORD:
        method->set_keywords(1 + method->get_keywords());
        break;
      case FORMAL_REST:
        method->set_rest_flag(true);
        break;
      case FORMAL_DICTIONARY:
        method->set_dict_flag(true);
        break;
    }
        
    return method->get_localtable()->insert_var(var_name, local_offset++, mach);
}


bool Semantics::default_value(FVal v)
{
    // first see if there is an optionals array:
    Array_ptr defaults = method->get_default();
    if (!defaults) {
        defaults = Array::create(1, 1, mach);
        method->set_default(defaults);
    }
    // this new value is for local_offset-1, but the defaults start
    // at parameters - optionals
    long index = local_offset - 1 - 
        (method->get_parameters() - method->get_optionals());
    // make sure array is long enough:
    while (defaults->get_array_len() <= index) {
        defaults->append(NULL, mach);
    }
    defaults->set_fastref(index, v, mach);
    return true;
}


bool Semantics::end_of_formals()
{
    // signature is number of formals
    // stack_offset is number of formals + locals
	// frame_slots is stack_offset + maximum stack size
	method->set_frame_slots(method->get_stack_offset() + 
							EXPR_STACK_MAX);
    return true;
}


bool Semantics::id(char *id)
{
	Symbol_ptr s = Symbol::create(id, mach);
	long index; // variable index in frame
	Method_ptr mp;
	mach->push(s);
	// is this a local? look in method symbol table
    if (method->get_localtable()->lookup(s, &index)) {
		must(emit(instr_compose(instr_load_local, (short) index)));
	} else if (fclass &&
               fclass->get_symboltable()->lookup(s, &mp, &index) &&
			   mp == NULL) {
		must(emit(instr_compose(instr_load_instvar, (short) index)));
	} else { // load value from a global
		index = insert_symbol(id);
		must(emit(instr_compose(instr_load_global, (short) index)));
	}
	mach->pop();
	return true;
}


bool Semantics::assign_id(char *id)
{
	Symbol_ptr s = Symbol::create(id, mach);
	long index; // variable index in frame
	Method_ptr mp;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品一区专区| 日韩激情视频在线观看| 国产成人午夜精品5599| 欧美经典一区二区三区| 成人h动漫精品| 亚洲狠狠爱一区二区三区| 欧美日韩国产高清一区二区三区| 亚洲1区2区3区4区| 欧美成人r级一区二区三区| 国产成人自拍在线| 亚洲精品欧美激情| 欧美一区二区三区在线视频| 精品亚洲免费视频| 成人欧美一区二区三区黑人麻豆 | 久久精品免费看| 精品理论电影在线| 91亚洲男人天堂| 午夜国产精品一区| 国产婷婷一区二区| 欧美四级电影网| 国产电影一区二区三区| 一区av在线播放| 久久亚洲精品小早川怜子| 99久久国产综合精品女不卡| 亚洲3atv精品一区二区三区| 久久精品视频免费| 欧美三级资源在线| 国产精品香蕉一区二区三区| 亚洲影视在线播放| 日本一区二区在线不卡| 欧美年轻男男videosbes| 国产精品1024| 石原莉奈在线亚洲二区| 国产精品国产三级国产aⅴ中文| 欧美日韩国产不卡| av激情综合网| 国产一区二区在线影院| 亚洲成人动漫在线观看| 国产精品午夜在线| 日韩免费观看高清完整版在线观看| 国产.欧美.日韩| 麻豆精品一区二区三区| 伊人色综合久久天天人手人婷| 久久先锋影音av| 欧美电影在线免费观看| 99久久99久久精品免费看蜜桃| 奇米精品一区二区三区四区 | 欧美成人bangbros| 欧美日韩综合色| 成人成人成人在线视频| 极品瑜伽女神91| 亚洲123区在线观看| 亚洲人成在线播放网站岛国| 国产午夜精品久久| 久久综合久久综合久久综合| 欧美剧情电影在线观看完整版免费励志电影| 福利电影一区二区三区| 麻豆国产一区二区| 天堂影院一区二区| 亚洲伊人伊色伊影伊综合网| 自拍偷在线精品自拍偷无码专区 | 97久久精品人人爽人人爽蜜臀| 美女精品自拍一二三四| 天堂成人国产精品一区| 亚洲成人免费视频| 亚洲444eee在线观看| 亚洲精品国产无天堂网2021| 国产精品久久午夜| 国产精品色噜噜| 中文字幕欧美三区| 国产精品久久久久久妇女6080 | 国产精品福利一区二区| 亚洲国产经典视频| 中文一区在线播放| 日韩一区日韩二区| 日韩毛片高清在线播放| 亚洲精品国产成人久久av盗摄 | 麻豆国产精品官网| 免费在线观看一区二区三区| 人人狠狠综合久久亚洲| 蜜臀久久久久久久| 麻豆精品国产91久久久久久| 经典三级视频一区| 国产精品一区免费在线观看| 国产经典欧美精品| 99久久精品国产精品久久| 色综合中文综合网| 国产高清无密码一区二区三区| 精品一区二区三区视频| 国产美女在线观看一区| 成人国产精品视频| 在线视频国产一区| 6080亚洲精品一区二区| 精品少妇一区二区三区 | 欧美一区二区免费视频| 日韩欧美一区在线| 欧美激情综合五月色丁香小说| 国产精品久久久久三级| 一区二区三区欧美在线观看| 亚洲福利视频导航| 精品一区二区三区久久久| 国产精品一区二区久久不卡| www.综合网.com| 欧美日韩国产成人在线免费| 日韩精品一区二区三区在线| 国产欧美日韩中文久久| 亚洲精品你懂的| 久久狠狠亚洲综合| 成人av网址在线观看| 欧美日韩国产区一| 国产片一区二区三区| 一级中文字幕一区二区| 久久精品噜噜噜成人88aⅴ| 波多野结衣在线aⅴ中文字幕不卡| 日本久久电影网| 日韩精品在线一区二区| 亚洲色图在线播放| 久久国产精品免费| 日本韩国一区二区三区视频| 欧美成人官网二区| 夜夜嗨av一区二区三区网页| 精品在线观看视频| 在线观看视频91| 国产女人aaa级久久久级| 午夜精品久久久久久久99水蜜桃| 国产成人精品亚洲777人妖 | eeuss鲁一区二区三区| 日韩一区二区三区电影在线观看 | 精品成人一区二区| 美洲天堂一区二卡三卡四卡视频 | 午夜国产不卡在线观看视频| 高清av一区二区| 日韩一区二区电影| 亚洲图片一区二区| 不卡欧美aaaaa| 久久久久久久综合日本| 免费精品视频在线| 欧美亚洲自拍偷拍| 亚洲欧美影音先锋| 久久99精品视频| 91精品国产品国语在线不卡| 亚洲欧美偷拍三级| 成人午夜电影网站| 久久亚洲综合色| 青青青爽久久午夜综合久久午夜 | 51精品秘密在线观看| 亚洲欧美偷拍卡通变态| 懂色中文一区二区在线播放| 日韩无一区二区| 日韩精品一二三| 欧美久久久久免费| 亚洲成精国产精品女| 一本一道波多野结衣一区二区| 国产目拍亚洲精品99久久精品| 久草中文综合在线| 91精品中文字幕一区二区三区| 亚洲视频一区在线| 色综合久久综合网97色综合| 中文字幕二三区不卡| 高清国产一区二区| 中文一区二区在线观看| 国产69精品久久久久777| 国产校园另类小说区| 国产高清一区日本| 国产欧美va欧美不卡在线| 国产福利不卡视频| 中文字幕欧美日韩一区| 不卡一区中文字幕| 亚洲男女一区二区三区| 91成人看片片| 亚洲成人777| 91精品国产入口| 精品一区二区在线免费观看| 欧美成人一区二区| 国产伦精品一区二区三区在线观看| 精品国产91亚洲一区二区三区婷婷| 老司机一区二区| 久久精品男人天堂av| 国产成人精品一区二区三区四区 | 日本一区二区三级电影在线观看| 风间由美一区二区av101| 国产精品美女久久久久av爽李琼| 成a人片亚洲日本久久| 亚洲美腿欧美偷拍| 欧美三级日韩三级| 老司机精品视频一区二区三区| 26uuu欧美日本| 91视视频在线观看入口直接观看www| 有码一区二区三区| 日韩一区二区中文字幕| 国产美女久久久久| 亚洲精品国产第一综合99久久| 欧美日韩精品综合在线| 狠狠久久亚洲欧美| 亚洲欧美日本韩国| 欧美一区午夜视频在线观看| 国产真实乱子伦精品视频| 国产精品国产精品国产专区不蜜 | 99久久国产综合精品色伊| 亚洲午夜精品在线|