diff options
-rw-r--r-- | CleanC.dcl | 10 | ||||
-rw-r--r-- | CleanC.icl | 7 | ||||
-rw-r--r-- | interface.c | 10 | ||||
-rw-r--r-- | test.c | 5 | ||||
-rw-r--r-- | test.icl | 6 |
5 files changed, 31 insertions, 7 deletions
@@ -23,12 +23,16 @@ SOFTWARE. */ definition module CleanC from StdClass import class toInt, class toString, class toReal, - class fromInt, class fromString, class fromReal + class fromInt, class fromString, class fromReal, + class == :: State -:: CType = Int | String | Real -:: CParam = CI Int | CS String | CR Real +:: CType = Int | String | Real | Void +:: CParam = CI Int | CS String | CR Real | CV + +instance == CType +instance == CParam cNewState :: *State @@ -28,6 +28,9 @@ from GenEq import generic gEq :: State :== Int derive gEq CType +derive gEq CParam +instance == CType where (==) x y = gEq{|*|} x y +instance == CParam where (==) x y = gEq{|*|} x y cNewState :: *State cNewState = 42 @@ -99,6 +102,7 @@ cSetReturnType :: !CType -> *State -> *State cSetReturnType Int = cSetReturnType_ 0 cSetReturnType String = cSetReturnType_ 1 cSetReturnType Real = cSetReturnType_ 2 +cSetReturnType Void = cSetReturnType_ 3 cCall_ :: !String !*State -> *State cCall_ f s = code inline { @@ -138,7 +142,8 @@ where cCall` t f [] s # s = cSetReturnType t s # s = cCall_ f s - = cGetParam t s + | t == Void = (CV, s) + | otherwise = cGetParam t s cCall` t f [p:ps] s # s = cPutParam p s = cCall` t f ps s diff --git a/interface.c b/interface.c index 2a9a106..e40ed86 100644 --- a/interface.c +++ b/interface.c @@ -68,17 +68,21 @@ void cleanPutr(double r) { void cleanSetReturnType(long i) { switch (i) { case 0: - return_type = &ffi_type_slong; + return_type = &ffi_type_slong; return_val = calloc(sizeof(long), 1); break; case 1: - return_type = &ffi_type_pointer; + return_type = &ffi_type_pointer; return_val = calloc(sizeof(char*), 1); break; case 2: - return_type = &ffi_type_double; + return_type = &ffi_type_double; return_val = calloc(sizeof(double), 1); break; + case 3: + return_type = &ffi_type_void; + return_val = calloc(sizeof(void), 1); + break; } } @@ -22,6 +22,7 @@ SOFTWARE. */ #include <stdlib.h> #include <string.h> +#include <stdio.h> double test_double(double x) { return x * 0.5; @@ -45,3 +46,7 @@ int test_two_params(int a, int b) { return a + b; } +void test_void(char* s) { + printf("%s", s); +} + @@ -33,6 +33,7 @@ Start w # (t1,s) = test_string s # (t2,s) = test_double s # (t3,s) = test_two_params s +# (t4,s) = test_void s # tests = [t0,t1,t2,t3] # passed = and tests # (io, w) = stdio w @@ -74,3 +75,8 @@ test_two_params s # (i, s) = cCall Int "test_two_params" (13,29) s = (fromCParam i == 42, s) +test_void :: *State -> (Bool, *State) +test_void s +# (i, s) = cCall Void "test_void" "Testing void function\n" s += (i == CV, s) + |