1. Storage of Euphoria variables

If I want to use assembler, or Peek and Poke, is there information available on

1. How an atom is stored
2. How a sequence is stored
3. how an object is stored
4. How variable names are stored.

new topic     » topic index » view message » categorize

2. Re: Storage of Euphoria variables

Vinoba said...

If I want to use assembler, or Peek and Poke, is there information available on

1. How an atom is stored
2. How a sequence is stored
3. how an object is stored
4. How variable names are stored.


You don't say why you want to know how the above items are stored.
You will have to study the source code and built in functions.
Maybe if you explain what you want to accomplish then someone could help you.
If you just want to write a a function then there is a an example
program called callmach.ex in the eu demo directory.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Storage of Euphoria variables

Vinoba said...

If I want to use assembler, or Peek and Poke, is there information available on

1. How an atom is stored
2. How a sequence is stored
3. how an object is stored
4. How variable names are stored.

Take a look at the Euphoria Internals section of the manual. It documents a lot (not sure how complete it is, exactly) of what you're looking for. You can also look at the C headers that define the structs and macros.

  • source/object.h:
    • struct s1
    • struct d
  • source/execute.h
    • Macros for inspecting and manipulating objects

Note that the 64-bit versions introduced in 4.1 will be slightly different. Of course, if you have more specific questions, please ask...

Matt

new topic     » goto parent     » topic index » view message » categorize

4. Re: Storage of Euphoria variables

mattlewis said...

Take a look at the Euphoria Internals section of the manual. It documents a lot (not sure how complete it is, exactly) of what you're looking for. You can also look at the C headers that define the structs and macros.

  • source/object.h:
    • struct s1
    • struct d
  • source/execute.h
    • Macros for inspecting and manipulating objects

Note that the 64-bit versions introduced in 4.1 will be slightly different. Of course, if you have more specific questions, please ask...

Matt

Thanks. I will have a look at those.
When I am working with DBF files, I have this information (see below) with me so I can know from Assembler or using Peek and Poke functions exactly what to do.
I was looking for similar information

The following is from a table but at present this particular software does not allow me to post in a table format or at least, i don't know how to post in a table format. I tidied up Table 1 a bit, but it gives you an idea what I work with. it is still readable.

dBASE III Database File Structure (from Ashton-Tate)
The structure of a dBASE III database file is composed of a header and data records.
The layout is given below.

Table 1: dBASE III DATABASE FILE HEADER:

BYTE....CONTENTS........MEANING .................................DETAILS
0.......1 byte ........ dBASE III version number................(03H without a .DBT file)
................................................................(83H with a .DBT file)
1-3.....3 BYTES ........date of last update ....................(YY MM DD) in binary format
4-7.....32 bit number...number of records in data file
8-9.....16 bit # .......length of header structure
10-11...16 bit #........length of the record
12-31...20 bytes........reserved bytes (version 1.00)
32-n....32 bytes each...field descriptor array..................See Table 2
n+1.....1 byte..........field terminator........................0D (HEX) CR, no LF

Table 2: A FIELD DESCRIPTOR:

BYTE CONTENTS MEANING DETAILS
0-10 11 bytes field name in ASCII zero-filled
11 1 byte field type in ASCII C N L D or M
12-15 32 bit # field data address address is set in memory
16 1 byte field length binary
17 1 byte field decimal count binary
18-31 14 bytes reserved bytes (version 1.00)

The data records are layed out as follows:
1. Data records are preceeded by one byte that is a space (20H) if the record is not deleted and an asterisk (2AH) if it is deleted.
2. Data fields are packed into records with no field separators or record terminators.
3. Data types are stored in ASCII format as follows:

Table 3: Types of Data
DATA TYPE DATA RECORD STORAGE DETAILS Character ASCII characters
Numeric - . 0 1 2 3 4 5 6 7 8 9
Logical ? Y y N n T t F f ? when not initialized
Memo 10 digits representing a .DBT block #
Date 8 digits YYYYMMDD e.g. 19840724

new topic     » goto parent     » topic index » view message » categorize

5. Re: Storage of Euphoria variables

Vinoba: 
 
This should get you started. 
It is not a complete program but it will give you an idea of 
how to do your conversion 
  

-- Using Euphoria Version 4 
include std/sequence.e 
include std/convert.e 
					 -- not open file in binary mode. 
integer fn = open("SomeFile.dbf", "rb")  -- some_file with the correct extent 
-- 
if fn = -1 then 
puts(1,"can't open file") 
end if 
-- 
sequence header = {}, field_descrp_array = {}, record = {} 
 
