Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename files, split c into its own file
- Loading branch information
Showing
7 changed files
with
101 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ _cgo* | |
_go_* | ||
*~ | ||
perl/_obj | ||
perl/cgo.cgo2.o | ||
perl/campher.cgo2.o | ||
6.out | ||
_gotest_* | ||
_test* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
static int dummy_argc = 3; | ||
static char** dummy_argv; | ||
static char** dummy_env; | ||
|
||
static void campher_init() { | ||
dummy_argv = malloc(sizeof(char*) * 3); | ||
dummy_env = malloc(sizeof(char*) * 2); | ||
dummy_argv[0] = "campher"; | ||
dummy_argv[1] = "-e"; | ||
dummy_argv[2] = "0"; | ||
dummy_env[0] = "FOO=bar"; | ||
dummy_env[1] = NULL; | ||
PERL_SYS_INIT3(&dummy_argc,&dummy_argv,&dummy_env); | ||
} | ||
|
||
static void campher_set_context(PerlInterpreter* perl) { | ||
PERL_SET_CONTEXT(perl); | ||
} | ||
|
||
static char *campher_embedding[] = { "", "-e", "0" }; | ||
|
||
static PerlInterpreter* campher_new_perl() { | ||
PerlInterpreter* my_perl = perl_alloc(); | ||
PERL_SET_CONTEXT(my_perl); | ||
perl_construct(my_perl); | ||
perl_parse(my_perl, NULL, 3, campher_embedding, NULL); | ||
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; | ||
perl_run(my_perl); | ||
return my_perl; | ||
} | ||
|
||
static SV* campher_eval_pv(PerlInterpreter* my_perl, char* code) { | ||
return eval_pv(code, TRUE); | ||
} | ||
|
||
static int campher_sv_int(PerlInterpreter* my_perl, SV* sv) { | ||
return SvIVx(sv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package perl | ||
|
||
/* | ||
#cgo CFLAGS: -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.10/CORE | ||
#cgo LDFLAGS: -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.10/CORE -lperl -ldl -lm -lpthread -lc -lcrypt | ||
#include <EXTERN.h> | ||
#include <perl.h> | ||
#include "campher.c" | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
func init() { | ||
C.campher_init() | ||
} | ||
|
||
type Interpreter struct { | ||
perl *_Ctypedef_PerlInterpreter | ||
} | ||
|
||
func (in *Interpreter) be_context() { | ||
C.campher_set_context(in.perl) | ||
} | ||
|
||
func NewInterpreter() *Interpreter { | ||
int := new(Interpreter) | ||
int.perl = C.campher_new_perl() | ||
// TODO: set finalizer and stuff | ||
return int | ||
} | ||
|
||
type SV *C.SV | ||
|
||
func (ip *Interpreter) Eval(str string) SV { | ||
ip.be_context() | ||
cstr := C.CString(str) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
return SV(C.campher_eval_pv(ip.perl, cstr)) | ||
} | ||
|
||
func (ip *Interpreter) EvalInt(str string) int { | ||
ip.be_context() | ||
cstr := C.CString(str) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
sv := C.campher_eval_pv(ip.perl, cstr) | ||
return int(C.campher_sv_int(ip.perl, sv)) | ||
} | ||
|
||
func (ip *Interpreter) EvalString(str string) string { | ||
ip.be_context() | ||
cstr := C.CString(str) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
//sv := C.campher_eval_pv(ip.perl, cstr) | ||
return "foo" // int(C.campher_sv_int(ip.perl, sv)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.