u< um/mod

llvm
Clyne 2 years ago
parent bf7fe756a1
commit c46f531b6b

@ -18,7 +18,6 @@ Running Alee without `core.fth` or `core-ext.fth` passed as arguments will leave
**Missing** core features: **Missing** core features:
* Pictured numeric output conversion (e.g. `<# #>`) * Pictured numeric output conversion (e.g. `<# #>`)
* Some words for unsigned integers: `U. U< UM/MOD`
* `>NUMBER` * `>NUMBER`
**Missing** core extensions: **Missing** core extensions:

@ -120,9 +120,9 @@ yes 6.1.2260 SWAP
yes 6.1.2270 THEN yes 6.1.2270 THEN
yes 6.1.2310 TYPE yes 6.1.2310 TYPE
yes 6.1.2320 U. yes 6.1.2320 U.
6.1.2340 U< yes 6.1.2340 U<
yes 6.1.2360 UM* yes 6.1.2360 UM*
6.1.2370 UM/MOD yes 6.1.2370 UM/MOD
yes 6.1.2380 UNLOOP yes 6.1.2380 UNLOOP
yes 6.1.2390 UNTIL yes 6.1.2390 UNTIL
yes 6.1.2410 VARIABLE yes 6.1.2410 VARIABLE

@ -160,19 +160,18 @@ T{ 0 MIN-INT > -> <TRUE> }T
T{ MAX-INT MIN-INT > -> <TRUE> }T T{ MAX-INT MIN-INT > -> <TRUE> }T
T{ MAX-INT 0 > -> <TRUE> }T T{ MAX-INT 0 > -> <TRUE> }T
." HEY! U< IS NOT IMPLEMENTED!" CR T{ 0 1 U< -> <TRUE> }T
\ T{ 0 1 U< -> <TRUE> }T T{ 1 2 U< -> <TRUE> }T
\ T{ 1 2 U< -> <TRUE> }T T{ 0 MID-UINT U< -> <TRUE> }T
\ T{ 0 MID-UINT U< -> <TRUE> }T T{ 0 MAX-UINT U< -> <TRUE> }T
\ T{ 0 MAX-UINT U< -> <TRUE> }T T{ MID-UINT MAX-UINT U< -> <TRUE> }T
\ T{ MID-UINT MAX-UINT U< -> <TRUE> }T T{ 0 0 U< -> <FALSE> }T
\ T{ 0 0 U< -> <FALSE> }T T{ 1 1 U< -> <FALSE> }T
\ T{ 1 1 U< -> <FALSE> }T T{ 1 0 U< -> <FALSE> }T
\ T{ 1 0 U< -> <FALSE> }T T{ 2 1 U< -> <FALSE> }T
\ T{ 2 1 U< -> <FALSE> }T T{ MID-UINT 0 U< -> <FALSE> }T
\ T{ MID-UINT 0 U< -> <FALSE> }T T{ MAX-UINT 0 U< -> <FALSE> }T
\ T{ MAX-UINT 0 U< -> <FALSE> }T T{ MAX-UINT MID-UINT U< -> <FALSE> }T
\ T{ MAX-UINT MID-UINT U< -> <FALSE> }T
T{ 0 1 MIN -> 0 }T T{ 0 1 MIN -> 0 }T
T{ 1 2 MIN -> 1 }T T{ 1 2 MIN -> 1 }T
@ -411,13 +410,13 @@ T{ MIN-INT MAX-INT M* MAX-INT SM/REM -> 0 MIN-INT }T
T{ MAX-INT MAX-INT M* MAX-INT SM/REM -> 0 MAX-INT }T T{ MAX-INT MAX-INT M* MAX-INT SM/REM -> 0 MAX-INT }T
\ T{ 0 0 1 UM/MOD -> 0 0 }T T{ 0 0 1 UM/MOD -> 0 0 }T
\ T{ 1 0 1 UM/MOD -> 0 1 }T T{ 1 0 1 UM/MOD -> 0 1 }T
\ T{ 1 0 2 UM/MOD -> 1 0 }T T{ 1 0 2 UM/MOD -> 1 0 }T
\ T{ 3 0 2 UM/MOD -> 1 1 }T T{ 3 0 2 UM/MOD -> 1 1 }T
\ T{ MAX-UINT 2 UM* 2 UM/MOD -> 0 MAX-UINT }T T{ MAX-UINT 2 UM* 2 UM/MOD -> 0 MAX-UINT }T
\ T{ MAX-UINT 2 UM* MAX-UINT UM/MOD -> 0 2 }T T{ MAX-UINT 2 UM* MAX-UINT UM/MOD -> 0 2 }T
\ T{ MAX-UINT MAX-UINT UM* MAX-UINT UM/MOD -> 0 MAX-UINT }T T{ MAX-UINT MAX-UINT UM* MAX-UINT UM/MOD -> 0 MAX-UINT }T
: IFFLOORED : IFFLOORED
[ -3 2 / -2 = INVERT ] LITERAL IF POSTPONE \ THEN ; [ -3 2 / -2 = INVERT ] LITERAL IF POSTPONE \ THEN ;

@ -230,6 +230,22 @@ execute:
state.push(dcell); state.push(dcell);
state.push(dcell >> (sizeof(Cell) * 8)); state.push(dcell >> (sizeof(Cell) * 8));
break; break;
case 35: // u<
cell = state.pop();
state.top() = static_cast<Addr>(state.top()) <
static_cast<Addr>(cell) ? -1 : 0;
break;
case 36: // um/mod
cell = state.pop();
dcell = state.pop();
dcell <<= sizeof(Cell) * 8;
dcell |= static_cast<Addr>(state.pop());
state.push(static_cast<DoubleAddr>(dcell) %
static_cast<Addr>(cell));
state.push(static_cast<DoubleAddr>(dcell) /
static_cast<Addr>(cell));
break;
default: default:
state.push(index - WordCount); state.push(index - WordCount);
break; break;

@ -31,7 +31,7 @@ void user_sys(State&);
class CoreWords class CoreWords
{ {
public: public:
constexpr static std::size_t WordCount = 35; constexpr static std::size_t WordCount = 37;
constexpr static int Semicolon = 26; constexpr static int Semicolon = 26;
/** /**
@ -54,7 +54,7 @@ public:
"<<\0>>\0:\0_'\0execute\0" "<<\0>>\0:\0_'\0execute\0"
"exit\0;\0_jmp0\0_jmp\0" "exit\0;\0_jmp0\0_jmp\0"
"depth\0_rdepth\0_in\0_ev\0find\0" "depth\0_rdepth\0_in\0_ev\0find\0"
"um*\0"; "um*\0u<\0um/mod\0";
}; };
#endif // ALEEFORTH_COREWORDS_HPP #endif // ALEEFORTH_COREWORDS_HPP

@ -28,6 +28,7 @@
using Addr = uint16_t; using Addr = uint16_t;
using Cell = int16_t; using Cell = int16_t;
using DoubleCell = int32_t; using DoubleCell = int32_t;
using DoubleAddr = uint32_t; // Only used for um/mod.
struct Dictionary; struct Dictionary;
struct State; struct State;

Loading…
Cancel
Save