Author: tewk
Date: Mon Dec 8 08:50:52 2008
New Revision: 33660
Added:
trunk/ext/SQLite3/gen_sqlite3.pl (contents, props changed)
- copied, changed from r33583, /trunk/compilers/ncigen/gen_sqlite3.pl
Removed:
trunk/compilers/ncigen/gen_sqlite3.pl
trunk/compilers/ncigen/k.h
trunk/compilers/ncigen/kk.h
Modified:
trunk/compilers/ncigen/NCIGENP6.pm
trunk/compilers/ncigen/src/NCIGENAST.pir
trunk/compilers/ncigen/src/parser/actions.pm
trunk/ext/SQLite3/Makefile.in
Log:
[ncigen] [sqlite] almost generating SQLite3.pir
Modified: trunk/compilers/ncigen/NCIGENP6.pm
==============================================================================
--- trunk/compilers/ncigen/NCIGENP6.pm (original)
+++ trunk/compilers/ncigen/NCIGENP6.pm Mon Dec 8 08:50:52 2008
@@ -77,7 +77,7 @@
for ($node.list()) -> $x {
$type ~= param_to_code($x);
}
- return ($node.name, $type);
+ return ($node.name, $type, $node.source());
}
sub format_func_decl($pirname, $cname, $type) {
@@ -99,6 +99,8 @@
when 'long' { return "V"; }
when 'char' { return "t"; }
when 'short' { return "V"; }
+ when 'double' { return "V"; }
+ when 'floag' { return "V"; }
default {
=begin
say "ERROR";
@@ -119,6 +121,8 @@
when 'long' { return "l"; }
when 'char' { return "c"; }
when 'short' { return "s"; }
+ when 'double' { return "d"; }
+ when 'floag' { return "f"; }
default { return "p"; }
}
}
Modified: trunk/compilers/ncigen/src/NCIGENAST.pir
==============================================================================
--- trunk/compilers/ncigen/src/NCIGENAST.pir (original)
+++ trunk/compilers/ncigen/src/NCIGENAST.pir Mon Dec 8 08:50:52 2008
@@ -149,6 +149,12 @@
.namespace [ 'NCIGENAST';'VarDecl' ]
+.sub 'source' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .tailcall self.'attr'('source', value, has_value)
+.end
+
.sub 'type' :method
.param pmc value :optional
.param int has_value :opt_flag
Modified: trunk/compilers/ncigen/src/parser/actions.pm
==============================================================================
--- trunk/compilers/ncigen/src/parser/actions.pm (original)
+++ trunk/compilers/ncigen/src/parser/actions.pm Mon Dec 8 08:50:52 2008
@@ -128,10 +128,14 @@
sub ispointer($/, $ast) {
if $/ {
- if $<declarator><pointer> {
+ if ($<declarator><pointer>) {
$ast.pointer(1);
$ast.pointer_cnt(countpointer($<declarator><pointer>));
}
+ if ($<abstract_declarator><pointer>) {
+ $ast.pointer(1);
+ $ast.pointer_cnt(countpointer($<abstract_declarator><pointer>));
+ }
}
my $lookup_ast := $ast;
Modified: trunk/ext/SQLite3/Makefile.in
==============================================================================
--- trunk/ext/SQLite3/Makefile.in (original)
+++ trunk/ext/SQLite3/Makefile.in Mon Dec 8 08:50:52 2008
@@ -69,7 +69,7 @@
all :
cd ../..; make perl6
- cd ../../compilers/ncigen/; $(PERL6) gen_sqlite3.pl
/usr/include/sqlite3.h > ../../ext/SQLite3/genSQLite3.pir
+ cd ../../compilers/ncigen; $(PERL6) ../../ext/SQLite3/gen_sqlite3.pl
/usr/include/sqlite3.h > ../../ext/SQLite3/genSQLite3.pir
test:
$(RM_F) test.db t/test.db
Copied: trunk/ext/SQLite3/gen_sqlite3.pl (from r33583,
/trunk/compilers/ncigen/gen_sqlite3.pl)
==============================================================================
--- /trunk/compilers/ncigen/gen_sqlite3.pl (original)
+++ trunk/ext/SQLite3/gen_sqlite3.pl Mon Dec 8 08:50:52 2008
@@ -8,27 +8,128 @@
my $fn = @*ARGS[0];
-print gen_preamble("SQLite3", "sqlite3");
-
my %rename_table = (
'open' => 'open_raw',
'prepare_v2' => 'prepare_raw',
);
+print preamble();
+
for (parse_ast($fn).kv) -> $k,$v {
#dump_node($v);
if ($v.WHAT eq "FuncDecl") {
my @result = pir($v);
+ my $cname = @result[0];
+ my $signature = @result[1];
+ my $source = @result[2];
my $suffix_name = @result[0];
my $suffix_name .= subst( /sqlite3_/, '' );
my $pirname = %rename_table{$suffix_name} || $suffix_name;
- say format_func_decl($pirname, |@result);
+ say " '_nci_init_symbol_'(lib, '$pirname', '$cname', '$signature')
#$source";
}
}
+print postamble();
+
+sub preamble() {
+qq{
+##GENERATED FILE DO NOT EDIT##
+##GENERATED BY gen_sqlite3.pl##
+.namespace ['SQLite']
+
+.const int SQLITE_OK = 0 # Successful result
+# beginning-of-error-codes
+.const int SQLITE_ERROR = 1 # SQL error or missing database
+.const int SQLITE_INTERNAL = 2 # Internal logic error in SQLite
+.const int SQLITE_PERM = 3 # Access permission denied
+.const int SQLITE_ABORT = 4 # Callback routine requested an abort
+.const int SQLITE_BUSY = 5 # The database file is locked
+.const int SQLITE_LOCKED = 6 # A table in the database is locked
+.const int SQLITE_NOMEM = 7 # A malloc() failed
+.const int SQLITE_READONLY = 8 # Attempt to write a readonly database
+.const int SQLITE_INTERRUPT = 9 # Operation terminated by
sqlite3_interrupt()
+.const int SQLITE_IOERR = 10 # Some kind of disk I/O error occurred
+.const int SQLITE_CORRUPT = 11 # The database disk image is malformed
+.const int SQLITE_NOTFOUND = 12 # NOT USED. Table or record not found
+.const int SQLITE_FULL = 13 # Insertion failed because database is
full
+.const int SQLITE_CANTOPEN = 14 # Unable to open the database file
+.const int SQLITE_PROTOCOL = 15 # NOT USED. Database lock protocol error
+.const int SQLITE_EMPTY = 16 # Database is empty
+.const int SQLITE_SCHEMA = 17 # The database schema changed
+.const int SQLITE_TOOBIG = 18 # String or BLOB exceeds size limit
+.const int SQLITE_CONSTRAINT = 19 # Abort due to constraint violation
+.const int SQLITE_MISMATCH = 20 # Data type mismatch
+.const int SQLITE_MISUSE = 21 # Library used incorrectly
+.const int SQLITE_NOLFS = 22 # Uses OS features not supported on host
+.const int SQLITE_AUTH = 23 # Authorization denied
+.const int SQLITE_FORMAT = 24 # Auxiliary database format error
+.const int SQLITE_RANGE = 25 # 2nd parameter to sqlite3_bind out of
range
+.const int SQLITE_NOTADB = 26 # File opened that is not a database file
+.const int SQLITE_ROW = 100 # sqlite3_step() has another row ready
+.const int SQLITE_DONE = 101 # sqlite3_step() has finished executing
+
+.sub '_nci_init_symbol_'
+ .param pmc lib
+ .param string pirname
+ .param string cname
+ .param string signature
+ .local pmc function
+
+ function = dlfunc lib, cname, signature
+ set_global pirname, function
+.end
+
+.sub '_sqlite_init' :load
+ .local pmc lib
+
+ lib = loadlib 'libsqlite3'
+ set_global '_sqlite3', lib
+};
+}
+
+sub postamble () {
+qq{.end
+
+.sub 'open'
+ .param string connectstr
+ .local pmc dbhandle
+ .local pmc open_raw
+ .local int rc
+
+ open_raw = get_global 'open_raw'
+ dbhandle = new 'Pointer'
+ rc = open_raw(connectstr, dbhandle)
+
+ .return(dbhandle)
+.end
+
+.sub 'prepare'
+ .param pmc dbhandle
+ .param string psstr
+ .local int psstrlen
+ .local pmc pshandle
+ .local pmc dummy
+ .local pmc prepare_raw
+ .local int rc
+
+ prepare_raw = get_global 'prepare_raw'
+
+ pshandle = new 'Pointer'
+ dummy = new 'Pointer'
+ psstrlen = length psstr
+ rc = prepare_raw(dbhandle, psstr, psstrlen, pshandle, dummy)
-say gen_postamble();
+ .return(pshandle)
+.end
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+};
+}
# Local Variables:
# mode: pir