summaryrefslogtreecommitdiff
path: root/parser/parse.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2024-03-14 14:37:32 +0100
committerMarc Vertes <mvertes@free.fr>2024-03-14 14:37:32 +0100
commit378683d25bdae89fa446b2b82f8dda5d6b34ea33 (patch)
treecbf624e4eb38fafe51a12a718b48f43192cfcfac /parser/parse.go
parent60170bad25f912e0ba44e4c0095b54f6e26e307e (diff)
feat: initial support of closures
Also detection and automatic execution of main function. Make sure that all debug is output to stderr.
Diffstat (limited to 'parser/parse.go')
-rw-r--r--parser/parse.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/parser/parse.go b/parser/parse.go
index 547957b..36ff125 100644
--- a/parser/parse.go
+++ b/parser/parse.go
@@ -24,6 +24,7 @@ type Parser struct {
labelCount map[string]int
breakLabel string
continueLabel string
+ clonum int // closure instance number
}
func (p *Parser) Scan(s string, endSemi bool) (Tokens, error) {
@@ -203,7 +204,13 @@ func (p *Parser) ParseFunc(in Tokens) (out Tokens, err error) {
// TODO: handle receiver (methods)
// TODO: handle parametric types (generics)
// TODO: handle variadic parameters
- fname := in[1].Str
+ var fname string
+ if in[1].Id == lang.Ident {
+ fname = in[1].Str
+ } else {
+ fname = "#f" + strconv.Itoa(p.clonum)
+ p.clonum++
+ }
ofname := p.fname
p.fname = fname
ofunc := p.function