MegaProcessor

Check-in [69958f5974]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:A little bit of cleanup.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:69958f59746e6925f0c7f4661bc2246bf91caf0d
User & Date: jos 2015-09-22 11:38:13
Context
2015-09-22
14:48
Making instructions ld.[bw] and st.[bw] do the right thing. check-in: d58b8e25e9 user: jos tags: trunk
11:38
A little bit of cleanup. check-in: 69958f5974 user: jos tags: trunk
2015-09-19
17:59
Added operand evaluation with symbol-table lookup, TODO: integrate it with the appropriate opcode-generating functions. In this commit, only "jmp start" gets assembled correctly. check-in: 8d5232f487 user: jos tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to eval_op.lua.

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

    while( val > 0 ) do
        local b = math.fmod(val,256);
        table.insert(r,b);
        val = math.floor(val / 256);
    end

    return r ;
end

--
-- Format array of byte-values into one string of
-- hex-format bytes separated by spaces.
--

function TableFormat( t )
    local r = "";
    t = t or {};
    for _,v in ipairs(t) do
        r = r .. string.format("%02x ",v) ;
    end
    return r ;
end

-- 
-- Evaluate a constant expression in any of the formats below
--    Decimal, just digits
--    Hex, prefix 0x or 0X







<
<
<
<
<
<
<
<
<
<
<
<
<
<







49
50
51
52
53
54
55














56
57
58
59
60
61
62

    while( val > 0 ) do
        local b = math.fmod(val,256);
        table.insert(r,b);
        val = math.floor(val / 256);
    end















    return r ;
end

-- 
-- Evaluate a constant expression in any of the formats below
--    Decimal, just digits
--    Hex, prefix 0x or 0X

Changes to lib.lua.

71
72
73
74
75
76
77


78
            cnt = cnt + 1;
        else
            result = result .. "   ";
        end--if
    end--for
    return result ;
end


-- EOF --







>
>

71
72
73
74
75
76
77
78
79
80
            cnt = cnt + 1;
        else
            result = result .. "   ";
        end--if
    end--for
    return result ;
end


-- EOF --

Added test/t_eval.lua.























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package.path = '../?.lua;'..package.path;

require( './lib' );
require( 'symtab' );
require('eval_op');

--
-- Format array of byte-values into one string of
-- hex-format bytes separated by spaces.
--

function TableFormat( t )
    local r = "";
    t = t or {};
    for _,v in ipairs(t) do
        r = r .. string.format("%02x ",v) ;
    end
    return r ;
end

------------------------------------------------------------------------------------

symtab_add("someSymbol", 0x5461);

local TestData = {
   '',
   '49152',
   '0xfedc1234',
   '4275878552',
   '0xCC45',
   '0XaEdC',
   '0b10011100',
   '%1101',
   '"SomeString"',
   '\'AnotherString\'',
   'someSymbol',
   '_another99',
};

for i,s in ipairs(TestData) do
   Printf("%d - :%s: - %s\n", i, s, TableFormat(Eval(s)) );
end