Example #1
0
def simulator_evaluate(expression):
    alto_source = Transcoder.to_alto("doIt [^[" + expression + "]]")
    object_cls = Runtime.Smalltalk._ref(UniqueString._for("Object"))
    method_tuple = Compiler().compileIn(ByteString(alto_source), object_cls)
    method = method_tuple._ref(Integer(2))
    result = Simulator(Context(None, None, object_cls, method)).run()
    print(expression, "=>", result)
def test_transcoder01():
    with open('evaluation.json') as json_file:
        json_data = json.load(json_file)
    for each in json_data:
        source = each['source']
        alto_source = each['alto_source']
        transcoded_source = Transcoder.to_alto("doIt [^[" + source + "]]")
        assert transcoded_source == alto_source
Example #3
0
def simulator_jevaluate(source, evaluation_list):
    evaluation_dictionary = {}
    evaluation_list.append(evaluation_dictionary)
    evaluation_dictionary['source'] = source
    alto_source = Transcoder.to_alto("doIt [^[" + source + "]]")
    evaluation_dictionary['alto_source'] = alto_source
    evaluation_dictionary['lexem'] = ([
        each if isinstance(each, int) else each.toString()
        for each in ByteString(alto_source).asVector().elements()
    ])
    object_cls = Runtime.Smalltalk._ref(UniqueString._for("Object"))
    method_tuple = Compiler().compileIn(ByteString(alto_source), object_cls)
    evaluation_dictionary['selector'] = method_tuple._ref(
        Integer(1)).toString()
    evaluation_dictionary['codes '] = str(
        EscapeAll(bytes(method_tuple._ref(Integer(2)).codes().fBytes)))
    method = method_tuple._ref(Integer(2))
    return Simulator(JContext().set(None, Obj.NIL, object_cls, method)).run()