Skip to content

Commit

Permalink
Made compact formatting the default for everything
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaumgarten committed Jan 10, 2021
1 parent 8b1efa8 commit 5a7e9ee
Show file tree
Hide file tree
Showing 31 changed files with 220 additions and 217 deletions.
11 changes: 5 additions & 6 deletions cmd/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra"
)

var spaces bool
var spaceless bool

// compileCmd represents the compile command
var compileCmd = &cobra.Command{
Expand All @@ -31,7 +31,7 @@ var compileCmd = &cobra.Command{
func compileFile(fpath string) {
outfile := strings.Replace(fpath, path.Ext(fpath), ".yolol", -1)
converter := nolol.NewConverter()
converter.UseSpaces = spaces
converter.Spaceless = spaceless
converter.Debug(debugLog)
converted, compileerr := converter.ConvertFile(fpath)

Expand All @@ -41,9 +41,8 @@ func compileFile(fpath string) {
}

gen := parser.Printer{}
gen.Mode = parser.PrintermodeSpaceless
if spaces {
gen.Mode = parser.PrintermodeCompact
if spaceless {
gen.Mode = parser.PrintermodeSpaceless
}
generated, err := gen.Print(converted)
exitOnError(err, "generating code")
Expand All @@ -61,5 +60,5 @@ func init() {
rootCmd.AddCommand(compileCmd)
compileCmd.Flags().StringVarP(&outputFile, "out", "o", "<inputfile>.out", "The output file")
compileCmd.Flags().BoolVarP(&debugLog, "debug", "d", false, "Print debug logs while parsing")
compileCmd.Flags().BoolVar(&spaces, "spaces", false, "If true, output code with spaces where normal languages would expect them")
compileCmd.Flags().BoolVar(&spaceless, "spaceless", false, "If true, output code with minimal spaces (might break script)")
}
5 changes: 4 additions & 1 deletion cmd/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func optimize(filepath string) {
err := opt.Optimize(parsed)
exitOnError(err, "performing optimisation")
gen := parser.Printer{}
gen.Mode = parser.PrintermodeSpaceless
if spaceless {
gen.Mode = parser.PrintermodeSpaceless
}
generated, err := gen.Print(parsed)
exitOnError(err, "generating code")
ioutil.WriteFile(outfile, []byte(generated), 0700)
Expand All @@ -49,4 +51,5 @@ func optimize(filepath string) {
func init() {
rootCmd.AddCommand(optimizeCmd)
optimizeCmd.Flags().StringVarP(&outputFile, "out", "o", "<inputfile>.out", "The output file")
optimizeCmd.Flags().BoolVar(&spaceless, "spaceless", false, "If true, output code with minimal spaces (might break script)")
}
22 changes: 11 additions & 11 deletions examples/nolol/array.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

// is good
// is best
define data = :d
define addr = :a
define write = :m
define data=:d
define addr=:a
define write=:m

// line() can take the name of a jump-label as an argument and returns the yolol-line to which the label points
:o = "start> is at line: " + line(start)
:o="start> is at line: "+line(start)

start>
// goto current line plus the value of offset. line() without arguments returns the current line number
$ _goto line() + addr $
$ _goto line()+addr $
// By using "$ stmt1; stmt2 $" we make sure, that the resulting yolol-code will have the EXACT same line-layout
// "_if" is the inline-variant of "if"
$ _if write then mem1 = data else data = mem1 end; addr = 0; goto start $
$ _if write then mem2 = data else data = mem2 end; addr = 0; goto start $
$ _if write then mem3 = data else data = mem3 end; addr = 0; goto start $
$ _if write then mem4 = data else data = mem4 end; addr = 0; goto start $
$ _if write then mem5 = data else data = mem5 end; addr = 0; goto start $
$ _if write then mem6 = data else data = mem6 end; addr = 0; goto start $
$ _if write then mem1=data else data=mem1 end;addr=0;goto start $
$ _if write then mem2=data else data=mem2 end;addr=0;goto start $
$ _if write then mem3=data else data=mem3 end;addr=0;goto start $
$ _if write then mem4=data else data=mem4 end;addr=0;goto start $
$ _if write then mem5=data else data=mem5 end;addr=0;goto start $
$ _if write then mem6=data else data=mem6 end;addr=0;goto start $
32 changes: 16 additions & 16 deletions examples/nolol/array_user.nolol
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
// This script uses array.nolol to store some values and retrieve themm again

define data = :d
define addr = :a
define write = :m
define data=:d
define addr=:a
define write=:m

// store value at idx in array
macro set(idx, value)
write = 1
data = value
addr = idx
write=1
data=value
addr=idx
// this will block until addr is 0.
// the array will set addr to 0 once it stored the value
wait addr
end

// retrieve value from idx
macro get(idx, value)
write = 0
addr = idx
write=0
addr=idx
// this will block until addr is 0.
// the array will set addr to 0 once it retrieved the value
wait addr
value = data
value=data
end

while ++i < 5 do
insert set(i, i * 2)
while ++i<5 do
insert set(i,i*2)
end

:sum = ""
while ++j < 5 do
insert get(j, retrieved)
:sum += retrieved + ","
:sum=""
while ++j<5 do
insert get(j,retrieved)
:sum+=retrieved+","
end

:done = 1
:done=1
28 changes: 14 additions & 14 deletions examples/nolol/case_insensitive.nolol
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// this program checks if the language is really case-insensitive
// despit the really excentric naming (of even the keywords) all global variables should have the value 1 at the end
Var = 123; var = 456
:assignok = Var == 456
Var=123;var=456
:assignok=Var==456

FoO = "test"
:derefok = Foo == FoO
FoO="test"
:derefok=Foo==FoO

:funcOK = sin(3) == SIN(3)
:funcOK=sin(3)==SIN(3)

if foo == FOO then
:ifok = 1
if foo==FOO then
:ifok=1
end

define TEST = "FOO"
:defineOK = test == "FOO"
define TEST="FOO"
:defineOK=test=="FOO"

NUM = 1
while num++ < 4 do
:loopok = num == NUM
NUM=1
while num++ <4 do
:loopok=num==NUM
end

macro fooBar(bar)
:macroOK = bar == BAR and bar == "FOO"
:macroOK=bar==BAR and bar=="FOO"
end

insert FOOBAR(TEST)

:done = 1
:done=1
24 changes: 12 additions & 12 deletions examples/nolol/definitions.nolol
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// define greeting to be hello
define greeting = "Hello"
define greeting="Hello"

:name = "Peter"
:name="Peter"

// definitions can be any expression you like and even contain other definitions, variables or functions
define message = greeting + " " + "world and " + :name
define message=greeting+" "+"world and "+:name

// you can define a new name for a variable
// if the defined value is a variable name (and nothing else), you can assign to it
// this is practically aliasing :out to :output
define :output = :out
define :output=:out

// :output is replaced by ":out" and message is replaced by the expression declared in it's definition
:output = message
:output=message


// your definitions can contain polaceholders (here a and b)
define addByte(a, b) = (a + b) % 2 ^ 8
define addByte(a, b)=(a+b)%2^8

a = 123
a=123
// definitions with placeholders can be used like functions. The aruments will replace the placeholders of the definition
:sum = addByte(a, 100)
:sum=addByte(a,100)

define foo(a, b, c, d) = a + b + c + d
define foo(a, b, c, d)=a+b+c+d

// Any valid expression can be used as value for a placeholder
:bar = foo(greeting, ",", " " + :name, addByte(a, 60))
:bar=foo(greeting,","," "+:name,addByte(a,60))

define pop(string) = string - --string
define pop(string)=string- --string

:done = 1
:done=1
26 changes: 13 additions & 13 deletions examples/nolol/fizzbuzz.nolol
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
define fizz = "fizz"
define buzz = "buzz"
define sep = " "
define upto = 100
define fizz="fizz"
define buzz="buzz"
define sep=" "
define upto=100

if :out == 0 then
:out = ""
if :out==0 then
:out=""
end
// main loop
while :number <= upto do
if :number % 3 == 0 and :number % 5 == 0 then
:out += fizz + buzz + sep
while :number<=upto do
if :number%3==0 and :number%5==0 then
:out+=fizz+buzz+sep
else
if :number % 3 == 0 then
:out += fizz + sep
else if :number % 5 == 0 then
:out += buzz + sep
if :number%3==0 then
:out+=fizz+sep
else if :number%5==0 then
:out+=buzz+sep
end
end
:number++
Expand Down
12 changes: 6 additions & 6 deletions examples/nolol/functions.nolol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
:timeok = time()
:absok = abs( -5) == ABS(5)
if abs( -2) == abs(2) then
:absinifok = 1
:timeok=time()
:absok=abs(-5)==ABS(5)
if abs(-2)==abs(2) then
:absinifok=1
end
:sqrtok = SQRT(16) == 4
:sqrtok=SQRT(16)==4

:done = 1
:done=1
18 changes: 9 additions & 9 deletions examples/nolol/goto.nolol
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// this example shows the use of labeled gotos
// but be cautious when using goto. It is bad style, error prone and hinders optimization
:out = "a"
:out="a"
goto b
// labels can be on the same line as a statement
c> :out += "c"
c> :out+="c"
goto d
b> :out += "b"
b> :out+="b"
goto c
d> // or on an own line. code automatically falls through empty lines


:out += "d"; goto e
:out+="d";goto e

if 1 == 0 then
if 1==0 then
// you can even jump into ifs
e> :out += "e"
e> :out+="e"
// and out again
goto f
end

f> :out += "f"; goto eof
f> :out+="f";goto eof

:out = "skip this"
:out="skip this"
eof>

:done = 1
:done=1
34 changes: 17 additions & 17 deletions examples/nolol/ifelse.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
// nolol ifs are multi-line
// when compiling thei are converted to yolol inline ifs if possible
// if the body of the if is too large for an inline if, the if will be implemented using a goto
if :day == "monday" then
:msg = "fuck"
else if :day == "tuesday" then
:msg = "still stupid"
else if :day == "wednesday" then
if :day=="monday" then
:msg="fuck"
else if :day=="tuesday" then
:msg="still stupid"
else if :day=="wednesday" then
// especially long string to force a multiline if
:msg = "half time!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
else if :day == "thursday" then
:msg = "almost..."
else if :day == "friday" then
:msg = "yay"
:msg="half time!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
else if :day=="thursday" then
:msg="almost..."
else if :day=="friday" then
:msg="yay"
else
:msg = "Weekend!!!"
:msg="Weekend!!!"
// ifs can be nested
if :day == "saturday" then
:msg += " PARTY!"
if :day=="saturday" then
:msg+=" PARTY!"
else
:msg += " is over :("
:msg+=" is over :("
end
end

// The old yolol-inline ifs can still be useful. For example if you absolutely need to make sure everything happens in one line.
// In this example, the two assignments and the if are guaranteed to happen on the same tick.
// To avoid confusion, when you need an inline-if, you need to use the "_if" keyword
a = 1; _if 1 == 1 then :foo = 1 else :foo = 2 end; b = 2
a=1;_if 1==1 then :foo=1 else :foo=2 end;b=2

:other = "done"
:done = 1
:other="done"
:done=1
6 changes: 3 additions & 3 deletions examples/nolol/included.nolol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define stop = 10
define stop=10

while i++ < stop do
:hello += "."
while i++ <stop do
:hello+="."
end
8 changes: 4 additions & 4 deletions examples/nolol/including.nolol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
define name = "daniel"
:hello = "hello "
define name="daniel"
:hello="hello "
// other nolol files can be included into nolol files
// the content of the included file will be pasted right where the include instruction was placed in the code
// this happens during compilation. Therefore the included path can not be dynamically created
include "included.nolol"
:hello += " " + name
:hello+=" "+name

:done = 1
:done=1
Loading

0 comments on commit 5a7e9ee

Please sign in to comment.