Esempio n. 1
0
func currentSection(vm *gelo.VM) (string, string) {
	k := gelo.StrToSym("section-tag")
	tag, ok := vm.Ns.Get(0, k)
	if !ok {
		runtimeError(vm, "Unable to get current section tag (not in the section?)")
	}

	k = gelo.StrToSym("section-name")
	name, ok := vm.Ns.Get(0, k)
	if !ok {
		runtimeError(vm, "Unable to get current section name (not in the section?)")
	}

	return tag.Ser().String(), name.Ser().String()
}
Esempio n. 2
0
func enterSection(vm *gelo.VM, tag string, name string) {
	vm.Ns.Fork(nil)

	k := gelo.StrToSym("section-tag")
	v := gelo.StrToSym(tag)
	if !vm.Ns.Set(0, k, v) {
		runtimeError(vm, "Unable to set section tag: section %s %s", tag, name)
	}

	k = gelo.StrToSym("section-name")
	v = gelo.StrToSym(name)
	if !vm.Ns.Set(0, k, v) {
		runtimeError(vm, "Unable to set section name: section %s %s", tag, name)
	}
}
Esempio n. 3
0
File: error.go Progetto: catb0t/gelo
func Die(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word {
	if ac == 0 {
		args = gelo.AsList(gelo.StrToSym("die"))
	}
	gelo.RuntimeError(vm, args)
	return gelo.Null //Issue 65
}
Esempio n. 4
0
func leaveSection(vm *gelo.VM, tag string, name string) {
	// In fact deleting keys is completely unneccessary; it is added only for additional check that we really are
	// in a section
	k := gelo.StrToSym("section-tag")
	if _, ok := vm.Ns.Del(k); !ok {
		runtimeError(vm, "Unable to delete section tag (not in the section?): section %s %s", tag, name)
	}
	k := gelo.StrToSym("section-name")
	if _, ok := vm.Ns.Del(k); !ok {
		runtimeError(vm, "Unable to delete section name (not in the section?): section %s %s", tag, name)
	}

	k = gelo.StrToSym
	if !vm.Ns.Unfork() {
		runtimeError(vm, "Unable to exit the namespace (not in the section?): section %s %s", tag, name)
	}
}
Esempio n. 5
0
File: dict.go Progetto: catb0t/gelo
func Dict_keys(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word {
	if ac != 1 {
		gelo.ArgumentError(vm, "dict.keys", "dictionary", args)
	}
	d, list := vm.API.DictOrElse(args.Value), extensions.ListBuilder()
	for k, _ := range d.Map() {
		list.Push(gelo.StrToSym(k))
	}
	return list.List()
}
Esempio n. 6
0
func checkNotInSection(vm *gelo.VM, command string) {
	k := gelo.StrToSym("section")
	if s, ok := vm.Ns.Get(0, k); ok {
		gelo.RuntimeError(
			vm,
			fmt.Sprintf(
				"%s command is used inside a section %s while it should be toplevel",
				command, s.Ser().String(),
			),
		)
	}
}
Esempio n. 7
0
func getOrMakeDict(vm *gelo.VM, name string) *gelo.Dict {
	k := gelo.StrToSym(name)
	dw, ok := vm.Ns.Get(0, k)
	var d *gelo.Dict
	if ok {
		d, ok = dw.(*gelo.Dict)
		if !ok {
			d = gelo.NewDict()
			vm.Ns.Set(0, k, d)
		}
	} else {
		d = gelo.NewDict()
		vm.Ns.Set(0, k, d)
	}
	return d
}
Esempio n. 8
0
func (c *couple) Type() gelo.Symbol {
	return gelo.StrToSym("*COUPLED-PORT*")
}
Esempio n. 9
0
File: tee.go Progetto: catb0t/gelo
func (t *tee) Type() gelo.Symbol {
	return gelo.StrToSym("*TEE-PORT*")
}
Esempio n. 10
0
File: log.go Progetto: catb0t/gelo
func (g *lr) Type() gelo.Symbol {
	return gelo.StrToSym("*LOGGER-PORT*")
}
Esempio n. 11
0
func (id SenderIdentity) Ser() gelo.Symbol {
	return gelo.StrToSym(fmt.Sprintf("%s %s", id.senderType, id.senderName))
}
Esempio n. 12
0
func (id SenderIdentity) Type() gelo.Symbol {
	return gelo.StrToSym("SenderIdentity")
}
Esempio n. 13
0
File: stdio.go Progetto: catb0t/gelo
}

func (s *_stdio) Copy() gelo.Word {
	return s
}

func (s *_stdio) DeepCopy() gelo.Word {
	return s
}

func (s *_stdio) Equals(w gelo.Word) bool {
	_, ok := w.(*_stdio)
	return ok
}

var _stdio_t = gelo.StrToSym("*STDIO*")

func (*_stdio) Type() gelo.Symbol {
	return _stdio_t
}

type _stderr struct{}

func (s *_stderr) Send(w gelo.Word) {
	os.Stderr.Write(w.Ser().Bytes())
	os.Stderr.WriteString("\n")
}

func (s *_stderr) Recv() gelo.Word {
	return gelo.Null
}
Esempio n. 14
0
func (r *Regexp) Ser() gelo.Symbol {
	return gelo.StrToSym(r.String())
}
Esempio n. 15
0
func (*Regexp) Type() gelo.Symbol {
	return gelo.StrToSym("*REGULAR-EXPRESSION*")
}