Adds intinc as a buildint function

This commit is contained in:
Johan B.W. de Vries 2026-01-25 13:02:08 +01:00
parent a282292604
commit 5369c15e05
6 changed files with 64 additions and 0 deletions

View File

@ -478,6 +478,9 @@ def emitheader():
emitln("def __strlen(a: str) -> str:")
emitln(" return str(len(a))")
emitln("")
emitln("def __intinc(a: str) -> str:")
emitln(" return str(int(a) + 1)")
emitln("")
emitln("# ### END OF RUNTIME ### #")
emitln("")
@ -503,6 +506,8 @@ def main():
mapsetkey("REGISTERID", "emit", "__emit")
mapsetkey("FUNCREG", "eq", "1")
mapsetkey("REGISTERID", "eq", "__eq")
mapsetkey("FUNCREG", "intinc", "1")
mapsetkey("REGISTERID", "intinc", "__intinc")
mapsetkey("FUNCREG", "lt", "1")
mapsetkey("REGISTERID", "lt", "__lt")
mapsetkey("FUNCREG", "not", "1")

View File

@ -537,6 +537,9 @@ emitheader:
emitln "def __strlen(a: str) -> str:"
emitln " return str(len(a))"
emitln ""
emitln "def __intinc(a: str) -> str:"
emitln " return str(int(a) + 1)"
emitln ""
emitln "# ### END OF RUNTIME ### #"
emitln ""
/
@ -564,6 +567,8 @@ main:
mapsetkey "REGISTERID" "emit" "__emit"
mapsetkey "FUNCREG" "eq" "1"
mapsetkey "REGISTERID" "eq" "__eq"
mapsetkey "FUNCREG" "intinc" "1"
mapsetkey "REGISTERID" "intinc" "__intinc"
mapsetkey "FUNCREG" "lt" "1"
mapsetkey "REGISTERID" "lt" "__lt"
mapsetkey "FUNCREG" "not" "1"

View File

@ -810,6 +810,19 @@ emitheader:
emitln " return buffer;"
emitln "}"
emitln ""
emitln "char * __intinc(char * inp)"
emitln "{"
emitln " char * buffer = malloc(20);"
emitln " char * endptr;"
emitln " unsigned long long number = strtoull(inp, &endptr, 10);"
emit " snprintf(buffer, 20, "
emit quote
emit "%llu"
emit quote
emitln ", number + 1);"
emitln " return buffer;"
emitln "}"
emitln ""
emitln "// ### END OF RUNTIME ### //"
emitln ""
return
@ -846,6 +859,8 @@ main:
mapsetkey "REGISTERID" "emit" "__emit"
mapsetkey "FUNCREG" "eq" "1"
mapsetkey "REGISTERID" "eq" "__eq"
mapsetkey "FUNCREG" "intinc" "1"
mapsetkey "REGISTERID" "intinc" "__intinc"
mapsetkey "FUNCREG" "lt" "1"
mapsetkey "REGISTERID" "lt" "__lt"
mapsetkey "FUNCREG" "not" "1"

View File

@ -155,6 +155,12 @@ Return true if the given strings are the same.
Return true if a would sort before b.
#### intinc
Assumes `a` is a string containing solely a decimal integer.
Returns a increased by one.
#### mapclear mapname
Maps are global and can be used from any function.

View File

@ -0,0 +1,5 @@
0 + 1: 1
5 + 1: 6
9 + 1: 10
15 + 1: 16
99 + 1: 100

View File

@ -0,0 +1,28 @@
main:
declare result
emit "0 + 1: "
calc result intinc "0"
emit result
emit eol
emit "5 + 1: "
calc result intinc "5"
emit result
emit eol
emit "9 + 1: "
calc result intinc "9"
emit result
emit eol
emit "15 + 1: "
calc result intinc "15"
emit result
emit eol
emit "99 + 1: "
calc result intinc "99"
emit result
emit eol
/