revert Core language, remove Ant lib, remove maven, update build.xml

This commit is contained in:
User 2019-02-07 02:09:36 +01:00
parent 8c65fe71cf
commit 846df01b11
14 changed files with 15 additions and 871 deletions

View File

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/antlr-4.7-complete.jar" sourcepath="lib/antlr-4.7-source.zip">
<attributes>
<attribute name="javadoc_location" value="http://www.antlr.org/api/Java/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/hamcrest-all-1.3.jar">
<attributes>
<attribute name="javadoc_location" value="http://hamcrest.org/JavaHamcrest/javadoc/1.3/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/junit-4.12.jar">
<attributes>
<attribute name="javadoc_location" value="http://junit.org/junit4/javadoc/4.12/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/commons-lang3-3.5.jar">
<attributes>
<attribute name="javadoc_location" value="https://commons.apache.org/proper/commons-lang/javadocs/api-3.5/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/commons-cli-1.4.jar">
<attributes>
<attribute name="javadoc_location" value="http://commons.apache.org/proper/commons-cli/javadocs/api-release/"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>boppi2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." name="boppi2"> <project basedir="." name="boppi">
<property environment="env" /> <property environment="env" />
<property name="junit.output.dir" value="doc/junit" /> <property name="junit.output.dir" value="doc/junit" />
<property name="g4.iloc" value="src/pp/iloc/parse" /> <property name="g4.iloc" value="src/pp/iloc/parse" />
@ -71,7 +71,7 @@
</target> </target>
<target name="do-junit"> <target name="do-junit">
<junit fork="yes" dir="src" printsummary="withOutAndErr"> <junit fork="yes" dir="src" showoutput="false" printsummary="withOutAndErr">
<formatter type="xml" /> <formatter type="xml" />
<batchtest todir="${junit.output.dir}"> <batchtest todir="${junit.output.dir}">
<fileset dir="src"> <fileset dir="src">
@ -89,7 +89,9 @@
<fileset dir="${junit.output.dir}"> <fileset dir="${junit.output.dir}">
<include name="TEST-*.xml" /> <include name="TEST-*.xml" />
</fileset> </fileset>
<report format="frames" todir="${junit.output.dir}" /> <report format="frames" todir="${junit.output.dir}">
<param name="TITLE" expression="Boppi test report. See 'System.out' per test case for source listings, ILOC listings and compiler messages."/>
</report>
</junitreport> </junitreport>
</target> </target>
@ -99,32 +101,20 @@
<pathelement location="lib/antlr-4.7-complete.jar" /> <pathelement location="lib/antlr-4.7-complete.jar" />
</classpath> </classpath>
<arg value="${g4.boppi}/Boppi.g4" /> <arg value="${g4.boppi}/Boppi.g4" />
<arg value="-o" /> <!-- <arg value="-o" />
<arg value="${g4.boppi}" /> <arg value="${g4.boppi}" /> -->
<arg value="-package" /> <arg value="-package" />
<arg value="pp.s1184725.boppi.antlr" /> <arg value="pp.s1184725.boppi.antlr" />
<arg value="-no-listener" /> <arg value="-no-listener" />
<arg value="-visitor" /> <arg value="-visitor" />
</java> </java>
<java classname="org.antlr.v4.Tool">
<classpath>
<pathelement location="lib/antlr-4.7-complete.jar" />
</classpath>
<arg value="${g4.boppi}/BoppiCore.g4" />
<arg value="-o" />
<arg value="${g4.boppi}" />
<arg value="-package" />
<arg value="pp.s1184725.boppi.antlr" />
<arg value="-listener" />
<arg value="-no-visitor" />
</java>
<java classname="org.antlr.v4.Tool"> <java classname="org.antlr.v4.Tool">
<classpath> <classpath>
<pathelement location="lib/antlr-4.7-complete.jar" /> <pathelement location="lib/antlr-4.7-complete.jar" />
</classpath> </classpath>
<arg value="${g4.iloc}/ILOC.g4" /> <arg value="${g4.iloc}/ILOC.g4" />
<arg value="-o" /> <!-- <arg value="-o" />
<arg value="${g4.iloc}" /> <arg value="${g4.iloc}" /> -->
<arg value="-listener" /> <arg value="-listener" />
<arg value="-no-visitor" /> <arg value="-no-visitor" />
</java> </java>
@ -132,12 +122,14 @@
<target name="do-javadoc"> <target name="do-javadoc">
<javadoc access="public" author="true" classpath="lib/commons-lang3-3.5.jar;lib/commons-cli-1.4.jar;lib/antlr-4.7-complete.jar;lib/junit-4.12.jar;lib/hamcrest-all-1.3.jar" destdir="doc/javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="pp.*" source="1.8" sourcepath="src" splitindex="false" use="true" version="true"> <javadoc access="public" author="true" classpath="lib/commons-lang3-3.5.jar;lib/commons-cli-1.4.jar;lib/antlr-4.7-complete.jar;lib/junit-4.12.jar;lib/hamcrest-all-1.3.jar" destdir="doc/javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="pp.*" source="1.8" sourcepath="src" splitindex="false" use="true" version="true">
<link href="http://www.antlr.org/api/Java/" /> <link href="https://www.antlr.org/api/Java/" />
<link href="http://hamcrest.org/JavaHamcrest/javadoc/1.3/" /> <link href="http://hamcrest.org/JavaHamcrest/javadoc/1.3/" />
<link href="https://docs.oracle.com/javase/8/docs/api/" /> <link href="https://docs.oracle.com/javase/8/docs/api/" />
<link href="http://junit.org/junit4/javadoc/4.12/" /> <link href="https://junit.org/junit4/javadoc/4.12/" />
<link href="https://commons.apache.org/proper/commons-lang/javadocs/api-3.5/" /> <link href="https://commons.apache.org/proper/commons-lang/javadocs/api-3.5/" />
<link href="http://commons.apache.org/proper/commons-cli/javadocs/api-release/" /> <link href="https://commons.apache.org/proper/commons-cli/javadocs/api-release/" />
<arg value="-Xdoclint:none" /> <!-- may disable tons of warnings in ILOC docs -->
<arg value="-html5" />
</javadoc> </javadoc>
</target> </target>

