1
#===========================================================================
2
# Filename : scm_decl.rb
3
# About : a function declaration processing library for SigScheme
5
# Copyright (C) 2005-2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
6
# Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
10
# Redistribution and use in source and binary forms, with or without
11
# modification, are permitted provided that the following conditions
14
# 1. Redistributions of source code must retain the above copyright
15
# notice, this list of conditions and the following disclaimer.
16
# 2. Redistributions in binary form must reproduce the above copyright
17
# notice, this list of conditions and the following disclaimer in the
18
# documentation and/or other materials provided with the distribution.
19
# 3. Neither the name of authors nor the names of its contributors
20
# may be used to endorse or promote products derived from this software
21
# without specific prior written permission.
23
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
24
# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
27
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
#===========================================================================
37
# scm_p_call_with_values(ScmObj producer, ScmObj consumer,
38
# ScmEvalState *eval_state)
41
# DECLARE_FUNCTION("call-with-values", procedure_fixed_tailrec_2);
46
# $1 :prototype SCM_EXPORT ScmObj scm_p_call_with_values(ScmObj producer, ScmObj consumer, ScmEvalState *eval_state)
47
# $2 :scope SCM_EXPORT
49
# $4 :func scm_p_call_with_values
51
# $6 :func_body call_with_values
52
# $7 :args ScmObj producer, ScmObj consumer, ScmEvalState *eval_state
53
# $8 :proc call-with-values
54
# $9 :functype_whole procedure_fixed_tailrec_2
55
# $10 :functype_prefix procedure
56
# $11 :functype_spec fixed_tailrec_2
57
SCM_DECL_RE = /\n((SCM_EXPORT\s+)?(ScmObj)\s+(scm_([sp])_(\w+))\(([^{]+)\))[ \t]*\n\s*\{[^{}]+DECLARE_FUNCTION\(\s*\"([^\"]+)\"[\s,]+(([^_]+)_([\w]+))\)/m
60
# :register_func scm_register_procedure_fixed_tailrec_2
61
# :functype_code SCM_PROCEDURE_FIXED_TAILREC_2
65
scan(SCM_DECL_RE) { |prototype, scope, ret, func, prefix, func_body, args, proc, functype_whole, functype_prefix, functype_spec|
67
:prototype => prototype.gsub(/\s+/, " "),
72
:func_body => func_body,
73
:args => args.gsub(/\s+/, " "),
75
:register_func => "scm_register_" + functype_whole,
76
:functype_code => "SCM_" + functype_whole.upcase,
77
:functype_whole => functype_whole,
78
:functype_prefix => functype_prefix,
79
:functype_spec => functype_spec,
88
#def scm_func_table_entry(decl)
89
# proc, func, register_func = decl.values_at(:proc, :func, :register_func)
90
# "{ \"#{proc}\", (ScmFuncType)#{func}, (ScmRegisterFunc)#{register_func} }"
93
def scm_func_table_entry(decl)
94
proc, func, functype_code = decl.values_at(:proc, :func, :functype_code)
95
"{ \"#{proc}\", (ScmFuncType)#{func}, #{functype_code} }"
98
def scm_func_register_exp(decl)
99
proc, func, register_func = decl.values_at(:proc, :func, :register_func)
100
"#{register_func}(\"#{proc}\", #{func})"
103
def scm_generate_func_table_body(str)
104
str.scan_scm_decl { |decl|
105
entry = scm_func_table_entry(decl)
110
def scm_generate_func_register_exps(str)
111
str.scan_scm_decl { |decl|
112
exp = scm_func_register_exp(decl)
117
def scm_generate_func_prototypes(str)
118
str.scan_scm_decl { |decl|
119
"#{decl[:prototype]};\n"
128
#print src.scan_scm_decl { |decl|
132
#print src.scan_scm_decl { |decl|
133
# if (/!$/ =~ decl[:proc])
135
# print "perl -i -pe 's/\\b#{func}\\b/#{func.sub(/d$/, "x")}/g'\n"
139
#print scm_generate_func_table_body(src)
140
#print scm_generate_func_register_exps(src)
141
#print scm_generate_func_prototypes(src)