//----------------------- SYSTEM ---------------------------------- func create(entry) gvar(blk_attr, blk_using, blk_vars, blk_lvars, blk_init, blk_proc_imp, blk_body, blk, CLASS, cil) cil = new array() // register own types register(1, int) register(2, str) register(7, real) register(104, bool) register(105, long) // create blocks blk_attr = block.reg("class_attr").inc() blk_using = block.reg("class_using") blk_body = block.reg("class_body").inc().inc() blk_vars = block.reg("class_vars").inc() blk_lvars = block.reg("class_lvars").inc() blk_init = block.reg("class_init").inc().inc() blk_proc_imp = block.reg("class_proc_imp") // set current block blk = blk_body end //Check_Infinite_Loop func cil(id) for(i = 0; i < cil.size(); i++) if(cil.get(i) == id) i = cil.size() cp = 1 end end return(cp) end func destroy(entry) // remove all blocks block.delete(blk_attr) block.delete(blk_using) block.delete(blk_body) block.delete(blk_vars) block.delete(blk_lvars) block.delete(blk_init) block.delete(blk_proc_imp) end func code_type(v) if(e = expof(v)) return(e) else return(typeof(v)) end end func is_int(v) return(code_type(v) == 1) end func is_str(v) return(code_type(v) == 2) end func is_bool(v) return(code_type(v) == 104) end func is_real(v) return(code_type(v) == 7) end func to_str(value) t = code_type(value) if(t == 0) return("") elseif(t == 1) return('(' + value + ').ToString()') elseif(t == 7) return('(' + value + ').ToString()') end return(value) end func to_int(value) t = code_type(value) if(t == 0) return(0) elseif(t == 2) return('Int32.Parse(' + value + ')') elseif(t == 7) return('(int)(' + value + ')') end return(value) end func to_real(value) t = code_type(value) if(t == 0) return(0) elseif(t == 2) return('Double.Parse(' + value + ')') end return(value) end func to_bool(value) t = code_type(value) if(t == 1) return('(' + value + ' != 0)') elseif(t == 2) return('bool.Parse(' + value + ')') end return(value) end func to_type(value, type) if(type == 2) return(to_str(value)) elseif(type == 1) return(to_int(value)) elseif(type == 7) return(to_real(value)) elseif(type == 5) return(to_int(value)) elseif(type == 104) return(to_bool(value)) end return(value) end //----------------------- USER ---------------------------------- func add_event_type(point, handler, type, data, args) if(this.points(point).point) e_args = 'object sender, ' + type + 'Args args' + (args ? (', ' + args) : '') blk_init.println('this.', (this.name=="EntryPoint")?'':this.codename + '.', handler, ' += new ', type, 'Handler(', point, this.id, ');') // store old block old_blk = blk old_lvars = blk_lvars // create event code blk_lvars = block.reggen().inc() blk = block.reggen().inc() event(point, data) // move block to implementation blk_proc_imp.println('private void ' + point + this.id + '(' + e_args + ') {').inc() if(not blk_lvars.empty()) blk_proc_imp.copyhere(blk_lvars) end blk_proc_imp.copyhere(blk) blk_proc_imp.println('}').println() // remove and restore block.delete(blk) block.delete(blk_lvars) blk = old_blk blk_lvars = old_lvars this.setfield(point, 'defined') end end func add_event_body(point, handler, body, data, args) if(this.points(point).point) e_args = 'object sender, System.EventArgs args' + (args ? (', ' + args) : '') blk_init.println('this.' + this.codename + '.' + handler + ' += new System.EventHandler(' + point + this.id + ');') // store old block old_blk = blk old_lvars = blk_lvars // create event code blk_lvars = block.reggen().inc().inc() blk = block.reggen().inc().inc() event(point, data) // move block to implementation blk_proc_imp.inc().println('private void ' + point + this.id + '(' + e_args + ') { // ' + this.codename) if(not blk_lvars.empty()) blk_proc_imp.copyhere(blk_lvars) end if(body) blk_proc_imp.copyhere(body) end blk_proc_imp.copyhere(blk) blk_proc_imp.println('}').dec().println() // remove and restore block.delete(blk) block.delete(blk_lvars) blk = old_blk blk_lvars = old_lvars this.setfield(point, 'defined') end end func add_event(point, handler, data, args) add_event_body(point, handler, 0, data, args) end func add_object(name, type) blk_vars.println('private ' + type + ' ' + name + ';') blk_init.println(name + ' = new ' + type + '();') end func add_widget(type) // declare and init control blk_vars.println('private ' + type + ' ' + this.codename + ';') blk_init.println(this.codename + ' = new ' + type + '();') blk_init.println('addWidget(' + this.codename + ', ' + this.props("Left") + ', ' + this.props("Top") + ', ' + this.props("Width") + ', ' + this.props("Height") + ');') // initialize inherited properties sys.set_undef_field_bool('Visible') sys.set_undef_field_const('Dock', this.props("Dock"), 'System.Windows.Forms.DockStyle') if(not isdef("Anchor")) a = this.props("Anchor") flg = ((a _and_ 1) ? '|AnchorStyles.Left' : '') + ((a _and_ 2) ? '|AnchorStyles.Top' : '') + ((a _and_ 4) ? '|AnchorStyles.Right' : '') + ((a _and_ 8) ? '|AnchorStyles.Bottom' : '') blk_init.println(this.codename + '.Anchor = AnchorStyles.None ' + flg + ';') end end func var_type(type) if(typeof(type) == 1) if(type == 1) return('int') elseif(type == 7) return('double') elseif(type == 104) return('bool') elseif(type == 105) return('long') else return('string') end end return(type) end // declare var in class section func add_var(name, type) f = name + this.id sub(f, type) blk_vars.println('private ' + var_type(type) + ' ' + f + ';') this.setfield(name, f) end // declare var in local section func add_var_loc(name, type) f = name + this.id sub(f, type) blk_lvars.println(var_type(type) + ' ' + f + ' = ' + to_type('', type) + ';') this.setfield(name, f) end // declare var by "Extern" property func add_var_extern(name, type) if(isdef("Extern")) add_var(name, type) else add_var_loc(name, type) end end func set_field(field, prop) if(typeof(prop) == 0) prop = this.props(field) end blk_init.println((this.name=="EntryPoint")?'this':this.codename, '.' + field + ' = ', prop.value, ';') end func set_undef_field(field, prop) if(typeof(prop) == 0) prop = this.props(field) end if(not prop.isdef) blk_init.println((this.name=="EntryPoint")?'this':this.codename, '.' + field + ' = ', prop.value, ';') end end func set_undef_field_bool(field, prop) if(typeof(prop) == 0) prop = this.props(field) end if(not prop.isdef) blk_init.println((this.name=="EntryPoint")?'this':this.codename, '.' + field + ' = ' + lower(prop.value) + ';') end end func set_undef_field_char(field, prop) if(typeof(prop) == 0) prop = this.props(field) end if(not prop.isdef) blk_init.println((this.name=="EntryPoint")?'this':this.codename, '.' + field + ' = Convert.ToChar(' + prop.value + ');') end end func set_undef_field_const(field, prop, constant) if(not prop.isdef) blk_init.println((this.name=="EntryPoint")?'this':this.codename, '.' + field + ' = ' + constant + '.' + prop.value + ';') end end //****************************************************************************** // simple element tools //****************************************************************************** func _se_init(proc, vname, vtype) this.setfield('vname', vname + this.id) this.setfield('vtype', vtype) this.setfield('proc', proc) if(linked("Result") and linked('do' + proc)) sys.add_var_extern(vname, vtype) end method('do' + proc, "p1", "p2", "p3") sys._se_dowork(args.p1, args.p2, args.p3) end method('Result') return(sys._se_result()) end end func _se_dowork(p1, p2, p3) if(linked("Result")) blk.println(this.vname, ' = ', this._se_make(p1, p2, p3), ';') event('on' + this.proc, this.vname) else event('on' + this.proc, this._se_make(p1, p2, p3)) end end func _se_result if(linked('do' + this.proc)) return(this.vname) else return(this._se_make()) end end