Changeset 510

Show
Ignore:
Timestamp:
02/10/08 23:53:46 (8 months ago)
Author:
krobillard
Message:

'loop is now an opcode and can act as loop.to for integers.
File port! read now handles optional limit.
console.out now handles binary!.
Can now 'make an int! from first 4 bytes of a binary!
Added ur_initDecimal macro.
Added 'fcalc.
Removed word inc/dec.

Location:
trunk/thune
Files:
1 added
23 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/boot.c

    r507 r510  
    3636  "  opcode! 31 'verify  make :verify\n" 
    3737  "  opcode! 32 'forever make :forever\n" 
     38  "  opcode! 33 'loop    make :loop\n" 
    3839  "  int!/decimal! :number!\n" 
    3940  "  word!/set-word!/get-word!/lit-word! :any-word!\n" 
     
    6566  "]\n" 
    6667  "'loop proc :while  ;(block cond -- )\n" 
    67   "[\n" 
    68   "  int! verify\n" 
    69   "  [dup zero? ift break over do dec] forever\n" 
    70   "  drop drop\n" 
    71   "]\n" 
    72   "'loop proc :loop   ;(block count -- )\n" 
    7368  "[body  n number!  limit number!] [\n" 
    7469  "  n\n" 
  • trunk/thune/config.t

    r458 r510  
    44[x] trig     "Include trigonometric math calls" 
    55[x] math3d   "Include vector & matrix math calls" 
    6              enable trig 
     6             enable [trig fcalc] 
    77[x] macros   "Reader macros" 
    88[x] net      "UDP socket port" 
    99[x] dataflow "Component! datatype for dataflow programming" 
     10[X] fcalc    "Floating point calculator" 
    1011 
    1112[ ] threads  "CPU Threads" 
  • trunk/thune/doc/UserManual

    r509 r510  
    364364either    (logic t-val f-val -- )    Evaluate either t-val or f-val. 
    365365forever   (block -- )                Evaluate block until exception thrown. 
     366loop_     (block n -- )              Repeat block **n** times. 
     367loop_     (block n limit -- )        Repeat block **n** to **limit** times. 
    366368iter      (ser body -- )             Iterate over series. 
    367369iter/N    (ser body -- )             Iterate over series with skip. 
     
    393395each.set  (ser words body -- )       Iterate over series and assign elements. 
    394396while     (body cond -- )            Evaluate body while cond is true. 
    395 loop      (block n -- )              Repeat block **n** times. 
    396397loop.to   (block n limit -- )        Repeat block **n** to **limit** times. 
    397398proc.env  (env body -- proc)         Create procedure with private context. 
     
    632633 
    633634 
     635loop 
     636---- 
     637:: 
     638 
     639    (block int -- ) 
     640    (block int int -- ) 
     641 
     642The first form simply evalutes the body block a given number of times. 
     643 
     644The second form pushes the counter value onto the stack before each loop, 
     645and stops when the limit is reached. 
     646 
     647Example:: 
     648 
     649    )> [.] -2 2 loop 
     650    -2 
     651    -1 
     652    0 
     653    1 
     654 
    634655 
    635656Data Manipulation Functions 
  • trunk/thune/doc/thune.vim

    r509 r510  
    117117syn keyword     thuneType       unset! datatype! none! logic! word! set-word! 
    118118syn keyword     thuneType       get-word! lit-word! select! set-select! opcode! 
    119 syn keyword     thuneType       char! int! int64! decimal! coord! vec3! 
     119syn keyword     thuneType       char! int! bignum! decimal! coord! vec3! vector! 
    120120syn keyword     thuneType       binary! string!  block! paren! path! setpath! 
    121 syn keyword     thuneType       slice! list! context! 
     121syn keyword     thuneType       list! context! port! 
    122122syn keyword     thuneType       function! call! date! time! bitset! error! code! 
    123123"syn keyword     thuneTypeFunction type? 
  • trunk/thune/files.c

    r483 r510  
    317317        UPortDevice* dev = _devicePtr( ut, ur_s_prev(tos) ); 
    318318        if( dev ) 
    319             dev->read( ut, tos /*, part*/ ); 
     319            dev->read( ut, tos, part ); 
    320320        return; 
    321321    } 
     
    10991099 
    11001100 
    1101 // (port buf len -- port buf) 
    1102 UR_CALL( _fileRead ) 
     1101// (port buf -- port buf) 
     1102void _fileRead( UThread* ut, UCell* tos, int part ) 
    11031103{ 
    11041104    UBlock* blk; 
     
    11221122 
    11231123 
    1124         len = READ_BUF_SIZE; 
     1124        len = part ? part : READ_BUF_SIZE; 
    11251125 
    11261126        if( ur_is(tos, UT_BINARY) || ur_is(tos, UT_STRING) ) 
  • trunk/thune/gc.c

    r509 r510  
    394394                break; 
    395395 
     396            case CC_LOOP: 
     397                --it; 
     398                SET_BIT_BLOCK_L( it->cell.series.n ) 
     399                --it; 
     400                break; 
     401 
    396402            case CC_REDUCE: 
    397403                SET_BIT_BLOCK_L( it->reduce.n ) 
  • trunk/thune/gl/gx_atoms.h

    r508 r510  
    11// This file is automatically generated - do not edit. 
    22 
    3 #define UR_ATOM_DRAW_LIST_OPCODES               323 
    4 #define UR_ATOM_WIDTH           324 
    5 #define UR_ATOM_HEIGHT          325 
    6 #define UR_ATOM_AREA            326 
    7 #define UR_ATOM_RECT            327 
    8 #define UR_ATOM_RASTER          328 
    9 #define UR_ATOM_TEXTURE         329 
    10 #define UR_ATOM_ELEM            330 
    11 #define UR_ATOM_CLOSE           184 
    12 #define UR_ATOM_FOCUS           331 
    13 #define UR_ATOM_RESIZE          332 
    14 #define UR_ATOM_KEY_DOWN                333 
    15 #define UR_ATOM_KEY_UP          334 
    16 #define UR_ATOM_MOUSE_MOVE              335 
    17 #define UR_ATOM_MOUSE_UP                336 
    18 #define UR_ATOM_MOUSE_DOWN              337 
    19 #define UR_ATOM_MOUSE_WHEEL             338 
    20 #define UR_ATOM_AMBIENT         339 
    21 #define UR_ATOM_DIFFUSE         340 
    22 #define UR_ATOM_SPECULAR                341 
    23 #define UR_ATOM_POS             342 
    24 #define UR_ATOM_SHADER          343 
    25 #define UR_ATOM_VERTEX          344 
    26 #define UR_ATOM_FRAGMENT                345 
    27 #define UR_ATOM_DEFAULT         346 
    28 #define UR_ATOM_WAIT            135 
    29 #define UR_ATOM_RGB             347 
    30 #define UR_ATOM_RGBA            348 
    31 #define UR_ATOM_DEPTH           349 
    32 #define UR_ATOM_CLAMP           350 
    33 #define UR_ATOM_REPEAT          351 
    34 #define UR_ATOM_NEAREST         352 
    35 #define UR_ATOM_LINEAR          353 
    36 #define UR_ATOM_MIN             354 
    37 #define UR_ATOM_MAG             355 
    38 #define UR_ATOM_MIPMAP          356 
    39 #define UR_ATOM_GRAY            357 
    40 #define UR_ATOM_RGB             347 
    41 #define UR_ATOM_RGBA            348 
    42 #define UR_ATOM_ON              267 
    43 #define UR_ATOM_OFF             269 
    44 #define UR_ATOM_ADD             203 
    45 #define UR_ATOM_BURN            358 
    46 #define UR_ATOM_COLOR           359 
    47 #define UR_ATOM_TRANS           360 
    48 #define UR_ATOM_SPRITE          361 
    49 #define UR_ATOM_ONCE            362 
    50 #define UR_ATOM_PING_PONG               363 
    51 #define UR_ATOM_PONG            364 
     3#define UR_ATOM_DRAW_LIST_OPCODES               326 
     4#define UR_ATOM_WIDTH           327 
     5#define UR_ATOM_HEIGHT          328 
     6#define UR_ATOM_AREA            329 
     7#define UR_ATOM_RECT            330 
     8#define UR_ATOM_RASTER          331 
     9#define UR_ATOM_TEXTURE         332 
     10#define UR_ATOM_ELEM            333 
     11#define UR_ATOM_CLOSE           186 
     12#define UR_ATOM_FOCUS           334 
     13#define UR_ATOM_RESIZE          335 
     14#define UR_ATOM_KEY_DOWN                336 
     15#define UR_ATOM_KEY_UP          337 
     16#define UR_ATOM_MOUSE_MOVE              338 
     17#define UR_ATOM_MOUSE_UP                339 
     18#define UR_ATOM_MOUSE_DOWN              340 
     19#define UR_ATOM_MOUSE_WHEEL             341 
     20#define UR_ATOM_AMBIENT         342 
     21#define UR_ATOM_DIFFUSE         343 
     22#define UR_ATOM_SPECULAR                344 
     23#define UR_ATOM_POS             345 
     24#define UR_ATOM_SHADER          346 
     25#define UR_ATOM_VERTEX          347 
     26#define UR_ATOM_FRAGMENT                348 
     27#define UR_ATOM_DEFAULT         349 
     28#define UR_ATOM_WAIT            137 
     29#define UR_ATOM_RGB             350 
     30#define UR_ATOM_RGBA            351 
     31#define UR_ATOM_DEPTH           352 
     32#define UR_ATOM_CLAMP           353 
     33#define UR_ATOM_REPEAT          354 
     34#define UR_ATOM_NEAREST         355 
     35#define UR_ATOM_LINEAR          356 
     36#define UR_ATOM_MIN             357 
     37#define UR_ATOM_MAG             358 
     38#define UR_ATOM_MIPMAP          359 
     39#define UR_ATOM_GRAY            360 
     40#define UR_ATOM_RGB             350 
     41#define UR_ATOM_RGBA            351 
     42#define UR_ATOM_ON              270 
     43#define UR_ATOM_OFF             272 
     44#define UR_ATOM_ADD             205 
     45#define UR_ATOM_BURN            361 
     46#define UR_ATOM_COLOR           362 
     47#define UR_ATOM_TRANS           363 
     48#define UR_ATOM_SPRITE          364 
     49#define UR_ATOM_ONCE            365 
     50#define UR_ATOM_PING_PONG               366 
     51#define UR_ATOM_PONG            367 
  • trunk/thune/internal.h

    r506 r510  
    108108typedef struct 
    109109{ 
     110    int16_t  code; 
     111    uint16_t flags; 
     112    int32_t  n; 
     113    int32_t  it; 
     114} 
     115CELoop; 
     116 
     117typedef struct 
     118{ 
    110119    int16_t code; 
    111120    int16_t locals; 
     
    118127typedef union 
    119128{ 
    120     char   bytes[16]; 
     129    UCell  cell; 
    121130    CEId   id; 
    122131    CECell cp; 
    123132    CEEnd  end; 
    124133    CEEval eval; 
     134    CELoop loop; 
    125135    CECell iter; 
    126136    CECell reduce; 
     
    134144#define CC_EVAL             2 
    135145#define CC_EVAL_RUNNING     3 
    136 #define CC_FOREVER          4 
    137 #define CC_REDUCE           5 
    138 #define CC_ITER             6 
    139 #define CC_EACH             7 
    140 #define CC_CATCH            8 
    141 #define CC_TERM             9 
    142 #define CC_END              10 
     146#define CC_REDUCE           4 
     147#define CC_FOREVER          5 
     148#define CC_LOOP             6 
     149#define CC_ITER             7 
     150#define CC_EACH             8 
     151#define CC_CATCH            9 
     152#define CC_TERM             10 
     153#define CC_END              11 
    143154#define CC_COUNT            (CC_END+1) 
    144155 
     
    147158#define CC_LEN_EVAL         1 
    148159#define CC_LEN_FOREVER      1 
     160#define CC_LEN_LOOP         2 
    149161#define CC_LEN_REDUCE       1 
    150162#define CC_LEN_ITER         2 
     
    210222#define OP_VERIFY           31 
    211223#define OP_FOREVER          32 
    212 #define OP_REDUCE           33 
    213 #define OP_DO_FUNC          34 
     224#define OP_LOOP             33 
     225#define OP_REDUCE           34 
     226#define OP_DO_FUNC          35 
    214227//#define OP_END              255 
    215228 
  • trunk/thune/make.c

    r508 r510  
    15821582                        n = ur_stringToInt( spA, spB, 0 ); 
    15831583                    } 
     1584                } 
     1585            } 
     1586            else if( ur_binarySlice(ut, tos, &spA, &spB) ) 
     1587            { 
     1588                if( (spB - spA) > 3 ) 
     1589                { 
     1590                    // Load 32-bit big-endian number. 
     1591                    uint8_t* bp = (uint8_t*) spA; 
     1592                    n = (bp[0] << 24) | (bp[1] << 16) | 
     1593                        (bp[2] <<  8) | bp[3]; 
    15841594                } 
    15851595            } 
  • trunk/thune/math.c

    r505 r510  
    977977#include "math3d.c" 
    978978#endif 
     979#ifdef UR_CONFIG_FCALC 
     980#include "fcalc.c" 
     981#endif 
    979982 
    980983 
     
    10181021    { uc_cross,        "cross" }, 
    10191022    { uc_normalize,    "normalize" }, 
    1020     { uc_set_stride,   "set-stride" } 
     1023    { uc_set_stride,   "set-stride" }, 
     1024#endif 
     1025 
     1026#ifdef UR_CONFIG_FCALC 
     1027    { uc_fcalc,         "fcalc" }, 
    10211028#endif 
    10221029}; 
  • trunk/thune/mkboot.t

    r507 r510  
    3737  opcode! 31 'verify  make :verify 
    3838  opcode! 32 'forever make :forever 
     39  opcode! 33 'loop    make :loop 
    3940 
    4041  int!/decimal! :number! 
     
    7273] 
    7374'loop proc :while  ;(block cond -- ) 
    74  
    75 [ 
    76   int! verify 
    77   [dup zero? ift break over do dec] forever 
    78   drop drop 
    79 ] 
    80 'loop proc :loop   ;(block count -- ) 
    8175 
    8276[body  n number!  limit number!] [ 
  • trunk/thune/net.c

    r471 r510  
    326326 
    327327// (port buf -- port buf) 
    328 UR_CALL( _netRead ) 
     328void _netRead( UThread* ut, UCell* tos, int part ) 
    329329{ 
    330330    UBinary* bin; 
     
    333333    UCell* val; 
    334334    UCell* pc = ur_s_prev(tos); 
     335 
     336    (void) part; 
    335337 
    336338    blk = ur_blockPtr( pc->port.valBlk ); 
  • trunk/thune/project.r

    r497 r510  
    1414default [ 
    1515    warn 
    16     debug 
    17     ;release 
     16   ;debug 
     17    release 
    1818 
    1919    cflags {-DLANG_THUNE} 
  • trunk/thune/read_config.r

    r458 r510  
    1414       dataflow: 
    1515       dt-code: 
     16       fcalc: 
    1617       net: 
    1718       uds: 
  • trunk/thune/scripts/mandel.t

    r226 r510  
    3131            40.0 div  y 40.0 div  mandelbrot '*' ' ' either prin 
    3232        ] 
    33         -39 39 loop.to 
     33        -39 39 loop 
    3434    ] 
    35     -39 39 loop.to 
     35    -39 39 loop 
    3636    eol prin 
    3737] 
  • trunk/thune/scripts/nsieve.t

    r338 r510  
    2727        ) 
    2828    ] 
    29     2 size loop.to 
     29    2 size loop 
    3030 
    3131    ;count 
     
    6262int! args/1 make :n 
    6363 
    64 [10000 n rot sub lshift nsieve] 0 3 loop.to 
     64[10000 n rot sub lshift nsieve] 0 3 loop 
    6565 
  • trunk/thune/stdio.c

    r469 r510  
    5656            fwrite( it, 1, end - it, stdout ); 
    5757        } 
     58    } 
     59    else if( ur_binarySlice(ut, tos, &it, &end) && it ) 
     60    { 
     61        fwrite( it, 1, end - it, stdout ); 
    5862    } 
    5963 
  • trunk/thune/tests/working/inc.good

    r353 r510  
    332.0 
    440.0 
    5 1 
    6 0 
    7 2.0 
    8 1.0 
  • trunk/thune/tests/working/inc.t

    r458 r510  
    551.0 dec . 
    66 
     7/* 
    780 :a 
    89++ a a . 
     
    1213++ a a . 
    1314-- a a . 
     15*/ 
    1416 
    1517.s 
  • trunk/thune/thune.c

    r506 r510  
    4545            case CC_EVAL: 
    4646            case CC_EVAL_RUNNING: 
     47            case CC_REDUCE: 
    4748            case CC_FOREVER: 
    48             case CC_REDUCE: 
    4949                toc -= CC_LEN_EVAL; 
    5050                break; 
    5151 
     52            case CC_LOOP: 
    5253            case CC_ITER: 
    5354            case CC_EACH: 
     
    795796                        goto bad_opcode_type; 
    796797                    break; 
    797  
     798#if 0 
    798799                case OP_INC_WORD:               // ( -- ) 
    799800                    if( (pc == end) || (! ur_is(pc, UT_WORD)) ) 
     
    841842                    } 
    842843                    break; 
    843  
     844#endif 
    844845                case OP_VERIFY:     // (val type -- val) 
    845846                                    // (v1 v2 t1 t2 -- v1 v2) 
     
    869870                    goto control; 
    870871 
     872                case OP_LOOP:           // (body n [n2] -- ) 
     873                { 
     874                    int n0, n1; 
     875                    int prevInt; 
     876                    UCell* prev = ur_s_prev(UR_TOS); 
     877 
     878                    if( ur_is(prev, UT_INT) ) 
     879                    { 
     880                        n0 = ur_int(prev); 
     881                        --prev; 
     882                        prevInt = 1; 
     883                    } 
     884                    else 
     885                    { 
     886                        n0 = 0; 
     887                        prevInt = 0; 
     888                    } 
     889 
     890                    if( ! ur_is(UR_TOS, UT_INT) || ! ur_is(prev, UT_BLOCK) ) 
     891                    { 
     892                        ur_throwErr( UR_ERR_DATATYPE, 
     893                                     "loop expected block! int!" ); 
     894                        goto throw_cc; 
     895                    } 
     896                    n1 = ur_int(UR_TOS); 
     897                    UR_S_DROP; 
     898                    if( prevInt ) 
     899                        UR_S_DROP; 
     900                    if( n1 > n0 ) 
     901                    { 
     902                        PUSHC_EVAL( blkN, start, pc ); 
     903                        SET_BLK_PC( UR_TOS->series.n, 
     904                                    UR_TOS->series.it ); 
     905                        ur_copyCell( ut->toc, *UR_TOS ); 
     906                        UR_C_GROW; 
     907 
     908                        UR_TOC->loop.code  = CC_LOOP; 
     909                        UR_TOC->loop.flags = prevInt; 
     910                        UR_TOC->loop.n     = n1; 
     911                        UR_TOC->loop.it    = n0; 
     912                        UR_C_GROW; 
     913 
     914                        if( prevInt )   // Loop body must drop counter. 
     915                        { 
     916                            ur_initInt( UR_TOS, n0 ); 
     917                            UR_S_GROW; 
     918                        } 
     919                    } 
     920                    UR_S_DROP; 
     921                } 
     922                    break; 
     923 
    871924                //case OP_END: 
    872925                //    goto finish; 
     
    10701123            goto control; 
    10711124 
    1072         case CC_FOREVER: 
    1073             SET_BLK_PC( UR_TOC->eval.n, UR_TOC->eval.it ); 
    1074             UR_C_GROW; 
    1075             goto execute; 
    1076  
    10771125        case CC_REDUCE: 
    10781126        { 
     
    10971145            ur_setSeries(ntos, rblkN, 0); 
    10981146        } 
     1147            goto control; 
     1148 
     1149        case CC_FOREVER: 
     1150            SET_BLK_PC( UR_TOC->eval.n, UR_TOC->eval.it ); 
     1151            UR_C_GROW; 
     1152            goto execute; 
     1153 
     1154        case CC_LOOP: 
     1155            if( ++UR_TOC->loop.it < UR_TOC->loop.n ) 
     1156            { 
     1157                UCell* ser = ut->toc - 1; 
     1158                if( UR_TOC->loop.flags ) 
     1159                { 
     1160                    UR_S_GROW;      // Loop code must drop TOS. 
     1161                    ur_initInt( UR_TOS, UR_TOC->loop.it ); 
     1162                } 
     1163                SET_BLK_PC( ser->series.n, ser->series.it ); 
     1164                UR_C_GROW; 
     1165                goto execute; 
     1166            } 
     <