fixnum-type
; make-primitive string->number
+:noname ( args -- string )
+ 2dup 1 ensure-arg-count
+ car symbol-type ensure-arg-type
+
+ drop pair-type
+ duplicate-charlist
+ drop string-type
+; make-primitive symbol->string
+
+:noname ( args -- symbol )
+ 2dup 1 ensure-arg-count
+ car string-type ensure-arg-type
+
+ drop pair-type
+ duplicate-charlist
+ charlist>symbol
+; make-primitive string->symbol
+
( = Arithmetic = )
: add-prim ( args -- fixnum )
0 fixnum-type
else
2dup car drop
- -rot cdr add-prim drop
- - fixnum-type
+ -rot cdr
+ 2dup nil objeq? if
+ 2drop negate
+ else
+ add-prim drop
+ -
+ then
+ fixnum-type
then
; make-primitive -
then
; make-primitive *
+:noname ( args -- fixnum )
+ 2dup 2 ensure-arg-count
+
+ 2dup car fixnum-type ensure-arg-type
+ 2swap cdr car fixnum-type ensure-arg-type
+
+ drop swap drop
+
+ / fixnum-type
+; make-primitive quotient
+
+:noname ( args -- fixnum )
+ 2dup 2 ensure-arg-count
+
+ 2dup car fixnum-type ensure-arg-type
+ 2swap cdr car fixnum-type ensure-arg-type
+
+ drop swap drop
+
+ mod fixnum-type
+; make-primitive remainder
objvar symbol-table
+: duplicate-charlist ( charlist -- copy )
+ 2dup nil objeq? false = if
+ 2dup car 2swap cdr recurse cons
+ then ;
+
+: charlist-equiv ( charlist charlist -- bool )
+
+ 2over 2over
+
+ \ One or both nil
+ nil? -rot 2drop
+ if
+ nil? -rot 2drop
+ if
+ 2drop 2drop true exit
+ else
+ 2drop 2drop false exit
+ then
+ else
+ nil? -rot 2drop
+ if
+ 2drop 2drop false exit
+ then
+ then
+
+ 2over 2over
+
+ \ Neither nil
+ car drop -rot car drop = if
+ cdr 2swap cdr recurse
+ else
+ 2drop 2drop false
+ then
+;
+
+: charlist>symbol ( charlist -- symbol-obj )
+
+ symbol-table fetchobj
+
+ begin
+ nil? false =
+ while
+ 2over 2over
+ car drop pair-type
+ charlist-equiv if
+ 2swap 2drop
+ car
+ exit
+ else
+ cdr
+ then
+ repeat
+
+ 2drop
+ drop symbol-type 2dup
+ symbol-table fetchobj cons
+ symbol-table setobj
+;
+
+
: (create-symbol) ( addr n -- symbol-obj )
dup 0= if
2drop nil
cons
;
-: charlist-equiv ( charlist charlist -- bool )
-
- 2over 2over
-
- \ One or both nil
- nil? -rot 2drop
- if
- nil? -rot 2drop
- if
- 2drop 2drop true exit
- else
- 2drop 2drop false exit
- then
- else
- nil? -rot 2drop
- if
- 2drop 2drop false exit
- then
- then
-
- 2over 2over
-
- \ Neither nil
- car drop -rot car drop = if
- cdr 2swap cdr recurse
- else
- 2drop 2drop false
- then
-;
-
-: charlist>symbol ( charlist -- symbol-obj )
-
- symbol-table fetchobj
-
- begin
- nil? false =
- while
- 2over 2over
- car drop pair-type
- charlist-equiv if
- 2swap 2drop
- car
- exit
- else
- cdr
- then
- repeat
-
- 2drop
- drop symbol-type 2dup
- symbol-table fetchobj cons
- symbol-table setobj
-;
-
: readpair ( -- pairobj )
eatspaces