Compare commits
2 Commits
7220bb82d2
...
68e3c12d80
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68e3c12d80 | ||
|
|
6055cddab2 |
@ -1,18 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def eq(a, b):
|
|
||||||
return a == b
|
|
||||||
|
|
||||||
def emit(string):
|
def emit(string):
|
||||||
sys.stdout.write(string)
|
sys.stdout.buffer.write(string.encode('latin_1'))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def trace(header, value):
|
def trace(header, value):
|
||||||
if os.environ.get('TRACE'):
|
if os.environ.get('TRACE'):
|
||||||
sys.stderr.write(f'{header}={value!r}\n')
|
sys.stderr.write(f'{header}={value!r}\n')
|
||||||
|
|
||||||
eof = chr(0)
|
eof = chr(0xFF)
|
||||||
eol = chr(10)
|
eol = chr(10)
|
||||||
quote = chr(34)
|
quote = chr(34)
|
||||||
PEEK = None
|
PEEK = None
|
||||||
@ -47,16 +44,10 @@ def __check(func, args: list[str], msg: list[str]) -> None:
|
|||||||
if result:
|
if result:
|
||||||
return
|
return
|
||||||
|
|
||||||
sys.stderr.write(' '.join(msg) + '\n')
|
sys.stderr.write('ERROR: ' + ' '.join(msg) + '\n')
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def intinc(a: str) -> str:
|
|
||||||
if not a:
|
|
||||||
return "1"
|
|
||||||
|
|
||||||
return str(int(a) + 1)
|
|
||||||
|
|
||||||
MAPSTORE = {}
|
MAPSTORE = {}
|
||||||
|
|
||||||
def mapclear(mapname: str) -> str:
|
def mapclear(mapname: str) -> str:
|
||||||
@ -75,11 +66,7 @@ def registerid(id: str) -> str:
|
|||||||
idname = mapgetkey("REGISTERID", id, "")
|
idname = mapgetkey("REGISTERID", id, "")
|
||||||
if idname:
|
if idname:
|
||||||
return idname
|
return idname
|
||||||
newidx = mapgetkey("REGISTERID", "__len__", "0")
|
idname = "id_" + id
|
||||||
idname = "identifier" + newidx
|
|
||||||
mapsetkey("REGISTERID", id, idname)
|
|
||||||
newlen = intinc(newidx)
|
|
||||||
mapsetkey("REGISTERID", "__len__", newlen)
|
|
||||||
return idname
|
return idname
|
||||||
|
|
||||||
def emitln(data):
|
def emitln(data):
|
||||||
@ -214,6 +201,8 @@ def parsestatreturn(indent):
|
|||||||
parseconststring()
|
parseconststring()
|
||||||
else:
|
else:
|
||||||
parseexprvarref()
|
parseexprvarref()
|
||||||
|
else:
|
||||||
|
emit('""')
|
||||||
emit(eol)
|
emit(eol)
|
||||||
skipchar(eol)
|
skipchar(eol)
|
||||||
|
|
||||||
@ -264,12 +253,13 @@ def parsestatcheck(indent):
|
|||||||
if eol == peek():
|
if eol == peek():
|
||||||
break
|
break
|
||||||
notfirst = True
|
notfirst = True
|
||||||
|
|
||||||
emitln('])')
|
emitln('])')
|
||||||
|
|
||||||
def parsestattrace(indent):
|
def parsestattrace(indent):
|
||||||
skipchar(' ')
|
skipchar(' ')
|
||||||
emit(' ' * indent)
|
emit(' ' * indent)
|
||||||
emit('trace("')
|
emit('__trace("')
|
||||||
|
|
||||||
varname = lexident()
|
varname = lexident()
|
||||||
varid = registerid(varname)
|
varid = registerid(varname)
|
||||||
@ -390,8 +380,7 @@ def parsefunc():
|
|||||||
skipchar(':')
|
skipchar(':')
|
||||||
skipchar(eol)
|
skipchar(eol)
|
||||||
|
|
||||||
emit('): # ')
|
emitln('):')
|
||||||
emitln(funcname)
|
|
||||||
|
|
||||||
parseblock(1)
|
parseblock(1)
|
||||||
|
|
||||||
@ -401,24 +390,24 @@ def emitheader():
|
|||||||
emitln("import os")
|
emitln("import os")
|
||||||
emitln("import sys")
|
emitln("import sys")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def __eq(a, b):")
|
emitln("def __eq(a: str, b: str) -> str:")
|
||||||
emitln(" return a == b")
|
emitln(" return '1' if a == b else ''")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def __lt(a, b):")
|
emitln("def __lt(a: str, b: str) -> str:")
|
||||||
emitln(" return a[0] < b[0]")
|
emitln(" return '1' if a < b else ''")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def __addstringchar(a, b):")
|
emitln("def __add(a: str, b: str) -> str:")
|
||||||
emitln(" return a + b[0]")
|
emitln(" return a + b")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def __emit(string):")
|
emitln("def __emit(string):")
|
||||||
emitln(" sys.stdout.write(string)")
|
emitln(" sys.stdout.buffer.write(string.encode('latin_1'))")
|
||||||
emitln(" sys.stdout.flush()")
|
emitln(" sys.stdout.flush()")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def trace(header, value):")
|
emitln("def __trace(header, value):")
|
||||||
emitln(" if os.environ.get('TRACE'):")
|
emitln(" if os.environ.get('TRACE'):")
|
||||||
emitln(" sys.stderr.write(f'{header}={value!r}\\n')")
|
emitln(" sys.stderr.write(f'{header}={value!r}\\n')")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("__EOF = chr(0)")
|
emitln("__EOF = chr(0xFF)")
|
||||||
emitln("__EOL = chr(10)")
|
emitln("__EOL = chr(10)")
|
||||||
emitln("__QUOTE = chr(34)")
|
emitln("__QUOTE = chr(34)")
|
||||||
emitln("")
|
emitln("")
|
||||||
@ -428,7 +417,7 @@ def emitheader():
|
|||||||
emitln("")
|
emitln("")
|
||||||
emitln("def _readchar():")
|
emitln("def _readchar():")
|
||||||
emitln(" char = sys.stdin.read(1)")
|
emitln(" char = sys.stdin.read(1)")
|
||||||
emitln(" trace('char', char)")
|
emitln(" __trace('char', char)")
|
||||||
emitln(" if not char:")
|
emitln(" if not char:")
|
||||||
emitln(" return __EOF")
|
emitln(" return __EOF")
|
||||||
emitln(" return char")
|
emitln(" return char")
|
||||||
@ -458,14 +447,14 @@ def emitheader():
|
|||||||
emitln("")
|
emitln("")
|
||||||
emitln("MAPSTORE = {}")
|
emitln("MAPSTORE = {}")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def mapclear(mapname: str) -> str:")
|
emitln("def __mapclear(mapname: str) -> str:")
|
||||||
emitln(" MAPSTORE.pop(mapname)")
|
emitln(" MAPSTORE.pop(mapname)")
|
||||||
emitln(" return ''")
|
emitln(" return ''")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def mapgetkey(mapname: str, key: str, default: str) -> str:")
|
emitln("def __mapgetkey(mapname: str, key: str, default: str) -> str:")
|
||||||
emitln(" return MAPSTORE.get(mapname, {}).get(key, default)")
|
emitln(" return MAPSTORE.get(mapname, {}).get(key, default)")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln("def mapsetkey(mapname: str, key: str, value: str) -> str:")
|
emitln("def __mapsetkey(mapname: str, key: str, value: str) -> str:")
|
||||||
emitln(" MAPSTORE.setdefault(mapname, {})")
|
emitln(" MAPSTORE.setdefault(mapname, {})")
|
||||||
emitln(" MAPSTORE[mapname][key] = value")
|
emitln(" MAPSTORE[mapname][key] = value")
|
||||||
emitln(" return ''")
|
emitln(" return ''")
|
||||||
@ -480,7 +469,7 @@ def emitheader():
|
|||||||
emitln(" if result:")
|
emitln(" if result:")
|
||||||
emitln(" return")
|
emitln(" return")
|
||||||
emitln("")
|
emitln("")
|
||||||
emitln(" sys.stderr.write(' '.join(msg) + '\\n')")
|
emitln(" sys.stderr.write('ERROR: ' + ' '.join(msg) + '\\n')")
|
||||||
emitln(" sys.stderr.flush()")
|
emitln(" sys.stderr.flush()")
|
||||||
emitln(" exit(1)")
|
emitln(" exit(1)")
|
||||||
|
|
||||||
@ -500,8 +489,8 @@ def main():
|
|||||||
mapsetkey("REGISTERID", "quote", "__QUOTE")
|
mapsetkey("REGISTERID", "quote", "__QUOTE")
|
||||||
|
|
||||||
# Standard library functions
|
# Standard library functions
|
||||||
mapsetkey("FUNCREG", "addstringchar", "1")
|
mapsetkey("FUNCREG", "add", "1")
|
||||||
mapsetkey("REGISTERID", "addstringchar", "__addstringchar")
|
mapsetkey("REGISTERID", "add", "__add")
|
||||||
mapsetkey("FUNCREG", "emit", "1")
|
mapsetkey("FUNCREG", "emit", "1")
|
||||||
mapsetkey("REGISTERID", "emit", "__emit")
|
mapsetkey("REGISTERID", "emit", "__emit")
|
||||||
mapsetkey("FUNCREG", "eq", "1")
|
mapsetkey("FUNCREG", "eq", "1")
|
||||||
@ -511,8 +500,11 @@ def main():
|
|||||||
mapsetkey("FUNCREG", "not", "1")
|
mapsetkey("FUNCREG", "not", "1")
|
||||||
mapsetkey("REGISTERID", "not", "__not")
|
mapsetkey("REGISTERID", "not", "__not")
|
||||||
mapsetkey("FUNCREG", "mapclear", "1")
|
mapsetkey("FUNCREG", "mapclear", "1")
|
||||||
|
mapsetkey("REGISTERID", "mapclear", "__mapclear")
|
||||||
mapsetkey("FUNCREG", "mapgetkey", "1")
|
mapsetkey("FUNCREG", "mapgetkey", "1")
|
||||||
|
mapsetkey("REGISTERID", "mapgetkey", "__mapgetkey")
|
||||||
mapsetkey("FUNCREG", "mapsetkey", "1")
|
mapsetkey("FUNCREG", "mapsetkey", "1")
|
||||||
|
mapsetkey("REGISTERID", "mapsetkey", "__mapsetkey")
|
||||||
mapsetkey("FUNCREG", "peek", "1")
|
mapsetkey("FUNCREG", "peek", "1")
|
||||||
mapsetkey("REGISTERID", "peek", "__peek")
|
mapsetkey("REGISTERID", "peek", "__peek")
|
||||||
mapsetkey("FUNCREG", "skip", "1")
|
mapsetkey("FUNCREG", "skip", "1")
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
skipchar exp:
|
registerid id:
|
||||||
declare act
|
declare idname
|
||||||
declare lineno
|
declare newidx
|
||||||
declare colno
|
|
||||||
calc act peek
|
calc idname mapgetkey "REGISTERID" id ""
|
||||||
calc lineno stdinlineno
|
if idname
|
||||||
calc colno stdincolno
|
return idname
|
||||||
check eq exp act : "Unexpected character" act "expected" exp "at" lineno colno
|
/
|
||||||
skip
|
|
||||||
|
calc idname add "id_" id
|
||||||
|
return idname
|
||||||
/
|
/
|
||||||
|
|
||||||
emitln data:
|
emitln data:
|
||||||
@ -14,14 +16,6 @@ emitln data:
|
|||||||
emit eol
|
emit eol
|
||||||
/
|
/
|
||||||
|
|
||||||
increaseindent indent:
|
|
||||||
calc indent addstringchar indent " "
|
|
||||||
calc indent addstringchar indent " "
|
|
||||||
calc indent addstringchar indent " "
|
|
||||||
calc indent addstringchar indent " "
|
|
||||||
return indent
|
|
||||||
/
|
|
||||||
|
|
||||||
lexident:
|
lexident:
|
||||||
declare word
|
declare word
|
||||||
set word ""
|
set word ""
|
||||||
@ -35,12 +29,28 @@ lexident:
|
|||||||
if isafterz
|
if isafterz
|
||||||
break
|
break
|
||||||
/
|
/
|
||||||
calc word addstringchar word char
|
calc word add word char
|
||||||
skip
|
skip
|
||||||
/
|
/
|
||||||
return word
|
return word
|
||||||
/
|
/
|
||||||
|
|
||||||
|
skipchar exp:
|
||||||
|
declare act
|
||||||
|
declare lineno
|
||||||
|
declare colno
|
||||||
|
calc act peek
|
||||||
|
calc lineno stdinlineno
|
||||||
|
calc colno stdincolno
|
||||||
|
check eq exp act : "Unexpected character" act "expected" exp "at" lineno colno
|
||||||
|
skip
|
||||||
|
/
|
||||||
|
|
||||||
|
increaseindent indent:
|
||||||
|
calc indent add indent " "
|
||||||
|
return indent
|
||||||
|
/
|
||||||
|
|
||||||
parseconststring:
|
parseconststring:
|
||||||
skipchar quote
|
skipchar quote
|
||||||
emit quote
|
emit quote
|
||||||
@ -63,12 +73,15 @@ parseconststring:
|
|||||||
|
|
||||||
parseexprvarref:
|
parseexprvarref:
|
||||||
calc varname lexident
|
calc varname lexident
|
||||||
emit varname
|
calc varid registerid varname
|
||||||
|
emit varid
|
||||||
/
|
/
|
||||||
|
|
||||||
parseexprcall:
|
parseexprcall:
|
||||||
calc funcname lexident
|
calc funcname lexident
|
||||||
emit funcname
|
calc funcid registerid funcname
|
||||||
|
check mapgetkey "FUNCREG" funcname "" : "Function" funcname "does not exist"
|
||||||
|
emit funcid
|
||||||
emit "("
|
emit "("
|
||||||
set first "1"
|
set first "1"
|
||||||
forever
|
forever
|
||||||
@ -100,16 +113,18 @@ parseexprcall:
|
|||||||
|
|
||||||
parsestatdeclare indent:
|
parsestatdeclare indent:
|
||||||
skipchar " "
|
skipchar " "
|
||||||
calc var lexident
|
calc varname lexident
|
||||||
|
calc varid registerid varname
|
||||||
skipchar eol
|
skipchar eol
|
||||||
/
|
/
|
||||||
|
|
||||||
parsestatset indent:
|
parsestatset indent:
|
||||||
skipchar " "
|
skipchar " "
|
||||||
calc var lexident
|
calc varname lexident
|
||||||
|
calc varid registerid varname
|
||||||
skipchar " "
|
skipchar " "
|
||||||
emit indent
|
emit indent
|
||||||
emit var
|
emit varid
|
||||||
emit " = "
|
emit " = "
|
||||||
parseconststring
|
parseconststring
|
||||||
emit eol
|
emit eol
|
||||||
@ -118,10 +133,11 @@ parsestatset indent:
|
|||||||
|
|
||||||
parsestatcalc indent:
|
parsestatcalc indent:
|
||||||
skipchar " "
|
skipchar " "
|
||||||
calc var lexident
|
calc varname lexident
|
||||||
|
calc varid registerid varname
|
||||||
skipchar " "
|
skipchar " "
|
||||||
emit indent
|
emit indent
|
||||||
emit var
|
emit varid
|
||||||
emit " = "
|
emit " = "
|
||||||
parseexprcall
|
parseexprcall
|
||||||
emit eol
|
emit eol
|
||||||
@ -160,6 +176,7 @@ parsestatreturn indent:
|
|||||||
emit "return "
|
emit "return "
|
||||||
calc char peek
|
calc char peek
|
||||||
calc isspace eq char " "
|
calc isspace eq char " "
|
||||||
|
calc isnotspace not isspace
|
||||||
if isspace
|
if isspace
|
||||||
skip
|
skip
|
||||||
calc char peek
|
calc char peek
|
||||||
@ -172,6 +189,10 @@ parsestatreturn indent:
|
|||||||
parseexprvarref
|
parseexprvarref
|
||||||
/
|
/
|
||||||
/
|
/
|
||||||
|
if isnotspace
|
||||||
|
emit quote
|
||||||
|
emit quote
|
||||||
|
/
|
||||||
emit eol
|
emit eol
|
||||||
skipchar eol
|
skipchar eol
|
||||||
/
|
/
|
||||||
@ -186,11 +207,12 @@ parsestatcheck indent:
|
|||||||
|
|
||||||
skipchar " "
|
skipchar " "
|
||||||
emit indent
|
emit indent
|
||||||
emit "assert "
|
emit "__check("
|
||||||
|
|
||||||
calc funcname lexident
|
calc funcname lexident
|
||||||
emit funcname
|
calc funcid registerid funcname
|
||||||
emit "("
|
emit funcid
|
||||||
|
emit ", ["
|
||||||
|
|
||||||
set notfirst ""
|
set notfirst ""
|
||||||
forever
|
forever
|
||||||
@ -220,7 +242,8 @@ parsestatcheck indent:
|
|||||||
|
|
||||||
skipchar ":"
|
skipchar ":"
|
||||||
|
|
||||||
emit "), ("
|
emit "], ["
|
||||||
|
|
||||||
set notfirst ""
|
set notfirst ""
|
||||||
|
|
||||||
forever
|
forever
|
||||||
@ -249,19 +272,20 @@ parsestatcheck indent:
|
|||||||
set notfirst "1"
|
set notfirst "1"
|
||||||
/
|
/
|
||||||
|
|
||||||
emitln ")"
|
emitln "])"
|
||||||
/
|
/
|
||||||
|
|
||||||
parsestattrace indent:
|
parsestattrace indent:
|
||||||
emit indent
|
emit indent
|
||||||
emit "trace("
|
emit "__trace("
|
||||||
emit quote
|
emit quote
|
||||||
skipchar " "
|
skipchar " "
|
||||||
calc varname lexident
|
calc varname lexident
|
||||||
|
calc varid registerid varname
|
||||||
emit varname
|
emit varname
|
||||||
emit quote
|
emit quote
|
||||||
emit ", "
|
emit ", "
|
||||||
emit varname
|
emit varid
|
||||||
emitln ")"
|
emitln ")"
|
||||||
skipchar eol
|
skipchar eol
|
||||||
/
|
/
|
||||||
@ -314,8 +338,9 @@ parsestat indent:
|
|||||||
parsestatcheck indent
|
parsestatcheck indent
|
||||||
return
|
return
|
||||||
/
|
/
|
||||||
|
calc callid registerid call
|
||||||
emit indent
|
emit indent
|
||||||
emit call
|
emit callid
|
||||||
emit "("
|
emit "("
|
||||||
set first "1"
|
set first "1"
|
||||||
forever
|
forever
|
||||||
@ -380,9 +405,11 @@ parseblock indent:
|
|||||||
|
|
||||||
parsefunc:
|
parsefunc:
|
||||||
calc funcname lexident
|
calc funcname lexident
|
||||||
|
calc funcid registerid funcname
|
||||||
trace funcname
|
trace funcname
|
||||||
|
mapsetkey "FUNCREG" funcname "1"
|
||||||
emit "def "
|
emit "def "
|
||||||
emit funcname
|
emit funcid
|
||||||
emit "("
|
emit "("
|
||||||
set isnotfirst ""
|
set isnotfirst ""
|
||||||
forever
|
forever
|
||||||
@ -393,11 +420,12 @@ parsefunc:
|
|||||||
break
|
break
|
||||||
/
|
/
|
||||||
skip
|
skip
|
||||||
calc var lexident
|
calc varname lexident
|
||||||
|
calc varid registerid varname
|
||||||
if isnotfirst
|
if isnotfirst
|
||||||
emit ", "
|
emit ", "
|
||||||
/
|
/
|
||||||
emit var
|
emit varid
|
||||||
set isnotfirst "1"
|
set isnotfirst "1"
|
||||||
/
|
/
|
||||||
calc char peek
|
calc char peek
|
||||||
@ -421,26 +449,31 @@ emitheader:
|
|||||||
emitln "import os"
|
emitln "import os"
|
||||||
emitln "import sys"
|
emitln "import sys"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def eq(a, b):"
|
emitln "def __eq(a: str, b: str) -> str:"
|
||||||
emitln " return a == b"
|
emitln " return '1' if a == b else ''"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def lt(a, b):"
|
emitln "def __lt(a: str, b: str) -> str:"
|
||||||
emitln " return a[0] < b[0]"
|
emitln " return '1' if a < b else ''"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def addstringchar(a, b):"
|
emitln "def __not(a: str) -> str:"
|
||||||
emitln " return a + b[0]"
|
emitln " if a:"
|
||||||
|
emitln " return ''"
|
||||||
|
emitln " return '1'"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def emit(string):"
|
emitln "def __add(a: str, b :str) -> str:"
|
||||||
emitln " sys.stdout.write(string)"
|
emitln " return a + b"
|
||||||
|
emitln ""
|
||||||
|
emitln "def __emit(string):"
|
||||||
|
emitln " sys.stdout.buffer.write(string.encode('latin_1'))"
|
||||||
emitln " sys.stdout.flush()"
|
emitln " sys.stdout.flush()"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def trace(header, value):"
|
emitln "def __trace(header, value):"
|
||||||
emitln " if os.environ.get('TRACE'):"
|
emitln " if os.environ.get('TRACE'):"
|
||||||
emitln " sys.stderr.write(f'{header}={value!r}\\n')"
|
emitln " sys.stderr.write(f'{header}={value!r}\\n')"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "eof = chr(0)"
|
emitln "__EOF = chr(0xFF)"
|
||||||
emitln "eol = chr(10)"
|
emitln "__EOL = chr(10)"
|
||||||
emitln "quote = chr(34)"
|
emitln "__QUOTE = chr(34)"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "STDINCOLNO = 0"
|
emitln "STDINCOLNO = 0"
|
||||||
emitln "STDINLINENO = 1"
|
emitln "STDINLINENO = 1"
|
||||||
@ -448,43 +481,102 @@ emitheader:
|
|||||||
emitln ""
|
emitln ""
|
||||||
emitln "def _readchar():"
|
emitln "def _readchar():"
|
||||||
emitln " char = sys.stdin.read(1)"
|
emitln " char = sys.stdin.read(1)"
|
||||||
emitln " trace('char', char)"
|
emitln " __trace('char', char)"
|
||||||
emitln " if not char:"
|
emitln " if not char:"
|
||||||
emitln " return eof"
|
emitln " return __EOF"
|
||||||
emitln " return char"
|
emitln " return char"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def peek():"
|
emitln "def __peek():"
|
||||||
emitln " return STDINPEEK"
|
emitln " return STDINPEEK"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def skip():"
|
emitln "def __skip():"
|
||||||
emitln " global STDINCOLNO"
|
emitln " global STDINCOLNO"
|
||||||
emitln " global STDINLINENO"
|
emitln " global STDINLINENO"
|
||||||
emitln " global STDINPEEK"
|
emitln " global STDINPEEK"
|
||||||
emitln " if eol == STDINPEEK:"
|
emitln " if __EOL == STDINPEEK:"
|
||||||
emitln " STDINLINENO += 1"
|
emitln " STDINLINENO += 1"
|
||||||
emitln " STDINCOLNO = 0"
|
emitln " STDINCOLNO = 0"
|
||||||
emitln " STDINCOLNO += 1"
|
emitln " STDINCOLNO += 1"
|
||||||
emitln " STDINPEEK = _readchar()"
|
emitln " STDINPEEK = _readchar()"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def stdinlineno():"
|
emitln "def __stdinlineno():"
|
||||||
emitln " global STDINLINENO"
|
emitln " global STDINLINENO"
|
||||||
emitln " return str(STDINLINENO)"
|
emitln " return str(STDINLINENO)"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "def stdincolno():"
|
emitln "def __stdincolno():"
|
||||||
emitln " global STDINCOLNO"
|
emitln " global STDINCOLNO"
|
||||||
emitln " return str(STDINCOLNO)"
|
emitln " return str(STDINCOLNO)"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "skip()"
|
emitln "__skip()"
|
||||||
emitln ""
|
emitln ""
|
||||||
|
emitln ""
|
||||||
|
emitln "MAPSTORE = {}"
|
||||||
|
emitln ""
|
||||||
|
emitln "def __mapclear(mapname: str) -> str:"
|
||||||
|
emitln " MAPSTORE.pop(mapname)"
|
||||||
|
emitln " return ''"
|
||||||
|
emitln ""
|
||||||
|
emitln "def __mapgetkey(mapname: str, key: str, default: str) -> str:"
|
||||||
|
emitln " return MAPSTORE.get(mapname, {}).get(key, default)"
|
||||||
|
emitln ""
|
||||||
|
emitln "def __mapsetkey(mapname: str, key: str, value: str) -> str:"
|
||||||
|
emitln " MAPSTORE.setdefault(mapname, {})"
|
||||||
|
emitln " MAPSTORE[mapname][key] = value"
|
||||||
|
emitln " return ''"
|
||||||
|
emitln ""
|
||||||
|
emitln "def __check(func, args: list[str], msg: list[str]) -> None:"
|
||||||
|
emitln " result = func(*args)"
|
||||||
|
emitln " if result:"
|
||||||
|
emitln " return"
|
||||||
|
emitln ""
|
||||||
|
emitln " sys.stderr.write('ERROR: ' + ' '.join(msg) + '\\n')"
|
||||||
|
emitln " sys.stderr.flush()"
|
||||||
|
emitln " exit(1)"
|
||||||
/
|
/
|
||||||
|
|
||||||
emitfooter:
|
emitfooter:
|
||||||
|
declare mainname
|
||||||
|
calc mainname registerid "main"
|
||||||
|
|
||||||
emitln "if __name__ == '__main__':"
|
emitln "if __name__ == '__main__':"
|
||||||
emitln " main()"
|
emit " "
|
||||||
|
emit mainname
|
||||||
|
emitln "()"
|
||||||
/
|
/
|
||||||
|
|
||||||
main:
|
main:
|
||||||
emitheader
|
emitheader
|
||||||
|
|
||||||
|
mapsetkey "REGISTERID" "eof" "__EOF"
|
||||||
|
mapsetkey "REGISTERID" "eol" "__EOL"
|
||||||
|
mapsetkey "REGISTERID" "quote" "__QUOTE"
|
||||||
|
|
||||||
|
mapsetkey "FUNCREG" "add" "1"
|
||||||
|
mapsetkey "REGISTERID" "add" "__add"
|
||||||
|
mapsetkey "FUNCREG" "emit" "1"
|
||||||
|
mapsetkey "REGISTERID" "emit" "__emit"
|
||||||
|
mapsetkey "FUNCREG" "eq" "1"
|
||||||
|
mapsetkey "REGISTERID" "eq" "__eq"
|
||||||
|
mapsetkey "FUNCREG" "lt" "1"
|
||||||
|
mapsetkey "REGISTERID" "lt" "__lt"
|
||||||
|
mapsetkey "FUNCREG" "not" "1"
|
||||||
|
mapsetkey "REGISTERID" "not" "__not"
|
||||||
|
mapsetkey "FUNCREG" "mapclear" "1"
|
||||||
|
mapsetkey "REGISTERID" "mapclear" "__mapclear"
|
||||||
|
mapsetkey "FUNCREG" "mapgetkey" "1"
|
||||||
|
mapsetkey "REGISTERID" "mapgetkey" "__mapgetkey"
|
||||||
|
mapsetkey "FUNCREG" "mapsetkey" "1"
|
||||||
|
mapsetkey "REGISTERID" "mapsetkey" "__mapsetkey"
|
||||||
|
mapsetkey "FUNCREG" "peek" "1"
|
||||||
|
mapsetkey "REGISTERID" "peek" "__peek"
|
||||||
|
mapsetkey "FUNCREG" "skip" "1"
|
||||||
|
mapsetkey "REGISTERID" "skip" "__skip"
|
||||||
|
mapsetkey "FUNCREG" "stdincolno" "1"
|
||||||
|
mapsetkey "REGISTERID" "stdincolno" "__stdincolno"
|
||||||
|
mapsetkey "FUNCREG" "stdinlineno" "1"
|
||||||
|
mapsetkey "REGISTERID" "stdinlineno" "__stdinlineno"
|
||||||
|
|
||||||
|
|
||||||
forever
|
forever
|
||||||
calc char peek
|
calc char peek
|
||||||
calc iseof eq char eof
|
calc iseof eq char eof
|
||||||
|
|||||||
@ -15,10 +15,7 @@ emitln data:
|
|||||||
/
|
/
|
||||||
|
|
||||||
increaseindent indent:
|
increaseindent indent:
|
||||||
calc indent addstringchar indent " "
|
calc indent add indent " "
|
||||||
calc indent addstringchar indent " "
|
|
||||||
calc indent addstringchar indent " "
|
|
||||||
calc indent addstringchar indent " "
|
|
||||||
return indent
|
return indent
|
||||||
/
|
/
|
||||||
|
|
||||||
@ -38,7 +35,7 @@ lexident:
|
|||||||
if isafterz
|
if isafterz
|
||||||
break
|
break
|
||||||
/
|
/
|
||||||
calc word addstringchar word char
|
calc word add word char
|
||||||
skip
|
skip
|
||||||
/
|
/
|
||||||
return word
|
return word
|
||||||
@ -227,7 +224,8 @@ parsestatreturn indent:
|
|||||||
/
|
/
|
||||||
/
|
/
|
||||||
if isnotspace
|
if isnotspace
|
||||||
emit "0"
|
emit quote
|
||||||
|
emit quote
|
||||||
/
|
/
|
||||||
emit ";"
|
emit ";"
|
||||||
emit eol
|
emit eol
|
||||||
@ -284,6 +282,7 @@ parsestatcheck indent:
|
|||||||
emit indent
|
emit indent
|
||||||
emitln "{"
|
emitln "{"
|
||||||
|
|
||||||
|
emit indent
|
||||||
emit " fprintf(stderr, "
|
emit " fprintf(stderr, "
|
||||||
emit quote
|
emit quote
|
||||||
emit "%s"
|
emit "%s"
|
||||||
@ -321,6 +320,14 @@ parsestatcheck indent:
|
|||||||
/
|
/
|
||||||
/
|
/
|
||||||
|
|
||||||
|
emit indent
|
||||||
|
emit " fprintf(stderr, "
|
||||||
|
emit quote
|
||||||
|
emit "%s"
|
||||||
|
emit quote
|
||||||
|
emit ", var_eol"
|
||||||
|
emitln ");"
|
||||||
|
|
||||||
emit indent
|
emit indent
|
||||||
emitln " exit(1);"
|
emitln " exit(1);"
|
||||||
emit indent
|
emit indent
|
||||||
@ -479,14 +486,23 @@ parsefunc:
|
|||||||
declare funcname
|
declare funcname
|
||||||
declare iseoblock
|
declare iseoblock
|
||||||
declare isfirst
|
declare isfirst
|
||||||
|
declare ismain
|
||||||
|
declare isnotmain
|
||||||
declare isspace
|
declare isspace
|
||||||
declare isnotfirst
|
declare isnotfirst
|
||||||
declare isnotspace
|
declare isnotspace
|
||||||
declare var
|
declare var
|
||||||
calc funcname lexident
|
calc funcname lexident
|
||||||
|
calc ismain eq funcname "main"
|
||||||
|
calc isnotmain not ismain
|
||||||
trace funcname
|
trace funcname
|
||||||
emit "char * "
|
emit "char * "
|
||||||
emit funcname
|
if ismain
|
||||||
|
emit "__main"
|
||||||
|
/
|
||||||
|
if isnotmain
|
||||||
|
emit funcname
|
||||||
|
/
|
||||||
emit "("
|
emit "("
|
||||||
set first "1"
|
set first "1"
|
||||||
forever
|
forever
|
||||||
@ -532,7 +548,7 @@ emitheader:
|
|||||||
emitln "#include <string.h>"
|
emitln "#include <string.h>"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "char var_eof[2] = {-1, 0};"
|
emitln "char var_eof[2] = {0xFF, 0};"
|
||||||
emitln "char var_eol[2] = {10, 0};"
|
emitln "char var_eol[2] = {10, 0};"
|
||||||
emitln "char var_quote[2] = {34, 0};"
|
emitln "char var_quote[2] = {34, 0};"
|
||||||
emitln "char var_false[1] = {0};"
|
emitln "char var_false[1] = {0};"
|
||||||
@ -553,14 +569,14 @@ emitheader:
|
|||||||
emitln " return (strcmp(a, var_true) != 0) ? var_true : var_false;"
|
emitln " return (strcmp(a, var_true) != 0) ? var_true : var_false;"
|
||||||
emitln "}"
|
emitln "}"
|
||||||
emitln ""
|
emitln ""
|
||||||
emitln "char * addstringchar(char * str, char * chr)"
|
emitln "char * add(char * lft, char * rgt)"
|
||||||
emitln "{"
|
emitln "{"
|
||||||
emitln " int str_len = strlen(str);"
|
emitln " int lft_len = strlen(lft);"
|
||||||
emitln " assert(strlen(chr) == 1);"
|
emitln " int rgt_len = strlen(rgt);"
|
||||||
emitln " char * res = malloc((str_len + 2) * sizeof(char));"
|
emitln " char * res = malloc((lft_len + rgt_len + 1) * sizeof(char));"
|
||||||
emitln " strcpy(res, str);"
|
emitln " strcpy(res, lft);"
|
||||||
emitln " res[str_len + 0] = chr[0];"
|
emitln " strcpy(res + lft_len, rgt);"
|
||||||
emitln " res[str_len + 1] = 0;"
|
emitln " res[lft_len + rgt_len] = 0;"
|
||||||
emitln " return res;"
|
emitln " return res;"
|
||||||
emitln "}"
|
emitln "}"
|
||||||
emitln ""
|
emitln ""
|
||||||
@ -644,7 +660,10 @@ emitheader:
|
|||||||
/
|
/
|
||||||
|
|
||||||
emitfooter:
|
emitfooter:
|
||||||
emit ""
|
emitln "int main() {"
|
||||||
|
emitln " __main();"
|
||||||
|
emitln " return 0;"
|
||||||
|
emitln "}"
|
||||||
return
|
return
|
||||||
/
|
/
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,7 @@ Exits the deepest `forever` loop.
|
|||||||
|
|
||||||
#### func args*
|
#### func args*
|
||||||
|
|
||||||
Calls the function name `func` with the given arguments. The result, if any, is ignored.
|
Calls the function name `func` with the given arguments. The return value is ignored.
|
||||||
|
|
||||||
#### if arg
|
#### if arg
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ Repeats the block until `break` or `return` is called.
|
|||||||
|
|
||||||
#### return var?
|
#### return var?
|
||||||
|
|
||||||
Returns the given value. You can not give an argument if your function is never used in `call`.
|
Returns the given value. If you don't give something to return, the function will return the empty string.
|
||||||
|
|
||||||
### Builtins
|
### Builtins
|
||||||
|
|
||||||
@ -137,9 +137,7 @@ Double quote character.
|
|||||||
|
|
||||||
### Standard library functions
|
### Standard library functions
|
||||||
|
|
||||||
#### addstringchar a b
|
#### add a b
|
||||||
|
|
||||||
`b` is expected to have length 1.
|
|
||||||
|
|
||||||
Creates a new string with `b` appended to `a`.
|
Creates a new string with `b` appended to `a`.
|
||||||
|
|
||||||
|
|||||||
2
tests/.gitignore
vendored
2
tests/.gitignore
vendored
@ -1 +1 @@
|
|||||||
/*.results
|
/Makefile.mk
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
.PRECIOUS: build/%.it0.py build/%.it0.c
|
|
||||||
.DELETE_ON_ERROR:
|
.DELETE_ON_ERROR:
|
||||||
|
|
||||||
PYVERSION=3.12
|
PYVERSION=3.12
|
||||||
@ -8,34 +7,29 @@ PYPREFIX=/usr
|
|||||||
CYTHON=cython3
|
CYTHON=cython3
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
# builtincheckfalse is separate since it's supposed to crash. It's a test for the test 'framework', if you will.
|
all: verify-results
|
||||||
TESTLIST=$(shell ls *.lang0 | grep -v -e 'builtincheckfalse' -e 'funcnotexists' | sed 's/.lang0//')
|
|
||||||
|
|
||||||
all: check
|
Makefile.mk: generate-recipes.py $(wildcard test_*/test_*)
|
||||||
|
python3 generate-recipes.py Makefile.mk it0 it1 it2
|
||||||
|
|
||||||
check: all-it0.results all-it1.results all-it2.results
|
include Makefile.mk
|
||||||
! grep -v 'Success' $^
|
|
||||||
|
|
||||||
all-it0.results: $(addprefix build/,$(addsuffix .it0, $(TESTLIST))) build/builtincheckfalse.it0
|
|
||||||
-rm -f $@
|
|
||||||
(cat funcnotexists.lang0 | ../0-lang0py/lang0py.exe 2>&1 1>/dev/null || true) | grep 'Function forgottodeclare does not exist'
|
|
||||||
cat test-input.txt | build/builtincheckfalse.it0 2> /dev/null 2>&1 | grep 'Success'
|
|
||||||
$(foreach test,$(TESTLIST), echo -n "$(test) " >> $@; cat test-input.txt | ./build/$(test).it0 >> $@ ; echo "" >> $@ ;)
|
|
||||||
|
|
||||||
all-it1.results: $(addprefix build/,$(addsuffix .it1, $(TESTLIST))) build/builtincheckfalse.it1
|
|
||||||
-rm -f $@
|
|
||||||
cat test-input.txt | build/builtincheckfalse.it1 2> /dev/null 2>&1 | grep 'Success'
|
|
||||||
(cat funcnotexists.lang0 | ../1-lang0py/lang0py.exe 2>&1 1>/dev/null || true) | grep 'Function forgottodeclare does not exist'
|
|
||||||
$(foreach test,$(TESTLIST), echo -n "$(test) " >> $@; cat test-input.txt | ./build/$(test).it1 >> $@ ; echo "" >> $@ ;)
|
|
||||||
|
|
||||||
all-it2.results: $(addprefix build/,$(addsuffix .it2, $(TESTLIST))) build/builtincheckfalse.it2
|
|
||||||
-rm -f $@
|
|
||||||
cat test-input.txt | build/builtincheckfalse.it2 2> /dev/null 2>&1 | grep 'Success'
|
|
||||||
(cat funcnotexists.lang0 | ../2-lang0py/lang0c.exe 2>&1 1>/dev/null || true) | grep 'Function forgottodeclare does not exist'
|
|
||||||
$(foreach test,$(TESTLIST), echo -n "$(test) " >> $@; cat test-input.txt | ./build/$(test).it2 >> $@ ; echo "" >> $@ ;)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f *.results build/*.it0* build/*.it1* build/*.it2*
|
find build -name '*.c' -delete
|
||||||
|
find build -name '*.it0' -delete
|
||||||
|
find build -name '*.it0.result' -delete
|
||||||
|
find build -name '*.it0.stderr' -delete
|
||||||
|
find build -name '*.it0.stdout' -delete
|
||||||
|
find build -name '*.it1' -delete
|
||||||
|
find build -name '*.it1.result' -delete
|
||||||
|
find build -name '*.it1.stderr' -delete
|
||||||
|
find build -name '*.it1.stdout' -delete
|
||||||
|
find build -name '*.it2' -delete
|
||||||
|
find build -name '*.it2.result' -delete
|
||||||
|
find build -name '*.it2.stderr' -delete
|
||||||
|
find build -name '*.it2.stdout' -delete
|
||||||
|
find build -name '*.py' -delete
|
||||||
|
find build -name '*.tmp' -delete
|
||||||
|
|
||||||
###
|
###
|
||||||
# it0
|
# it0
|
||||||
|
|||||||
@ -3,12 +3,21 @@
|
|||||||
/*.it0.o
|
/*.it0.o
|
||||||
/*.it0.py
|
/*.it0.py
|
||||||
/*.it0.py.tmp
|
/*.it0.py.tmp
|
||||||
|
/*.it0.result
|
||||||
|
/*.it0.stderr
|
||||||
|
/*.it0.stdout
|
||||||
/*.it1
|
/*.it1
|
||||||
/*.it1.c
|
/*.it1.c
|
||||||
/*.it1.o
|
/*.it1.o
|
||||||
/*.it1.py
|
/*.it1.py
|
||||||
/*.it1.py.tmp
|
/*.it1.py.tmp
|
||||||
|
/*.it1.result
|
||||||
|
/*.it1.stderr
|
||||||
|
/*.it1.stdout
|
||||||
/*.it2
|
/*.it2
|
||||||
/*.it2.c
|
/*.it2.c
|
||||||
/*.it2.c.tmp
|
/*.it2.c.tmp
|
||||||
/*.it2.o
|
/*.it2.o
|
||||||
|
/*.it2.result
|
||||||
|
/*.it2.stderr
|
||||||
|
/*.it2.stdout
|
||||||
23
tests/build/test_flow_control/.gitignore
vendored
Normal file
23
tests/build/test_flow_control/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*.it0
|
||||||
|
/*.it0.c
|
||||||
|
/*.it0.o
|
||||||
|
/*.it0.py
|
||||||
|
/*.it0.py.tmp
|
||||||
|
/*.it0.result
|
||||||
|
/*.it0.stderr
|
||||||
|
/*.it0.stdout
|
||||||
|
/*.it1
|
||||||
|
/*.it1.c
|
||||||
|
/*.it1.o
|
||||||
|
/*.it1.py
|
||||||
|
/*.it1.py.tmp
|
||||||
|
/*.it1.result
|
||||||
|
/*.it1.stderr
|
||||||
|
/*.it1.stdout
|
||||||
|
/*.it2
|
||||||
|
/*.it2.c
|
||||||
|
/*.it2.c.tmp
|
||||||
|
/*.it2.o
|
||||||
|
/*.it2.result
|
||||||
|
/*.it2.stderr
|
||||||
|
/*.it2.stdout
|
||||||
23
tests/build/test_parsing/.gitignore
vendored
Normal file
23
tests/build/test_parsing/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*.it0
|
||||||
|
/*.it0.c
|
||||||
|
/*.it0.o
|
||||||
|
/*.it0.py
|
||||||
|
/*.it0.py.tmp
|
||||||
|
/*.it0.result
|
||||||
|
/*.it0.stderr
|
||||||
|
/*.it0.stdout
|
||||||
|
/*.it1
|
||||||
|
/*.it1.c
|
||||||
|
/*.it1.o
|
||||||
|
/*.it1.py
|
||||||
|
/*.it1.py.tmp
|
||||||
|
/*.it1.result
|
||||||
|
/*.it1.stderr
|
||||||
|
/*.it1.stdout
|
||||||
|
/*.it2
|
||||||
|
/*.it2.c
|
||||||
|
/*.it2.c.tmp
|
||||||
|
/*.it2.o
|
||||||
|
/*.it2.result
|
||||||
|
/*.it2.stderr
|
||||||
|
/*.it2.stdout
|
||||||
23
tests/build/test_stdlib_constants/.gitignore
vendored
Normal file
23
tests/build/test_stdlib_constants/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*.it0
|
||||||
|
/*.it0.c
|
||||||
|
/*.it0.o
|
||||||
|
/*.it0.py
|
||||||
|
/*.it0.py.tmp
|
||||||
|
/*.it0.result
|
||||||
|
/*.it0.stderr
|
||||||
|
/*.it0.stdout
|
||||||
|
/*.it1
|
||||||
|
/*.it1.c
|
||||||
|
/*.it1.o
|
||||||
|
/*.it1.py
|
||||||
|
/*.it1.py.tmp
|
||||||
|
/*.it1.result
|
||||||
|
/*.it1.stderr
|
||||||
|
/*.it1.stdout
|
||||||
|
/*.it2
|
||||||
|
/*.it2.c
|
||||||
|
/*.it2.c.tmp
|
||||||
|
/*.it2.o
|
||||||
|
/*.it2.result
|
||||||
|
/*.it2.stderr
|
||||||
|
/*.it2.stdout
|
||||||
23
tests/build/test_stdlib_functions/.gitignore
vendored
Normal file
23
tests/build/test_stdlib_functions/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*.it0
|
||||||
|
/*.it0.c
|
||||||
|
/*.it0.o
|
||||||
|
/*.it0.py
|
||||||
|
/*.it0.py.tmp
|
||||||
|
/*.it0.result
|
||||||
|
/*.it0.stderr
|
||||||
|
/*.it0.stdout
|
||||||
|
/*.it1
|
||||||
|
/*.it1.c
|
||||||
|
/*.it1.o
|
||||||
|
/*.it1.py
|
||||||
|
/*.it1.py.tmp
|
||||||
|
/*.it1.result
|
||||||
|
/*.it1.stderr
|
||||||
|
/*.it1.stdout
|
||||||
|
/*.it2
|
||||||
|
/*.it2.c
|
||||||
|
/*.it2.c.tmp
|
||||||
|
/*.it2.o
|
||||||
|
/*.it2.result
|
||||||
|
/*.it2.stderr
|
||||||
|
/*.it2.stdout
|
||||||
23
tests/build/test_variables/.gitignore
vendored
Normal file
23
tests/build/test_variables/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*.it0
|
||||||
|
/*.it0.c
|
||||||
|
/*.it0.o
|
||||||
|
/*.it0.py
|
||||||
|
/*.it0.py.tmp
|
||||||
|
/*.it0.result
|
||||||
|
/*.it0.stderr
|
||||||
|
/*.it0.stdout
|
||||||
|
/*.it1
|
||||||
|
/*.it1.c
|
||||||
|
/*.it1.o
|
||||||
|
/*.it1.py
|
||||||
|
/*.it1.py.tmp
|
||||||
|
/*.it1.result
|
||||||
|
/*.it1.stderr
|
||||||
|
/*.it1.stdout
|
||||||
|
/*.it2
|
||||||
|
/*.it2.c
|
||||||
|
/*.it2.c.tmp
|
||||||
|
/*.it2.o
|
||||||
|
/*.it2.result
|
||||||
|
/*.it2.stderr
|
||||||
|
/*.it2.stdout
|
||||||
@ -1,3 +0,0 @@
|
|||||||
main:
|
|
||||||
check not "1" : "Success"
|
|
||||||
/
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
main:
|
|
||||||
check not "" : "Failure"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
main:
|
|
||||||
declare bool
|
|
||||||
set bool ""
|
|
||||||
if bool
|
|
||||||
return
|
|
||||||
/
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
main:
|
|
||||||
declare bool
|
|
||||||
set bool "1"
|
|
||||||
if bool
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
/
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
func:
|
|
||||||
return
|
|
||||||
/
|
|
||||||
|
|
||||||
main:
|
|
||||||
func
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
func:
|
|
||||||
declare result
|
|
||||||
set result "Success"
|
|
||||||
return result
|
|
||||||
/
|
|
||||||
|
|
||||||
main:
|
|
||||||
declare result
|
|
||||||
calc result func
|
|
||||||
emit result
|
|
||||||
/
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
func:
|
|
||||||
return "Success"
|
|
||||||
/
|
|
||||||
|
|
||||||
main:
|
|
||||||
declare result
|
|
||||||
calc result func
|
|
||||||
emit result
|
|
||||||
/
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
main:
|
|
||||||
declare foo
|
|
||||||
calc foo forgottodeclare "1" "2"
|
|
||||||
/
|
|
||||||
106
tests/generate-recipes.py
Normal file
106
tests/generate-recipes.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
import glob
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class Rule:
|
||||||
|
def __init__(self, target: str, prerequisites: list[str], recipe: list[str]) -> None:
|
||||||
|
self.target = target
|
||||||
|
self.prerequisites = prerequisites
|
||||||
|
self.recipe = recipe
|
||||||
|
|
||||||
|
def make_lines(self):
|
||||||
|
return [
|
||||||
|
self.target + ': ' + ' '.join(self.prerequisites),
|
||||||
|
] + [
|
||||||
|
'\t' + line
|
||||||
|
for line in self.recipe
|
||||||
|
] + ['']
|
||||||
|
|
||||||
|
def get_file_list():
|
||||||
|
return sorted(glob.glob('test_*/*.lang0'))
|
||||||
|
|
||||||
|
def make_rules(file_path, lang0it):
|
||||||
|
result: list[Rule] = []
|
||||||
|
|
||||||
|
stdin = file_path.replace('.lang0', '.stdin')
|
||||||
|
exp_stdout = file_path.replace('.lang0', '.exp.stdout')
|
||||||
|
exp_stderr = file_path.replace('.lang0', '.exp.stderr')
|
||||||
|
|
||||||
|
act_result = 'build/' + file_path.replace('.lang0', f'.{lang0it}.result')
|
||||||
|
act_stderr = 'build/' + file_path.replace('.lang0', f'.{lang0it}.stderr')
|
||||||
|
act_stdout = 'build/' + file_path.replace('.lang0', f'.{lang0it}.stdout')
|
||||||
|
program = 'build/' + file_path.replace('.lang0', f'.{lang0it}')
|
||||||
|
|
||||||
|
if os.path.isfile(exp_stdout) or os.path.isfile(exp_stderr):
|
||||||
|
result.append(Rule(
|
||||||
|
act_stdout,
|
||||||
|
[program] + ([stdin] if os.path.isfile(stdin) else []),
|
||||||
|
[
|
||||||
|
'-' + (f'cat {stdin} | ' if os.path.isfile(stdin) else 'echo x | ')
|
||||||
|
+ f'{program} 1> {act_stdout} 2> {act_stderr}',
|
||||||
|
]
|
||||||
|
))
|
||||||
|
|
||||||
|
exp_list = [exp_stdout, exp_stderr]
|
||||||
|
act_list = [act_stdout, act_stderr]
|
||||||
|
|
||||||
|
result.append(Rule(
|
||||||
|
act_result,
|
||||||
|
[act_stdout] + [
|
||||||
|
x
|
||||||
|
for x in exp_list
|
||||||
|
if os.path.isfile(x)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rm -f $@',
|
||||||
|
] + [
|
||||||
|
f'-diff {exp_file} {act_file} >> $@'
|
||||||
|
for exp_file, act_file in zip(exp_list, act_list, strict=True)
|
||||||
|
if os.path.isfile(exp_file)
|
||||||
|
] + [
|
||||||
|
f'-diff /dev/null {act_file} >> $@'
|
||||||
|
for exp_file, act_file in zip(exp_list, act_list, strict=True)
|
||||||
|
if not os.path.isfile(exp_file)
|
||||||
|
]
|
||||||
|
))
|
||||||
|
|
||||||
|
assert result[-1].prerequisites, f'Missing expectations for {file_path}'
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def main(program, write_to, *lang0it):
|
||||||
|
rule_list_list = [
|
||||||
|
make_rules(file_path, it)
|
||||||
|
for file_path in get_file_list()
|
||||||
|
for it in lang0it
|
||||||
|
]
|
||||||
|
|
||||||
|
result_targets = [
|
||||||
|
rule.target
|
||||||
|
for rule_list in rule_list_list
|
||||||
|
for rule in rule_list
|
||||||
|
if rule.target.endswith('.result')
|
||||||
|
]
|
||||||
|
|
||||||
|
rule_list_list.append([Rule(
|
||||||
|
'verify-results',
|
||||||
|
result_targets,
|
||||||
|
[
|
||||||
|
'@echo Finding failed test results...',
|
||||||
|
'@find $^ -not -empty -print -exec false {} +',
|
||||||
|
'@echo All tests passed.'
|
||||||
|
]
|
||||||
|
)])
|
||||||
|
|
||||||
|
data = '\n'.join(
|
||||||
|
line
|
||||||
|
for rule_list in rule_list_list
|
||||||
|
for rule in rule_list
|
||||||
|
for line in rule.make_lines()
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(write_to, 'wt', encoding='ASCII') as fil:
|
||||||
|
fil.write(data)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(*sys.argv)
|
||||||
@ -1,10 +0,0 @@
|
|||||||
func/
|
|
||||||
|
|
||||||
main:
|
|
||||||
check func : "The function should return 1, even though it is not defined yet"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
|
|
||||||
func:
|
|
||||||
return "1"
|
|
||||||
/
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
func arg/
|
|
||||||
|
|
||||||
main:
|
|
||||||
check func "1" : "The function should return 1, even though it is not defined yet"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
|
|
||||||
func arg:
|
|
||||||
return arg
|
|
||||||
/
|
|
||||||
@ -1,86 +0,0 @@
|
|||||||
main:
|
|
||||||
declare char
|
|
||||||
declare colno
|
|
||||||
declare lineno
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "H" : "Read: H" char
|
|
||||||
check eq colno "1" : "The column number should not have advanced yet" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "e" : "Read: e" char
|
|
||||||
check eq colno "2" : "The column number should have been advanced by 1" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "l" : "Read: l" char
|
|
||||||
check eq colno "3" : "The column number should have been advanced by 2" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "l" : "Read: l" char
|
|
||||||
check eq colno "4" : "The column number should have been advanced by 3" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "o" : "Read: o" char
|
|
||||||
check eq colno "5" : "The column number should have been advanced by 4" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "!" : "Read: !" char
|
|
||||||
check eq colno "6" : "The column number should have been advanced by 5" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char eol : "Read: eol" char
|
|
||||||
check eq colno "7" : "The column number should have been advanced by 6" colno
|
|
||||||
check eq lineno "1" : "The line number should not have advanced yet" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char eol : "Read: eol" char
|
|
||||||
check eq colno "1" : "The column number should have been reset" colno
|
|
||||||
check eq lineno "2" : "The line number should have advanced by 1" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "T" : "Read: T" char
|
|
||||||
check eq colno "1" : "The column number should have been reset again" colno
|
|
||||||
check eq lineno "3" : "The line number should have advanced by 2" lineno
|
|
||||||
skip
|
|
||||||
|
|
||||||
calc char peek
|
|
||||||
calc colno stdincolno
|
|
||||||
calc lineno stdinlineno
|
|
||||||
check eq char "h" : "Read: h" char
|
|
||||||
check eq colno "2" : "The line number should not have been advanced by 1" colno
|
|
||||||
check eq lineno "3" : "The line number should not have advanced further" lineno
|
|
||||||
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
main:
|
|
||||||
declare result
|
|
||||||
calc result addstringchar "abc" "d"
|
|
||||||
check eq result "abcd" : "Adding abc and d should be abcd"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
main:
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
main:
|
|
||||||
declare bool
|
|
||||||
calc bool eq "1" "2"
|
|
||||||
check not bool : "1 should not equal 2"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
main:
|
|
||||||
declare bool
|
|
||||||
check eq "1" "1" : "1 should equal 1"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
main:
|
|
||||||
declare bool
|
|
||||||
calc bool lt "b" "a"
|
|
||||||
check not bool : "a should should sort before b"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
main:
|
|
||||||
declare bool
|
|
||||||
check lt "a" "b" : "a should should sort before b"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
main:
|
|
||||||
declare char
|
|
||||||
calc char peek
|
|
||||||
check eq char "H" : "The first byte we're passed is expected to be an 'H'"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
main:
|
|
||||||
declare char
|
|
||||||
skip
|
|
||||||
calc char peek
|
|
||||||
check eq char "e" : "The second byte we're passed is expected to be an 'e'"
|
|
||||||
skip
|
|
||||||
skip
|
|
||||||
skip
|
|
||||||
calc char peek
|
|
||||||
check eq char "o" : "The fifth byte we're passed is expected to be an 'o'"
|
|
||||||
emit "Success"
|
|
||||||
/
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
Hello!
|
|
||||||
|
|
||||||
This is an example of standard input.
|
|
||||||
1
tests/test_builtins/test_check.exp.stderr
Normal file
1
tests/test_builtins/test_check.exp.stderr
Normal file
@ -0,0 +1 @@
|
|||||||
|
ERROR: Check failed successfully
|
||||||
1
tests/test_builtins/test_check.exp.stdout
Normal file
1
tests/test_builtins/test_check.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
Still alive
|
||||||
8
tests/test_builtins/test_check.lang0
Normal file
8
tests/test_builtins/test_check.lang0
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
main:
|
||||||
|
check not "" : "This should not trigger"
|
||||||
|
emit "Still alive"
|
||||||
|
emit eol
|
||||||
|
check not "1" : "Check failed successfully"
|
||||||
|
emit "This should not be output"
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
1
tests/test_flow_control/test_break.exp.stdout
Normal file
1
tests/test_flow_control/test_break.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
Success
|
||||||
@ -1,6 +1,7 @@
|
|||||||
main:
|
main:
|
||||||
forever
|
forever
|
||||||
|
emit "Suc"
|
||||||
break
|
break
|
||||||
/
|
/
|
||||||
emit "Success"
|
emit "cess"
|
||||||
/
|
/
|
||||||
1
tests/test_flow_control/test_call.exp.stdout
Normal file
1
tests/test_flow_control/test_call.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
Success
|
||||||
2
tests/test_flow_control/test_if.exp.stdout
Normal file
2
tests/test_flow_control/test_if.exp.stdout
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1 is true
|
||||||
|
A is true
|
||||||
18
tests/test_flow_control/test_if.lang0
Normal file
18
tests/test_flow_control/test_if.lang0
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
main:
|
||||||
|
declare bool
|
||||||
|
set bool ""
|
||||||
|
if bool
|
||||||
|
emit "empty string is true"
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
|
set bool "1"
|
||||||
|
if bool
|
||||||
|
emit "1 is true"
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
|
set bool "A"
|
||||||
|
if bool
|
||||||
|
emit "A is true"
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
|
/
|
||||||
3
tests/test_flow_control/test_return.exp.stdout
Normal file
3
tests/test_flow_control/test_return.exp.stdout
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
funca Constant
|
||||||
|
funcb Variable
|
||||||
|
funcc
|
||||||
32
tests/test_flow_control/test_return.lang0
Normal file
32
tests/test_flow_control/test_return.lang0
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
funca:
|
||||||
|
return "Constant"
|
||||||
|
/
|
||||||
|
|
||||||
|
funcb:
|
||||||
|
declare var
|
||||||
|
set var "Variable"
|
||||||
|
return var
|
||||||
|
/
|
||||||
|
|
||||||
|
funcc:
|
||||||
|
return
|
||||||
|
/
|
||||||
|
|
||||||
|
main:
|
||||||
|
declare var
|
||||||
|
|
||||||
|
calc var funca
|
||||||
|
emit "funca "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
calc var funcb
|
||||||
|
emit "funcb "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
calc var funcc
|
||||||
|
emit "funcc "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
2
tests/test_parsing/test_predeclare_functions.exp.stdout
Normal file
2
tests/test_parsing/test_predeclare_functions.exp.stdout
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Predeclared without argument: 1
|
||||||
|
Predeclared with argument: 2
|
||||||
24
tests/test_parsing/test_predeclare_functions.lang0
Normal file
24
tests/test_parsing/test_predeclare_functions.lang0
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
funca/
|
||||||
|
funcb arg/
|
||||||
|
|
||||||
|
main:
|
||||||
|
declare var
|
||||||
|
|
||||||
|
calc var funca
|
||||||
|
emit "Predeclared without argument: "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
calc var funcb "2"
|
||||||
|
emit "Predeclared with argument: "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
|
|
||||||
|
funca:
|
||||||
|
return "1"
|
||||||
|
/
|
||||||
|
|
||||||
|
funcb arg:
|
||||||
|
return arg
|
||||||
|
/
|
||||||
1
tests/test_stdlib_constants/test_eof.exp.stdout
Normal file
1
tests/test_stdlib_constants/test_eof.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>
|
||||||
3
tests/test_stdlib_constants/test_eof.lang0
Normal file
3
tests/test_stdlib_constants/test_eof.lang0
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
main:
|
||||||
|
emit eof
|
||||||
|
/
|
||||||
1
tests/test_stdlib_constants/test_eol.exp.stdout
Normal file
1
tests/test_stdlib_constants/test_eol.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
||||||
3
tests/test_stdlib_constants/test_eol.lang0
Normal file
3
tests/test_stdlib_constants/test_eol.lang0
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
main:
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
1
tests/test_stdlib_constants/test_quote.exp.stdout
Normal file
1
tests/test_stdlib_constants/test_quote.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
"
|
||||||
3
tests/test_stdlib_constants/test_quote.lang0
Normal file
3
tests/test_stdlib_constants/test_quote.lang0
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
main:
|
||||||
|
emit quote
|
||||||
|
/
|
||||||
3
tests/test_stdlib_functions/test_add.exp.stdout
Normal file
3
tests/test_stdlib_functions/test_add.exp.stdout
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
1 + 2 = 12
|
||||||
|
10 + 20 = 1020
|
||||||
|
101 + 202 = 101202
|
||||||
29
tests/test_stdlib_functions/test_add.lang0
Normal file
29
tests/test_stdlib_functions/test_add.lang0
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
func tst a b:
|
||||||
|
declare var
|
||||||
|
calc var add a b
|
||||||
|
emit a
|
||||||
|
emit " + "
|
||||||
|
emit b
|
||||||
|
emit " = "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
|
|
||||||
|
main:
|
||||||
|
declare var
|
||||||
|
|
||||||
|
calc var add "1" "2"
|
||||||
|
emit "1 + 2 = "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
calc var add "10" "20"
|
||||||
|
emit "10 + 20 = "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
calc var add "101" "202"
|
||||||
|
emit "101 + 202 = "
|
||||||
|
emit var
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
1
tests/test_stdlib_functions/test_emit.exp.stdout
Normal file
1
tests/test_stdlib_functions/test_emit.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello, world!
|
||||||
4
tests/test_stdlib_functions/test_emit.lang0
Normal file
4
tests/test_stdlib_functions/test_emit.lang0
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
main:
|
||||||
|
emit "Hello"
|
||||||
|
emit ", world!"
|
||||||
|
/
|
||||||
4
tests/test_stdlib_functions/test_eq.exp.stdout
Normal file
4
tests/test_stdlib_functions/test_eq.exp.stdout
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
eq A A: 1
|
||||||
|
eq A B:
|
||||||
|
eq AA AA: 1
|
||||||
|
eq AA AB:
|
||||||
19
tests/test_stdlib_functions/test_eq.lang0
Normal file
19
tests/test_stdlib_functions/test_eq.lang0
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
main:
|
||||||
|
declare result
|
||||||
|
emit "eq A A: "
|
||||||
|
calc result eq "A" "A"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "eq A B: "
|
||||||
|
calc result eq "A" "B"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "eq AA AA: "
|
||||||
|
calc result eq "AA" "AA"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "eq AA AB: "
|
||||||
|
calc result eq "AA" "AB"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
6
tests/test_stdlib_functions/test_lt.exp.stdout
Normal file
6
tests/test_stdlib_functions/test_lt.exp.stdout
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
lt A A:
|
||||||
|
lt A B: 1
|
||||||
|
lt B A:
|
||||||
|
lt AA AA:
|
||||||
|
lt AA AB: 1
|
||||||
|
lt AB AA:
|
||||||
27
tests/test_stdlib_functions/test_lt.lang0
Normal file
27
tests/test_stdlib_functions/test_lt.lang0
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
main:
|
||||||
|
declare result
|
||||||
|
emit "lt A A: "
|
||||||
|
calc result lt "A" "A"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "lt A B: "
|
||||||
|
calc result lt "A" "B"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "lt B A: "
|
||||||
|
calc result lt "B" "A"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "lt AA AA: "
|
||||||
|
calc result lt "AA" "AA"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "lt AA AB: "
|
||||||
|
calc result lt "AA" "AB"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
emit "lt AB AA: "
|
||||||
|
calc result lt "AB" "AA"
|
||||||
|
emit result
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
1
tests/test_stdlib_functions/test_peek.exp.stdout
Normal file
1
tests/test_stdlib_functions/test_peek.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
AAA
|
||||||
9
tests/test_stdlib_functions/test_peek.lang0
Normal file
9
tests/test_stdlib_functions/test_peek.lang0
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
main:
|
||||||
|
declare char
|
||||||
|
calc char peek
|
||||||
|
emit char
|
||||||
|
calc char peek
|
||||||
|
emit char
|
||||||
|
calc char peek
|
||||||
|
emit char
|
||||||
|
/
|
||||||
1
tests/test_stdlib_functions/test_peek.stdin
Normal file
1
tests/test_stdlib_functions/test_peek.stdin
Normal file
@ -0,0 +1 @@
|
|||||||
|
ABC
|
||||||
1
tests/test_stdlib_functions/test_skip.exp.stdout
Normal file
1
tests/test_stdlib_functions/test_skip.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
ABD
|
||||||
12
tests/test_stdlib_functions/test_skip.lang0
Normal file
12
tests/test_stdlib_functions/test_skip.lang0
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
main:
|
||||||
|
declare char
|
||||||
|
calc char peek
|
||||||
|
emit char
|
||||||
|
skip
|
||||||
|
calc char peek
|
||||||
|
emit char
|
||||||
|
skip
|
||||||
|
skip
|
||||||
|
calc char peek
|
||||||
|
emit char
|
||||||
|
/
|
||||||
1
tests/test_stdlib_functions/test_skip.stdin
Normal file
1
tests/test_stdlib_functions/test_skip.stdin
Normal file
@ -0,0 +1 @@
|
|||||||
|
ABCD
|
||||||
4
tests/test_stdlib_functions/test_stdincolno.exp.stdout
Normal file
4
tests/test_stdlib_functions/test_stdincolno.exp.stdout
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
"A" 1
|
||||||
|
"
|
||||||
|
" 2
|
||||||
|
"B" 1
|
||||||
35
tests/test_stdlib_functions/test_stdincolno.lang0
Normal file
35
tests/test_stdlib_functions/test_stdincolno.lang0
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
main:
|
||||||
|
declare char
|
||||||
|
declare colno
|
||||||
|
|
||||||
|
calc char peek
|
||||||
|
calc colno stdincolno
|
||||||
|
emit quote
|
||||||
|
emit char
|
||||||
|
emit quote
|
||||||
|
emit " "
|
||||||
|
emit colno
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
skip
|
||||||
|
|
||||||
|
calc char peek
|
||||||
|
calc colno stdincolno
|
||||||
|
emit quote
|
||||||
|
emit char
|
||||||
|
emit quote
|
||||||
|
emit " "
|
||||||
|
emit colno
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
skip
|
||||||
|
|
||||||
|
calc char peek
|
||||||
|
calc colno stdincolno
|
||||||
|
emit quote
|
||||||
|
emit char
|
||||||
|
emit quote
|
||||||
|
emit " "
|
||||||
|
emit colno
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
3
tests/test_stdlib_functions/test_stdincolno.stdin
Normal file
3
tests/test_stdlib_functions/test_stdincolno.stdin
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
4
tests/test_stdlib_functions/test_stdinlineno.exp.stdout
Normal file
4
tests/test_stdlib_functions/test_stdinlineno.exp.stdout
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
"A" 1
|
||||||
|
"
|
||||||
|
" 1
|
||||||
|
"B" 2
|
||||||
35
tests/test_stdlib_functions/test_stdinlineno.lang0
Normal file
35
tests/test_stdlib_functions/test_stdinlineno.lang0
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
main:
|
||||||
|
declare char
|
||||||
|
declare lineno
|
||||||
|
|
||||||
|
calc char peek
|
||||||
|
calc lineno stdinlineno
|
||||||
|
emit quote
|
||||||
|
emit char
|
||||||
|
emit quote
|
||||||
|
emit " "
|
||||||
|
emit lineno
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
skip
|
||||||
|
|
||||||
|
calc char peek
|
||||||
|
calc lineno stdinlineno
|
||||||
|
emit quote
|
||||||
|
emit char
|
||||||
|
emit quote
|
||||||
|
emit " "
|
||||||
|
emit lineno
|
||||||
|
emit eol
|
||||||
|
|
||||||
|
skip
|
||||||
|
|
||||||
|
calc char peek
|
||||||
|
calc lineno stdinlineno
|
||||||
|
emit quote
|
||||||
|
emit char
|
||||||
|
emit quote
|
||||||
|
emit " "
|
||||||
|
emit lineno
|
||||||
|
emit eol
|
||||||
|
/
|
||||||
3
tests/test_stdlib_functions/test_stdinlineno.stdin
Normal file
3
tests/test_stdlib_functions/test_stdinlineno.stdin
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
1
tests/test_variables/test_calc.exp.stdout
Normal file
1
tests/test_variables/test_calc.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
Success
|
||||||
1
tests/test_variables/test_set.exp.stdout
Normal file
1
tests/test_variables/test_set.exp.stdout
Normal file
@ -0,0 +1 @@
|
|||||||
|
Success
|
||||||
Loading…
x
Reference in New Issue
Block a user