Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

PortablE

PortablE E language
63 posts | Last Activity on 07-11-2011 17:03 by SamuraiCrow
S
SamuraiCrow 07-11-2011 17:03, 12 years ago
Re: bitset inventory example
Thanks for the tip about BIGVALUE! Here's the latest version. [code]OPT MODULE CLASS item itemnum:INT pad1:INT description:ARRAY OF CHAR ENDCLASS DEF nextitem:INT,itemlist[SIZEOF BIGVALUE*8]:ARRAY OF PTR TO item PROC makeitem(describe:ARRAY OF CHAR) NEW OF item self.itemnum:=nextitem itemlist[nextitem]:=self ++nextitem IF nextitem>(SIZEOF BIGVALUE*8) THEN Raise("ARG") self.description:=describe ENDPROC PROC getmask() OF item RETURNS mask:BIGVALUE IS 1 SHL self.itemnum PROC getdescription() OF item IS self.description CLASS inventory mask:BIGVALUE ENDCLASS PROC makeinventory() NEW OF inventory self.mask:=0 ENDPROC PROC additem(myitem:PTR TO item) OF inventory self.mask:=self.mask OR myitem.getmask() ENDPROC PROC removeitem(youritem:PTR TO item) OF inventory self.mask:=self.mask AND NOT youritem.getmask() ENDPROC PROC hasitem(myitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:= (self.mask AND myitem.getmask()=myitem.getmask()) ENDPROC PROC hasany(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=(self.mask AND items.mask <> 0) ENDPROC PROC hasall(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=(self.mask AND items.mask = items.mask) ENDPROC PROC getitem(source:PTR TO inventory, theitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:=FALSE IF source.hasitem(theitem) source.removeitem(theitem) self.additem(theitem) ret:=TRUE ENDIF ENDPROC PROC giveitem(destination:PTR TO inventory, theitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:=destination.getitem(self,theitem) ENDPROC PROC useall(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=FALSE IF self.hasall(items) self.mask:=self.mask AND NOT items.mask ret:=TRUE ENDIF ENDPROC PROC list() OF inventory DEF count:INT,current:PTR TO item FOR count:=0 TO nextitem-1 current:=itemlist[count] IF self.hasitem(current) Print('\s\n',current.getdescription()) ENDIF ENDFOR ENDPROC [/code] Notice that I switched from using assumed constants for the size of the BIGVALUE and used the SIZEOF operator to find the size in bytes? That should make the code easier to read and easier to port! :)
ChrisH
ChrisH 04-11-2011 05:10, 12 years ago
Re: bitset inventory example
@SamuraiCrow PortablE already supports the equivalent of "long long" (i.e. 64-bits). It is called BIGVALUE. (Although you can only write 32-bit numbers directly in the code.) P.S. Cast cost programmer time & in general should be avoided.
S
SamuraiCrow 03-11-2011 22:38, 12 years ago
Re: bitset inventory example
I'm looking forward to the equivalent of long long in PortablE. :) I know that C99 supports it. Besides, casts cost nothing when it's run through GCC.
ChrisH
ChrisH 03-11-2011 17:26, 12 years ago
Re: bitset inventory example
I haven't had time to closely examine the code, but... [quote][code] PROC getmask() OF item RETURNS mask:LONG IS 1 SHL self.itemnum [/code] [code] CLASS inventory mask:LONG ENDCLASS [/code][/quote] Just a little bit of advice: It almost never makes sense to use the :LONG type, since it causes unnecessary casts without any benefit. Better to use no type at all, which means it automatically defaults to :VALUE . This avoids unnecessary casts, but is the same size (at least until PortablE runs on a 64-bit native OS+CPU).
S
SamuraiCrow 01-11-2011 15:03, 12 years ago
Re: bitset inventory example
For those of you who have downloaded the source, I'm afraid you'll have to download it again. ChrisH was kind enough to point out a mistake in my code regarding QUAD variables. I had to replace them with LONGs instead and correct the size of the bitset.
ChrisH
ChrisH 01-11-2011 13:12, 12 years ago
Re: Developer environment
[quote]So that would probably also mean that i wrongly assume portableE is written in E ?[/quote] PortablE is written in PortablE :-) although originally it was written in AmigaE (to "boot strap" itself).
Responded in Developer environment
S
SamuraiCrow 31-10-2011 12:31, 12 years ago
Re: bitset inventory example
Ok, class, now let's look through each line of the inventory.e module. [code] OPT MODULE [/code] This tells PortablE that this will be a module rather than a program. A module is similar to a linker library on other languages. [code] CLASS item itemnum:INT pad1:INT description:ARRAY OF CHAR ENDCLASS [/code] The class definition tells what data items are stored in a single item record. Notice that pad1 is not used later on. It is only there because the array won't perform quickly if it isn't aligned to a 4-byte boundary. An INT in PortablE is only 2 bytes long. [code] DEF nextitem:INT,itemlist[32]:ARRAY OF PTR TO item [/code] Here are some global variables. The nextitem variable will be used to hold the number of items available defined. The itemlist variable allocates space to store a table of pointers to the item definitions. The reason it's only 32 items in length is that that is the number of bits in a LONG variable. Since this is a bitset, each bit will represent a slot in the inventory. [code] PROC makeitem(describe:ARRAY OF CHAR) NEW OF item self.itemnum:=nextitem itemlist[nextitem]:=self ++nextitem IF nextitem>31 THEN Raise("ARG") self.description:=describe ENDPROC [/code] This is a procedure. It defines an action the computer can take to do a particular purpose. Since it says NEW OF item at the beginning it defines when it can be used. The NEW tells that it is used with the NEW operator so this is considered to be a constructor. The OF item tells that this is actually a method associated with the item class. A constructor tells the computer what needs to be done to set the initial values for the item class. [code] PROC getmask() OF item RETURNS mask:LONG IS 1 SHL self.itemnum [/code] Here is another method of the item class. It is not a constructor because the NEW is not listed before the OF item. It tells how to define a mask of an item. [code] PROC getdescription() OF item IS self.description [/code] This method is called a "getter" method. It just gets some information from the item class and returns it. The reason for having a getter method is that it allows a piece of information to be hidden in the class using the PRIVATE directive. Since there is no PRIVATE directive this is just used for future necessity rather than real present need. [code] CLASS inventory mask:LONG ENDCLASS [/code] Here's another class definition. It holds only one item: the mask. It is not optional to have this as a class though, because we will be defining many methods of it. [code] PROC makeinventory() NEW OF inventory self.mask:=0 ENDPROC [/code] Here is the constructor. All it does is clear the mask. It is necessary to do this to a class because the operating system might not clear the memory a class is declared in. If it does, we wouldn't have needed a constructor at all in this case. Another thing to note: Since there is only one command inside the procedure, we could have used the IS command to make it all one line of code. It's just for clarity that I wrote it out the long way. [code] PROC additem(myitem:PTR TO item) OF inventory self.mask:=self.mask OR myitem.getmask() ENDPROC PROC removeitem(youritem:PTR TO item) OF inventory self.mask:=self.mask AND NOT youritem.getmask() ENDPROC [/code] These two methods mask on or off a single bit of memory using AND, OR and NOT operators. These are packing boolean values. These are the fundamental operators of a bitset. [code] PROC hasitem(myitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:= (self.mask AND myitem.getmask()=myitem.getmask()) ENDPROC PROC hasany(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=(self.mask AND items.mask <> 0) ENDPROC PROC hasall(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=(self.mask AND items.mask = items.mask) ENDPROC [/code] These three methods test a bit or bits to see if the masks of an item or another inventory can compare to the masks in the current item. [code] PROC getitem(source:PTR TO inventory, theitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:=FALSE IF source.hasitem(theitem) source.removeitem(theitem) self.additem(theitem) ret:=TRUE ENDIF ENDPROC [/code] This method uses 3 other methods to do a bit transfer. The hasitem method checks if the item is available, and the other two clear and set the appropriate bitmask. [code] PROC giveitem(destination:PTR TO inventory, theitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:=destination.getitem(self,theitem) ENDPROC [/code] This method does the reverse of the getitem method. Notice how it just uses the getitem method with the source and destination reversed. [code] PROC useall(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=FALSE IF self.hasall(items) self.mask:=self.mask AND NOT items.mask ret:=TRUE ENDIF ENDPROC [/code] This method allows items to be consumed in their use. Like the previous two, it returns a boolean value (true or false) that tells if the method succeeded. [code] PROC list() OF inventory DEF count:INT,current:PTR TO item FOR count:=0 TO nextitem-1 current:=itemlist[count] IF self.hasitem(current) Print('\s\n',current.getdescription()) ENDIF ENDFOR ENDPROC [/code] And this last method is a bit more complicated. It lists out each item in an inventory by counting through all the used items, fetching the item from the table, checking if it is used in this inventory, and printing its description if it is.
S
SamuraiCrow 30-10-2011 17:34, 12 years ago
Re: bitset inventory example
Ok! Here is the long awaited inventory example! Call this file inventory.e [code] OPT MODULE CLASS item itemnum:INT pad1:INT description:ARRAY OF CHAR ENDCLASS DEF nextitem:INT,itemlist[32]:ARRAY OF PTR TO item PROC makeitem(describe:ARRAY OF CHAR) NEW OF item self.itemnum:=nextitem itemlist[nextitem]:=self ++nextitem IF nextitem>31 THEN Raise("ARG") self.description:=describe ENDPROC PROC getmask() OF item RETURNS mask:LONG IS 1 SHL self.itemnum PROC getdescription() OF item IS self.description CLASS inventory mask:LONG ENDCLASS PROC makeinventory() NEW OF inventory self.mask:=0 ENDPROC PROC additem(myitem:PTR TO item) OF inventory self.mask:=self.mask OR myitem.getmask() ENDPROC PROC removeitem(youritem:PTR TO item) OF inventory self.mask:=self.mask AND NOT youritem.getmask() ENDPROC PROC hasitem(myitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:= (self.mask AND myitem.getmask()=myitem.getmask()) ENDPROC PROC hasany(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=(self.mask AND items.mask <> 0) ENDPROC PROC hasall(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=(self.mask AND items.mask = items.mask) ENDPROC PROC getitem(source:PTR TO inventory, theitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:=FALSE IF source.hasitem(theitem) source.removeitem(theitem) self.additem(theitem) ret:=TRUE ENDIF ENDPROC PROC giveitem(destination:PTR TO inventory, theitem:PTR TO item) OF inventory RETURNS ret:BOOL ret:=destination.getitem(self,theitem) ENDPROC PROC useall(items:PTR TO inventory) OF inventory RETURNS ret:BOOL ret:=FALSE IF self.hasall(items) self.mask:=self.mask AND NOT items.mask ret:=TRUE ENDIF ENDPROC PROC list() OF inventory DEF count:INT,current:PTR TO item FOR count:=0 TO nextitem-1 current:=itemlist[count] IF self.hasitem(current) Print('\s\n',current.getdescription()) ENDIF ENDFOR ENDPROC [/code] And here's the code to test it out: [code] MODULE '*inventory' DEF lamp:PTR TO item, torch:PTR TO item, bag:PTR TO item, room:PTR TO inventory, mystuff:PTR TO inventory, lights:PTR TO inventory, allstuff:PTR TO inventory PROC getit(what:PTR TO item) IF mystuff.getitem(room,what) Print('You\'ve picked up \s.\n', what.getdescription()) ELSE Print('You aleady have \s.\n', what.getdescription()) ENDIF ENDPROC PROC main() DEF in[4]:STRING NEW lamp.makeitem('a lamp') NEW torch.makeitem('a torch') NEW bag.makeitem('a bag') NEW room.makeinventory() NEW mystuff.makeinventory() NEW lights.makeinventory() NEW allstuff.makeinventory() room.additem(lamp) room.additem(torch) room.additem(bag) lights.additem(lamp) lights.additem(torch) allstuff.additem(lamp) allstuff.additem(torch) allstuff.additem(bag) REPEAT IF mystuff.hasany(lights) Print('You are in a room with no doors and no windows.\n') Print('You see:\n') room.list() ELSE Print('It\'s dark. You are likely to be eaten by a grue.\n') ENDIF Print('\nWhat do you grab?\n') PrintFlush() ReadStr(stdin,in) SELECT in[0] CASE "l"; getit(lamp) CASE "t"; getit(torch) CASE "b"; getit(bag) DEFAULT; Print('I don\'t see it here.\n') ENDSELECT UNTIL mystuff.hasall(allstuff) Print('You have everything! You win!\n') PrintFlush() FINALLY PrintException() ENDPROC [/code] I'll break this down for you in the next week or so.
S
SamuraiCrow 26-10-2011 11:56, 13 years ago
Re: Developer environment
Thinking back, I think that ChrisH already fixed PortablE for AROS so that the errors I ran into won't be there in the final release 6 version. He just hasn't come out with the final release yet. Recently I remember him cleaning up bugs on AROS and MorphOS both. I hope he finds time to finish up the release so I can continue the tutorial. @Magorium I don't know if the server services from VirtualBox would be more viable. There is an option to do something like that in the Icaros installer though, IIRC.
Responded in Developer environment
M
magorium 22-10-2011 11:25, 13 years ago
Re: Developer environment
@SamuraiCrow: Ah ic. I took develop environment a little too literaly ;) Sorry 'bout that. Yeah, i am familiar with the problem you're facing. Missing VB-GA sux. I doubt that you didn't already think of this yourself (or perhaps you are unable to apply in practice) but whenever i need to transfer files from one box to another i use the VBox network. If i have to transfer out of the box'es i use an USB stick or serial port (installed virtual serial port on host-OS). This is the reason i was thinking about something like freenas in a extra Box in order to transfer back and forth between guest and host in a more consisent way Alas, it really doesn't make things smoother :( OT: Since you have more aros experience, do you think it would be viable to interact with the VM's server services from aros ? @cavemann: Thank you for sharing that link :). I didn't know about that. regards,
Responded in Developer environment
S
SamuraiCrow 21-10-2011 13:08, 13 years ago
Re: bitset inventory example
[url]http://cshandley.co.uk/amigae/[/url] is the E manual as a webpage. [url]http://cshandley.co.uk/portable/[/url] is the homepage of PortablE including download links. [url]http://cshandley.co.uk/portable/PortablE.html[/url] is the PortablE manual listing all of the differences between PortablE and AmigaE. [url]http://cshandley.co.uk/portable/StandardFunctionality.html[/url] is the manual for the PortablE classes.
S
SamuraiCrow 21-10-2011 12:41, 13 years ago
Re: Developer environment
I had difficulty installing Icaros in such a way that I could transfer files to and from the host MacOSX 10.6.x environment. In the past I had used hosted AROS on Linux in VirtualBox so that I could use the VirtualBox Guest Additions. Editors have very little to do with what problems I'm having. I used TextEdit under MacOSX for the IRC tutorial series so it doesn't have to be anything advanced.
Responded in Developer environment
amigamia
amigamia 20-10-2011 08:57, 13 years ago
Re: bitset inventory example
Would you mind to post the link to online material such as Books or Manuals we may need on E and PortablE? :)
M
magorium 19-10-2011 20:58, 13 years ago
Re: Developer environment
Thank you for moving :-) Sorry I made a wrong assumption about the OS SamauraiCrow ... Ofcourse you are correct -> if you where using windows you could use the windows version :mestupid: So that would probably also mean that i wrongly assume portableE is written in E ? I intentionaly mentioned editors that are available for AROS, as i thought that _is_ the issue. Or did i misunderstand the intentional problem ? btw Annotate works for me under icaros desktop. PS sorry to see on that you mentioned having problems with compiling due to header errors. regards
Responded in Developer environment
C
cavemann 19-10-2011 20:45, 13 years ago
Re: Developer environment
I don't think the most recent version (2.7.8) has been ported to AROS yet. [url]http://hem.bredband.net/deniil/[/url]
Responded in Developer environment
amigamia
amigamia 19-10-2011 20:05, 13 years ago
Re: Developer environment
I think it already is, isn't it? AROS ARCHIVES: [url]http://archives.aros-exec.org/index.php?function=showfile&file=utility/text/edit/annotate.i386-aros.zip[/url] From OnyxSoft: [url]http://www.onyxsoft.se/annotate.html[/url] It shows 2.7 on both..
Responded in Developer environment
S
SamuraiCrow 19-10-2011 16:10, 13 years ago
Re: Developer environment
Yes, Annotate does have AmigaE syntax highlighting. I've used it under OS 3. I hope that the latest version gets backported from OS 4 to OS 3 and AROS.
Responded in Developer environment
amigamia
amigamia 19-10-2011 14:58, 13 years ago
Re: Developer environment
I thought Annotate had E language Syntax Highlighting and it is now available for AROS. I guess that could be a good editor under windows?
Responded in Developer environment
S
SamuraiCrow 19-10-2011 11:22, 13 years ago
Re: Developer environment
I use VirtualBox for Mac. I haven't used Windows for a good many years except at friends' and relatives' houses. If I had Windows, I could just use the Windows version of PortablE. I normally use hosted AROS from within a Linux virtual machine. But my Linux VM is getting hard to manage and I can't seem to get either Mac or Linux versions of X11 to enable the Backingstore option.
Responded in Developer environment
M
magorium 19-10-2011 11:16, 13 years ago
Re: Developer environment
Hi SamuraiCrow, Sorry for (sort of) hijacking this thread, please replace or delete if wanted. [moved to new thread --SamuraiCrow] 1) could Frexxed ([url]http://daniel.haxx.se/frexxed/[/url]) be a viable option ? 2) if you are using VB then i assume u use windblows ? If so, perhaps programmer's notepad ([url]www.pnotepad.org/[/url]) is an option ? I realize then there is a problem with executing code that uses gui elements as E does not have support for them under windblows. It is an interresting topic, also for me, because it's a bit problematic: developing in other languages then c in combination with AROS -> the lack of a real configurable editor that is aimed for developers. I could not find anything else myself. atm i run two VB's one with windblows another with aros. This is because i have to test the software on two platforms and the editor is in windows. I use VB's internal network to communicate between the two, but i'm thinking of changing it in adding a third box with something like freenas. I believe aros does not has a remote-shell ? That would be a better option. Please share the experience (others are welcome) if you can spare the time. regards red: forgot to mention annotate ([url]http://www.onyxsoft.se/annotate.html[/url])
Responded in Developer environment
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
Moderator: Administrator

Filter by Tags

Popular Threads This Week

AROS One x86 Work In Progressby AMIGASYSTEM 139 posts
Tiny Aros DistrĂ²by Amiwell79 100 posts
ADoom3 benchmarkby retrofaza 39 posts
Development Planby deadwood 32 posts
The Fulcrum Scene Demoby Farox 16 posts
Odyssey Resourceby Amiwell79 15 posts
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 9
Members Online 0

Total Members: 224
Newest Member: Zhule
Member Polls
Should AROSWorld continue with AROS-Exec files (SMF based)?
Yes44 %
44% [12 Votes]
No26 %
26% [7 Votes]
Not sure30 %
30% [8 Votes]