Binary file not shown.

25
pom.xml
View File

@ -1,25 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pp.s1184725.boppi</groupId>
<artifactId>boppi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>boppi</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -13,6 +13,7 @@ import pp.iloc.model.Num;
import pp.iloc.model.Op; import pp.iloc.model.Op;
import pp.iloc.model.OpClaz; import pp.iloc.model.OpClaz;
import pp.iloc.model.OpCode; import pp.iloc.model.OpCode;
import pp.iloc.model.Operand.Type;
import pp.iloc.model.Program; import pp.iloc.model.Program;
import pp.iloc.parse.FormatException; import pp.iloc.parse.FormatException;

View File

@ -1,114 +0,0 @@
package pp.s1184725.boppi;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import pp.s1184725.boppi.antlr.*;
import pp.s1184725.boppi.antlr.BoppiCoreParser.*;
import pp.s1184725.boppi.exception.*;
import pp.s1184725.boppi.type.*;
/**
* This class performs type checking and variable assignment on a bare parse
* tree.
*
* @author Frank Wibbelink
*/
public class BoppiCoreChecker extends BoppiCoreBaseListener {
public static void main(String[] args) {
BoppiCoreLexer lexer = new BoppiCoreLexer(ToolChain.getCharStream(BoppiCoreChecker.class, "test/test2.core"));
BoppiCoreParser parser = new BoppiCoreParser(new CommonTokenStream(lexer));
ParseTree ast = parser.program();
Logger logger = Logger.getLogger("TEST");
Annotations annotations = checkProgram(ast, logger);
System.out.println(ToolChain.getAnnotatedDOT(ast, annotations));
}
private Annotations an;
private Logger log;
/**
* Checks and annotates a program. Problems are reported to the given
* logger.
*
* @param ast
* the program's AST
* @param logger
* the logger object to write warnings and errors to
* @return the generated annotations
*/
public static Annotations checkProgram(ParseTree ast, Logger logger) {
BoppiCoreChecker checker = new BoppiCoreChecker(logger, new Annotations());
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(checker, ast);
return checker.an;
}
protected BoppiCoreChecker(Logger logger, Annotations annotations) {
an = annotations;
log = logger;
}
/**
* Checks whether two types are compatible and log an error if they do not.
*
* @param type1
* the left hand or actual type
* @param type2
* the right hand or desired type
* @param node
* the context used for logging
*/
private void checkConstraint(Type type1, Type type2, ParserRuleContext node) {
if (!type2.equals(type1))
log.severe(getError(node, Messages.getString("BoppiChecker.0"), type1.toString(), type2.toString())); //$NON-NLS-1$
}
/**
* Returns an error message for a given parse tree node.
*
* @param ctx
* the parse tree node at which the error occurred
* @param message
* the error message
* @param args
* arguments for the message, see {@link String#format}
*/
private String getError(ParserRuleContext node, String message, Object... args) {
int line = node.getStart().getLine();
int column = node.getStart().getCharPositionInLine();
return String.format(Messages.getString("BoppiChecker.1"), line, column, String.format(message, args)); //$NON-NLS-1$
}
/**
* Returns whether the current context resides within a given rule context
* within a set root (may be {@code null}). Effectively traverses between
* {@code current} and {@code root} in the parent hierarchy looking for a
* {@code rule} class.
*
* @param <T>
* the rule class
* @param ctx
* the node to start traversing
* @param root
* the node to stop traversing
* @param rule
* the ParserRuleContext class to look for
* @return whether a matching rule is found between the current and root
* node
*/
private <T extends ParserRuleContext> boolean isWithinRule(ParserRuleContext ctx, ParserRuleContext root,
Class<T> rule) {
for (ParserRuleContext node = ctx; node != root && node != null; node = node.getParent())
if (node.getClass().isAssignableFrom(rule))
return true;
return false;
}
}