-- BYTE....CONTENTS........MEANING .................................DETAILS 
-- 0.......1 byte ........ dBASE III version number................(03H without a .DBT file) 
-- ................................................................(83H with a .DBT file) 
-- 1-3.....3 BYTES ........date of last update ....................(YY MM DD) in binary format 
-- 4-7.....32 bit number...number of records in data file 
-- 8-9.....16 bit # .......length of header structure 
-- 10-11...16 bit #........length of the record 
-- 12-31...20 bytes........reserved bytes (version 1.00) 
-- 
-- read 32 the above header bytes 
-- 
for i = 0 to 31 do 
header &= getc(fn) 
end for 
-- Now the sequence holds the header has been read into 
-- a sequence NOTE THE SEQENCE STARTS AT ONE NOT ZERO 
-- 
-- header[1]      contains version number 
-- pad with zeros because bytes_to_int converts four bytes 
atom version = bytes_to_int({0,0,0}&header[1]) -- note 1 byte with 3 zeros 
-- header[2]      contains YY 
atom year = bytes_to_int({0,0,0}&header[2]) 
-- header[3]      contains MM 
atom month = bytes_to_int({0,0,0}&header[3]) 
-- header[4]      contains DD 
atom day = bytes_to_int({0,0,0}&header[4]) 
-- header[5..8]   contains number of records 
atom no_rec = bytes_to_int({0,0}&header[5..8]) 
-- header[9..10]  contains length of header structure 
atom len_hdr = bytes_to_int({0,0}&header[9..10]) 
-- header[11..12] contains length of record 
atom len_rec = bytes_to_int({0,0}&header[11..12]) 
-- header[13..33] contains reseved bytes 
-- *** reseved bytes are not used 
-- 
-- Now we read the array of field descriptor. 
-- NOTE THAT THE FILE IS STILL OPEN 
-- SO WE WILL START ON THE VERY NEXT BYTE. 
-- 
-- 32-n....32 bytes each...field descriptor array..................See Table 2 
-- n+1.....1 byte..........field terminator........................0D (HEX) CR, no LF 
-- 
atom byte = -1 
while 1 do 
  for r = 0 to 31 do 
    byte = getc(fn) 
    if byte = -1 then exit end if -- end of file 
    field_dscrip &= getc(fn) 
  end for 
  if byte = -1 then exit end if -- end of file 
  field_descrp_array &= {field_dscrip} 
end while 
-- Close the file IF YOUR done 
close(fn) 
 
 
-- The array will look like this. 
-- field_descrp_array { {field_dscrip#1},{field_dscrip#2},{field_dscrip#3} } 
-- You would go through and  decode each field_dscrip like this: 
--- 
 
 
-- Table 2: A FIELD DESCRIPTOR: 
-- BYTE CONTENTS MEANING DETAILS 
-- 0-10 11 bytes field name in ASCII zero-filled 
-- 11 1 byte field type in ASCII C N L D or M 
-- 12-15 32 bit # field data address address is set in memory 
-- 16 1 byte field length binary 
-- 17 1 byte field decimal count binary 
-- 18-31 14 bytes reserved bytes (version 1.00) 
 
-- field_dscrip[1..11]  contains name 
sequence name = field_dscrip[1..11] 
for i = 11 to 1 do -- trim off the zeros 
if name[i] = 0 then name = name[1..$-1] else exit end if 
end for 
-- field_dscrip[13..16] contains field data address 
atom  address = bytes_to_int(field_dscrip[13..16]) 
-- field_dscrip[17]     contains field length binary 
atom field_len = bits_to_int(field_dscrip[17]) 
-- field_dscrip[18]     contains decimal count binary 
atom dec_cnt = bits_to_int(field_dscrip[18]) 
-- field_dscrip[19..32] contains 14 bytes reserved bytes 
-- ***** NOT USED 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Storage of Euphoria variables

Zebra: I do not think you got my meaning. I gave just one example of a file info I use to be able to work with DBF files. I generally am much more comfortable when I have information of the TYPE of data or file I demonstrated. Any person working using in line assembler, and Peek and Poke function needs to know that type of information for Euphoria Objects, variables, sequences etc. something like:

Location 00 - 2 bytes Description of this item one
Location 02 - 4 bytes Description of this item two
Location 06 - 8 bytes Description of this item three
Location 0E - 2 bytes Description of this item four
Location 10 - 2 bytes Description of this item five
Location 12 - 4 bytes Description of this item six
Location 16 - 4 bytes Description of this item seven

And so on.
All assembly language programmers have information of this type for data structures they are working with. Similar info needed using Peek and Poke.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Storage of Euphoria variables

Vinoba said...

Zebra: I do not think you got my meaning. I gave just one example of a file info I use to be able to work with DBF files. I generally am much more comfortable when I have information of the TYPE of data or file I demonstrated. Any person working using in line assembler, and Peek and Poke function needs to know that type of information for Euphoria Objects, variables, sequences etc. something like:

Location 00 - 2 bytes Description of this item one
Location 02 - 4 bytes Description of this item two
Location 06 - 8 bytes Description of this item three
Location 0E - 2 bytes Description of this item four
Location 10 - 2 bytes Description of this item five
Location 12 - 4 bytes Description of this item six
Location 16 - 4 bytes Description of this item seven

And so on.
All assembly language programmers have information of this type for data structures they are working with. Similar info needed using Peek and Poke.

Are you trying to access these data items when they are in RAM or when they are on disk?

If RAM, then you do not need the exact implementation details that Euphoria uses - just use standard Euphoria access methods. Using peek/poke is not advised because it would be generally slower than the optimized Euphoria syntax, and the internal implementation could change without notice in future Euphoria versions.

It is not possible to get the RAM address of the stored data from your Euphoria code so even if you knew how it was stored, you still couldn't get access to it.

If you want to use peek() to access your data, you will also need to use poke() to store it and manage it yourself. You will not be able to use in-line assembler to access native Euphoria data.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Storage of Euphoria variables

Thank you all for the replies and information.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu