From 0beaa27fe7d6c6e119280e1dff06352aa703fa14 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Sat, 4 Jul 2026 09:30:02 +0300 Subject: [PATCH] added _main --- clyx-go/clyx.go | 6 +++++- clyx-python/clyx/clyx.py | 6 +++++- test.clx | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/clyx-go/clyx.go b/clyx-go/clyx.go index 579dccb..73e1943 100644 --- a/clyx-go/clyx.go +++ b/clyx-go/clyx.go @@ -460,5 +460,9 @@ func RunFile(filePath string, libCode string) { defer func() { if r := recover(); r != nil { fmt.Fprintf(os.Stderr, "Error executing %s: %v\n", filePath, r); os.Exit(1) } }() - NewClyx("", libCode).Run(string(content)) + c := NewClyx("", libCode) + c.Run(string(content)) + if c.HasWord("_main") { + c.Run("_main") + } } diff --git a/clyx-python/clyx/clyx.py b/clyx-python/clyx/clyx.py index aa148bf..c9da19c 100755 --- a/clyx-python/clyx/clyx.py +++ b/clyx-python/clyx/clyx.py @@ -123,7 +123,11 @@ class Clyx: run = lambda self, code: self._exec_quot(self._tokenize(code)) def clyx(f): - try: Clyx().run(open(f).read()) + try: + c = Clyx() + c.run(open(f).read()) + if '_main' in c._words: + c.run('_main') except Exception as e: (sys.stderr.write(f'Error executing {f}: {e}\n'), sys.exit(1)) repl = lambda: clyx(replpath) diff --git a/test.clx b/test.clx index 84f2d25..ed4d5c2 100755 --- a/test.clx +++ b/test.clx @@ -1,7 +1,7 @@ #!/usr/bin/env clyx # Clyx core implementation test suite # Created by Luxferre in 2026, released into the public domain - +:: _main [ # 1. Stack Manipulation "Testing stack operations..." puts cr @@ -224,4 +224,4 @@ hsargs isquot [ hsargs qlen 0 > ] and if [ ] 0 hsexit - +]