View File

@ -1,34 +0,0 @@
grammar BoppiCore;
import BoppiCoreTokens;
program: expr EOF;
block: BLOCKOPEN ((data|let) DELIM)+ BLOCKCLOSE;
data: DATA id EQUALS BLOCKOPEN (id DELIM)+ BLOCKCLOSE;
let: LET id EQUALS expr;
id: IDENTIFIER (HASTYPE aexpr)?;
expr
: expr expr #eApp
| LAMBDA id expr #eAbs
| PI id expr #eQuant
| block expr #eDecl
| CASE aexpr BLOCKOPEN (alt DELIM)+ BLOCKCLOSE #eCase
| aexpr #eSimple
;
alt: id TO expr;
aexpr
: id
| literal
| PAROPEN expr PARCLOSE
;
literal
: LITERALINT
| LITERALCHAR
;

View File

@ -1,23 +0,0 @@
lexer grammar BoppiCoreTokens;
DELIM: ';';
HASTYPE: ':';
LAMBDA: '\u03BB';
PI: '\u03A0';
PAROPEN: '(';
PARCLOSE: ')';
DATA: 'data';
LET: 'let';
IN: 'in';
CASE: 'case';
TO: '\u2192';
EQUALS: '=';
BLOCKOPEN: '{';
BLOCKCLOSE: '}';
LITERALINT: '0' | [1-9][0-9]*;
LITERALCHAR: '\'' . '\'';
IDENTIFIER: [\p{Alphabetic}]+ | '_' | '\u2605';
WHITESPACE: [\p{White_Space}] -> skip;
BLOCKCOMMENT: '/*' .*? '*/' -> skip;

View File

@ -1 +0,0 @@
5

View File

@ -1,12 +0,0 @@
{
data Boolean:★ = {
True;
False;
};
data List:(Π _:★ ★) = {
Cons : (Π a:★ Π _:a Π _:(List a) List a);
Nil : (Π a:★ List a);
};
let main = True;
}
main

View File

@ -1,17 +0,0 @@
package pp.s1184725.boppi.type;
/**
* Type-level variable.
*
* @author Frank Wibbelink
*
*/
public class TypeVar implements Type {
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
}

View File

