Changeset 229c7393422c788b47fb6fe491fad591fe049d3f

User picture

Commiter: Charles Childers

Author: Charles Childers

Parent: fbec8f49ae

(2010/03/11 01:11) Almost 2 years ago

hack old gonga sources to support implicit calls; exits via port 5 query -9

Affected files

Updated vm/golang/Makefile Download diff

fbec8f49aece25bf72a68c06ecb0cd01dd84f757229c7393422c788b47fb6fe491fad591fe049d3f
3
TARG=ngaro
3
TARG=ngaro
4
GOFILES=ngaro.go
4
GOFILES=ngaro.go
5
5
6
retro: emptyimg gonga retroImage
7
	echo '#!/usr/bin/gonga -' | cat - retroImage > retro
8
	chmod +x retro
9
10
embed: embedimage gonga
11
12
gonga: ./$(TARG).a gonga.go image.go
6
gonga: ./$(TARG).a gonga.go image.go
13
	$(GC) -o gonga.$O image.go gonga.go
7
	$(GC) -o gonga.$O image.go gonga.go
14
	$(LD) -o $@ gonga.$O
8
	$(LD) -o $@ gonga.$O
...
...
16
./$(TARG).a: ./_obj/$(TARG).a
10
./$(TARG).a: ./_obj/$(TARG).a
17
	cp ./_obj/$(TARG).a .
11
	cp ./_obj/$(TARG).a .
18
12
19
emptyimg:
20
	echo 'package main; var retroImage = [...]int{}' | gofmt > image.go
21
22
IMGRETRO=' \
23
	here \
24
	: dump 0 @+ (.) swap for char: , emit space @+ (.) next ; \
25
	dump bye'
26
27
IMGAWK=' \
28
	/ok[ 	]+dump/ { \
29
		sub(/^.*dump/, ""); \
30
		print "package main"; \
31
		print "var retroImage = [...]int{" $$0 "}"; \
32
	}'
33
34
embedimage: retroImage
35
	echo $(IMGRETRO) | gonga retroImage | awk $(IMGAWK) | gofmt > image.go
36
37
include $(GOROOT)/src/Make.pkg
13
include $(GOROOT)/src/Make.pkg

Updated vm/golang/ngaro.go Download diff

fbec8f49aece25bf72a68c06ecb0cd01dd84f757229c7393422c788b47fb6fe491fad591fe049d3f
33
	: ->c ( xy- ) 2 out wait ; ( send x to channel y )
33
	: ->c ( xy- ) 2 out wait ; ( send x to channel y )
34
	: c-> ( x-y ) 1 out wait 1 in ; ( receive y from channel x )
34
	: c-> ( x-y ) 1 out wait 1 in ; ( receive y from channel x )
35
	: delchan ( x- ) dup 1 out 2 out wait ; ( delete channel )
35
	: delchan ( x- ) dup 1 out 2 out wait ; ( delete channel )
36
	: cores ( -x ) -7 5 out wait 5 in ; ( number of running cores )
36
	: cores ( -x ) 1 5 out wait 5 in ; ( number of running cores )
37
	: chans ( -x ) -8 5 out wait 5 in ; ( number of channels in use )
37
	: chans ( -x ) 2 5 out wait 5 in ; ( number of channels in use )
38
38
39
	Example:
39
	Example:
40
40
...
...
188
	return vm.channel[id]
188
	return vm.channel[id]
189
}
189
}
190
190
191
func (vm *NgaroVM) wait(port *[nports]int, tos int) (spdec int) {
191
func (vm *NgaroVM) wait(port *[nports]int, tos int, ip int) (spdec int) {
192
	if port[0] == 1 {
192
	if port[0] == 1 {
193
		return
193
		return
194
	}
194
	}
...
...
265
		port[5] = stackDepth
265
		port[5] = stackDepth
266
		port[0] = 1
266
		port[0] = 1
267
267
268
	case -7: // Number of cores
268
	case -9:
269
		ip = vm.size
270
271
	case 1: // Number of cores
269
		port[5] = vm.cores
272
		port[5] = vm.cores
270
		port[0] = 1
273
		port[0] = 1
271
274
272
	case -8: // Number of channels
275
	case 2: // Number of channels
273
		port[5] = len(vm.channel)
276
		port[5] = len(vm.channel)
274
		port[0] = 1
277
		port[0] = 1
275
278
...
...
420
			port[data[sp]] = data[sp-1]
423
			port[data[sp]] = data[sp-1]
421
			sp = sp - 2
424
			sp = sp - 2
422
		case Wait:
425
		case Wait:
423
			sp -= vm.wait(&port, tos)
426
			sp -= vm.wait(&port, tos, ip)
424
		default:
427
		default:
425
			ip = vm.size
428
			rsp++
429
			addr[rsp] = ip
430
			ip = vm.img[ip] - 1
426
		}
431
		}
427
		// to avoid segfaults:
432
		// to avoid segfaults:
428
		if sp < 0 {
433
		if sp < 0 {