Skip to content

Commit

Permalink
add and export StringFunction, check for array index
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Feb 11, 2020
1 parent e5d9f22 commit 57dc536
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/dangerous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ using ..MetaModelica

""" O(1) """
function arrayGetNoBoundsChecking(arr::Array{A}, index::ModelicaInteger)::A where {A <: Any}
if index < 0
println("arrayGetNoBoundsChecking: index < 0!")
end
@inbounds arr[index]
end

""" O(1) """
function arrayUpdateNoBoundsChecking(arr::Array{A}, index::ModelicaInteger, newValue::A)::Array{A} where {A <: Any}
local newArray::Array{A} = arr
if index < 0
println("arrayUpdateNoBoundsChecking: index < 0!")
end
@inbounds newArray[index] = newValue
newArray
end
Expand All @@ -33,6 +39,9 @@ end
""" O(1) """
function stringGetNoBoundsChecking(str::String, index::ModelicaInteger)::ModelicaInteger
local ch::ModelicaInteger
if index < 0
println("stringGetNoBoundsChecking: index < 0!")
end
ch = @inbounds str[index]
end

Expand Down
2 changes: 2 additions & 0 deletions src/exportmetaRuntime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export arrayGet
export arrayLength
export arrayList
export arrayUpdate
export boolNot
export boolAnd
export boolEq
export boolOr
Expand Down Expand Up @@ -114,3 +115,4 @@ export valueHashMod
export valueSlots
export _listAppend
export getInstanceName
export StringFunction
40 changes: 36 additions & 4 deletions src/metaRuntime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,30 @@ end

""" O(1) """
function stringGet(str::String, index::ModelicaInteger)::ModelicaInteger
if index < 0
println("stringGet: index < 0!")
fail()
end
str[index]
end

""" O(1) """
function stringGetStringChar(str::String, index::ModelicaInteger)::String
if index < 0
println("stringGetStringChar: index < 0!")
fail()
end
local ch::String = string(str[index])
ch
end

""" O(n) """
function stringUpdateStringChar(str::String, newch::String, index::ModelicaInteger)::String
local news::String = str
if index < 0
println("stringUpdateStringChar: index < 0!")
fail()
end
news[index] = newch[1]
news
end
Expand Down Expand Up @@ -467,6 +479,10 @@ function stringHashSdbm(str::String)::ModelicaInteger
end

function substring(str::String, start #=start index, first character is 1 =#::ModelicaInteger, stop #= stop index, first character is 1 =#::ModelicaInteger)::String
if start < 0
println("substring: start < 0!")
fail()
end
local out = str[start:stop]
out
end
Expand All @@ -483,6 +499,10 @@ end

""" O(1) """
function arrayGet(arr::Array{A}, index::ModelicaInteger)::A where {A}
if index < 0
println("arrayGet: index < 0!")
fail()
end
arr[index]
end

Expand Down Expand Up @@ -512,10 +532,14 @@ end
""" O(1) """
function arrayUpdate(arr::Array{A}, index::ModelicaInteger, newValue::B)::Array{A} where {A,B}
local newArray #= same as the input array; used for folding =#::Array{A} = arr
if !(A <: B)
println("!(A<:B)")
@show A
@show B
#if !(A <: B)
# println("!(A<:B)")
# @show A
# @show B
#end
if index < 0
println("arrayUpdate: index < 0!")
fail()
end
newArray[index] = newValue
#= Defined in the runtime =#
Expand Down Expand Up @@ -755,3 +779,11 @@ end
function getInstanceName()::String
"__NOT_IMPLEMENTED__"
end

function StringFunction(i::Int64)::String
intString(i)
end

function StringFunction(r::Float64)::String
realString(r)
end

0 comments on commit 57dc536

Please sign in to comment.