@ -1,532 +0,0 @@
fst_ptr <- 0
slot1 <- 4
header <- 8
off_oref <- -8
off_osize <- -4
off_next <- 0
off_size <- 4
// memlib - simple memory allocator for ILOC
//
// This library maintains a single-linked list (of monotonically increasing addresses) of free
// slots in memory and a reference count for occupied slots. Each slot contains a tuple `(next
// free slot address,size)` followed by `size` free bytes. The memory is initiliased with a
// pointer to the first free slot at `#fst_ptr` and one free slot at `#slot1` of size
// `brk-slot1-header`. When a piece of memory is requested for allocation, a tuple
// `(reference count, size)` followed by `size` bytes for the object is formed. The calling
// convention of the functions in this library consists of pushing the return address followed by
// any arguments (in order) to the stack. Any return values will be pushed to the stack likewise.
//
// Requires a register `brk` for the highest address available for heap allocation.
// Requires an instruction `halt` when memory runs out
//
// @author Frank Wibbelink
// initialise
memlib_: loadI 0 => m_0
loadI @slot1 => m_1
subI brk,@slot1 => m_2
subI m_2,@header => m_2
storeAI m_1 => m_0,@fst_ptr // pointer to first slot
storeAI m_0 => m_1,@off_next // next slot is null
storeAI m_2 => m_1,@off_size // first slot size
jumpI -> ememlib_
// allocate memory
// searches through the free slots for either a slot size of ~~exactly #4+8 or a size of~~ at
// least #4+16
// stack: [return address, object size] -> [object address]
memalloc: loadI 0 => m_0
pop => m_s // load size
loadI @fst_ptr => m_p // load previous address (base pointer)
loadAI m_p,@off_next => m_c // load current address (first slot)
ma_loop: cmp_EQ m_0,m_c => m_1 // check if address pointer is null
cbr m_1 -> ma_null,ma_cont // if null, go to end and return null pointer
ma_cont: loadAI m_c,@off_size => m_1 // load slot size
cmp_EQ m_1,m_s => m_2 // check if request fits exactly
cbr m_2 -> ma_yxct,ma_nxct
ma_nxct: subI m_1,@header => m_1 // subtract free slot size
cmp_GE m_1,m_s => m_1 // check if request fits
cbr m_1 -> ma_found,ma_next
ma_next: i2i m_c => m_p
loadAI m_p,@off_next => m_c
jumpI -> ma_loop
ma_yxct: loadAI m_c,@off_next => m_n // location of next free slot
jumpI -> ma_final
ma_found: addI m_s,@header => m_1
add m_1,m_c => m_n // location of new free slot
loadAI m_c,@off_size => m_1
subI m_1,@header => m_1
sub m_1,m_s => m_1 // size of new free slot
storeAI m_1 => m_n,@off_size
loadAI m_c,@off_next => m_1 // location of next free slot
storeAI m_1 => m_n,@off_next
ma_final: storeAI m_n => m_p,@off_next // link previous free slot to new
addI m_c,@header => m_c // move to object location
loadI 1 => m_1
storeAI m_1 => m_c,@off_oref // set reference count to 1
storeAI m_s => m_c,@off_osize // set object size
ma_zerc: cbr m_s -> ma_zerl,ma_null // zero memory
ma_zerl: subI m_s,1 => m_s
cstoreAO m_0 => m_c,m_s
jumpI -> ma_zerc
ma_null: pop => m_1 // load return address
push m_c // store object address
jump -> m_1
// increase reference count of object
// stack: [return address, object address] -> []
memaddref: loadI 0 => m_0
pop => m_n // load object address
cmp_EQ m_0,m_n => m_1
cbr m_1 -> mr_ynul,mr_nnul // check if null pointer
mr_ynul: haltI 1865445997
mr_nnul: loadAI m_n,@off_oref => m_1
addI m_1,1 => m_1
storeAI m_1 => m_n,@off_oref
pop => m_1 // load return address
jump -> m_1
// decrease reference count of object
// frees memory if count goes to zero
// stack: [return address, object address] -> []
memfree: loadI 0 => m_0
pop => m_n // load object address
cmp_EQ m_0,m_n => m_1
cbr m_1 -> mf_ynul,mf_nnul // check if null pointer
mf_ynul: haltI 1865442925
mf_nnul: loadAI m_n,@off_oref => m_1
subI m_1,1 => m_1
cmp_GT m_1,m_0 => m_2
cbr m_2 -> mf_exit,mf_free
mf_exit: storeAI m_1 => m_n,@off_oref
pop => m_1 // load return address
jump -> m_1
mf_free: subI m_n,@header => m_n
loadI @fst_ptr => m_p
loadAI m_p,@off_next => m_c
mf_loop: cmp_EQ m_0,m_c => m_1 // loop until the surrounding free blocks are found
cbr m_1 -> mf_halt,mf_cont // check if address pointer is null
mf_halt: haltI 1882220141 // halt program; object beyond last free slot (or memory corrupted)
mf_cont: cmp_EQ m_c,m_n => m_1
cbr m_1 -> mf_hal2,mf_con2
mf_hal2: haltI 1717855853 // halt program; object is free slot
mf_con2: cmp_LE m_c,m_n => m_1
cbr m_1 -> mf_next,mf_done
mf_next: i2i m_c => m_p
loadAI m_p,@off_next => m_c
jumpI -> mf_loop
mf_done: loadAI m_p,@off_size => m_1
addI m_1,@header => m_1
add m_1,m_p => m_2
cmp_EQ m_2,m_n => m_2
cbr m_2 -> mf_yprv,mf_nprv
mf_yprv: loadAI m_n,@off_size => m_2 // merge with previous free slot
add m_1,m_2 => m_1 // new size of previous free slot
storeAI m_1 => m_p,@off_size
i2i m_p => m_n
jumpI -> mf_dprv
mf_nprv: storeAI m_n => m_p,@off_next // link previous free slot with new
mf_dprv: loadAI m_n,@off_size => m_1
addI m_1,@header => m_1
add m_1,m_n => m_2
cmp_EQ m_2,m_c => m_2
cbr m_2 -> mf_ynxt,mf_nnxt
mf_ynxt: loadAI m_c,@off_size => m_2 // merge with next free slot
add m_1,m_2 => m_1 // new size of next free slot
storeAI m_1 => m_n,@off_size
loadAI m_c,@off_next => m_1
storeAI m_1 => m_n,@off_next // move link of next's next to new free slot
pop => m_1 // load return address
jump -> m_1
mf_nnxt: storeAI m_c => m_n,@off_next // link new free slot with next
pop => m_1 // load return address
jump -> m_1
// copy object to location
// stack: [return address, object address, destination] -> []
memcopy: loadI 0 => m_0
haltI 1835626101 // unimplemented
pop => m_1 // load return address
jump -> m_1
ememlib_: nop
// end of memlib
// stdlib - generic subroutines for ILOC
//
// This library contains a few common subroutines for Boppi.
//
// @author Frank Wibbelink
// initialise
stdlib_: jumpI -> estdlib_
// write a boolean to output
// stack: [return address, bool] -> []
stdbout: pop => m_1 // get boolean
loadI 0 => m_2 // load zero-length string
push m_2
cbr m_1 -> sbout_t,sbout_f
sbout_t: cout "true"
jumpI -> sbout_e
sbout_f: cout "false"
sbout_e: pop => m_1 // load return address
jump -> m_1
// write an array of characters (a string) to output
// stack: [return address, address] -> []
stdsout: pop => m_1 // get address
loadAI m_1,@off_osize => m_2 // get length
sout_lc: cbr m_2 -> sout_ll,sout_le // check if any character to push
sout_ll: subI m_2,1 => m_2 // iterate backward
cloadAO m_1,m_2 => m_c // get character
cpush m_c // push character
jumpI -> sout_lc // repeat
sout_le: loadAI m_1,@off_osize => m_2 // get length
push m_2 // push string length
cout "" // print string
pop => m_1 // get return address
jump -> m_1
// read a character from input
// stack: [return address] -> [char]
stdcin: cin "" // get line
pop => m_1 // get length
cbr m_1 -> scin_t,stdcin // repeat until at least one character
scin_t: cpop => m_2 // save character
scin_lc: subI m_1,1 => m_1 // decrement char count
cbr m_1 -> scin_ll,scin_le
scin_ll: cpop => m_0 // discard character
jumpI -> scin_lc // repeat
scin_le: loadI 0 => m_0 // reset zero register
pop => m_1 // get return address
cpush m_2 // push result character
jump -> m_1
// read an array of characters (a string) from input
// the memalloc label cannot be used, so address 28 is used instead
// stack: [return address] -> [address]
stdsin: cin "" // get line
pop => m_2 // get length
push m_2 // save length
loadI #ssin_a => m_1 // call malloc
push m_1 // call malloc
push m_2 // call malloc
loadI 28 => m_c // call malloc
jump -> m_c // call malloc
ssin_a: pop => m_1 // get array address
pop => m_2 // get length
i2i m_1 => m_n // load character iterator
ssin_c: cbr m_2 -> ssin_l,ssin_e // pop characters into the array
ssin_l: subI m_2,1 => m_2
cpop => m_c // pop character
cstore m_c => m_n // save character
addI m_n,1 => m_n // increment iterator
jumpI -> ssin_c
ssin_e: pop => m_2 // get return address
push m_1 // push array address
jump -> m_2
estdlib_: nop
// end of stdlib
loadI 0 => r_nul // initialise zero register
loadI 217 => r_arp // malloc
push r_arp // malloc
loadI 28 => r_arp // malloc
push r_arp // malloc
jumpI -> memalloc // malloc
pop => r_arp // malloc
addI r_arp,16 => r_arp // construct main AR
jumpI -> s0 // define f1 - jump over body
nop // define f1 - entry point
addI r_arp,0 => r_1 // add offset
load r_1 => r_1 // load address
storeAI r_1 => r_arp,-12 // define f1 - move result
loadAI r_arp,-8 => r_2 // load ref count
loadI 1 => r_1 // one
cmp_LE r_2,r_1 => r_2 // check more than one ref
cbr r_2 -> ycl1,ncl2 // remove vars if last reference
ycl1: nop // cleanup target
ncl2: nop // no cleanup target
loadAI r_arp,-8 => r_1 // define f1 - load return address
jump -> r_1 // define f1 - go to return address
s0: nop // define f1 - skip target
loadI 238 => r_1 // malloc
push r_1 // malloc
loadI 12 => r_1 // malloc
push r_1 // malloc
jumpI -> memalloc // malloc
pop => r_1 // malloc
loadI 220 => r_2 // define f1 - load target address
storeAI r_2 => r_1,0 // define f1 - set target address
storeAI r_arp => r_1,4 // define f1 - copy ARP
loadI 20 => r_2 // define f1 - load AR size
storeAI r_2 => r_1,8 // define f1 - set AR size
storeAI r_1 => r_arp,4 // define f1 - set function reference
i2i r_arp => ART // AR incRef
cmp_NE ART,r_nul => r_1 // AR incRef
cbr r_1 -> aril3,arid4 // AR incRef
aril3: loadI 253 => r_1 // AR incRef
push r_1 // AR incRef
subI ART,16 => r_1 // AR incRef
push r_1 // AR incRef
jumpI -> memaddref // AR incRef
loadAI ART,-16 => ART // AR incRef
cmp_NE ART,r_nul => r_1 // AR incRef
cbr r_1 -> aril3,arid4 // AR incRef
arid4: nop // AR incRef
loadI 0 => r_1 // false
cbr r_1 -> if_t5,if_e7 //
if_t5: nop //
addI r_arp,4 => r_1 // add offset
load r_1 => r_1 // load address
loadI 266 => r_3 // memaddref
push r_3 // memaddref
push r_1 // memaddref
jumpI -> memaddref // memaddref
loadAI r_1,4 => r_2 // add new reference
i2i r_2 => ART // AR incRef
cmp_NE ART,r_nul => r_3 // AR incRef
cbr r_3 -> aril8,arid9 // AR incRef
aril8: loadI 275 => r_3 // AR incRef
push r_3 // AR incRef
subI ART,16 => r_3 // AR incRef
push r_3 // AR incRef
jumpI -> memaddref // AR incRef
loadAI ART,-16 => ART // AR incRef
cmp_NE ART,r_nul => r_3 // AR incRef
cbr r_3 -> aril8,arid9 // AR incRef
arid9: nop // AR incRef
addI r_arp,0 => r_2 // add offset
load r_2 => r_3 // load reference
cmp_EQ r_3,r_nul => r_4 // remove old reference
cbr r_4 -> ynul10,nnul11 // remove old reference
nnul11: nop // remove old reference
loadI 288 => r_4 // free
push r_4 // free
push r_3 // free
jumpI -> memfree // free
loadAI r_3,4 => r_3 // remove old reference
i2i r_3 => ART // AR decRef
cmp_NE ART,r_nul => r_4 // AR decRef
cbr r_4 -> ardl12,ardd13 // AR decRef
ardl12: loadI 297 => r_4 // AR decRef
push r_4 // AR decRef
subI ART,16 => r_4 // AR decRef
push r_4 // AR decRef
jumpI -> memfree // AR decRef
loadAI ART,-16 => ART // AR decRef
cmp_NE ART,r_nul => r_4 // AR decRef
cbr r_4 -> ardl12,ardd13 // AR decRef
ardd13: nop // AR decRef
ynul10: nop // remove old reference
store r_1 => r_2 // to f
load r_2 => r_3 // load reference
loadI 308 => r_5 // memaddref
push r_5 // memaddref
push r_3 // memaddref
jumpI -> memaddref // memaddref
loadAI r_3,4 => r_4 // add new reference
i2i r_4 => ART // AR incRef
cmp_NE ART,r_nul => r_5 // AR incRef
cbr r_5 -> aril14,arid15 // AR incRef
aril14: loadI 317 => r_5 // AR incRef
push r_5 // AR incRef
subI ART,16 => r_5 // AR incRef
push r_5 // AR incRef
jumpI -> memaddref // AR incRef
loadAI ART,-16 => ART // AR incRef
cmp_NE ART,r_nul => r_5 // AR incRef
cbr r_5 -> aril14,arid15 // AR incRef
arid15: nop // AR incRef
cmp_EQ r_1,r_nul => r_3 // remove old reference
cbr r_3 -> ynul16,nnul17 // remove old reference
nnul17: nop // remove old reference
loadI 328 => r_3 // free
push r_3 // free
push r_1 // free
jumpI -> memfree // free
loadAI r_1,4 => r_1 // remove old reference
i2i r_1 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl18,ardd19 // AR decRef
ardl18: loadI 337 => r_3 // AR decRef
push r_3 // AR decRef
subI ART,16 => r_3 // AR decRef
push r_3 // AR decRef
jumpI -> memfree // AR decRef
loadAI ART,-16 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl18,ardd19 // AR decRef
ardd19: nop // AR decRef
ynul16: nop // remove old reference
addI r_arp,0 => r_4 // add offset
load r_4 => r_4 // load address
loadI 348 => r_2 // memaddref
push r_2 // memaddref
push r_4 // memaddref
jumpI -> memaddref // memaddref
loadAI r_4,4 => r_3 // add new reference
i2i r_3 => ART // AR incRef
cmp_NE ART,r_nul => r_2 // AR incRef
cbr r_2 -> aril20,arid21 // AR incRef
aril20: loadI 357 => r_2 // AR incRef
push r_2 // AR incRef
subI ART,16 => r_2 // AR incRef
push r_2 // AR incRef
jumpI -> memaddref // AR incRef
loadAI ART,-16 => ART // AR incRef
cmp_NE ART,r_nul => r_2 // AR incRef
cbr r_2 -> aril20,arid21 // AR incRef
arid21: nop // AR incRef
addI r_arp,0 => r_2 // add offset
load r_2 => r_1 // load reference
cmp_EQ r_1,r_nul => r_3 // remove old reference
cbr r_3 -> ynul22,nnul23 // remove old reference
nnul23: nop // remove old reference
loadI 370 => r_3 // free
push r_3 // free
push r_1 // free
jumpI -> memfree // free
loadAI r_1,4 => r_1 // remove old reference
i2i r_1 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl24,ardd25 // AR decRef
ardl24: loadI 379 => r_3 // AR decRef
push r_3 // AR decRef
subI ART,16 => r_3 // AR decRef
push r_3 // AR decRef
jumpI -> memfree // AR decRef
loadAI ART,-16 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl24,ardd25 // AR decRef
ardd25: nop // AR decRef
ynul22: nop // remove old reference
store r_4 => r_2 // to f
load r_2 => r_3 // load reference
loadI 390 => r_5 // memaddref
push r_5 // memaddref
push r_3 // memaddref
jumpI -> memaddref // memaddref
loadAI r_3,4 => r_1 // add new reference
i2i r_1 => ART // AR incRef
cmp_NE ART,r_nul => r_5 // AR incRef
cbr r_5 -> aril26,arid27 // AR incRef
aril26: loadI 399 => r_5 // AR incRef
push r_5 // AR incRef
subI ART,16 => r_5 // AR incRef
push r_5 // AR incRef
jumpI -> memaddref // AR incRef
loadAI ART,-16 => ART // AR incRef
cmp_NE ART,r_nul => r_5 // AR incRef
cbr r_5 -> aril26,arid27 // AR incRef
arid27: nop // AR incRef
if_e7: nop // end target
loadI 409 => r_3 // malloc
push r_3 // malloc
loadI 8 => r_3 // malloc
push r_3 // malloc
jumpI -> memalloc // malloc
pop => r_3 // malloc
loadI 2 => r_2 // 2
storeAI r_2 => r_3,0 // store array element
loadI 2 => r_4 // 2
storeAI r_4 => r_3,4 // store array element
addI r_arp,8 => r_2 // add offset
load r_2 => r_1 // load reference
cmp_EQ r_1,r_nul => r_4 // remove old reference
cbr r_4 -> ynul28,nnul29 // remove old reference
nnul29: nop // remove old reference
loadI 423 => r_4 // free
push r_4 // free
push r_1 // free
jumpI -> memfree // free
ynul28: nop // remove old reference
store r_3 => r_2 // to arr
load r_2 => r_4 // load reference
loadI 430 => r_5 // memaddref
push r_5 // memaddref
push r_4 // memaddref
jumpI -> memaddref // memaddref
cmp_EQ r_3,r_nul => r_4 // remove old reference
cbr r_4 -> ynul30,nnul31 // remove old reference
nnul31: nop // remove old reference
loadI 437 => r_4 // free
push r_4 // free
push r_3 // free
jumpI -> memfree // free
ynul30: nop // remove old reference
addI r_arp,8 => r_2 // add offset
load r_2 => r_2 // get array object
loadI 0 => r_4 // 0
loadAI r_2,-4 => r_3 // check array index
divI r_3,4 => r_3 // check array index
cmp_LT r_4,r_3 => r_3 // check array index
cmp_GE r_4,r_nul => r_1 // check array index
and r_3,r_1 => r_1 // check array index
cbr r_1 -> nob33,oob32 // check array index
oob32: haltI 1634692962 // array index out of bounds
nob33: multI r_4,4 => r_4 // multiply index by size
add r_2,r_4 => r_2 // get array index address
load r_2 => r_2 // load address
addI r_arp,8 => r_1 // add offset
load r_1 => r_1 // get array object
loadI 1 => r_3 // 1
loadAI r_1,-4 => r_5 // check array index
divI r_5,4 => r_5 // check array index
cmp_LT r_3,r_5 => r_5 // check array index
cmp_GE r_3,r_nul => r_4 // check array index
and r_5,r_4 => r_4 // check array index
cbr r_4 -> nob35,oob34 // check array index
oob34: haltI 1634692962 // array index out of bounds
nob35: multI r_3,4 => r_3 // multiply index by size
add r_1,r_3 => r_1 // get array index address
load r_1 => r_1 // load address
add r_2,r_1 => r_2 // +
out "",r_2 //
loadAI r_arp,0 => r_1 // remove reference get var
cmp_EQ r_1,r_nul => r_3 // remove reference
cbr r_3 -> ynul36,nnul37 // remove reference
nnul37: nop // remove reference
loadI 474 => r_3 // free
push r_3 // free
push r_1 // free
jumpI -> memfree // free
loadAI r_1,4 => r_1 // remove reference
i2i r_1 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl38,ardd39 // AR decRef
ardl38: loadI 483 => r_3 // AR decRef
push r_3 // AR decRef
subI ART,16 => r_3 // AR decRef
push r_3 // AR decRef
jumpI -> memfree // AR decRef
loadAI ART,-16 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl38,ardd39 // AR decRef
ardd39: nop // AR decRef
ynul36: nop // remove reference
loadAI r_arp,4 => r_1 // remove reference get var
cmp_EQ r_1,r_nul => r_3 // remove reference
cbr r_3 -> ynul40,nnul41 // remove reference
nnul41: nop // remove reference
loadI 496 => r_3 // free
push r_3 // free
push r_1 // free
jumpI -> memfree // free
loadAI r_1,4 => r_1 // remove reference
i2i r_1 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl42,ardd43 // AR decRef
ardl42: loadI 505 => r_3 // AR decRef
push r_3 // AR decRef
subI ART,16 => r_3 // AR decRef
push r_3 // AR decRef
jumpI -> memfree // AR decRef
loadAI ART,-16 => ART // AR decRef
cmp_NE ART,r_nul => r_3 // AR decRef
cbr r_3 -> ardl42,ardd43 // AR decRef
ardd43: nop // AR decRef
ynul40: nop // remove reference
loadAI r_arp,8 => r_1 // remove reference get var
cmp_EQ r_1,r_nul => r_3 // remove reference
cbr r_3 -> ynul44,nnul45 // remove reference
nnul45: nop // remove reference
loadI 518 => r_3 // free
push r_3 // free
push r_1 // free
jumpI -> memfree // free
ynul44: nop // remove reference
subI r_arp,16 => r_arp // deconstruct main AR
loadI 524 => r_2 // free
push r_2 // free
push r_arp // free
jumpI -> memfree // free

View File

@ -1,5 +0,0 @@
var (int)->int f;
function int f1(int x) x;
if false then f := f1; f := f fi;
var int[] arr; arr := [2,2];
print(arr[0]+arr[1]);