Example #1
0
File: word.go Project: mk2/yon
func CheckChainWord(w kit.Word) bool {

	switch w.GetWordType() {
	case TChainWord | TArrayWord | TFuncWord:
		return true
	default:
		return false
	}
}
Example #2
0
File: stack.go Project: mk2/yon
func printWord(depth int, w kit.Word) {

	switch w.GetWordType() {

	case word.TNumberWord:
		printNumberWord(depth, w.(kit.NumberWord))

	case word.TStringWord:
		printStringWord(depth, w.(kit.StringWord))

	case word.TNameWord:
		printNameWord(depth, w.(kit.NameWord))

	case word.TBoolWord:
		printBoolWord(depth, w.(kit.BoolWord))

	case word.TFuncWord:
		printFuncWord(depth, w.(kit.FuncWord))

	case word.TArrayWord:
		printArrayWord(depth, w.(kit.ArrayWord))
	}
}
Example #3
0
File: interp.go Project: mk2/yon
func (ip *interp) run(words kit.WordScanner) {

	m := ip.memo

	var (
		w   kit.Word
		err error
	)

	kit.Println("start RUN_LOOP")

RUN_LOOP:
	for {

		if w, err = words.ReadWord(); err != nil {
			ip.errorCh <- err
			break RUN_LOOP
		}

		kit.Printf("word: %+v", w)

		switch w.GetWordType() {

		case word.TNumberWord:
			kit.Println("number word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TStringWord:
			kit.Println("string word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TBoolWord:
			kit.Println("bool word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TArrayWord:
			kit.Println("array word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TFuncWord:
			kit.Println("func word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TNilWord:
			kit.Println("nil word")
			break RUN_LOOP

		default:
			kit.Printf("unknown word: %+v\n", w)
			ip.errorCh <- errors.New("unknown word")
			break RUN_LOOP

		}

	}

	kit.Println("exit RUN_LOOP")

	ip.stoppedCh <- struct{}{}
}