mirror of
https://gitlab.cs.washington.edu/fidelp/frustration.git
synced 2024-12-26 21:58:20 +01:00
settle on unsigned comparison
This commit is contained in:
parent
2543097fec
commit
342490230a
1 changed files with 7 additions and 12 deletions
|
@ -145,8 +145,8 @@ const PRIMITIVES: [Primitive; 16] = [
|
||||||
x.dstack.push(!v1);
|
x.dstack.push(!v1);
|
||||||
},
|
},
|
||||||
| x | { // geq (unsigned)
|
| x | { // geq (unsigned)
|
||||||
let v1 = x.dstack.pop();
|
|
||||||
let v2 = x.dstack.pop();
|
let v2 = x.dstack.pop();
|
||||||
|
let v1 = x.dstack.pop();
|
||||||
x.dstack.push(if v1 >= v2 { 0xffff } else { 0 });
|
x.dstack.push(if v1 >= v2 { 0xffff } else { 0 });
|
||||||
},
|
},
|
||||||
| x | { // io
|
| x | { // io
|
||||||
|
@ -258,17 +258,13 @@ fn build_dictionary(c: &mut Core) {
|
||||||
d.entry(); d.name(2, *b"0= "); let zero_eq = d.here;
|
d.entry(); d.name(2, *b"0= "); let zero_eq = d.here;
|
||||||
forth!(Q, zero, Literal(0), INV, RET);
|
forth!(Q, zero, Literal(0), INV, RET);
|
||||||
|
|
||||||
// >= ( a b -- a>=b ) // note: signed comparison
|
|
||||||
d.entry(); d.name(2, *b">= "); let geq = d.here;
|
|
||||||
forth!(sub, Literal(0x4000), DUP, ADD, AND, zero_eq, RET);
|
|
||||||
|
|
||||||
// = ( a b -- a=b )
|
// = ( a b -- a=b )
|
||||||
d.entry(); d.name(1, *b"= "); let eq = d.here;
|
d.entry(); d.name(1, *b"= "); let eq = d.here;
|
||||||
forth!(sub, zero_eq, RET);
|
forth!(sub, zero_eq, RET);
|
||||||
|
|
||||||
// Advance past whitespace
|
// Advance past whitespace
|
||||||
let skip_helper = d.here;
|
let skip_helper = d.here;
|
||||||
forth!(RTO, DRP, key, DUP, Literal(33), geq, Q, RET, DRP, skip_helper);
|
forth!(RTO, DRP, key, DUP, Literal(33), GEQ, Q, RET, DRP, skip_helper);
|
||||||
|
|
||||||
d.entry(); d.name(6, *b"ski"); let skipws = d.here;
|
d.entry(); d.name(6, *b"ski"); let skipws = d.here;
|
||||||
forth!(skip_helper);
|
forth!(skip_helper);
|
||||||
|
@ -287,7 +283,7 @@ fn build_dictionary(c: &mut Core) {
|
||||||
|
|
||||||
// min ( a b -- n )
|
// min ( a b -- n )
|
||||||
d.entry(); d.name(3, *b"min"); let min = d.here;
|
d.entry(); d.name(3, *b"min"); let min = d.here;
|
||||||
forth!(twodup, geq, Q, SWP, DRP, RET);
|
forth!(twodup, GEQ, Q, SWP, DRP, RET);
|
||||||
|
|
||||||
// c@ ( a -- n )
|
// c@ ( a -- n )
|
||||||
d.entry(); d.name(2, *b"c@ "); let cld = d.here;
|
d.entry(); d.name(2, *b"c@ "); let cld = d.here;
|
||||||
|
@ -305,7 +301,7 @@ fn build_dictionary(c: &mut Core) {
|
||||||
// Load letters into buffer until whitespace is hit again.
|
// Load letters into buffer until whitespace is hit again.
|
||||||
// Return the whitespace character that was seen.
|
// Return the whitespace character that was seen.
|
||||||
let getcs_helper = d.here;
|
let getcs_helper = d.here;
|
||||||
forth!(RTO, DRP, stchar, key, DUP, Literal(32), SWP, geq, Q, RET, getcs_helper);
|
forth!(RTO, DRP, stchar, key, DUP, Literal(32), SWP, GEQ, Q, RET, getcs_helper);
|
||||||
|
|
||||||
d.entry(); d.name(5, *b"get"); let getcs = d.here;
|
d.entry(); d.name(5, *b"get"); let getcs = d.here;
|
||||||
forth!(getcs_helper, RET);
|
forth!(getcs_helper, RET);
|
||||||
|
@ -413,10 +409,9 @@ fn build_dictionary(c: &mut Core) {
|
||||||
|
|
||||||
let number_helper = d.here;
|
let number_helper = d.here;
|
||||||
forth!(RTO, DRP, DUP, Literal(word_buf), ADD, cld,
|
forth!(RTO, DRP, DUP, Literal(word_buf), ADD, cld,
|
||||||
Literal(48), sub, Literal(16383), and, // "unsigned comparison"
|
Literal(48), sub, DUP, Literal(10), GEQ, Q, bad_num,
|
||||||
DUP, Literal(10), geq, Q, bad_num,
|
|
||||||
SWP, TOR, SWP, x10, ADD, RTO,
|
SWP, TOR, SWP, x10, ADD, RTO,
|
||||||
DUP, Literal(word_buf), cld, geq, Q, end_num,
|
DUP, Literal(word_buf), cld, GEQ, Q, end_num,
|
||||||
Literal(1), ADD, number_helper);
|
Literal(1), ADD, number_helper);
|
||||||
|
|
||||||
// number ( -- n|-1 )
|
// number ( -- n|-1 )
|
||||||
|
@ -475,7 +470,7 @@ fn build_dictionary(c: &mut Core) {
|
||||||
d.entry(); d.name(2, *b"or "); forth!(OR, RET);
|
d.entry(); d.name(2, *b"or "); forth!(OR, RET);
|
||||||
d.entry(); d.name(3, *b"and"); forth!(AND, RET);
|
d.entry(); d.name(3, *b"and"); forth!(AND, RET);
|
||||||
d.entry(); d.name(3, *b"inv"); forth!(INV, RET);
|
d.entry(); d.name(3, *b"inv"); forth!(INV, RET);
|
||||||
d.entry(); d.name(3, *b"geq"); forth!(GEQ, RET);
|
d.entry(); d.name(3, *b"u>="); forth!(GEQ, RET);
|
||||||
d.entry(); d.name(2, *b"io "); let io = d.here; forth!(IO, RET);
|
d.entry(); d.name(2, *b"io "); let io = d.here; forth!(IO, RET);
|
||||||
|
|
||||||
d.c.store(latest_ptr, io-6);
|
d.c.store(latest_ptr, io-6);
|
||||||
|
|
Loading…
Reference in a new issue