Files
five/examples/go_native.prg
Charles KWON OhJun 59568f3301 Five v0.9 — Harbour + Go fusion language
- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline
- Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch
- RTL: 351 Harbour-compatible functions
- RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization
- Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec)
- HB_FUNC API: Full Harbour C API compatible Go bridge
- Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT
- Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST
- Macro Compiler: Runtime AST parsing and evaluation
- Debugger: TUI debugger with source display, breakpoints, stepping
- FRB: Native + Pcode dual mode runtime binary
- Tests: 13 packages ALL PASS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:41:50 +09:00

42 lines
1.2 KiB
Plaintext

// Five Example: Native Go Package Usage — NO #pragma BEGINDUMP
//
// Just IMPORT and use Go packages directly from PRG!
// Five generates the bridge code automatically.
//
// pkg.Func() → direct Go call (gengo emits native Go)
// obj:Method() → reflect bridge (runtime GoCall)
IMPORT "strings"
IMPORT "strconv"
IMPORT "fmt"
PROCEDURE Main()
LOCAL cResult, nVal, cFormatted
? "=== Five Native Go Calls ==="
?
// strings.ToUpper — direct Go package call
cResult := strings.ToUpper("hello five!")
? "strings.ToUpper:", cResult
// strings.Contains
? "strings.Contains('Five is great', 'great'):", strings.Contains("Five is great", "great")
// strings.Replace
cResult := strings.ReplaceAll("foo-bar-baz", "-", "_")
? "strings.ReplaceAll:", cResult
// strings.Split → returns Go slice → auto-converted to Harbour array
? "strings.Split('a,b,c', ','):", strings.Split("a,b,c", ",")
// strconv.Atoi — returns (int, error)
nVal := strconv.Atoi("42")
? "strconv.Atoi('42'):", nVal
// fmt.Sprintf — format strings the Go way
cFormatted := fmt.Sprintf("Name: %s, Age: %d, Score: %.1f", "Charles", 30, 98.5)
? "fmt.Sprintf:", cFormatted
RETURN