added _main

This commit is contained in:
Luxferre
2026-07-04 09:30:02 +03:00
parent ce18aa76b5
commit 0beaa27fe7
3 changed files with 12 additions and 4 deletions
+5 -1
View File
@@ -460,5 +460,9 @@ func RunFile(filePath string, libCode string) {
defer func() { defer func() {
if r := recover(); r != nil { fmt.Fprintf(os.Stderr, "Error executing %s: %v\n", filePath, r); os.Exit(1) } 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")
}
} }
+5 -1
View File
@@ -123,7 +123,11 @@ class Clyx:
run = lambda self, code: self._exec_quot(self._tokenize(code)) run = lambda self, code: self._exec_quot(self._tokenize(code))
def clyx(f): 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)) except Exception as e: (sys.stderr.write(f'Error executing {f}: {e}\n'), sys.exit(1))
repl = lambda: clyx(replpath) repl = lambda: clyx(replpath)
+2 -2
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env clyx #!/usr/bin/env clyx
# Clyx core implementation test suite # Clyx core implementation test suite
# Created by Luxferre in 2026, released into the public domain # Created by Luxferre in 2026, released into the public domain
:: _main [
# 1. Stack Manipulation # 1. Stack Manipulation
"Testing stack operations..." puts cr "Testing stack operations..." puts cr
@@ -224,4 +224,4 @@ hsargs isquot [ hsargs qlen 0 > ] and if [
] ]
0 hsexit 0 hsexit
]