Skip to content

Commit d77aa3a

Browse files
committed
Release-as: quickjs/v1.0.0
1 parent 8dc55f7 commit d77aa3a

File tree

15 files changed

+2923
-0
lines changed

15 files changed

+2923
-0
lines changed

quickjs/_demo/add/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"github.com/goplus/llpkg/quickjs"
6+
)
7+
8+
func main() {
9+
rt := quickjs.JSNewRuntime()
10+
if rt == nil {
11+
panic("none")
12+
}
13+
rt.JsStdInitHandlers()
14+
ctx := rt.JSNewContext()
15+
if ctx == nil {
16+
panic("none")
17+
}
18+
ctx.JsStdAddHelpers(0, nil)
19+
jsCode := c.Str("console.log('Hello from QuickJS! 1 + 2 =', 1 + 2);")
20+
result := ctx.JSEval(jsCode, c.Strlen(jsCode), c.Str("<input>"), 0)
21+
ctx.X__JSFreeValue(result)
22+
ctx.JSFreeContext()
23+
rt.JSFreeRuntime()
24+
}

quickjs/cutils.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package quickjs
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"unsafe"
6+
)
7+
8+
const UTF8_CHAR_LEN_MAX = 6
9+
10+
type BOOL c.Int
11+
12+
const (
13+
FALSE c.Int = 0
14+
TRUE c.Int = 1
15+
)
16+
17+
//go:linkname Pstrcpy C.pstrcpy
18+
func Pstrcpy(buf *int8, buf_size c.Int, str *int8)
19+
20+
//go:linkname Pstrcat C.pstrcat
21+
func Pstrcat(buf *int8, buf_size c.Int, s *int8) *int8
22+
23+
//go:linkname Strstart C.strstart
24+
func Strstart(str *int8, val *int8, ptr **int8) c.Int
25+
26+
//go:linkname HasSuffix C.has_suffix
27+
func HasSuffix(str *int8, suffix *int8) c.Int
28+
29+
type PackedU64 struct {
30+
V uint64
31+
}
32+
33+
type PackedU32 struct {
34+
V uint32
35+
}
36+
37+
type PackedU16 struct {
38+
V uint16
39+
}
40+
41+
// llgo:type C
42+
type DynBufReallocFunc func(unsafe.Pointer, unsafe.Pointer, uintptr) unsafe.Pointer
43+
44+
type DynBuf struct {
45+
Buf *uint8
46+
Size uintptr
47+
AllocatedSize uintptr
48+
Error BOOL
49+
ReallocFunc *unsafe.Pointer
50+
Opaque unsafe.Pointer
51+
}
52+
53+
// llgo:link (*DynBuf).DbufInit C.dbuf_init
54+
func (recv_ *DynBuf) DbufInit() {
55+
}
56+
57+
// llgo:link (*DynBuf).DbufInit2 C.dbuf_init2
58+
func (recv_ *DynBuf) DbufInit2(opaque unsafe.Pointer, realloc_func DynBufReallocFunc) {
59+
}
60+
61+
// llgo:link (*DynBuf).DbufRealloc C.dbuf_realloc
62+
func (recv_ *DynBuf) DbufRealloc(new_size uintptr) c.Int {
63+
return 0
64+
}
65+
66+
// llgo:link (*DynBuf).DbufWrite C.dbuf_write
67+
func (recv_ *DynBuf) DbufWrite(offset uintptr, data *uint8, len uintptr) c.Int {
68+
return 0
69+
}
70+
71+
// llgo:link (*DynBuf).DbufPut C.dbuf_put
72+
func (recv_ *DynBuf) DbufPut(data *uint8, len uintptr) c.Int {
73+
return 0
74+
}
75+
76+
// llgo:link (*DynBuf).DbufPutSelf C.dbuf_put_self
77+
func (recv_ *DynBuf) DbufPutSelf(offset uintptr, len uintptr) c.Int {
78+
return 0
79+
}
80+
81+
// llgo:link (*DynBuf).DbufPutc C.dbuf_putc
82+
func (recv_ *DynBuf) DbufPutc(c uint8) c.Int {
83+
return 0
84+
}
85+
86+
// llgo:link (*DynBuf).DbufPutstr C.dbuf_putstr
87+
func (recv_ *DynBuf) DbufPutstr(str *int8) c.Int {
88+
return 0
89+
}
90+
91+
// llgo:link (*DynBuf).DbufPrintf C.dbuf_printf
92+
func (recv_ *DynBuf) DbufPrintf(fmt *int8, __llgo_va_list ...interface{}) c.Int {
93+
return 0
94+
}
95+
96+
// llgo:link (*DynBuf).DbufFree C.dbuf_free
97+
func (recv_ *DynBuf) DbufFree() {
98+
}
99+
100+
//go:linkname UnicodeToUtf8 C.unicode_to_utf8
101+
func UnicodeToUtf8(buf *uint8, c c.Uint) c.Int
102+
103+
//go:linkname UnicodeFromUtf8 C.unicode_from_utf8
104+
func UnicodeFromUtf8(p *uint8, max_len c.Int, pp **uint8) c.Int
105+
106+
//go:linkname Rqsort C.rqsort
107+
func Rqsort(base unsafe.Pointer, nmemb uintptr, size uintptr, cmp func(unsafe.Pointer, unsafe.Pointer, unsafe.Pointer) c.Int, arg unsafe.Pointer)

