interpreter in go?

blov · 2017-07-04 04:00:05 · 606 次点击    
这是一个分享于 2017-07-04 04:00:05 的资源,其中的信息可能已经有所发展或是发生改变。

So I want to make a small concatenative language interpreter written in Go. I made a small prototype in c++ (https://github.com/allenj12/nnd). I would like the language to be very closely tied to Go if possible using the same primitives, being able to call Go functions etc...

Calling Go functions in the standard library does not seem too much of a problem using reflection however if I want to call a function in Go that requires an import it seems I would have to import that library at runtime. I see options like https://golang.org/pkg/plugin/ and https://github.com/hashicorp/go-plugin but I cant find much info on them and am not sure if its the right way to go. Would either of these packages help, or am I going about this the wrong way?

EDIT: just realized I could have made the title more descriptive :frowning:


评论:

danredux:

To import dynamically, there's 3 real options.

One is to include a Go interpreter and use that for the Go libs. This would be the best solution for your end-users because of the debugging ability and tight integration.

Two is to use the "go" tool to write and compile a plugin dynamically that imports the library and wraps it for use by your interpreter. This is the quickest solution but introduces the Go tool as a dependency for using the interpreted language.

Third is to import the library and transpile it to your own language, then just run it. This is the best solution because people using the library can either read/use it as Go or as your custom language, but it's a massive amount of work.

I recommend number 2, and if it becomes worth it in the long run, invest the time into number 3.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

606 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传