Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /MLRISC/trunk/vararg-ccall/varargs.sml
ViewVC logotype

Diff of /MLRISC/trunk/vararg-ccall/varargs.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3067, Thu Jun 5 22:18:34 2008 UTC revision 3068, Fri Jun 6 00:25:53 2008 UTC
# Line 15  Line 15 
15      type 'a valist      type 'a valist
16      type ('a, 'b) vararg = 'a valist -> ('b -> 'a) valist      type ('a, 'b) vararg = 'a valist -> ('b -> 'a) valist
17    
     datatype argument = I of int | R of real | B of bool | S of string  
   
18      val int : ('a, int) vararg      val int : ('a, int) vararg
19      val real : ('a, real) vararg      val real : ('a, real) vararg
20      val bool : ('a, bool) vararg      val bool : ('a, bool) vararg
# Line 26  Line 24 
24    
25      val call : ('a vararg_fn) -> ('a valist -> 'b valist) -> 'b      val call : ('a vararg_fn) -> ('a valist -> 'b valist) -> 'b
26    
27        val printf : unit vararg_fn
28    
29    end;    end;
30    
31  structure VarArgs :> VAR_ARGS =  structure VarArgs :> VAR_ARGS =
32    struct    struct
33    
34    (* an evaluation engine that serves as a target *)    (* an evaluation engine that serves as a target *)
35      datatype argument = I of int | R of real | B of bool | S of string      datatype argument = datatype VarargCCall.argument
36    
37      fun arg2str (I i) = Int.toString i      fun arg2str (I i) = Int.toString i
38        | arg2str (R r) = Real.toString r        | arg2str (R r) = Real.toString r
# Line 40  Line 40 
40        | arg2str (S s) = concat["\"", String.toString s, "\""]        | arg2str (S s) = concat["\"", String.toString s, "\""]
41    
42      val stk = ref([] : argument list)      val stk = ref([] : argument list)
43      fun push arg = (      fun push arg = stk := arg :: !stk
44            print(concat["push(", arg2str arg, ")\n"]);      fun callWithArgs (cFun, x) = let
           stk := arg :: !stk)  
     fun callWithArgs f = let  
45            val args = !stk            val args = !stk
46            in            in
47              stk := [];              stk := [];
48              f args              IA32VarargCCall.callWithArgs (cFun, args);
49                x
50            end            end
51    
52      type 'a valist = ((unit -> unit) -> 'a)      type 'a valist = ((unit -> unit) -> 'a)
# Line 63  Line 62 
62    
63      fun call f spec = spec (fn k => (k(); callWithArgs f)) (fn () => ())      fun call f spec = spec (fn k => (k(); callWithArgs f)) (fn () => ())
64    
65      type 'a vararg_fn = argument list -> 'a      type 'a vararg_fn = string * 'a
66    
67        val printf = ("printf", ())
68    
69    end    end

Legend:
Removed from v.3067  
changed lines
  Added in v.3068

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0