diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-11-22 21:41:08 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-11-22 21:41:08 -0500 |
commit | 60dcc7c3c013a2492d8db1b04d28cb437921cced (patch) | |
tree | 0abd57ee7f5fa9a6b9f1b1bc9b305a75ba0b96ef | |
parent | fc650edf6a1ad7b043ccd92495d8e600fd094963 (diff) |
[PARSE] Remove IsBlock
-rw-r--r-- | src/texec/libtnsl.go | 14 | ||||
-rw-r--r-- | src/tparse/token.go | 2 | ||||
-rw-r--r-- | src/tparse/tree-list.go | 6 | ||||
-rw-r--r-- | src/tparse/tree-preproc.go | 8 | ||||
-rw-r--r-- | src/tparse/tree-statement.go | 5 | ||||
-rw-r--r-- | src/tparse/tree-value.go | 14 |
6 files changed, 25 insertions, 24 deletions
diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index bff8d48..000af7d 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -46,6 +46,8 @@ var ( tFile = TType{Pre: []string{}, T: TArtifact{Path: []string{"tnsl", "io"}, Name: "File"}, Post: []string{}} tString = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: []string{}} tInt = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"int"}, Post: []string{}} + tByte = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: []string{}} + tByteArray = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: []string{}} tFloat = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"float"}, Post: []string{}} tCharp = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: []string{}} tNull = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name: "null"}, Post: []string{}} @@ -143,10 +145,14 @@ func tfile_read(file TVariable) TVariable { // tnsl.io.File.write func tfile_write(file, in TVariable) { - b := []byte{0} - if equateType(file.Type, tFile) && (equateType(in.Type, tCharp) || equateType(in.Type, tInt)) { - b[0] = (in.Data).(byte) - (file.Data).(*os.File).Write(b) + if equateType(file.Type, tFile) { + if equateType(in.Type, tCharp) || equateType(in.Type, tByte) { + b := []byte{0} + b[0] = (in.Data).(byte) + (file.Data).(*os.File).Write(b) + } else if equateType(in.Type, tByteArray) { + (file.Data).(*os.File).Write((in.Data).([]byte)) + } } else { (file.Data).(*os.File).Close() panic(fmt.Sprintf("Failed to write to file, attempted to use unsupported type (%v)\n", in.Type)) diff --git a/src/tparse/token.go b/src/tparse/token.go index b358568..620dab2 100644 --- a/src/tparse/token.go +++ b/src/tparse/token.go @@ -28,8 +28,6 @@ type Token struct { type Node struct { Data Token - IsBlock bool - Sub []Node } diff --git a/src/tparse/tree-list.go b/src/tparse/tree-list.go index d415594..3acc426 100644 --- a/src/tparse/tree-list.go +++ b/src/tparse/tree-list.go @@ -31,7 +31,7 @@ func getClosing(start string) string { // Parse a list of values func parseValueList(tokens *[]Token, tok, max int) (Node, int) { - out := Node{Data: Token{Type: 10, Data: "vlist"}, IsBlock: false} + out := Node{Data: Token{Type: 10, Data: "vlist"}} var tmp Node for ; tok < max; { @@ -56,7 +56,7 @@ func parseValueList(tokens *[]Token, tok, max int) (Node, int) { // Parse list of parameters func parseParamList(tokens *[]Token, tok, max int) (Node, int) { - out := Node{Data: Token{Type: 10, Data: "plist"}, IsBlock: false} + out := Node{Data: Token{Type: 10, Data: "plist"}} var tmp Node if isTypeThenValue(tokens, tok, max) { @@ -95,7 +95,7 @@ func parseParamList(tokens *[]Token, tok, max int) (Node, int) { // Parse a list of types func parseTypeList(tokens *[]Token, tok, max int) (Node, int) { - out := Node{Data: Token{Type: 10, Data: "tlist"}, IsBlock: false} + out := Node{Data: Token{Type: 10, Data: "tlist"}} var tmp Node for ; tok < max; { diff --git a/src/tparse/tree-preproc.go b/src/tparse/tree-preproc.go index 8fec30c..2e56705 100644 --- a/src/tparse/tree-preproc.go +++ b/src/tparse/tree-preproc.go @@ -17,7 +17,7 @@ package tparse func parsePreBlock (tokens *[]Token, tok, max int) (Node, int) { - out := Node{IsBlock: true} + out := Node{} out.Data = Token{Type: 11, Data: (*tokens)[tok].Data} tok++ @@ -29,7 +29,7 @@ func parsePreBlock (tokens *[]Token, tok, max int) (Node, int) { break } - tmp := Node{Data: t, IsBlock: false} + tmp := Node{Data: t} out.Sub = append(out.Sub, tmp) } @@ -37,12 +37,12 @@ func parsePreBlock (tokens *[]Token, tok, max int) (Node, int) { } func parsePre (tokens *[]Token, tok, max int) (Node, int) { - out := Node{IsBlock: false} + out := Node{} out.Data = Token{Type: 11, Data: (*tokens)[tok].Data} tok++ - tmp := Node{Data: (*tokens)[tok], IsBlock: false} + tmp := Node{Data: (*tokens)[tok]} out.Sub = append(out.Sub, tmp) tok++ diff --git a/src/tparse/tree-statement.go b/src/tparse/tree-statement.go index ec6230c..25ddab6 100644 --- a/src/tparse/tree-statement.go +++ b/src/tparse/tree-statement.go @@ -20,7 +20,6 @@ package tparse func parseBlock(tokens *[]Token, tok, max int) (Node, int) { out, tmp, def, name, sparse := Node{}, Node{}, Node{}, false, false out.Data = Token{Type: 10, Data: "block"} - out.IsBlock = true def.Data = Token{Type: 10, Data: "bdef"} @@ -90,7 +89,7 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) { if (*tokens)[tok+1].Type != DEFWORD && !name { errOut("You must provide a name for a module or method.", t) } else if !name { - tmp.Sub = append(tmp.Sub, Node{(*tokens)[tok+1], false, []Node{}}) + tmp.Sub = append(tmp.Sub, Node{(*tokens)[tok+1], []Node{}}) tok++ } tmp.Data = t @@ -172,9 +171,7 @@ func parseStatement(tokens *[]Token, tok, max int) (Node, int) { func keywordStatement(tokens *[]Token, tok, max int) (Node, int) { out := Node{} out.Data = (*tokens)[tok] - out.IsBlock = false var tmp Node - tmp.IsBlock = false if tok + 1 < max { tok++ diff --git a/src/tparse/tree-value.go b/src/tparse/tree-value.go index 330194d..609e9d7 100644 --- a/src/tparse/tree-value.go +++ b/src/tparse/tree-value.go @@ -108,7 +108,7 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { if vnode != &out { errOut("Composite values may not use unary operators.", out.Data) } - (*vnode) = Node{Token{10, "comp", 0, 0}, false, []Node{Node{}}} + (*vnode) = Node{Token{10, "comp", 0, 0}, []Node{Node{}}} (*vnode).Sub[0], tok = parseValueList(tokens, tok + 1, max) val = true comp = true @@ -123,7 +123,7 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { if !prs { errOut("Parser bug! Operator failed to load into AST.", t) } else { - (*vnode) = Node{t, false, []Node{Node{}}} + (*vnode) = Node{t, []Node{Node{}}} vnode = &((*vnode).Sub[0]) } default: @@ -181,7 +181,7 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { // Works? Please test. func parseBinaryOp(tokens *[]Token, tok, max int) (Node) { - out := Node{IsBlock: false} + out := Node{} first := tok var high, highOrder, bincount int = first, 0, 0 var curl, brak, parn int = 0, 0, 0 @@ -327,12 +327,12 @@ func parseValue(tokens *[]Token, tok, max int) (Node, int) { // Works? Please test. func parseTypeParams(tokens *[]Token, tok, max int) (Node, int) { - out := Node{Data: (*tokens)[tok], IsBlock: false} + out := Node{Data: (*tokens)[tok]} tok++ for ; tok < max; tok++{ t := (*tokens)[tok] - tmp := Node{IsBlock: false} + tmp := Node{} switch t.Type { case DELIMIT: if tok < max { @@ -368,7 +368,7 @@ func parseTypeParams(tokens *[]Token, tok, max int) (Node, int) { // TODO: make sure this actually works func parseType(tokens *[]Token, tok, max int, param bool) (Node, int) { - out := Node{Data: Token{Type: 10, Data: "type"}, IsBlock: false} + out := Node{Data: Token{Type: 10, Data: "type"}} for ; tok < max; tok++ { t := (*tokens)[tok] @@ -392,7 +392,7 @@ func parseType(tokens *[]Token, tok, max int, param bool) (Node, int) { out.Sub = append(out.Sub, tmp) if param && (*tokens)[tok].Data == "`" { - tmp = Node{(*tokens)[tok], false, []Node{}} + tmp = Node{(*tokens)[tok], []Node{}} out.Sub = append(out.Sub, tmp) tok++ } |