Case Lang Evaluation Template

This document serves as an evaluation template for OO languages. The described language "jam" is a fictional one.

Requirements

  • Each module implements a specialized Talker, which inherits from Talker
  • Each module should be executable by it's own (should contain entry/test code)
  • Each module should be importable (e.g. interactive shell, code)

Language

  • jam
  • www.jam-fictional-website.org

Installation

  • No Prerequisites
  • www.jam-fictional-website.org/install

Project Setup

  • create a folder "jam"
  • create a file "Talker.*"

Simple Class

# within file "Talker"

define a class "Talker"

class Talker
  method sayHello
    print "Hello world"

define main method:

john = Talker.new()
john.sayHello()

Execution

  • Run from Command Line
    $ jam Talker
    
  • Run within an Interactive Environment
$ jam  [opens interactive shell]
jam> import 'Talker'
jam> john = Talker.new()
jam> john.sayHello 

Simple Variable Access

create 2 variables "name" and "age"

class TalkerVar inherits Talker
  string name
  int age 

  method sayYourName():
    print "my name is #{name}" 

  method sayYourAge():
    print "and I am #{age} minutes old" 

  method talk()
    Talker.sayHello()
    sayYourName()
    sayYourAge()

Main Function

method main(args)
  john = TalkerVar.new()
  john.name = "John" 

  john.talk()

Simple Reflective Data Access

class TalkerReflectSimple inherits Talker
    method sayYourClassName()  // prints "TalkerReflectA"
        print "My class name is #{self.class.name}"

    method talk()
        john.super(Talker).talk()
        sayYourClassName()

Main Function

method main(args)
  john = TalkerReflectSimple.new()
  john.name = "John"
  john.talk() 

Advanced Reflective Data Access

class TalkerReflectAdvanced inherits Talker
    method thisMethodName 
        return self.method[1].name
        // [Returns name of method this was called from] 

    sayHelloAdvanced 
        print "Hello World" + thisMethodName()
        # simpler way:
        # print "Hello World" + self.method.name

method main(args)
    john = TalkerReflectAdvanced.new()
    john.name = "John"
    john.talk() 

Expert Reflective Data Access

class TalkerReflectExpert inherits Talker
    method sayYourClassDefinition 
    # prints Class Definition (methods, fields)]
    # recreates the whole class-definition
    # whilst using the object-model of the language (e.g. metaclasses)
    # does not include the method-bodies (source code)

provide alternative methods (e.g. file based), if
access to object model not available or limited.

output should be formated 

    method sayYourClassCode 
    # [prints Class Definition, including recreated Source Code]  
    # same as above, but recreates source-code, too
    # uses the object-model (MetaClasses) and the AST

alternatively provide e.g. file-based mechanism 

    method sayYourInstanceVarName 
    #[prints 'john' via reflection]
        print self.InstanceVarName # build in function

extend talker-code john.sayYourClassDefinition john.sayYourClassCode john.sayYourInstanceVarName

Metadata

task: change the object model on the fly.

Apply Metadata to any Object (Classes, Object Intances, Variables, Methods)

Or: annotate the entities

# ruby example

class Object

def meta # adds attribute "meta" to all objects

end

extend talker-code Talker.meta = "Class meta information" john.meta = "Instance meta information" 1234.meta = 'any Instance meta information"

puts Talker.meta puts john.meta puts 1234.meta # an integer object


Code Generator

Generate Cpp? - Implements a C++ Code Generator Reuse / Complement the above code to create an

C++ Code Generator.

Requirements:

  • - This can be limited to a few code-constructs (e.g. if-then)
  • - Low effort to add new code-constructs
  • - Not all constructs of the language must be transformable to C++
  • - less code as possible

Output files:

  • - C++ header file
  • - C++ source-code file

extend talker-code john.Generate Cpp?("filename")