|
From: Ina C. <in...@st...> - 2001-01-31 00:46:50
|
Here is the diff that doesn't work:
Index: soap_test_methods.m
===================================================================
RCS file: /cvsroot/quicksilver/webserver/server/soap_test_methods.m,v
retrieving revision 1.1
diff -u -r1.1 soap_test_methods.m
--- soap_test_methods.m 2001/01/25 06:54:42 1.1
+++ soap_test_methods.m 2001/01/31 00:40:03
@@ -23,14 +23,30 @@
:- interface.
:- import_module io, int, list, std_util.
-:- pred hello(state::di, state::uo) is det.
+:- pred hello(univ::out) is det.
+% :- pred hello(io__state::di, io__state::uo) is det.
+% :- pred hello(list(univ)::in, univ::out) is det.
:- pred get_sp(list(univ)::in, univ::out) is det.
:- func get_stockprice(list(univ)) = univ.
%---------------------------------------------------------------------%
:- implementation.
@@ -50,8 +66,14 @@
%---------------------------------------------------------------------%
% Hello
%---------------------------------------------------------------------%
+
+% hello --> print("Hello, world").
+
+hello(ResultAsUniv) :-
+ ResultAsUniv = univ("<output>Hello, world</output>").
-hello --> print("Hello, world\n").
+% hello(_List, ResultAsUniv) :-
+% ResultAsUniv = univ("<output>Hello, world</output>").
%---------------------------------------------------------------------%
% GetStockPrice
Index: web_methods.m
===================================================================
RCS file: /cvsroot/quicksilver/webserver/server/web_methods.m,v
retrieving revision 1.1
diff -u -r1.1 web_methods.m
--- web_methods.m 2001/01/25 06:54:42 1.1
+++ web_methods.m 2001/01/31 00:40:03
@@ -172,8 +105,12 @@
% Opens library file, invokes desire function, and gets back
% corresponding response and http code.
-load_dynamic_library(L, Request, Response, HttpCode) -->
- dl__open(L, lazy, local, MaybeHandle),
+ %
+ % LibFile format = "./libfilename.so"
+ %
+load_dynamic_library(LibFile, Request, Response, HttpCode) -->
+ dl__open(LibFile, lazy, local, MaybeHandle),
+ { get_filename(LibFile, Filename) },
(
{ MaybeHandle = error(OpenMsg) },
{ string__append("dlopen failed: ", OpenMsg, OpenErrorMsg) },
@@ -185,17 +122,20 @@
% Hello has no parameter
{ Request^name = "Hello" }
->
- call_Hello_pred(Handle, Request, Response0, HttpCode0)
+ call_Hello_pred(Handle, Filename, Request,
+ Response0, HttpCode0)
;
% GetStockPrice has 1 parameter
{ Request^name = "GetStockPrice" }
->
- call_SP_func(Handle, Request, Response0, HttpCode0)
+ call_SP_func(Handle, Filename, Request,
+ Response0, HttpCode0)
;
% GetBookPrice takes in a struct
{ Request^name = "GetBookPrice" }
->
- call_BP_pred(Handle, Request, Response0, HttpCode0)
+ call_BP_pred(Handle, Filename, Request,
+ Response0, HttpCode0)
;
{ Response0 = yes("Method requested not
implemented.") },
@@ -232,13 +172,13 @@
% Hello
%-----------------------------------------------------------------------%
-:- pred call_Hello_pred(handle, web_method_request, maybe(string), http_code,
- io__state, io__state).
-:- mode call_Hello_pred(in, in, out, out, di, uo) is det.
-
-call_Hello_pred(Handle, _Request, Response, HttpCode) -->
- { HelloProc = mercury_proc(predicate, unqualified(soap_library_file),
- "hello", 2, 0) },
+:- pred call_Hello_pred(handle, string, web_method_request, maybe(string),
+ http_code, io__state, io__state).
+:- mode call_Hello_pred(in, in, in, out, out, di, uo) is det.
+
+call_Hello_pred(Handle, Filename, _Request, Response, HttpCode) -->
+ { HelloProc = mercury_proc(predicate, unqualified(Filename),
+ "hello", 1, 0) },
dl__mercury_sym(Handle, HelloProc, MaybeHello),
(
{ MaybeHello = error(Msg) },
@@ -254,9 +194,27 @@
% Call the procedure whose address
% we just obtained.
- HelloPred,
+ % HelloPred,
+
+ % XXX error occurs
+ % if change hello(io__state::di, io__state::uo) is det
+ % to hello(univ::out) is det or
+ % hello(list(univ)::in, univ::out) is det ????
+
+/*
+This is the same error that I have for the MLDS closure problem
+
+*** Mercury runtime: caught segmentation violation ***
+PC at signal: 1074572806 (400cae06)
+address involved: 0x40017de8
+This may have been caused by a stack overflow, due to unbounded recursion.
+exiting from signal handler
+*/
+ { HelloPred(HelloUniv) },
+ { det_univ_to_type(HelloUniv, HelloString) },
- { Response = yes("<output>Hello World</output>") },
+ % { HelloString = "<output>Hello, world</output>" },
+ { Response = yes(HelloString) },
{ HttpCode = 200 }
).
@@ -265,32 +223,43 @@
% `hello' procedure is `pred(di, uo) is det', before we can actually
% call it. The function inst_cast_hello/1 defined below does that.
-:- type io_pred == pred(io__state, io__state).
-:- inst io_pred == (pred(di, uo) is det).
+:- type hello_pred == pred(univ).
+:- inst hello_pred == (pred(out) is det).
-:- func inst_cast_hello(io_pred) = io_pred.
-:- mode inst_cast_hello(in) = out(io_pred) is det.
-:- pragma c_code(inst_cast_hello(X::in) = (Y::out(io_pred)),
+% :- type hello_pred == pred(io__state, io__state).
+% :- inst hello_pred == (pred(di, uo) is det).
+
+:- func inst_cast_hello(hello_pred) = hello_pred.
+:- mode inst_cast_hello(in) = out(hello_pred) is det.
+:- pragma c_code(inst_cast_hello(X::in) = (Y::out(hello_pred)),
[will_not_call_mercury, thread_safe], "Y = X").
%-----------------------------------------------------------------------%
% GetStockPrice
%-----------------------------------------------------------------------%
+
+:- pred call_SP_func(handle, string, web_method_request, maybe(string),
+ http_code, io__state, io__state).
+:- mode call_SP_func(in, in, in, out, out, di, uo) is det.
+
+ % XXX error occurs for function but not for predicate
+/*
+
+Uncaught exception:
+Software Error: dl__mercury_sym: result type is not a higher-order type
-:- pred call_SP_func(handle, web_method_request, maybe(string), http_code,
- io__state, io__state).
-:- mode call_SP_func(in, in, out, out, di, uo) is det.
+*/
-call_SP_func(Handle, Request, Response, HttpCode) -->
+call_SP_func(Handle, Filename, Request, Response, HttpCode) -->
{ list__length(Request^params, Arity) },
% XXX test for function
- % { GetSPProc = mercury_proc(function, unqualified(soap_library_file),
- % "get_stockprice", Arity, 0) },
+ { GetSPProc = mercury_proc(function, unqualified(Filename),
+ "get_stockprice", Arity, 0) },
% XXX test for predicate
- { GetSPProc = mercury_proc(predicate, unqualified(soap_library_file),
- "get_sp", 2, 0) },
+ % { GetSPProc = mercury_proc(predicate, unqualified(Filename),
+ % "get_sp", 2, 0) },
dl__mercury_sym(Handle, GetSPProc, MaybeGetStockPrice),
(
@@ -304,22 +273,18 @@
% Cast the higher-order term that we obtained
% to the correct higher-order inst.
% XXX test for predicate
- { SPProc = inst_cast_sp(SPProc0) },
+ % { SPProc = inst_cast_sp(SPProc0) },
% XXX test for function
- % { wrapper(SPFunc) = inst_cast_stockprice(SPProc0) },
+ { wrapper(SPFunc) = inst_cast_stockprice(SPProc0) },
% Convert parameters (string) to the corresponding types
{ list__map(lookup_SP_schema, Request^params, UnivList) },
% Call the procedure whose address we just obtained
% XXX test for predicate
- { call(SPProc, UnivList, SPUniv) },
+ % { call(SPProc, UnivList, SPUniv) },
% XXX test for function
- % { SPUniv = SPFunc(UnivList) },
+ { SPUniv = SPFunc(UnivList) },
{ det_univ_to_type(SPUniv, SPInt) },
{ string__int_to_string(SPInt, SPString) },
@@ -384,13 +349,13 @@
% inst cast for get_sp (predicate)
-:- type sp_pred == pred(list(univ), univ).
-:- inst sp_pred == (pred(in, out) is det).
+% :- type sp_pred == pred(list(univ), univ).
+% :- inst sp_pred == (pred(in, out) is det).
-:- func inst_cast_sp(sp_pred) = sp_pred.
-:- mode inst_cast_sp(in) = out(sp_pred) is det.
-:- pragma c_code(inst_cast_sp(X::in) = (Y::out(sp_pred)),
- [will_not_call_mercury, thread_safe], "Y=X").
+% :- func inst_cast_sp(sp_pred) = sp_pred.
+% :- mode inst_cast_sp(in) = out(sp_pred) is det.
+% :- pragma c_code(inst_cast_sp(X::in) = (Y::out(sp_pred)),
+% [will_not_call_mercury, thread_safe], "Y=X").
% inst cast for get_stockprice (function)
:- type stockprice == (func(list(univ)) = univ ).
@@ -561,6 +550,14 @@
%-----------------------------------------------------------------------%
% Shared functions
%-----------------------------------------------------------------------%
+
+ % Returns filename from ./libfilename.so
+:- pred get_filename(string::in, string::out) is det.
+
+get_filename(LibFile, Filename) :-
+ string__split(LibFile, 5, _Left, Filename0),
+ string__length(Filename0, Length),
+ string__left(Filename0, Length-3, Filename).
% Separates prefix and suffix.
:- pred split_on_colon(string::in, string::out, string::out) is det.
|