quickjs/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/goplus/llpkg/quickjs
2+
3+
go 1.20
4+
5+
require github.com/goplus/llgo v0.10.0

quickjs/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/goplus/llgo v0.10.0 h1:s3U3cnO3cploF1xCCJleAb16NQFAmHxdUmdrNhRH3hY=
2+
github.com/goplus/llgo v0.10.0/go.mod h1:YfOHsT/g3lc9b4GclLj812YzdSsJr0kd3CCB830TqHE=

quickjs/libregexp.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package quickjs
2+
3+
import (
4+
"github.com/goplus/llgo/c"
5+
"unsafe"
6+
)
7+
8+
//go:linkname LreCompile C.lre_compile
9+
func LreCompile(plen *c.Int, error_msg *int8, error_msg_size c.Int, buf *int8, buf_len uintptr, re_flags c.Int, opaque unsafe.Pointer) *uint8
10+
11+
//go:linkname LreGetCaptureCount C.lre_get_capture_count
12+
func LreGetCaptureCount(bc_buf *uint8) c.Int
13+
14+
//go:linkname LreGetFlags C.lre_get_flags
15+
func LreGetFlags(bc_buf *uint8) c.Int
16+
17+
//go:linkname LreGetGroupnames C.lre_get_groupnames
18+
func LreGetGroupnames(bc_buf *uint8) *int8
19+
20+
//go:linkname LreExec C.lre_exec
21+
func LreExec(capture **uint8, bc_buf *uint8, cbuf *uint8, cindex c.Int, clen c.Int, cbuf_type c.Int, opaque unsafe.Pointer) c.Int
22+
23+
//go:linkname LreParseEscape C.lre_parse_escape
24+
func LreParseEscape(pp **uint8, allow_utf16 c.Int) c.Int
25+
26+
//go:linkname LreIsSpace C.lre_is_space
27+
func LreIsSpace(c c.Int) c.Int
28+
29+
/* must be provided by the user */
30+
//go:linkname LreCheckStackOverflow C.lre_check_stack_overflow
31+
func LreCheckStackOverflow(opaque unsafe.Pointer, alloca_size uintptr) c.Int
32+
33+
//go:linkname LreRealloc C.lre_realloc
34+
func LreRealloc(opaque unsafe.Pointer, ptr unsafe.Pointer, size uintptr) unsafe.Pointer
35+
36+
//go:linkname LreJsIsIdentNext C.lre_js_is_ident_next
37+
func LreJsIsIdentNext(c c.Int) c.Int

0 commit comments

Comments
 (0)