1. oexw error
- Posted by Mario Steele <eumario at trilake.net> Dec 13, 2004
- 493 views
Hey Matt, I just wanted to let ya know, that I started working with your OO interpreter, but I ran into a problem, following the documentation you gave. Below is the code I used to try this with: ootest.exw: ------------------------------------------------
euclass Test ( sequence data ) function create() return {1,2} end function function PatchWin() return this[1] end function function Status() return this[2] end function end euclass Test wnd wnd = Test.create() printf(1,"PatchWin: %d\nStatus: %d",{wnd.PatchWin(),wnd.Status()}) while get_key() = -1 do end while
When doing this, nothing happens, no warning, no nothing. It just poofs. But, when I change }}} <eucode>wnd = Test.creat()</eucode> {{{ to }}} <eucode>wnd = Test.create(0)</eucode> {{{ or }}} <eucode>wnd = Test.create({})</eucode> {{{ it comes back as saying not initalized. I know there's something wrong with this, and just figured I'd let ya know. Mario
2. Re: oexw error
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> Dec 13, 2004
- 485 views
Mario Steele wrote: > > Hey Matt, > > I just wanted to let ya know, that I started working with your OO interpreter, > > but I ran into a problem, following the documentation you gave. Thanks, I found a related bug, but hadn't really fixed it yet. With your example, it's better now. Here's what Method() and MethodFunc() should be now (BTW, making it Test.create(0) will give a type check error):
procedure Method( token tok ) -- parse a method call statement integer scope, opcode, class_, tok1, real_instance token temp_tok symtab_index s, sym, csym -- tok1 is the method name, so we need to capture the -- instance and the dot to replace them tok1 = length(line_tokens) - 2 method_stack &= {tok} method_args &= { {} } method_name = append( method_name, SymTab[tok[T_SYM]][S_NAME] ) -- prevent an erroneous warning: SymTab[tok[T_SYM]][S_USAGE] = or_bits( U_READ, U_WRITTEN ) current_method += 1 parse_method_stack &= 1 tok_match(LEFT_ROUND) s = tok[T_SYM] -- first, send the 'this' as an argument sym = current_instance[$] if not find( sym, class_table[CLASS_SYM] ) then -- the 'current_instance' is a real instance SymTab[sym][S_USAGE] = or_bits(SymTab[sym][S_USAGE], U_READ) InitCheck(sym, TRUE) emit_opnd(sym) real_instance = 1 else -- the 'current_instance' is really a class, so the first parameter -- will be treated as the class real_instance = 0 end if ParseMethodArgs(tok) if find( sym, class_table[CLASS_SYM] ) then if not length(method_args[$]) then CompileErr( "method procedure requires a 'this' parameter" ) end if method_args[$] = method_args[$][2..$] class_ = find( current_instance[$], class_table[CLASS_SYM] ) else -- now, find the actual method csym = SymTab[current_instance[$]][S_VTYPE] class_ = find( csym, class_table[CLASS_SYM] ) end if s = PolyMorph( class_ ) add_ref( {PROC, s} ) method_name = method_name[1..$-1] scope = SymTab[s][S_SCOPE] opcode = SymTab[s][S_OPCODE] if SymTab[s][S_EFFECT] then SymTab[CurrentSub][S_EFFECT] = or_bits(SymTab[CurrentSub][S_EFFECT], SymTab[s][S_EFFECT]) end if if scope = SC_PREDEF then emit_op(opcode) if opcode = ABORT then temp_tok = next_token() putback(temp_tok) NotReached(temp_tok[T_ID], "abort()") end if else op_info1 = s emit_op(PROC) if not TRANSLATE then if OpTrace then emit_op(UPDATE_GLOBALS) end if end if end if method_args = method_args[1..$-1] method_stack = method_stack[1..$-1] current_method -= 1 parse_method_stack = parse_method_stack[1..$-1] end procedure procedure MethodFunc( token tok ) -- parse a method call statement integer scope, opcode, class_, e, real_instance, tok1 symtab_index s, sym, csym sequence pdec tok = next_token() -- tok1 is the method name, so we need to capture the -- instance and the dot to replace them tok1 = length(line_tokens) - 2 method_stack &= {tok} method_args &= { {} } method_name = append( method_name, SymTab[tok[T_SYM]][S_NAME] ) -- prevent an erroneous warning: SymTab[tok[T_SYM]][S_USAGE] = or_bits( U_READ, U_WRITTEN ) current_method += 1 parse_method_stack &= 1 tok_match(LEFT_ROUND) s = tok[T_SYM] -- first, send the 'this' as an argument sym = current_instance[$] if not find( sym, class_table[CLASS_SYM] ) then -- the 'current_instance' is a real instance SymTab[sym][S_USAGE] = or_bits(SymTab[sym][S_USAGE], U_READ) InitCheck(sym, TRUE) emit_opnd(sym) real_instance = 1 else -- the 'current_instance' is really a class, so the first parameter -- will be treated as the class real_instance = 0 end if ParseMethodArgs(tok) -- now, find the actual method if find( sym, class_table[CLASS_SYM] ) then if not length(method_args[$]) then CompileErr( "method function requires a 'this' parameter" ) end if method_args[$] = method_args[$][2..$] class_ = find( current_instance[$], class_table[CLASS_SYM] ) else -- now, find the actual method csym = SymTab[current_instance[$]][S_VTYPE] class_ = find( csym, class_table[CLASS_SYM] ) end if s = PolyMorph( class_ ) if preprocess then pdec = pp_decorate( SymTab[s][S_NAME]) & "(" if real_instance then -- have to add the first argument pdec &= SymTab[line_tokens[tok1][T_SYM]][S_NAME] if SymTab[s][S_NUM_ARGS] > 1 then pdec &= ", " end if end if replace_tokens( tok1, tok1 + 3, pdec ) end if add_ref( {FUNC, s} ) method_name = method_name[1..$-1] -- end mwl e = SymTab[s][S_EFFECT] if e then -- the routine we are calling has side-effects if e = E_ALL_EFFECT or s > left_sym then -- it can access the LHS var (it uses indirect calls or comes later) side_effect_calls = or_bits(side_effect_calls, e) end if SymTab[CurrentSub][S_EFFECT] = or_bits(SymTab[CurrentSub][S_EFFECT], e) if short_circuit > 0 and short_circuit_B then -- and -- find(id, {FUNC, QUALIFIED_FUNC}) then Warning(sprintf( "%.99s:%d - call to %s() might be short-circuited", {file_name[current_file_no], line_number, SymTab[s][S_NAME]})) end if end if scope = SymTab[s][S_SCOPE] opcode = SymTab[s][S_OPCODE] if scope = SC_PREDEF then emit_op(opcode) else op_info1 = s emit_op(PROC) if not TRANSLATE then if OpTrace then emit_op(UPDATE_GLOBALS) end if end if end if method_args = method_args[1..$-1] method_stack = method_stack[1..$-1] current_method -= 1 parse_method_stack = parse_method_stack[1..$-1] end procedure
Matt Lewis