Merge branch 'issue/106'
This commit is contained in:
commit
e1bf77d486
|
@ -206,6 +206,7 @@ There is a chat room on chat.freenode.org, channel #picrin.
|
||||||
|
|
||||||
Picrin scheme depends on some external libraries to build the binary:
|
Picrin scheme depends on some external libraries to build the binary:
|
||||||
|
|
||||||
|
- perl
|
||||||
- lex (preferably, flex)
|
- lex (preferably, flex)
|
||||||
- getopt
|
- getopt
|
||||||
- readline (optional)
|
- readline (optional)
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
@files = (
|
||||||
|
'piclib/built-in.scm',
|
||||||
|
'piclib/srfi/1.scm',
|
||||||
|
'piclib/srfi/26.scm',
|
||||||
|
'piclib/srfi/95.scm'
|
||||||
|
);
|
||||||
|
|
||||||
|
print <<EOL;
|
||||||
|
#include "picrin.h"
|
||||||
|
#include "picrin/error.h"
|
||||||
|
|
||||||
|
EOL
|
||||||
|
|
||||||
|
foreach my $file (@files) {
|
||||||
|
my $var = &escape_v($file);
|
||||||
|
print "const char *$var =\n";
|
||||||
|
|
||||||
|
open IN, $file;
|
||||||
|
while (<IN>) {
|
||||||
|
chomp;
|
||||||
|
s/\\/\\\\/g;
|
||||||
|
s/"/\\"/g;
|
||||||
|
print "\"$_\\n\"\n";
|
||||||
|
}
|
||||||
|
print ";\n\n";
|
||||||
|
}
|
||||||
|
close IN;
|
||||||
|
|
||||||
|
print <<EOL;
|
||||||
|
void
|
||||||
|
pic_load_piclib(pic_state *pic)
|
||||||
|
{
|
||||||
|
pic_try {
|
||||||
|
EOL
|
||||||
|
|
||||||
|
foreach my $file (@files) {
|
||||||
|
my $var = &escape_v($file);
|
||||||
|
print " pic_load_cstr(pic, $var);\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print <<EOL;
|
||||||
|
}
|
||||||
|
pic_catch {
|
||||||
|
/* error! */
|
||||||
|
fputs("fatal error: failure in loading built-in.scm\\n", stderr);
|
||||||
|
fputs(pic_errmsg(pic), stderr);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
puts("successfully loaded stdlib");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
EOL
|
||||||
|
|
||||||
|
sub escape_v {
|
||||||
|
my ($_) = @_;
|
||||||
|
s/\.scm$//g;
|
||||||
|
s/[\/-]/_/g;
|
||||||
|
$_;
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
import re
|
|
||||||
import os
|
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
outfn = 'src/load_piclib.c'
|
|
||||||
|
|
||||||
libs = [
|
|
||||||
'piclib/built-in.scm',
|
|
||||||
'piclib/srfi/1.scm',
|
|
||||||
'piclib/srfi/26.scm',
|
|
||||||
'piclib/srfi/95.scm',
|
|
||||||
]
|
|
||||||
|
|
||||||
if os.path.exists(outfn):
|
|
||||||
os.remove(outfn)
|
|
||||||
|
|
||||||
piclibs = OrderedDict()
|
|
||||||
for lib in libs:
|
|
||||||
vname = lib[:-4]
|
|
||||||
vname = re.sub(r'/', r'_', vname)
|
|
||||||
vname = re.sub(r'-', r'_', vname)
|
|
||||||
piclibs[lib] = vname
|
|
||||||
|
|
||||||
def escape_scm(infn, outfn, vname):
|
|
||||||
with open(outfn, 'a') as output:
|
|
||||||
output.write('const char *{} =\n'.format(vname))
|
|
||||||
with open(infn, 'r') as input:
|
|
||||||
for line in input:
|
|
||||||
output.write('"')
|
|
||||||
line = line.strip('\n')
|
|
||||||
line = re.sub(r'\\', r'\\\\', line)
|
|
||||||
line = re.sub(r'"', r'\"', line)
|
|
||||||
output.write(line)
|
|
||||||
output.write('\\n"\n')
|
|
||||||
output.write(';\n\n')
|
|
||||||
|
|
||||||
piclib_load_head = """
|
|
||||||
#include "picrin.h"
|
|
||||||
#include "picrin/error.h"
|
|
||||||
"""
|
|
||||||
|
|
||||||
piclib_load_tail = """
|
|
||||||
void
|
|
||||||
pic_load_piclib(pic_state *pic)
|
|
||||||
{{
|
|
||||||
pic_try {{
|
|
||||||
{}
|
|
||||||
}}
|
|
||||||
pic_catch {{
|
|
||||||
/* error! */
|
|
||||||
fputs("fatal error: failure in loading built-in.scm\\n", stderr);
|
|
||||||
fputs(pic_errmsg(pic), stderr);
|
|
||||||
abort();
|
|
||||||
}}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
puts("successfully loaded stdlib");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def gen_piclib_load_c(outfn):
|
|
||||||
with open(outfn, 'a') as f:
|
|
||||||
f.write(piclib_load_head)
|
|
||||||
loads = ""
|
|
||||||
for infn,vname in piclibs.items():
|
|
||||||
escape_scm(infn, outfn, vname)
|
|
||||||
loads += "pic_load_cstr(pic, {});\n ".format(vname)
|
|
||||||
with open(outfn, 'a') as f:
|
|
||||||
f.write('\n\n')
|
|
||||||
f.write(piclib_load_tail.format(loads))
|
|
||||||
|
|
||||||
gen_piclib_load_c(outfn)
|
|
|
@ -7,12 +7,11 @@ set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${PROJECT_SOURCE
|
||||||
set(XFILE_SOURCES extlib/xfile/xfile.c)
|
set(XFILE_SOURCES extlib/xfile/xfile.c)
|
||||||
|
|
||||||
# piclib
|
# piclib
|
||||||
set(Python_ADDITIONAL_VERSIONS 2.7)
|
find_package(Perl REQUIRED)
|
||||||
find_package(PYTHON REQUIRED)
|
|
||||||
set(PICLIB_SOURCES ${PROJECT_SOURCE_DIR}/src/load_piclib.c)
|
set(PICLIB_SOURCES ${PROJECT_SOURCE_DIR}/src/load_piclib.c)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${PICLIB_SOURCES}
|
OUTPUT ${PICLIB_SOURCES}
|
||||||
COMMAND ${PYTHON_EXECUTABLE} etc/libemb.py
|
COMMAND ${PERL_EXECUTABLE} etc/libemb.pl > ${PROJECT_SOURCE_DIR}/src/load_piclib.c
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue