Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type check for vm #2046

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions packages/migration/clb/clb_data_contracts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/migration/contracts/first_ecosystem/Import.sim
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ contract Import {
if app_map {
var app_id int ival string
ival = Str(app_map["value.app_name"])
app_id = DBFind("@1applications").Columns("id").Where({"name": ival, "ecosystem": $ecosystem_id}).One("id")
app_id = Int(DBFind("@1applications").Columns("id").Where({"name": ival, "ecosystem": $ecosystem_id}).One("id"))
if app_id {
$ApplicationId = Int(app_id)
$ApplicationId = app_id
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions packages/migration/contracts/first_ecosystem/ImportUpload.sim
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ contract ImportUpload {
Data file
}
conditions {
$Data = BytesToString($Data["Body"])
$Body = BytesToString($Data["Body"])
$limit = 10 // data piece size of import
}
action {
// init buffer_data, cleaning old buffer
var initJson map
$import_id = DBFind("@1buffer_data").Where({"account": $account_id, "key": "import", "ecosystem": $ecosystem_id}).One("id")
$import_id = Int(DBFind("@1buffer_data").Where({"account": $account_id, "key": "import", "ecosystem": $ecosystem_id}).One("id"))
if $import_id {
$import_id = Int($import_id)
DBUpdate("@1buffer_data", $import_id, {"value": initJson})
DBUpdate("@1buffer_data", $import_id, {"value": initJson})
} else {
$import_id = DBInsert("@1buffer_data", {"account": $account_id, "key": "import", "value": initJson, "ecosystem": $ecosystem_id})
}
$info_id = DBFind("@1buffer_data").Where({"account": $account_id, "key": "import_info", "ecosystem": $ecosystem_id}).One("id")
$info_id = Int(DBFind("@1buffer_data").Where({"account": $account_id, "key": "import_info", "ecosystem": $ecosystem_id}).One("id"))
if $info_id {
$info_id = Int($info_id)
DBUpdate("@1buffer_data", $info_id, {"value": initJson})
} else {
$info_id = DBInsert("@1buffer_data", {"account": $account_id, "key": "import_info", "value": initJson, "ecosystem": $ecosystem_id})
}
var input map arrData array
input = JSONDecode($Data)
input = JSONDecode($Body)
arrData = input["data"]
var pages_arr blocks_arr menu_arr parameters_arr languages_arr contracts_arr tables_arr array
// IMPORT INFO
Expand Down
2 changes: 1 addition & 1 deletion packages/migration/contracts_data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions packages/migration/first_ecosys_contracts_data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 18 additions & 17 deletions packages/script/code_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,27 @@ type ObjInfo struct {
// Types that are valid to be assigned to Value:
// *CodeBlock
// *ExtFuncInfo
// *ObjInfo_IndexOfVars
// *ObjInfo_ExtVarName
// *ObjInfo_Variable
// *ObjInfo_ExtendVariable
Value isObjInfoValue
}

type isObjInfoValue interface {
isObjInfoValue()
}
type ObjInfo_IndexOfVars struct {
type ObjInfo_Variable struct {
Name string
Index int
}
type ObjInfo_ExtVarName struct {
//object variable name
type ObjInfo_ExtendVariable struct {
//object extend variable name
Name string
}

func (*CodeBlock) isObjInfoValue() {}
func (*ExtFuncInfo) isObjInfoValue() {}
func (*ObjInfo_IndexOfVars) isObjInfoValue() {}
func (*ObjInfo_ExtVarName) isObjInfoValue() {}
func (*CodeBlock) isObjInfoValue() {}
func (*ExtFuncInfo) isObjInfoValue() {}
func (*ObjInfo_Variable) isObjInfoValue() {}
func (*ObjInfo_ExtendVariable) isObjInfoValue() {}

func (m *ObjInfo) GetValue() isObjInfoValue {
if m != nil {
Expand All @@ -171,18 +172,18 @@ func (m *ObjInfo) GetExtFuncInfo() *ExtFuncInfo {
return nil
}

func (m *ObjInfo) GetIndex() int {
if x, ok := m.GetValue().(*ObjInfo_IndexOfVars); ok {
return x.Index
func (m *ObjInfo) GetVariable() *ObjInfo_Variable {
if x, ok := m.GetValue().(*ObjInfo_Variable); ok {
return x
}
return 0
return nil
}

func (m *ObjInfo) GetName() string {
if x, ok := m.GetValue().(*ObjInfo_ExtVarName); ok {
return x.Name
func (m *ObjInfo) GetExtendVariable() *ObjInfo_ExtendVariable {
if x, ok := m.GetValue().(*ObjInfo_ExtendVariable); ok {
return x
}
return ""
return nil
}

func NewCodeBlock() *CodeBlock {
Expand Down
2 changes: 1 addition & 1 deletion packages/script/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ main:
logger.WithFields(log.Fields{"lex_value": lexeme.Value, "type": consts.ParseError}).Error("unknown variable")
return fmt.Errorf(`unknown variable %s`, lexeme.Value.(string))
}
buffer.push(newByteCode(cmdIndex, lexeme.Line, &IndexInfo{VarOffset: objInfo.GetIndex(), Owner: tobj}))
buffer.push(newByteCode(cmdIndex, lexeme.Line, &IndexInfo{VarOffset: objInfo.GetVariable().Index, Owner: tobj}))
}
}
if !call {
Expand Down
7 changes: 4 additions & 3 deletions packages/script/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ func ExecContract(rt *RunTime, name, txs string, params ...any) (any, error) {
}
rt.extend[Extend_parent] = prevparent
rt.extend[Extend_this_contract] = prevthis

result := rt.extend[Extend_result]
for key := range rt.extend {
if isSysVar(key) {
continue
Expand All @@ -171,7 +169,10 @@ func ExecContract(rt *RunTime, name, txs string, params ...any) (any, error) {
for key, item := range prevExtend {
rt.extend[key] = item
}

result, ok := rt.extend[Extend_result]
if !ok {
return "", nil
}
return result, nil
}

Expand Down
6 changes: 3 additions & 3 deletions packages/script/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func fNameBlock(buf *CodeBlocks, state stateTypes, lexeme *Lexeme) error {
Owner: (*buf)[0].Owner}
default:
itype = ObjectType_Func
fblock.Info = &FuncInfo{}
fblock.Info = &FuncInfo{Name: name}
}
fblock.Type = itype
if _, ok := prev.Objects[name]; ok {
Expand Down Expand Up @@ -177,7 +177,7 @@ func fFparam(buf *CodeBlocks, state stateTypes, lexeme *Lexeme) error {
return fmt.Errorf("'%s' redeclared in this code block", lexeme.Value.(string))
}
}
block.Objects[lexeme.Value.(string)] = &ObjInfo{Type: ObjectType_Var, Value: &ObjInfo_IndexOfVars{Index: len(block.Vars)}}
block.Objects[lexeme.Value.(string)] = &ObjInfo{Type: ObjectType_Var, Value: &ObjInfo_Variable{Name: lexeme.Value.(string), Index: len(block.Vars)}}
block.Vars = append(block.Vars, reflect.TypeOf(nil))
return nil
}
Expand Down Expand Up @@ -306,7 +306,7 @@ func fAssignVar(buf *CodeBlocks, state stateTypes, lexeme *Lexeme) error {
lexeme.GetLogger().WithFields(log.Fields{"type": consts.ParseError, "lex_value": lexeme.Value}).Error("modifying system variable")
return fmt.Errorf(eSysVar, lexeme.Value.(string))
}
ivar = VarInfo{Obj: &ObjInfo{Type: ObjectType_ExtVar, Value: &ObjInfo_ExtVarName{Name: lexeme.Value.(string)}}, Owner: nil}
ivar = VarInfo{Obj: &ObjInfo{Type: ObjectType_ExtVar, Value: &ObjInfo_ExtendVariable{Name: lexeme.Value.(string)}}, Owner: nil}
} else {
objInfo, tobj := findVar(lexeme.Value.(string), buf)
if objInfo == nil || objInfo.Type != ObjectType_Var {
Expand Down
2 changes: 1 addition & 1 deletion packages/script/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type typeInfo struct {
}

var (
// The list of key words
// The list of keywords
keywords = map[string]uint32{
`contract`: keyContract,
`func`: keyFunc,
Expand Down
Loading