Skip to content

Commit

Permalink
Merge pull request #36 from adrpo/Fixes20191115
Browse files Browse the repository at this point in the history
implement more of the MM runtime
  • Loading branch information
JKRT committed Jan 29, 2020
2 parents 492789d + b267174 commit 3d9eed6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 58 deletions.
6 changes: 5 additions & 1 deletion src/matchcontinue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ function handle_match_case(value, case, tail, asserts, matchcontinue::Bool)
# showerror(stderr, e, catch_backtrace())
#end
if !isa(e, MetaModelicaException) && !isa(e, ImmutableListException)
showerror(stderr, e, catch_backtrace())
if isa(e, MatchFailure)
println("MatchFailure:" + e.msg)
else
showerror(stderr, e, catch_backtrace())
end
rethrow(e)
end
__omc_match_done = false
Expand Down
100 changes: 43 additions & 57 deletions src/metaRuntime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,52 +165,43 @@ end

""" Returns bitwise inverted Integer number of i """
function intBitNot(i::ModelicaInteger)::ModelicaInteger
local o::ModelicaInteger
#= Defined in the runtime =#
local o::ModelicaInteger = ~i
o
end

""" Returns bitwise \'and\' of Integers i1 and i2 """
function intBitAnd(i1::ModelicaInteger, i2::ModelicaInteger)::ModelicaInteger
local o::ModelicaInteger
#= Defined in the runtime =#
local o::ModelicaInteger = i1 & i2
o
end

""" Returns bitwise 'or' of Integers i1 and i2 """
function intBitOr(i1::ModelicaInteger, i2::ModelicaInteger)::ModelicaInteger
local o::ModelicaInteger
#= Defined in the runtime =#
local o::ModelicaInteger = i1 | i2
o
end

""" Returns bitwise 'xor' of Integers i1 and i2 """
function intBitXor(i1::ModelicaInteger, i2::ModelicaInteger)::ModelicaInteger
local o::ModelicaInteger

#= Defined in the runtime =#
local o::ModelicaInteger = i1 i2
o
end

""" Returns bitwise left shift of Integer i by s bits """
function intBitLShift(i::ModelicaInteger, s::ModelicaInteger)::ModelicaInteger
local o::ModelicaInteger

#= Defined in the runtime =#
local o::ModelicaInteger = i << i
o
end

""" Returns bitwise right shift of Integer i by s bits """
function intBitRShift(i::ModelicaInteger, s::ModelicaInteger)::ModelicaInteger
local o::ModelicaInteger

#= Defined in the runtime =#
local o::ModelicaInteger = i >> s
o
end

""" Converts Integer to Real """
function intReal(i::ModelicaInteger)::ModelicaReal
float(i)
Float64(i)
end

""" Converts Integer to String """
Expand Down Expand Up @@ -325,40 +316,33 @@ function realString(r::ModelicaReal)::String
end

function stringCharInt(ch::String)::ModelicaInteger
local i::ModelicaInteger

#= Defined in the runtime =#
local i::ModelicaInteger = Int64(char(ch[1]))
i
end

function intStringChar(i::ModelicaInteger)::String
local ch::String

#= Defined in the runtime =#
local ch::String = string(char(i))
ch
end

function stringInt(str::String)::ModelicaInteger
local i::ModelicaInteger

#= Defined in the runtime =#
local i::ModelicaInteger = Int64(str)
i
end

""" This function fails unless the whole string can be consumed by strtod without
setting errno. For more details, see man 3 strtod """
function stringReal(str::String)::ModelicaReal
local r::ModelicaReal

#= Defined in the runtime =#
local r::ModelicaReal = Float64(str)
r
end

""" O(str) """
function stringListStringChar(str::String)::List{String}
local chars::List{String}

#= Defined in the runtime =#
local chars::List{String} = nil
for i in length(chars):-1:1
chars = _cons(string(str[i]), chars)
end
chars
end

Expand Down Expand Up @@ -418,17 +402,14 @@ end

""" O(1) """
function stringGetStringChar(str::String, index::ModelicaInteger)::String
local ch::String

#= Defined in the runtime =#
local ch::String = string(str[index])
ch
end

""" O(n) """
function stringUpdateStringChar(str::String, newch::String, index::ModelicaInteger)::String
local news::String

#= Defined in the runtime =#
local news::String = str
news[index] = newch[1]
news
end

Expand Down Expand Up @@ -617,16 +598,20 @@ end
boxed values. The number of bits reserved for the constructor is generally
between 6 and 8 bits. """
function valueConstructor(value::A)::ModelicaInteger where {A}
local ctor::ModelicaInteger
#= Defined in the runtime =#
# hack! hack! hack!
local ctor::ModelicaInteger = myhash(string(typeof(value)))
ctor
end

""" The number of slots a boxed value has. This is dependent on sizeof(void*)
on the architecture in question. """
function valueSlots(value::A)::ModelicaInteger where {A}
local slots::ModelicaInteger
#= Defined in the runtime =#
local slots::ModelicaInteger = 0
try
slots = nfields(value)
catch ex
# do nothing
end
slots
end

Expand All @@ -642,14 +627,19 @@ end

""" a1 > a2? """
function valueCompare(a1::A, a2::A)::ModelicaInteger where {A}
local i #= -1, 0, 1 =#::ModelicaInteger
@assert (false)
#= Defined in the runtime =#
local i::ModelicaInteger =
if valueConstructor(a1) < valueConstructor(a2)
-1
elseif valueConstructor(a1) > valueConstructor(a2)
1
else
0
end
i #= -1, 0, 1 =#
end

function valueHashMod(value::A, mod::ModelicaInteger)::ModelicaInteger where {A}
local h::ModelicaInteger = mod(ModelicaInteger(myhash(value)), m)
local h::ModelicaInteger = mod(ModelicaInteger(myhash(string(value))), m)
h
end

Expand All @@ -663,16 +653,14 @@ end
be used for debugging. """
function referencePointerString(ref::A)::String where {A}
local str::String

#= Defined in the runtime =#
@assert false "not implemented"
str
end

""" Use the diff to compare two time samples to each other. Not very accurate. """
function clock()::ModelicaReal
local t::ModelicaReal

#= Defined in the runtime =#
@assert false "not implemented"
t
end

Expand All @@ -688,15 +676,15 @@ end

function listStringCharString(strs::List{String})::String
local str::String

#= Defined in the runtime =#
@assert false "not implemented"
str
end

function stringCharListString(strs::List{String})::String
local str::String

#= Defined in the runtime =#
local str::String = ""
for s in strs
str = str + s
end
str
end

Expand All @@ -714,15 +702,13 @@ end

function referenceDebugString(functionSymbol::A)::String where {A}
local name::String

#= Defined in the runtime =#
@assert false "not implemented"
name
end

""" TODO: I am far from sure that this will fly.. in Julia. The code generated from the transpiler is correct however"""
function isPresent(ident::T)::Bool where {T}
local b::Bool

b = true
b
end
Expand Down

0 comments on commit 3d9eed6

Please sign in to comment.