mirror of
https://github.com/laravel-ls/go-php
synced 2026-06-18 13:00:02 +02:00
Initial commit
This commit is contained in:
commit
4cbf7e62b7
19 changed files with 1295 additions and 0 deletions
35
compile.go
Normal file
35
compile.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package php
|
||||
|
||||
// #include "compile.h"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// The program struct contains the program in compiled format.
|
||||
type program struct {
|
||||
op_array *C.zend_op_array
|
||||
}
|
||||
|
||||
// Compile a program from source code
|
||||
func Compile(code []byte) (*program, error) {
|
||||
cCode := C.CString(string(code))
|
||||
defer C.free(unsafe.Pointer(cCode))
|
||||
|
||||
op_array := C.compile(cCode)
|
||||
if op_array == nil {
|
||||
return nil, errors.New("failed to compile code")
|
||||
}
|
||||
|
||||
return &program{op_array: op_array}, nil
|
||||
}
|
||||
|
||||
func (p *program) Free() {
|
||||
if p.op_array != nil {
|
||||
C.destroy_op_array(p.op_array)
|
||||
C._efree(unsafe.Pointer(p.op_array))
|
||||
}
|
||||
p.op_array = nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue