Re: Object-oriented preprocessor
- Posted by jmduro Sep 11, 2022
- 1674 views
I have tested the program as a preprocessor with following command and it works with no change.
eui -p oex:preprocessor.ex test_classes.oex
It translates following class-like program:
include win32lib_r2.ew as win class TWin32() integer self.hwnd = 0 sequence self.caption = "" atom self.pOwner = 0 object self.x = 0, self.y = 0, self.cx = 0, self.cy = 0 object self.styleFlags = 0 procedure create(sequence params) self.caption = params[1] self.pOwner = params[2] self.x = params[3] self.y = params[4] self.cx = params[5] self.cy = params[6] self.styleFlags = params[7] end procedure end class class TWindow(TWin32) sequence self.additional = "unused" procedure create(sequence params) super.create(params) self.additional = params[8] self.hwnd = win:create(Window, self.caption, self.pOwner, self.x, self.y, self.cx, self.cy, self.styleFlags) end procedure end class class TMleText(TWin32) procedure create(sequence params) super.create(params) self.hwnd = win:create(MleText, self.caption, self.pOwner, self.x, self.y, self.cx, self.cy, self.styleFlags) end procedure procedure set(sequence params) win:setText(self.hwnd, params[1]) end procedure function get(sequence params) return win:getText(self.hwnd) end function end class sequence mainWin = new(TWindow) mainWin.create({"MLE Test", 0, 0, 0, 300, 300, 0, "unused"}) mainWin.cx = 400 sequence mle = new(TMleText) mle.create({"", mainWin.hwnd, 10, 10, 200, 200, 0}) mle.set({"Line 1\nLine 2\nLine 3"}) WinMain(mainWin.hwnd, Normal)
Resulting code, test_classes.pp.oex, is as follows:
include win32lib_r2.ew as win include classes.e f_debug = open("debug.log", "w") --- class TWin32 --------------------------------------------------------------- integer TWin32 = class("TWin32") addProperty(TWin32, "hwnd", 0) addProperty(TWin32, "caption", "") addProperty(TWin32, "pOwner", 0) addProperty(TWin32, "x", 0) addProperty(TWin32, "y", 0) addProperty(TWin32, "cx", 0) addProperty(TWin32, "cy", 0) addProperty(TWin32, "styleFlags", 0) function TWin32_create(integer instanceID, sequence params) setProperty(instanceID, "caption", params[1]) setProperty(instanceID, "pOwner", params[2]) setProperty(instanceID, "x", params[3]) setProperty(instanceID, "y", params[4]) setProperty(instanceID, "cx", params[5]) setProperty(instanceID, "cy", params[6]) setProperty(instanceID, "styleFlags", params[7]) return 0 end function addMethod(TWin32, "create", routine_id("TWin32_create")) --- class TWindow -------------------------------------------------------------- integer TWindow = class("TWindow", TWin32) addProperty(TWindow, "additional", "unused") function TWindow_create(integer instanceID, sequence params) callParentMethod(instanceID, "create", params) setProperty(instanceID, "additional", params[8]) setProperty(instanceID, "hwnd", win:create(Window, getProperty(instanceID, "caption"), getProperty(instanceID, "pOwner"), getProperty(instanceID, "x"), getProperty(instanceID, "y"), getProperty(instanceID, "cx"), getProperty(instanceID, "cy"), getProperty(instanceID, "styleFlags"))) return 0 end function addMethod(TWindow, "create", routine_id("TWindow_create")) --- class TMleText ------------------------------------------------------------- integer TMleText = class("TMleText", TWin32) function TMleText_create(integer instanceID, sequence params) callParentMethod(instanceID, "create", params) setProperty(instanceID, "hwnd", win:create(MleText, getProperty(instanceID, "caption"), getProperty(instanceID, "pOwner"), getProperty(instanceID, "x"), getProperty(instanceID, "y"), getProperty(instanceID, "cx"), getProperty(instanceID, "cy"), getProperty(instanceID, "styleFlags"))) return 0 end function addMethod(TMleText, "create", routine_id("TMleText_create")) function TMleText_set(integer instanceID, sequence params) win:setText(getProperty(instanceID, "hwnd"), params[1]) return 0 end function addMethod(TMleText, "set", routine_id("TMleText_set")) function TMleText_get(integer instanceID, sequence params) return win:getText(getProperty(instanceID, "hwnd")) end function addMethod(TMleText, "get", routine_id("TMleText_get")) -------------------------------------------------------------------------------- integer mainWin = classes:new("mainWin", TWindow) callMethod(mainWin, "create", {"MLE Test", 0, 0, 0, 300, 300, 0, "unused"}) setProperty(mainWin, "cx", 400) integer mle = classes:new("mle", TMleText) callMethod(mle, "create", {"", getProperty(mainWin, "hwnd"), 10, 10, 200, 200, 0}) callMethod(mle, "set", {"Line 1\nLine 2\nLine 3"}) WinMain(getProperty(mainWin, "hwnd"), Normal) close(f_debug)
Of course, you have to update eu.cfg to your own configuration.
I wonder if it would make sense to rewrite whole Win32Lib_r2 one of both ways (with the preprocessor or in the resulting style).
Jean-Marc