Added some type conversion prims.
authorTim Vaughan <tgvaughan@gmail.com>
Tue, 19 Jul 2016 20:25:45 +0000 (08:25 +1200)
committerTim Vaughan <tgvaughan@gmail.com>
Tue, 19 Jul 2016 20:25:45 +0000 (08:25 +1200)
scheme-primitives.4th
scheme.4th

index 3de4d37..4cba91e 100644 (file)
     car primitive-type istype? -rot 2drop boolean-type
 ; make-primitive procedure?
 
+( = Type conversions = )
+
+:noname ( args -- fixnum )
+    2dup 1 ensure-arg-count
+    car character-type ensure-arg-type
+
+    drop fixnum-type
+; make-primitive char->integer
+
+:noname ( args -- fixnum )
+    2dup 1 ensure-arg-count
+    car fixnum-type ensure-arg-type
+
+    drop character-type
+; make-primitive integer->char
+
 ( = Arithmeic = )
 
 : add-prim ( args -- fixnum )
index 1953cf9..644ee19 100644 (file)
@@ -296,6 +296,17 @@ global-env setobj
     then
 ;
 
+: arg-type-error
+            bold fg red ." Incorrect argument type." reset-term cr
+            abort
+;
+
+: ensure-arg-type ( arg type -- )
+    istype? false = if
+        arg-type-error
+    then
+;
+
 include scheme-primitives.4th
 
 \ }}}